Skip to content

Commit

Permalink
1.2 support (rpc should now work again)
Browse files Browse the repository at this point in the history
  • Loading branch information
makc committed Oct 22, 2013
1 parent 531bfcb commit 48f27bf
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 198 deletions.
Binary file modified ColtPlugin.fdz
Binary file not shown.
1 change: 0 additions & 1 deletion ColtPlugin/ColtPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Rpc\AppStarter.cs" />
<Compile Include="COLTRemoteProject.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PluginMain.cs" />
Expand Down
198 changes: 105 additions & 93 deletions ColtPlugin/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Text.RegularExpressions;
using ASCompletion.Model;
using System.Xml;
using System.Runtime.InteropServices;

namespace ColtPlugin
{
Expand Down Expand Up @@ -105,12 +106,21 @@ public Object Settings
#endregion

#region Required Methods

// [DllImport("kernel32.dll", SetLastError = true)]
// [return: MarshalAs(UnmanagedType.Bool)]
// static extern bool AllocConsole();

// [DllImport("kernel32.dll", SetLastError = true)]
// [return: MarshalAs(UnmanagedType.Bool)]
// static extern bool FreeConsole();

/// <summary>
/// Initializes the plugin
/// </summary>
public void Initialize()
{
// AllocConsole();
InitBasics();
LoadSettings();
InitLocalization();
Expand Down Expand Up @@ -164,7 +174,7 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
// todo: FD might send this for projects other than PluginBase.CurrentProject - figure out how to catch that
if (settingObject.InterceptBuilds && allowBuildInterception && toolbarButton2.Enabled)
{
new AppStarter(ProductionBuild, cmd == "ProjectManager.TestingProject");
ProductionBuild(cmd == "ProjectManager.TestingProject");

e.Handled = true;
}
Expand Down Expand Up @@ -359,30 +369,12 @@ private ToolStripButton CreateToolbarButton(ToolStrip toolStrip, String image, S

private void OnClick(Object sender, EventArgs e)
{
ExportAndOpen(settingObject.AutoRun);//FIXME
/* if (settingObject.SecurityToken != null)
{
new AppStarter(ExportAndOpen, settingObject.AutoRun);
}
else
{
new AppStarter(GetSecurityToken, true);
}*/
ExportAndOpen(settingObject.AutoRun);
}

private void OnClick2(Object sender, EventArgs e)
{
FindAndOpen(settingObject.AutoRun);//FIXME
/* if (settingObject.SecurityToken != null)
{
new AppStarter(FindAndOpen, settingObject.AutoRun);
}
else
{
new AppStarter(GetSecurityToken, true);
}*/
FindAndOpen(settingObject.AutoRun);
}

#endregion
Expand Down Expand Up @@ -632,33 +624,39 @@ private string LineIndentPosition(ScintillaNet.ScintillaControl sci, int line)

#endregion

private void GetSecurityToken(Boolean param)
private void GetSecurityToken()
{
JsonRpcClient client = new JsonRpcClient("FIXME");
// we expect this file to be open by now
// because we get here from auth exception
String coltFileName = GetCOLTFile();

try
if (coltFileName != null)
{
// knock
client.Invoke("requestShortCode", new Object[] { LocaleHelper.GetString("Info.Description").TrimEnd(new Char[] { '.' }) });
try
{
JsonRpcClient client = new JsonRpcClient(coltFileName);
// knock
client.Invoke("requestShortCode", new Object[] { "FlashDevelop" /*LocaleHelper.GetString("Info.Description").TrimEnd(new Char[] { '.' })*/ });

// if still here, user needs to enter the code
Forms.FirstTimeDialog dialog = new Forms.FirstTimeDialog(settingObject.InterceptBuilds, settingObject.AutoRun);
dialog.ShowDialog();
// if still here, user needs to enter the code
Forms.FirstTimeDialog dialog = new Forms.FirstTimeDialog(settingObject.InterceptBuilds, settingObject.AutoRun);
dialog.ShowDialog();

// regardless of the code, set boolean options
settingObject.AutoRun = dialog.AutoRun;
settingObject.InterceptBuilds = dialog.InterceptBuilds;
// regardless of the code, set boolean options
settingObject.AutoRun = dialog.AutoRun;
settingObject.InterceptBuilds = dialog.InterceptBuilds;

if ((dialog.ShortCode != null) && (dialog.ShortCode.Length == 4))
{
// short code looks right - request security token
settingObject.SecurityToken = client.Invoke("obtainAuthToken", new Object[] { dialog.ShortCode }).ToString();
if ((dialog.ShortCode != null) && (dialog.ShortCode.Length == 4))
{
// short code looks right - request security token
settingObject.SecurityToken = client.Invoke("obtainAuthToken", new Object[] { dialog.ShortCode }).ToString();
}
}
}

catch (Exception details)
{
HandleAuthenticationExceptions(details);
catch (Exception details)
{
HandleAuthenticationExceptions(details);
}
}
}

Expand All @@ -668,47 +666,49 @@ private void GetSecurityToken(Boolean param)
private void ProductionBuild(Boolean run)
{
// make sure the COLT project is open
// todo: currently no way to know if this fails, check the state before running the build in the future
FindAndOpen(false);
String path = FindAndOpen(false);

try
if (path != null)
{
JsonRpcClient client = new JsonRpcClient("FIXME");
client.Invoke("runProductionCompilation", new Object[] { settingObject.SecurityToken, /*run*/false });
try
{
JsonRpcClient client = new JsonRpcClient(path);
client.PingOrRunCOLT(settingObject.Executable);

// leverage FD launch mechanism
if (run)
// leverage FD launch mechanism
if (run)
{
client.InvokeAsync("runProductionCompilation", RunAfterProductionBuild, new Object[] { settingObject.SecurityToken, /*run*/false });
}
else
{
client.InvokeAsync("runProductionCompilation", HandleAuthenticationExceptions, new Object[] { settingObject.SecurityToken, /*run*/false });
}
}
catch (Exception details)
{
EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ProjectManager.PlayOutput", null));
HandleAuthenticationExceptions(details);
}
}
catch (Exception details)
{
HandleAuthenticationExceptions(details);
}
}

private void OpenInCOLT(string pathToProject)
private void RunAfterProductionBuild(Object result)
{
// put it on recent files list
string coltFolder = System.Environment.GetEnvironmentVariable("USERPROFILE") + @"\.colt\";

XmlDocument workingSet = new XmlDocument();
workingSet.Load(coltFolder + "workingset.xml");
XmlElement root = (XmlElement)workingSet.SelectSingleNode("/workingset");
XmlElement project = (XmlElement)root.PrependChild(workingSet.CreateElement("", "project", ""));
project.Attributes.Append(workingSet.CreateAttribute("path")).Value = pathToProject;
workingSet.Save(coltFolder + "workingset.xml");

// open COLT exe
Process.Start(settingObject.Executable);
Exception exception = result as Exception;
if (exception != null)
{
HandleAuthenticationExceptions(exception);
}
else
{
EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ProjectManager.PlayOutput", null));
}
}


/// <summary>
/// Opens the project in COLT and optionally runs live session
/// </summary>
private void FindAndOpen(Boolean run)
private String FindAndOpen(Boolean run)
{
// Create COLT subfolder if does not exist yet
// While at that, start listening for colt/compile_errors.log changes
Expand All @@ -722,22 +722,26 @@ private void FindAndOpen(Boolean run)
{
try
{
OpenInCOLT(coltFileName);
if (run)
{
JsonRpcClient client = new JsonRpcClient(coltFileName);
client.PingOrRunCOLT(settingObject.Executable);
client.InvokeAsync("runBaseCompilation", HandleAuthenticationExceptions, new Object[] { settingObject.SecurityToken });
}

// TODO: if (run) client.Invoke...
/* JsonRpcClient client = new JsonRpcClient("FIXME");
client.Invoke("loadProject", new Object[] { settingObject.SecurityToken, coltFileName });
if (run) client.Invoke("runBaseCompilation", new Object[] { settingObject.SecurityToken });*/
return coltFileName;
}
catch (Exception details)
{
HandleAuthenticationExceptions(details);
return null;
}
}

else
{
toolbarButton2.Enabled = false;
return null;
}

}
Expand All @@ -760,12 +764,13 @@ private void ExportAndOpen(Boolean run)
// Export the project as xml file
project.Save();

// Open it
OpenInCOLT(project.path);

/* JsonRpcClient client = new JsonRpcClient("FIXME");
client.Invoke("createProject", new Object[] { settingObject.SecurityToken, project });
*/
// Optionally run base compilation
if (run)
{
JsonRpcClient client = new JsonRpcClient(project.path);
client.PingOrRunCOLT(settingObject.Executable);
client.InvokeAsync("runBaseCompilation", HandleAuthenticationExceptions, new Object[] { settingObject.SecurityToken });
}

// Enable "open" button
toolbarButton2.Enabled = true;
Expand All @@ -778,9 +783,6 @@ private void ExportAndOpen(Boolean run)
File.Delete(oldFile);
}
}

//TODO this must return...
/* if (run) client.Invoke("runBaseCompilation", new Object[] { settingObject.SecurityToken });*/
}
catch (Exception details)
{
Expand All @@ -792,23 +794,33 @@ private void ExportAndOpen(Boolean run)
/// <summary>
/// Handles possible authentication exceptions
/// </summary>
private void HandleAuthenticationExceptions(Exception exception)
private void HandleAuthenticationExceptions(object param)
{
JsonRpcException rpcException = exception as JsonRpcException;
if (rpcException != null)
Exception exception = param as Exception;
if (exception != null)
{
// if the exception comes from rpc, we have two special situations to handle:
// 1 short code was wrong (might happen a lot)
// 2 security token was wrong (should never happen)
// in both cases, we need to request new security token
if ((rpcException.TypeName == "codeOrchestra.lcs.rpc.security.InvalidShortCodeException") ||
(rpcException.TypeName == "codeOrchestra.lcs.rpc.security.InvalidAuthTokenException"))
JsonRpcException rpcException = exception as JsonRpcException;
if (rpcException != null)
{
settingObject.SecurityToken = null;
// if the exception comes from rpc, we have two special situations to handle:
// 1 short code was wrong (might happen a lot)
// 2 security token was wrong (should never happen)
// in both cases, we need to request new security token
if ((rpcException.TypeName == "codeOrchestra.colt.core.rpc.security.InvalidShortCodeException") ||
(rpcException.TypeName == "codeOrchestra.colt.core.rpc.security.InvalidAuthTokenException"))
{
settingObject.SecurityToken = null;

// request new security token immediately
GetSecurityToken();
}
}
}

TraceManager.Add(exception.ToString(), -1);
else
{
TraceManager.Add(exception.ToString(), -1);
}
}
}

/// <summary>
Expand Down
Loading

0 comments on commit 48f27bf

Please # to comment.