~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/ProcessHostController.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
using System.Reflection;
39
39
using Timer = System.Timers.Timer;
40
40
using MonoDevelop.Core.Logging;
 
41
using Mono.Addins;
41
42
 
42
43
namespace MonoDevelop.Core.Execution
43
44
{
110
111
                                        string location = Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly ().Location);
111
112
                                        location = Path.Combine (location, "mdhost.exe");
112
113
                                        
113
 
                                        ProcessHostConsole cons = new ProcessHostConsole ();
114
114
                                        tmpFile = Path.GetTempFileName ();
115
 
                                        File.WriteAllText (tmpFile, sref + "\n" + Process.GetCurrentProcess ().Id + "\n");
 
115
                                        StreamWriter sw = new StreamWriter (tmpFile);
 
116
                                        sw.WriteLine (sref);
 
117
                                        sw.WriteLine (Process.GetCurrentProcess ().Id);
 
118
                                        sw.WriteLine (Runtime.SystemAssemblyService.CurrentRuntime.RuntimeId);
 
119
                                        
 
120
                                        // Explicitly load Mono.Addins since the target runtime may not have it installed
 
121
                                        sw.WriteLine (2);
 
122
                                        sw.WriteLine (typeof(AddinManager).Assembly.Location);
 
123
                                        sw.WriteLine (typeof(Mono.Addins.Setup.SetupService).Assembly.Location);
 
124
                                        sw.Close ();
 
125
                                        
116
126
                                        string arguments = string.Format("{0} \"{1}\"", id, tmpFile);
117
127
                                        DotNetExecutionCommand cmd = new DotNetExecutionCommand(location, arguments, AppDomain.CurrentDomain.BaseDirectory);
118
128
                                        cmd.DebugMode = isDebugMode;
 
129
                                        ProcessHostConsole cons = new ProcessHostConsole ();
119
130
                                        process = executionHandlerFactory.Execute (cmd, cons);
120
131
                                        Counters.ExternalHostProcesses++;
121
132
                                        
154
165
                                remoteObjects.Clear ();
155
166
                                
156
167
                                exitedEvent.Set ();
 
168
                                
 
169
                                // If the remote process crashes, a thread may be left hung in WaitForExit. This will awaken it.
 
170
                                exitRequestEvent.Set ();
 
171
                                
157
172
                                if (oper != process) return;
158
173
 
159
174
                                // The process suddently died
181
196
                                // Before creating the instance, load the add-ins on which it depends
182
197
                                if (addins != null && addins.Length > 0)
183
198
                                        processHost.LoadAddins (addins);
 
199
                                RemotingService.RegisterAssemblyForSimpleResolve (type.Assembly.GetName ().Name);
184
200
                                object obj = processHost.CreateInstance (type);
185
201
                                RemotingService.RegisterMethodCallback (obj, "Dispose", RemoteProcessObjectDisposing, null);
 
202
                                RemotingService.RegisterMethodCallback (obj, "Shutdown", RemoteProcessObjectShuttingDown, null);
186
203
                                remoteObjects.Add (obj);
187
204
                                Counters.ExternalObjects++;
188
205
                                return obj;
209
226
                                // Before creating the instance, load the add-ins on which it depends
210
227
                                if (addins != null && addins.Length > 0)
211
228
                                        processHost.LoadAddins (addins);
 
229
                                RemotingService.RegisterAssemblyForSimpleResolve (Path.GetFileNameWithoutExtension (assemblyPath));
212
230
                                object obj = processHost.CreateInstance (assemblyPath, typeName);
213
231
                                RemotingService.RegisterMethodCallback (obj, "Dispose", RemoteProcessObjectDisposing, null);
 
232
                                RemotingService.RegisterMethodCallback (obj, "Shutdown", RemoteProcessObjectShuttingDown, null);
214
233
                                remoteObjects.Add (obj);
215
234
                                Counters.ExternalObjects++;
216
235
                                return obj;
232
251
                        return new ReturnMessage (null, null, 0, msg.LogicalCallContext, msg);
233
252
                }
234
253
                
 
254
                IMethodReturnMessage RemoteProcessObjectShuttingDown (object obj, IMethodCallMessage msg)
 
255
                {
 
256
                        ThreadPool.QueueUserWorkItem (delegate {
 
257
                                try {
 
258
                                        process.Cancel ();
 
259
                                } catch {
 
260
                                }
 
261
                        });
 
262
                        return new ReturnMessage (null, null, 0, msg.LogicalCallContext, msg);
 
263
                }
 
264
                
235
265
                public void ReleaseInstance (object obj)
236
266
                {
237
267
                        ReleaseInstance (obj, 2000);
333
363
        
334
364
        class ProcessHostConsole: IConsole
335
365
        {
336
 
                public event EventHandler CancelRequested;
 
366
                //nothing fires this event so make a dummy implementation to keep csc happy
 
367
                event EventHandler IConsole.CancelRequested { add { } remove {} }
337
368
                
338
369
                public TextReader In {
339
370
                        get { return Console.In; }