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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationService.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:
39
39
using System.Threading;
40
40
using System.Linq;
41
41
using System.Runtime.Serialization.Formatters.Binary;
 
42
using MonoDevelop.Core.Execution;
42
43
 
43
44
namespace MonoDevelop.Core.Instrumentation
44
45
{
60
61
                        startTime = DateTime.Now;
61
62
                }
62
63
                
63
 
                public static int PublishService (int port)
 
64
                public static int PublishService ()
64
65
                {
65
 
                        // Get a free port
66
 
                        TcpListener listener = new TcpListener (IPAddress.Loopback, port);
67
 
                        listener.Start ();
68
 
                        if (port == 0)
69
 
                                port = ((IPEndPoint)listener.LocalEndpoint).Port;
70
 
                        listener.Stop ();
71
 
                        
72
 
                        Hashtable dict = new Hashtable ();
73
 
                        BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
74
 
                        BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
75
 
                        dict ["port"] = port;
76
 
                        serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
77
 
                        ChannelServices.RegisterChannel (new TcpChannel (dict, clientProvider, serverProvider), false);
78
 
                        publicPort = port;
 
66
                        RemotingService.RegisterRemotingChannel ();
 
67
                        TcpChannel ch = (TcpChannel) ChannelServices.GetChannel ("tcp");
 
68
                        Uri u = new Uri (ch.GetUrlsForUri ("test")[0]);
 
69
                        publicPort = u.Port;
79
70
                        
80
71
                        InstrumentationServiceBackend backend = new InstrumentationServiceBackend ();
81
72
                        System.Runtime.Remoting.RemotingServices.Marshal (backend, "InstrumentationService");
82
73
                        
83
 
                        return port;
 
74
                        return publicPort;
84
75
                }
85
76
                
86
77
                public static void StartMonitor ()
88
79
                        if (publicPort == -1)
89
80
                                throw new InvalidOperationException ("Service not published");
90
81
                        
 
82
                        if (PropertyService.IsMac) {
 
83
                                var macOSDir = PropertyService.EntryAssemblyPath.ParentDirectory.ParentDirectory.ParentDirectory;
 
84
                                var app = macOSDir.Combine ("MDMonitor.app");
 
85
                                if (Directory.Exists (app)) {
 
86
                                        var psi = new ProcessStartInfo ("open", string.Format ("-n '{0}' --args -c localhost:{1} ", app, publicPort)) {
 
87
                                                UseShellExecute = false,
 
88
                                        };
 
89
                                        Process.Start (psi);
 
90
                                        return;
 
91
                                }
 
92
                        }       
 
93
                        
91
94
                        string exe = Path.Combine (Path.GetDirectoryName (Assembly.GetEntryAssembly ().Location), "mdmonitor.exe");
92
95
                        string args = "-c localhost:" + publicPort;
93
96
                        Runtime.SystemAssemblyService.CurrentRuntime.ExecuteAssembly (exe, args);