42
42
using System.Collections;
43
43
using Mono.Remoting.Channels.Unix;
45
using System.Runtime.Remoting.Channels.Tcp;
46
47
public class MonoDevelopProcessHost
49
static string ParentRuntime;
48
51
public static int Main (string[] args)
50
53
string tmpFile = null;
63
66
string sref = input.ReadLine ();
64
67
string pidToWatch = input.ReadLine ();
68
ParentRuntime = input.ReadLine ();
69
int numAsm = int.Parse (input.ReadLine ());
70
while (numAsm-- > 0) {
71
Assembly.LoadFrom (input.ReadLine ());
66
74
if (tmpFile != null) {
107
115
static string RegisterRemotingChannel ()
117
IDictionary formatterProps = new Hashtable ();
118
formatterProps ["includeVersions"] = false;
119
formatterProps ["strictBinding"] = false;
109
121
IDictionary dict = new Hashtable ();
110
BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
111
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
112
string unixRemotingFile = Path.GetTempFileName ();
113
dict ["portName"] = Path.GetFileName (unixRemotingFile);
122
BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider(formatterProps, null);
123
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider(formatterProps, null);
114
124
serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
115
ChannelServices.RegisterChannel (new IpcChannel (dict, clientProvider, serverProvider), false);
116
return unixRemotingFile;
126
// Mono's and .NET's IPC channels have interoperability issues, so use TCP in this case
127
if (CurrentRuntime != ParentRuntime) {
128
// Running Mono on Windows
130
dict ["rejectRemoteRequests"] = true;
131
ChannelServices.RegisterChannel (new TcpChannel (dict, clientProvider, serverProvider), false);
135
string unixRemotingFile = Path.GetTempFileName ();
136
dict ["portName"] = Path.GetFileName (unixRemotingFile);
137
ChannelServices.RegisterChannel (new IpcChannel (dict, clientProvider, serverProvider), false);
138
return unixRemotingFile;
142
static string CurrentRuntime {
144
if (Type.GetType ("Mono.Runtime") != null)
119
151
static void WatchParentProcess (int pid)
121
153
Thread t = new Thread (delegate () {
124
System.Diagnostics.Process.GetProcessById (pid);
156
// Throws exception if process is not running.
157
// When watching a .NET process from Mono, GetProcessById may
158
// return the process with HasExited=true
159
var p = System.Diagnostics.Process.GetProcessById (pid);
126
Environment.Exit (1);
128
165
Thread.Sleep (1000);
167
Environment.Exit (1);
131
169
t.Name = "Parent process watcher";
132
170
t.IsBackground = true;