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

« back to all changes in this revision

Viewing changes to src/tools/mdhost/src/mdhost.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:
42
42
using System.Collections;
43
43
using Mono.Remoting.Channels.Unix;
44
44
using Mono.Addins;
 
45
using System.Runtime.Remoting.Channels.Tcp;
45
46
 
46
47
public class MonoDevelopProcessHost
47
48
{
 
49
        static string ParentRuntime;
 
50
        
48
51
        public static int Main (string[] args)
49
52
        {
50
53
                string tmpFile = null;
62
65
                        
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 ());
 
72
                        }
65
73
                        
66
74
                        if (tmpFile != null) {
67
75
                                try {
70
78
                                } catch {
71
79
                                }
72
80
                        }
73
 
                        
 
81
 
74
82
                        WatchParentProcess (int.Parse (pidToWatch));
75
83
                        
76
84
                        string unixPath = RegisterRemotingChannel ();
106
114
                
107
115
        static string RegisterRemotingChannel ()
108
116
        {
 
117
                IDictionary formatterProps = new Hashtable ();
 
118
                formatterProps ["includeVersions"] = false;
 
119
                formatterProps ["strictBinding"] = false;
 
120
                
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;
 
125
                
 
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
 
129
                        dict ["port"] = 0;
 
130
                        dict ["rejectRemoteRequests"] = true;
 
131
                        ChannelServices.RegisterChannel (new TcpChannel (dict, clientProvider, serverProvider), false);
 
132
                        return null;
 
133
                }
 
134
                else {
 
135
                        string unixRemotingFile = Path.GetTempFileName ();
 
136
                        dict ["portName"] = Path.GetFileName (unixRemotingFile);
 
137
                        ChannelServices.RegisterChannel (new IpcChannel (dict, clientProvider, serverProvider), false);
 
138
                        return unixRemotingFile;
 
139
                }
 
140
        }
 
141
        
 
142
        static string CurrentRuntime {
 
143
                get {
 
144
                        if (Type.GetType ("Mono.Runtime") != null)
 
145
                                return "Mono";
 
146
                        else
 
147
                                return ".NET";
 
148
                }
117
149
        }
118
150
        
119
151
        static void WatchParentProcess (int pid)
121
153
                Thread t = new Thread (delegate () {
122
154
                        while (true) {
123
155
                                try {
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);
 
160
                                        if (p.HasExited)
 
161
                                                break;
125
162
                                } catch {
126
 
                                        Environment.Exit (1);
 
163
                                        break;
127
164
                                }
128
165
                                Thread.Sleep (1000);
129
166
                        }
 
167
                        Environment.Exit (1);
130
168
                });
131
169
                t.Name = "Parent process watcher";
132
170
                t.IsBackground = true;