Пример #1
0
 protected virtual void InitializeEvents()
 {
     _process.OutputDataReceived += (sender, args) =>
     {
         if (args.Data != null)
         {
             OnOutputDataReceived?.Invoke(sender, args.Data);
         }
     };
     _process.ErrorDataReceived += (sender, args) =>
     {
         if (args.Data != null)
         {
             OnErrorDataReceived?.Invoke(sender, args.Data);
         }
     };
     _process.Exited += (sender, _) =>
     {
         if (sender is Process process)
         {
             OnExited?.Invoke(sender, process.ExitCode);
         }
         else
         {
             OnExited?.Invoke(sender, _process.ExitCode);
         }
     };
 }
 public Action <IReference> CreateOnExited(Action <IReference> onExited)
 {
     return((IReference reference) => {
         onExited?.Invoke(reference);
         OnExited?.Invoke(reference);
     });
 }
Пример #3
0
 /// <summary>
 /// 等待进程退出
 /// </summary>
 /// <param name="millisec">要等待的毫秒数,-1为无限等待</param>
 /// <param name="nativeWait">是否直接使用WaitForSingleObject等待</param>
 public int?WaitForExit(int millisec, bool nativeWait)
 {
     if (nativeWait)
     {
         int rslt = WaitForSingleObject(NativeProcessHandle.DangerousGetHandle(), millisec);
         ThrowExceptionByCode(rslt);
         if (GetExitCodeProcess(NativeProcessHandle.DangerousGetHandle(), out var exitCode))
         {
             if (exitCode == 0)
             {
                 OnExited?.Invoke(exitCode);
             }
             else
             {
                 OnExitCodeNonZero?.Invoke(exitCode);
             }
             NativeProcessHandle = null;
             return(exitCode);
         }
         OnExited?.Invoke(null);
         NativeProcessHandle = null;
         return(null);
     }
     CurrentProcess.WaitForExit(millisec);
     NativeProcessHandle = null;
     return(CurrentProcess.ExitCode);
 }
 private void Awake()
 {
     State.OnTransitionIn  += (_) => OnTransitionIn.Invoke();
     State.OnTransitionOut += (_) => OnTransitionOut.Invoke();
     State.OnEntered       += (_) => OnEntered.Invoke();
     State.OnExited        += (_) => OnExited.Invoke();
 }
        public async Task <int> ExecuteCommand(string command, string args, CancellationToken token)
        {
            var processInfo = new ProcessStartInfo(command, args);

            processInfo.CreateNoWindow         = true;
            processInfo.UseShellExecute        = false;
            processInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            processInfo.RedirectStandardError  = true;
            processInfo.RedirectStandardOutput = true;

            int exitCode;

            using (var process = new Process())
            {
                process.StartInfo = processInfo;

                process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
                                              OnConsoleRunnerDataReceived?.Invoke(sender, e.Data);

                process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
                                             OnConsoleRunnerErrorDataReceived?.Invoke(sender, e.Data);

                process.Exited += (object sender, EventArgs e) =>
                {
                    OnExited?.Invoke(sender, e);
                };

                try
                {
                    var processStarted = process.Start();

                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();

                    await Task.Run(() => process.WaitForExit(), token);

                    process.CancelOutputRead();
                    process.CancelErrorRead();
                }
                catch (OperationCanceledException ex)
                {
                    process.CancelOutputRead();
                    process.CancelErrorRead();
                    process.Kill();
                }
                finally
                {
                    exitCode = process.ExitCode;
                    process.Close();
                }
            }

            return(exitCode);
        }
Пример #6
0
        private void ThriftRpcProcess_Exited(object sender, EventArgs e)
        {
            Process proc = (Process)sender;

            if (proc.ExitCode == 0)
            {
                ThriftRpcLog.Info("Thrift RPC Agent has terminated with exit code 0");
            }
            else
            {
                ThriftRpcLog.Fatal($"Thrift RPC Agent has exited abnormally with exit code {proc.ExitCode}");
            }
            OnExited?.Invoke(this, EventArgs.Empty);
        }
Пример #7
0
        protected async Task HandleExitedAsync(IReference refback)
        {
            // No need for transitions when the component is hidden
            var transition = string.Empty;

            var styles = new Dictionary <string, object>
            {
                { "transition", transition },
                { "webkitTransition", transition }
            };

            await DomHelpers.SetStyleAsync(refback.Current, styles, trigger : false);

            OnExited?.Invoke(refback);
        }
Пример #8
0
        private void OnCompilerExited(object sender, EventArgs e)
        {
            // release process
            var cl = (Process)sender;

            if (cl.ExitCode == 0)
            {
                _compileErrors.Clear();
            }

            cl.OutputDataReceived -= OnCompilerOutputDataReceived;
            cl.ErrorDataReceived  -= OnCompilerOutputDataReceived;
            cl.Exited             -= OnCompilerExited;
            cl.Dispose();

            IsBusy = false;
            OnExited?.Invoke(_compileErrors, _compileWarnings);
        }
Пример #9
0
        public void DrawMenu()
        {
            OnEntered?.Invoke(this);
            MenuLogicHelper.CopyEvents(this);
            _needsRedraw = true;
            _open        = true;

            while (_open)
            {
                if (!_needsRedraw)
                {
                    //Only check the hashes if we are not already redrawing
                    _needsRedraw = HashHelper.NeedsToRedraw(_lastDrawnHash, this);
                }

                if (_needsRedraw)
                {
                    Console.Clear();
                    MenuLogicHelper.DrawContents(this);

                    _needsRedraw   = false;
                    _lastDrawnHash = HashHelper.MakeHash(this);
                }

                if (!Console.KeyAvailable)
                {
                    continue;
                }

                var key = Console.ReadKey(true);
                if (key.Key == ConsoleKey.Escape)
                {
                    break;
                }

                MenuLogicHelper.ProcessKey(this, key);
                _needsRedraw = true;
            }

            OnExited?.Invoke(this);
        }
        protected async Task PerformExit()
        {
            if (!(Exit.HasValue && Exit.Value))
            {
                Current = TransitionState.Exited;

                // TODO: need to check
                Next = TransitionState.None;

                await LocalStateHasChanged();

                await(OnExited?.Invoke(RefBack) ?? Task.CompletedTask);

                return;
            }

            Current = TransitionState.Exit;

            await LocalStateHasChanged();

            await(OnExit?.Invoke(RefBack) ?? Task.CompletedTask);

            Current = TransitionState.Exiting;

            await LocalStateHasChanged();

            await(OnExiting?.Invoke(RefBack) ?? Task.CompletedTask);

            await OnTransitionEnd(async() =>
            {
                Current = UnmountOnExit ? TransitionState.Unmounted : TransitionState.Exited;

                // TODO: need to check
                Next = TransitionState.None;

                await LocalStateHasChanged(force: UnmountOnExit);

                await(OnExited?.Invoke(RefBack) ?? Task.CompletedTask);
            }, TimeoutExit);
        }
Пример #11
0
 protected void HandleExited(IReference refback)
 {
     OnExited?.Invoke(refback);
 }
Пример #12
0
 protected virtual void RaiseOnExited()
 {
     OnExited?.Invoke();
 }
Пример #13
0
 protected void OnStop()
 {
     IsRunning = false;
     OnExited?.Invoke();
 }
Пример #14
0
 public void Exit()
 {
     OnExited?.Invoke();
 }
Пример #15
0
 public void Eject(T pieceToMove)
 {
     EjectInternal(pieceToMove);
     OnExited?.Invoke(pieceToMove);
 }
Пример #16
0
 private void Process_Exited(object sender, EventArgs e)
 {
     OnExited?.Invoke(this, process.ExitCode);
     Dispose();
 }