Esempio n. 1
0
        public static ProcessWrapper StartProcess(ProcessStartInfo startInfo, TextWriter outWriter, TextWriter errorWriter, EventHandler exited, StringDictionary environmentOverride)
        {
            ProcessEventHandler wout = OutWriter.GetWriteHandler(outWriter);
            ProcessEventHandler werr = OutWriter.GetWriteHandler(errorWriter);

            return(StartProcess(startInfo, wout, werr, exited, environmentOverride));
        }
Esempio n. 2
0
        public static ProcessWrapper StartProcess(string command, string arguments, string workingDirectory, TextWriter outWriter, TextWriter errorWriter, EventHandler exited, bool redirectStandardInput)
        {
            ProcessEventHandler wout = OutWriter.GetWriteHandler(outWriter);
            ProcessEventHandler werr = OutWriter.GetWriteHandler(errorWriter);

            return(StartProcess(command, arguments, workingDirectory, wout, werr, exited, redirectStandardInput));
        }
Esempio n. 3
0
        // @environmentOverride overrides even the global override values
        public static ProcessWrapper StartProcess(ProcessStartInfo startInfo, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited, StringDictionary environmentOverride)
        {
            if (startInfo == null)
            {
                throw new ArgumentException("startInfo");
            }

            ProcessWrapper p = new ProcessWrapper();

            if (outputStreamChanged != null)
            {
                p.OutputStreamChanged += outputStreamChanged;
            }

            if (errorStreamChanged != null)
            {
                p.ErrorStreamChanged += errorStreamChanged;
            }

            if (exited != null)
            {
                p.Exited += exited;
            }

            p.StartInfo = startInfo;
            ProcessEnvironmentVariableOverrides(p.StartInfo, environmentOverride);

            // WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process"
            // Process leaks when an exit event is registered
            // instead we use another thread to monitor I/O and wait for exit
            // p.EnableRaisingEvents = true;

            p.Start();
            return(p);
        }
Esempio n. 4
0
        public new void Start()
        {
            CheckDisposed();

            base.EnableRaisingEvents = true;

            base.Exited += (s, args) => {
                try {
                    endEventExit.Set();
                    WaitHandle.WaitAll(new WaitHandle[] { endEventOut, endEventErr });
                } catch (ObjectDisposedException) {
                    return;                     // we already called Dispose
                }

                OnExited(this, EventArgs.Empty);
            };

            base.OutputDataReceived += (s, args) => {
                if (args.Data == null)
                {
                    try {
                        endEventOut.Set();
                    } catch (ObjectDisposedException) {
                        return;                         // we already called Dispose
                    }
                }
                else
                {
                    ProcessEventHandler handler = OutputStreamChanged;
                    if (handler != null)
                    {
                        handler(this, args.Data + Environment.NewLine);
                    }
                }
            };

            base.ErrorDataReceived += (s, args) => {
                if (args.Data == null)
                {
                    try {
                        endEventErr.Set();
                    } catch (ObjectDisposedException) {
                        return;                         // we already called Dispose
                    }
                }
                else
                {
                    ProcessEventHandler handler = ErrorStreamChanged;
                    if (handler != null)
                    {
                        handler(this, args.Data + Environment.NewLine);
                    }
                }
            };

            base.Start();

            base.BeginOutputReadLine();
            base.BeginErrorReadLine();
        }
        /// <summary>
        ///
        /// </summary>
        public static Task StartAsync(this Process self, ProcessEventHandler events = null)
        {
            var  tcs     = new TaskCompletionSource <bool>();
            bool started = false;

            self.Exited += (sender, args) => {
                tcs.SetResult(true);
                events?.onExit(sender, args);
            };

            self.OutputDataReceived +=
                (sender, args) => {
                if (!string.IsNullOrEmpty(args.Data))
                {
                    events?.onIOData(sender, args);
                }
            };

            self.ErrorDataReceived +=
                (sender, args) => {
                if (!string.IsNullOrEmpty(args.Data))
                {
                    events?.onIOError(sender, args);
                }
            };

            started = self.Start();
            self.BeginOutputReadLine();
            self.BeginErrorReadLine();

            return(tcs.Task);
        }
		// @environmentOverride overrides even the global override values
		public static ProcessWrapper StartProcess (ProcessStartInfo startInfo, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited, StringDictionary environmentOverride)
		{
			if (startInfo == null)
				throw new ArgumentException ("startInfo");

			ProcessWrapper p = new ProcessWrapper();

			if (outputStreamChanged != null) {
				p.OutputStreamChanged += outputStreamChanged;
			}

			if (errorStreamChanged != null)
				p.ErrorStreamChanged += errorStreamChanged;

			if (exited != null)
				p.Exited += exited;

			p.StartInfo = startInfo;
			ProcessEnvironmentVariableOverrides (p.StartInfo, environmentOverride);

			// WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process"
			// Process leaks when an exit event is registered
			// instead we use another thread to monitor I/O and wait for exit
			// p.EnableRaisingEvents = true;

			p.Start ();
			return p;
		}
Esempio n. 7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            ResultView += new ProcessEventHandler(Current);

            checkThread = new Thread(getCPU_Info);
            checkThread.Start(); //checkThread 스레드 프로세스 시작
        }
Esempio n. 8
0
 public void RegisterProcessModified(ProcessEventHandler handler)
 {
     foreach (ProcessWatcher watcher in mProcessWatchers)
     {
         watcher.ProcessModified += handler;
     }
 }
        public ProcessWrapper LogCat(AndroidDevice device, ProcessEventHandler outputLog,
                                     ProcessEventHandler errorLog)
        {
            var args = string.Format("-s {0} logcat", device.ID);

            return(StartProcess(AdbExe, args, outputLog, errorLog));
        }
Esempio n. 10
0
        public ProcessWrapper StartProcess(ProcessStartInfo startInfo, TextWriter outWriter, TextWriter errorWriter, EventHandler exited)
        {
            ProcessEventHandler wout = OutWriter.GetWriteHandler(outWriter);
            ProcessEventHandler werr = OutWriter.GetWriteHandler(errorWriter);

            return(StartProcess(startInfo, wout, werr, exited));
        }
 public void RegisterProcessModified(ProcessEventHandler handler)
 {
     foreach (ProcessWatcher watcher in mProcessWatchers)
     {
         watcher.ProcessModified += handler;
     }
 }
Esempio n. 12
0
        public IProcessAsyncOperation ForwardPort(AndroidDevice device, int devicePort, int localPort,
                                                  ProcessEventHandler outputLog, ProcessEventHandler errorLog)
        {
            var args = string.Format("-s {0} forward tcp:{1} tcp:{2}", device.ID, localPort, devicePort);

            return(StartProcess(AdbExe, args, outputLog, errorLog));
        }
Esempio n. 13
0
        protected virtual void OnRaiseProcessEvent(ProcessEventArgs e)
        {
            ProcessEventHandler handler = OnProcessEvent;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Esempio n. 14
0
 public void ScanAll(ProcessEventHandler handler)
 {
     if (handler != null)
     {
         foreach (Process p in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(processName)))
         {
             handler.Invoke(this, new ProcessEventArgs((uint)p.Id, processName));
         }
     }
 }
Esempio n. 15
0
        private void ProcessEventArrived(object sender, EventArrivedEventArgs e, ProcessEventHandler handler)
        {
            if (handler == null)
            {
                return;
            }
            String name = (String)e.NewEvent.GetPropertyValue("ProcessName");

            if (name == processName)
            {
                handler.Invoke(this, new ProcessEventArgs((UInt32)e.NewEvent.GetPropertyValue("ProcessID"), name));
            }
        }
Esempio n. 16
0
        public ProcessWrapper StartProcess(ProcessStartInfo startInfo, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited)
        {
            if (startInfo == null)
            {
                throw new ArgumentException("startInfo");
            }

            ProcessWrapper p = new ProcessWrapper();

            if (outputStreamChanged != null)
            {
                startInfo.RedirectStandardOutput = true;
                p.OutputStreamChanged           += outputStreamChanged;
            }

            if (errorStreamChanged != null)
            {
                startInfo.RedirectStandardError = true;
                p.ErrorStreamChanged           += errorStreamChanged;
            }

            startInfo.CreateNoWindow = true;
            p.StartInfo = startInfo;
            ProcessEnvironmentVariableOverrides(p.StartInfo);

            // FIXME: the bug is long gone, but removing the hacks in ProcessWrapper w/o bugs will be tricky
            // WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process"
            // Process leaks when an exit event is registered
            // instead we use another thread to monitor I/O and wait for exit
            // if (exited != null)
            //  p.Exited += exited;
            // p.EnableRaisingEvents = true;

            if (exited != null)
            {
                MonoDevelop.Core.OperationHandler handler = null;
                handler = delegate(MonoDevelop.Core.IAsyncOperation op) {
                    op.Completed -= handler;
                    exited(p, EventArgs.Empty);
                };
                ((MonoDevelop.Core.IAsyncOperation)p).Completed += handler;
            }

            Counters.ProcessesStarted++;
            p.Start();
            return(p);
        }
Esempio n. 17
0
        ProcessWrapper StartProcess(string name, string args, ProcessEventHandler outputLog, ProcessEventHandler errorLog)
        {
            var psi = new ProcessStartInfo(name, args)
            {
                UseShellExecute = false,
            };

            if (outputLog != null)
            {
                psi.RedirectStandardOutput = true;
            }
            if (errorLog != null)
            {
                psi.RedirectStandardError = true;
            }
            psi.EnvironmentVariables["PATH"] = pathOverride;
            return(Runtime.ProcessService.StartProcess(psi, outputLog, errorLog, null));
        }
Esempio n. 18
0
        public ProcessWrapper StartProcess(ProcessStartInfo startInfo, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited)
        {
            if (startInfo == null)
            {
                throw new ArgumentException("startInfo");
            }

            ProcessWrapper p = new ProcessWrapper();

            if (outputStreamChanged != null)
            {
                startInfo.RedirectStandardOutput = true;
                p.OutputStreamChanged           += outputStreamChanged;
            }

            if (errorStreamChanged != null)
            {
                startInfo.RedirectStandardError = true;
                p.ErrorStreamChanged           += errorStreamChanged;
            }

            startInfo.CreateNoWindow = true;
            p.StartInfo = startInfo;
            ProcessEnvironmentVariableOverrides(p.StartInfo);

            // FIXME: the bug is long gone, but removing the hacks in ProcessWrapper w/o bugs will be tricky
            // WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process"
            // Process leaks when an exit event is registered
            // instead we use another thread to monitor I/O and wait for exit
            // if (exited != null)
            //  p.Exited += exited;
            // p.EnableRaisingEvents = true;

            Counters.ProcessesStarted++;
            p.Start();

            if (exited != null)
            {
                p.Task.ContinueWith(t => exited(p, EventArgs.Empty), Runtime.MainTaskScheduler);
            }

            return(p);
        }
Esempio n. 19
0
 /// <summary>
 /// 开始执行带事务的过程
 /// </summary>
 public void BeginTransaction(TransactionDelegate de, dynamic dy)
 {
     if (ProcessEventHandler != null)
     {
         try
         {
             this.Start();
             ProcessEventHandler.Invoke(this, dy);
         }
         catch (Exception ex)
         {
             //MessageBox.Show(ex.Message);
             isCommit    = false;
             isHaveError = true;
             throw;
         }
         finally
         {
             this.Close();
         }
     }
 }
Esempio n. 20
0
		public new void Start ()
		{
			CheckDisposed ();

			base.EnableRaisingEvents = true;

			base.Exited += (s, args) => {
				endEventExit.Set ();

				WaitHandle.WaitAll (new WaitHandle[] { endEventOut, endEventErr });
				OnExited (this, EventArgs.Empty);
			};

			base.OutputDataReceived += (s, args) => {
				if (args.Data == null) {
					endEventOut.Set ();
				} else {
					ProcessEventHandler handler = OutputStreamChanged;
					if (handler != null)
						handler (this, args.Data);
				}
			};

			base.ErrorDataReceived += (s, args) => {
				if (args.Data == null) {
					endEventErr.Set ();
				} else {
					ProcessEventHandler handler = ErrorStreamChanged;
					if (handler != null)
						handler (this, args.Data);
				}
			};

			base.Start ();

			base.BeginOutputReadLine ();
			base.BeginErrorReadLine ();
		}
Esempio n. 21
0
 public ProcessWrapper StartProcess(string command, string arguments, string workingDirectory, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited, bool redirectStandardInput)
 {
     return StartProcess (CreateProcessStartInfo (command, arguments, workingDirectory, redirectStandardInput),
         outputStreamChanged, errorStreamChanged, exited);
 }
Esempio n. 22
0
        public ProcessWrapper StartProcess(ProcessStartInfo startInfo, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited)
        {
            if (startInfo == null)
                throw new ArgumentException ("startInfo");

            ProcessWrapper p = new ProcessWrapper();

            if (outputStreamChanged != null) {
                p.OutputStreamChanged += outputStreamChanged;
            }

            if (errorStreamChanged != null)
                p.ErrorStreamChanged += errorStreamChanged;

            startInfo.CreateNoWindow = true;
            p.StartInfo = startInfo;
            ProcessEnvironmentVariableOverrides (p.StartInfo);

            // FIXME: the bug is long gone, but removing the hacks in ProcessWrapper w/o bugs will be tricky
            // WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process"
            // Process leaks when an exit event is registered
            // instead we use another thread to monitor I/O and wait for exit
            // if (exited != null)
            // 	p.Exited += exited;
            // p.EnableRaisingEvents = true;

            if (exited != null) {
            //	MonoDevelop.Core.OperationHandler handler = null;
            //	handler = delegate (MonoDevelop.Core.IAsyncOperation op) {
            //		op.Completed -= handler;
            //		exited (p, EventArgs.Empty);
            //	};
            //	((MonoDevelop.Core.IAsyncOperation)p).Completed += handler;
            }

            //Counters.ProcessesStarted++;

            p.Start ();
            return p;
        }
Esempio n. 23
0
    public void RunEmulator(string command, string arguments, string workDir, ProcessEventHandler pve)
    {
        this.ProcessOutput.Clear();
        ProcessWrapper pw = new ProcessWrapper();

        if (pve != null){
            pw = MainClass.ProcessService.StartProcess(command, arguments, workDir, pve, pve);
        }
        else{
            pw = MainClass.ProcessService.StartProcess(command, arguments, workDir, ProcessOutputChange, ProcessErrorChange);
        }

        //VRATIT SPET
        //runningEmulator = true;
        runningEmulator = false;

        pw.Exited += delegate(object sender, EventArgs e) {
            Console.WriteLine("Emulator exit");
            runningEmulator = false;
            if (pve != null)
                pve(null, " ");
        };
    }
Esempio n. 24
0
 public ProcessWrapper StartProcess(string command, string arguments, string workingDirectory, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited)
 {
     return StartProcess (command, arguments, workingDirectory, outputStreamChanged, errorStreamChanged, exited, false);
 }
Esempio n. 25
0
 public static ProcessWrapper StartProcess(string command, string arguments, string workingDirectory, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited, bool redirectStandardInput)
 {
     return(StartProcess(CreateProcessStartInfo(command, arguments, workingDirectory, redirectStandardInput),
                         outputStreamChanged, errorStreamChanged, exited, null));
 }
Esempio n. 26
0
 public void RunProcessWait(string command, string arguments, string workDir,ProcessEventHandler pve,EventHandler exitHandler)
 {
     ProcessWrapper pw = MainClass.ProcessService.StartProcess(command, arguments, workDir, pve, pve);
     pw.Exited += exitHandler;
     pw.WaitForExit();
 }
Esempio n. 27
0
		public IProcessAsyncOperation StartActivity (AndroidDevice device, string activity,
			ProcessEventHandler outputLog, ProcessEventHandler errorLog)
		{
			var args = new ProcessArgumentBuilder ();
			args.Add ("-s", device.ID, "shell", "am", "start", "-a", "android.intent.action.MAIN", "-n");
			args.AddQuoted (activity);
			
			return StartProcess (AdbExe, args.ToString (), outputLog, errorLog);
		}
Esempio n. 28
0
 public static ProcessWrapper StartProcess(string command, string arguments, string workingDirectory, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited)
 {
     return(StartProcess(command, arguments, workingDirectory, outputStreamChanged, errorStreamChanged, exited, false));
 }
        public ProcessWrapper StartProcess(string command, string arguments, string workingDirectory, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            if (command.Length == 0)
                throw new ArgumentException("command");

            ProcessWrapper p = new ProcessWrapper();

            if (outputStreamChanged != null) {
                p.OutputStreamChanged += outputStreamChanged;
            }

            if (errorStreamChanged != null)
                p.ErrorStreamChanged += errorStreamChanged;

            if (exited != null)
                p.Exited += exited;

            if(arguments == null || arguments.Length == 0)
                p.StartInfo = new ProcessStartInfo (command);
            else
                p.StartInfo = new ProcessStartInfo (command, arguments);

            if(workingDirectory != null && workingDirectory.Length > 0)
                p.StartInfo.WorkingDirectory = workingDirectory;

            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.UseShellExecute = false;
            p.EnableRaisingEvents = true;

            p.Start ();
            return p;
        }
Esempio n. 30
0
 private static extern bool SetConsoleCtrlHandler(ProcessEventHandler handler, bool add);
Esempio n. 31
0
		public ProcessWrapper StartProcess (ProcessStartInfo startInfo, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited)
		{
			if (startInfo == null)
				throw new ArgumentException ("startInfo");
		
			ProcessWrapper p = new ProcessWrapper();

			if (outputStreamChanged != null) {
				startInfo.RedirectStandardOutput = true;
				p.OutputStreamChanged += outputStreamChanged;
			}
				
			if (errorStreamChanged != null) {
				startInfo.RedirectStandardError = true;
				p.ErrorStreamChanged += errorStreamChanged;
			}

			startInfo.CreateNoWindow = true;
			p.StartInfo = startInfo;
			ProcessEnvironmentVariableOverrides (p.StartInfo);
			
			// FIXME: the bug is long gone, but removing the hacks in ProcessWrapper w/o bugs will be tricky
			// WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process"
			// Process leaks when an exit event is registered
			// instead we use another thread to monitor I/O and wait for exit
			// if (exited != null)
			// 	p.Exited += exited;
			// p.EnableRaisingEvents = true;
			
			Counters.ProcessesStarted++;
			p.Start ();

			if (exited != null)
				p.Task.ContinueWith (t => exited (p, EventArgs.Empty), Runtime.MainTaskScheduler);

			return p;
		}
Esempio n. 32
0
		ProcessWrapper StartProcess (string name, string args, ProcessEventHandler outputLog, ProcessEventHandler errorLog)
		{
			var psi = new ProcessStartInfo (name, args) {
				UseShellExecute = false,
			};
			if (outputLog != null)
				psi.RedirectStandardOutput = true;
			if (errorLog != null)
				psi.RedirectStandardError = true;
			psi.EnvironmentVariables["PATH"] = pathOverride;
			return Runtime.ProcessService.StartProcess (psi, outputLog, errorLog, null);
		}
Esempio n. 33
0
		public IProcessAsyncOperation ForwardPort (AndroidDevice device, int devicePort, int localPort,
			ProcessEventHandler outputLog, ProcessEventHandler errorLog)
		{
			var args = string.Format ("-s {0} forward tcp:{1} tcp:{2}", device.ID, localPort, devicePort);
			return StartProcess (AdbExe, args, outputLog, errorLog);
		}
Esempio n. 34
0
 private void Form2_Load(object sender, EventArgs e)
 {
     resultView  = new ProcessEventHandler(Current);
     checkThread = new Thread(getCPU_Info);
     checkThread.Start();
 }
Esempio n. 35
0
		public ProcessWrapper LogCat (AndroidDevice device, ProcessEventHandler outputLog,
			ProcessEventHandler errorLog)
		{
			var args = string.Format ("-s {0} logcat", device.ID);
			return StartProcess (AdbExe, args, outputLog, errorLog);
		}