Ejemplo n.º 1
0
        public void OnOperationCompleted()
        {
            cancelRegistration.Dispose();
            try {
                if (exited != null)
                {
                    Runtime.RunInMainThread(() => {
                        exited(operation, EventArgs.Empty);
                    });
                }

                if (!Platform.IsWindows && Mono.Unix.Native.Syscall.WIFSIGNALED(operation.ExitCode))
                {
                    console.Log.WriteLine(GettextCatalog.GetString("The application was terminated by a signal: {0}"), Mono.Unix.Native.Syscall.WTERMSIG(operation.ExitCode));
                }
                else if (operation.ExitCode != 0)
                {
                    console.Log.WriteLine(GettextCatalog.GetString("The application exited with code: {0}"), operation.ExitCode);
                }
            } catch (ArgumentException ex) {
                // ArgumentException comes from Syscall.WTERMSIG when an unknown signal is encountered
                console.Error.WriteLine(GettextCatalog.GetString("The application was terminated by an unknown signal: {0}"), ex.Message);
            } finally {
                console.Dispose();
            }
        }
Ejemplo n.º 2
0
        public void OnOperationCompleted()
        {
            cancelRegistration.Dispose();
            try {
                if (exited != null)
                {
                    Runtime.RunInMainThread(() => {
                        exited(operation, EventArgs.Empty);
                    });
                }

                if (!Platform.IsWindows && Mono.Unix.Native.Syscall.WIFSIGNALED(operation.ExitCode))
                {
                    console.Log.WriteLine(GettextCatalog.GetString("The application was terminated by a signal: {0}"), Mono.Unix.Native.Syscall.WTERMSIG(operation.ExitCode));
                }
                else if (operation.ExitCode != 0)
                {
                    console.Log.WriteLine(GettextCatalog.GetString("The application exited with code: {0}"), operation.ExitCode);
                }
            } finally {
                console.Dispose();
            }
        }
Ejemplo n.º 3
0
        public ProcessAsyncOperation StartConsoleProcess(string command, string arguments, string workingDirectory, OperationConsole console,
                                                         IDictionary <string, string> environmentVariables = null, EventHandler exited = null)
        {
            var externalConsole = console as ExternalConsole;

            if ((console == null || externalConsole != null) && externalConsoleHandler != null)
            {
                var dict = new Dictionary <string, string> ();
                if (environmentVariables != null)
                {
                    foreach (var kvp in environmentVariables)
                    {
                        dict[kvp.Key] = kvp.Value;
                    }
                }
                if (environmentVariableOverrides != null)
                {
                    foreach (var kvp in environmentVariableOverrides)
                    {
                        dict[kvp.Key] = kvp.Value;
                    }
                }

                var p = externalConsoleHandler(command, arguments, workingDirectory, dict,
                                               externalConsole?.Title ?? GettextCatalog.GetString("{0} External Console", BrandingService.ApplicationName),
                                               externalConsole != null ? !externalConsole.CloseOnDispose : false);

                if (p != null)
                {
                    if (exited != null)
                    {
                        p.Task.ContinueWith(t => exited(p, EventArgs.Empty), Runtime.MainTaskScheduler);
                    }
                    Counters.ProcessesStarted++;
                    return(p);
                }
                else
                {
                    LoggingService.LogError("Could not create external console for command: " + command + " " + arguments);
                }
            }
            ProcessStartInfo psi = CreateProcessStartInfo(command, arguments, workingDirectory, false);

            if (environmentVariables != null)
            {
                foreach (KeyValuePair <string, string> kvp in environmentVariables)
                {
                    psi.EnvironmentVariables [kvp.Key] = kvp.Value;
                }
            }
            try {
                ProcessWrapper pw = StartProcess(psi, console.Out, console.Error, null);
                new ProcessMonitor(console, pw.ProcessAsyncOperation, exited);
                return(pw.ProcessAsyncOperation);
            } catch (Exception ex) {
                // If the process can't be started, dispose the console now since ProcessMonitor won't do it
                console.Error.WriteLine(GettextCatalog.GetString("The application could not be started"));
                LoggingService.LogError("Could not start process for command: " + psi.FileName + " " + psi.Arguments, ex);
                console.Dispose();
                return(NullProcessAsyncOperation.Failure);
            }
        }
Ejemplo n.º 4
0
		public ProcessAsyncOperation StartConsoleProcess (string command, string arguments, string workingDirectory, OperationConsole console,
			IDictionary<string, string> environmentVariables = null, EventHandler exited = null)
		{
			var externalConsole = console as ExternalConsole;

			if ((console == null || externalConsole != null) && externalConsoleHandler != null) {

				var dict = new Dictionary<string,string> ();
				if (environmentVariables != null)
					foreach (var kvp in environmentVariables)
						dict[kvp.Key] = kvp.Value;
				if (environmentVariableOverrides != null)
					foreach (var kvp in environmentVariableOverrides)
						dict[kvp.Key] = kvp.Value;
				
				var p = externalConsoleHandler (command, arguments, workingDirectory, dict,
					GettextCatalog.GetString ("{0} External Console", BrandingService.ApplicationName),
					externalConsole != null ? !externalConsole.CloseOnDispose : false);

				if (p != null) {
					if (exited != null)
						p.Task.ContinueWith (t => exited (p, EventArgs.Empty), Runtime.MainTaskScheduler);
					Counters.ProcessesStarted++;
					return p;
				} else {
					LoggingService.LogError ("Could not create external console for command: " + command + " " + arguments);
				}
			}
			ProcessStartInfo psi = CreateProcessStartInfo (command, arguments, workingDirectory, false);
			if (environmentVariables != null)
				foreach (KeyValuePair<string, string> kvp in environmentVariables)
					psi.EnvironmentVariables [kvp.Key] = kvp.Value;
			try {
				ProcessWrapper pw = StartProcess (psi, console.Out, console.Error, null);
				new ProcessMonitor (console, pw.ProcessAsyncOperation, exited);
				return pw.ProcessAsyncOperation;
			} catch (Exception ex) {
				// If the process can't be started, dispose the console now since ProcessMonitor won't do it
				console.Error.WriteLine (GettextCatalog.GetString ("The application could not be started"));
				LoggingService.LogError ("Could not start process for command: " + psi.FileName + " " + psi.Arguments, ex);
				console.Dispose ();
				return NullProcessAsyncOperation.Failure;
			}
		}
Ejemplo n.º 5
0
 public override void Dispose()
 {
     base.Dispose();
     console.Dispose();
 }