Пример #1
0
		public static ProcessSerialNumber OpenApplication (ApplicationStartInfo application)
		{
			if (application == null)
				throw new ArgumentNullException ("application");
			
			if (string.IsNullOrEmpty (application.Application) || !System.IO.Directory.Exists (application.Application))
				throw new ArgumentException ("Application is not valid");
			
			var appParams = new LSApplicationParameters ();
			if (application.NewInstance)
				appParams.flags |= LSLaunchFlags.NewInstance;
			if (application.Async)
				appParams.flags |= LSLaunchFlags.Async;
			
			NSArray argv = null;
			if (application.Args != null && application.Args.Length > 0) {
				var args = application.Args;
				NSObject[] arr = new NSObject[args.Length];
				for (int i = 0; i < args.Length; i++)
					arr[i] = new NSString (args[i]);
				argv = NSArray.FromNSObjects (arr);
				appParams.argv = argv.Handle;
			}
			
			NSDictionary dict = null;
			if (application.Environment.Count > 0) {
				dict = new NSMutableDictionary ();
				foreach (var kvp in application.Environment)
					dict.SetValueForKey (new NSString (kvp.Value), new NSString (kvp.Key));
				appParams.environment = dict.Handle;
			}
			
			var cfUrl = global::MonoMac.CoreFoundation.CFUrl.FromFile (application.Application);
			ProcessSerialNumber psn;
			
			try {
				appParams.application = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (FSRef)));
			
				if (!CoreFoundation.CFURLGetFSRef (cfUrl.Handle, appParams.application))
					throw new Exception ("Could not create FSRef from CFUrl");
				
				var status = LSOpenApplication (ref appParams, out psn);
				if (status != OSStatus.Ok)
					throw new Exception ("Failed to start process: " + ((int)status).ToString ());
			} finally {
				if (appParams.application != IntPtr.Zero)
					Marshal.FreeHGlobal (appParams.application);
				appParams.application = IntPtr.Zero;
				if (dict != null)
					dict.Dispose (); //also ensures the NSDictionary is kept alive for the params
				if (argv != null)
					argv.Dispose (); //also ensures the NSArray is kept alive for the params
			}
			
			return psn;
		}
Пример #2
0
        public static MonoMacProcess OpenApplication(MonoMacExecutionCommand command, ApplicationStartInfo asi,
                                                     Action <string> stdout, Action <string> stderr)
        {
            var logDir = command.AppPath.ParentDirectory;
            var outLog = logDir.Combine("stdout.log");
            var errLog = logDir.Combine("stderr.log");

            try {
                if (File.Exists(errLog))
                {
                    File.Delete(errLog);
                }
                if (File.Exists(outLog))
                {
                    File.Delete(outLog);
                }
            } catch (IOException) {}

            var outTail = new Tail(outLog, stdout);
            var errTail = new Tail(errLog, stderr);

            outTail.Start();
            errTail.Start();

            if (asi == null)
            {
                asi = new ApplicationStartInfo(command.AppPath);
            }
            asi.NewInstance = true;

            //need async or we won't be able to debug things that happen while the app is launching
            asi.Async = true;

            var monoRuntime = (MonoDevelop.Core.Assemblies.MonoTargetRuntime)command.Runtime;

            //assume MD is running on /L/F/M.f/V/Current
            //if target runtime is different then override for bundle
            if (!monoRuntime.IsRunning)
            {
                asi.Environment ["MONOMAC_DEBUGLAUNCHER_RUNTIME"] = monoRuntime.Prefix;
            }

            asi.Environment ["MONOMAC_DEBUGLAUNCHER_LOGDIR"] = logDir;

            var psn = LaunchServices.OpenApplication(asi);

            return(new MonoMacProcess(psn, outTail, errTail));
        }
		protected override void OnRun (DebuggerStartInfo startInfo)
		{
			var dsi = (MonoMacDebuggerStartInfo) startInfo;
			var startArgs = (SoftDebuggerRemoteArgs) dsi.StartArgs;
			var cmd = dsi.ExecutionCommand;		
			
			int assignedPort;
			StartListening (dsi, out assignedPort);
			
			Action<string> stdout = s => OnTargetOutput (false, s);
			Action<string> stderr = s => OnTargetOutput (true, s);
			
			var asi = new ApplicationStartInfo (cmd.AppPath);
			asi.Environment ["MONOMAC_DEBUGLAUNCHER_OPTIONS"]
				= string.Format ("--debug --debugger-agent=transport=dt_socket,address={0}:{1}", startArgs.Address, assignedPort);
			
			process = MonoMacExecutionHandler.OpenApplication (cmd, asi, stdout, stderr);
			
			process.Completed += delegate {
				EndSession ();
				process = null;
			};
		}
Пример #4
0
        public static ProcessSerialNumber OpenApplication(ApplicationStartInfo application)
        {
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            if (string.IsNullOrEmpty(application.Application) || !System.IO.Directory.Exists(application.Application))
            {
                throw new ArgumentException("Application is not valid");
            }

            var appParams = new LSApplicationParameters();

            if (application.NewInstance)
            {
                appParams.flags |= LSLaunchFlags.NewInstance;
            }
            if (application.Async)
            {
                appParams.flags |= LSLaunchFlags.Async;
            }

            NSArray argv = null;

            if (application.Args != null && application.Args.Length > 0)
            {
                var        args = application.Args;
                NSObject[] arr  = new NSObject[args.Length];
                for (int i = 0; i < args.Length; i++)
                {
                    arr[i] = new NSString(args[i]);
                }
                argv           = NSArray.FromNSObjects(arr);
                appParams.argv = argv.Handle;
            }

            NSDictionary dict = null;

            if (application.Environment.Count > 0)
            {
                dict = new NSMutableDictionary();
                foreach (var kvp in application.Environment)
                {
                    dict.SetValueForKey(new NSString(kvp.Value), new NSString(kvp.Key));
                }
                appParams.environment = dict.Handle;
            }

            var cfUrl = global::MonoMac.CoreFoundation.CFUrl.FromFile(application.Application);
            ProcessSerialNumber psn;

            try {
                appParams.application = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FSRef)));

                if (!CoreFoundation.CFURLGetFSRef(cfUrl.Handle, appParams.application))
                {
                    throw new Exception("Could not create FSRef from CFUrl");
                }

                var status = LSOpenApplication(ref appParams, out psn);
                if (status != OSStatus.Ok)
                {
                    throw new Exception("Failed to start process: " + ((int)status).ToString());
                }
            } finally {
                if (appParams.application != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(appParams.application);
                }
                appParams.application = IntPtr.Zero;
                if (dict != null)
                {
                    dict.Dispose();                      //also ensures the NSDictionary is kept alive for the params
                }
                if (argv != null)
                {
                    argv.Dispose();                      //also ensures the NSArray is kept alive for the params
                }
            }

            return(psn);
        }