public void Start() { lock (this) { if (starting) { return; } starting = true; exitRequestEvent.Reset(); RemotingService.RegisterRemotingChannel(); BinaryFormatter bf = new BinaryFormatter(); ObjRef oref = RemotingServices.Marshal(this); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, oref); string sref = Convert.ToBase64String(ms.ToArray()); string tmpFile = null; if (executionHandlerFactory == null) { executionHandlerFactory = Runtime.SystemAssemblyService.CurrentRuntime.GetExecutionHandler(); } try { string location = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); location = Path.Combine(location, "mdhost.exe"); ProcessHostConsole cons = new ProcessHostConsole(); tmpFile = Path.GetTempFileName(); File.WriteAllText(tmpFile, sref + "\n" + Process.GetCurrentProcess().Id + "\n"); string arguments = string.Format("{0} \"{1}\"", id, tmpFile); DotNetExecutionCommand cmd = new DotNetExecutionCommand(location, arguments, AppDomain.CurrentDomain.BaseDirectory); cmd.DebugMode = isDebugMode; process = executionHandlerFactory.Execute(cmd, cons); Counters.ExternalHostProcesses++; process.Completed += ProcessExited; } catch (Exception ex) { if (tmpFile != null) { try { File.Delete(tmpFile); } catch { } } LoggingService.LogError(ex.ToString()); throw; } } }
public void Start (IList<string> userAssemblyPaths = null) { lock (this) { if (starting) return; starting = true; exitRequestEvent.Reset (); RemotingService.RegisterRemotingChannel (); BinaryFormatter bf = new BinaryFormatter (); ObjRef oref = RemotingServices.Marshal (this); MemoryStream ms = new MemoryStream (); bf.Serialize (ms, oref); string sref = Convert.ToBase64String (ms.ToArray ()); string tmpFile = null; if (executionHandlerFactory == null) executionHandlerFactory = Runtime.SystemAssemblyService.CurrentRuntime.GetExecutionHandler (); try { string location = Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly ().Location); location = Path.Combine (location, "mdhost.exe"); tmpFile = Path.GetTempFileName (); StreamWriter sw = new StreamWriter (tmpFile); sw.WriteLine (sref); sw.WriteLine (Process.GetCurrentProcess ().Id); sw.WriteLine (Runtime.SystemAssemblyService.CurrentRuntime.RuntimeId); // Explicitly load Mono.Addins since the target runtime may not have it installed sw.WriteLine (2); sw.WriteLine (typeof(AddinManager).Assembly.Location); sw.WriteLine (typeof(Mono.Addins.Setup.SetupService).Assembly.Location); sw.Close (); string arguments = string.Format ("{0} \"{1}\"", id, tmpFile); DotNetExecutionCommand cmd = new DotNetExecutionCommand (location, arguments, AppDomain.CurrentDomain.BaseDirectory); if (userAssemblyPaths != null) cmd.UserAssemblyPaths = userAssemblyPaths; cmd.DebugMode = isDebugMode; ProcessHostConsole cons = new ProcessHostConsole (); var p = process = executionHandlerFactory.Execute (cmd, cons); Counters.ExternalHostProcesses++; process.Task.ContinueWith ((t) => ProcessExited (p)); } catch (Exception ex) { if (tmpFile != null) { try { File.Delete (tmpFile); } catch { } } LoggingService.LogError (ex.ToString ()); throw; } } }
public void Start(IList <string> userAssemblyPaths = null) { lock (this) { if (starting) { return; } starting = true; exitRequestEvent.Reset(); RemotingService.RegisterRemotingChannel(); BinaryFormatter bf = new BinaryFormatter(); ObjRef oref = RemotingServices.Marshal(this); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, oref); string sref = Convert.ToBase64String(ms.ToArray()); string tmpFile = null; if (executionHandlerFactory == null) { executionHandlerFactory = Runtime.SystemAssemblyService.CurrentRuntime.GetExecutionHandler(); } try { string location = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); location = Path.Combine(location, "mdhost.exe"); tmpFile = Path.GetTempFileName(); StreamWriter sw = new StreamWriter(tmpFile); sw.WriteLine(sref); sw.WriteLine(Process.GetCurrentProcess().Id); sw.WriteLine(Runtime.SystemAssemblyService.CurrentRuntime.RuntimeId); // Explicitly load Mono.Addins since the target runtime may not have it installed sw.WriteLine(2); sw.WriteLine(typeof(AddinManager).Assembly.Location); sw.WriteLine(typeof(Mono.Addins.Setup.SetupService).Assembly.Location); sw.Close(); string arguments = string.Format("{0} \"{1}\"", id, tmpFile); DotNetExecutionCommand cmd = new DotNetExecutionCommand(location, arguments, AppDomain.CurrentDomain.BaseDirectory); if (userAssemblyPaths != null) { cmd.UserAssemblyPaths = userAssemblyPaths; } cmd.DebugMode = isDebugMode; ProcessHostConsole cons = new ProcessHostConsole(); process = executionHandlerFactory.Execute(cmd, cons); Counters.ExternalHostProcesses++; process.Completed += ProcessExited; } catch (Exception ex) { if (tmpFile != null) { try { File.Delete(tmpFile); } catch { } } LoggingService.LogError(ex.ToString()); throw; } } }
public void Start () { lock (this) { if (starting) return; starting = true; exitRequestEvent.Reset (); RemotingService.RegisterRemotingChannel (); BinaryFormatter bf = new BinaryFormatter (); ObjRef oref = RemotingServices.Marshal (this); MemoryStream ms = new MemoryStream (); bf.Serialize (ms, oref); string sref = Convert.ToBase64String (ms.ToArray ()); string tmpFile = null; if (executionHandlerFactory == null) executionHandlerFactory = Runtime.SystemAssemblyService.CurrentRuntime.GetExecutionHandler (); try { string location = Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly ().Location); location = Path.Combine (location, "mdhost.exe"); ProcessHostConsole cons = new ProcessHostConsole (); tmpFile = Path.GetTempFileName (); File.WriteAllText (tmpFile, sref + "\n" + Process.GetCurrentProcess ().Id + "\n"); string arguments = string.Format("{0} \"{1}\"", id, tmpFile); DotNetExecutionCommand cmd = new DotNetExecutionCommand(location, arguments, AppDomain.CurrentDomain.BaseDirectory); cmd.DebugMode = isDebugMode; process = executionHandlerFactory.Execute (cmd, cons); Counters.ExternalHostProcesses++; process.Completed += ProcessExited; } catch (Exception ex) { if (tmpFile != null) { try { File.Delete (tmpFile); } catch { } } LoggingService.LogError (ex.ToString ()); throw; } } }