Ejemplo n.º 1
0
        private static Task <ICommandResult> RunProcess(ProcessStartInfo startInfo, int timeout)
        {
            var tcs = new TaskCompletionSource <ICommandResult>();

            void ReturnResult(ICommandResult result)
            {
                tcs.SetResult(result);
            }

            using (Process process = new Process())
            {
                process.Exited += (sender, eventArgs) =>
                {
                    int              exitCode  = process.ExitCode;
                    string           stdOut    = process.StandardOutput.ReadToEnd();
                    string           stdErr    = process.StandardError.ReadToEnd();
                    CommandErrorType errorType = exitCode == 0 ? CommandErrorType.None : CommandErrorType.ExecutionError;
                    ReturnResult(new CommandResult
                    {
                        ErrorType      = errorType,
                        ExitCode       = exitCode,
                        StandardError  = stdErr,
                        StandardOutput = stdOut
                    });
                };

                process.EnableRaisingEvents = true;
                process.StartInfo           = startInfo;

                if (!process.Start())
                {
                    ReturnResult(new CommandResult()
                    {
                        ErrorType = CommandErrorType.StartError
                    });
                }

                if (!process.WaitForExit(timeout))
                {
                    ReturnResult(new CommandResult()
                    {
                        ErrorType = CommandErrorType.TimeOutError
                    });
                    process.EnableRaisingEvents = false;
                    process.StandardOutput.Dispose();
                    process.StandardError.Dispose();
                    process.Kill();
                }
            }

            return(tcs.Task);
        }
Ejemplo n.º 2
0
 public CommandHandleStatus(
     CommandErrorType errorType,
     string errorSummary = null,
     IEnumerable <KeyValuePair <string, string> > errorFields = null,
     string systemError      = null,
     DomainError domainError = null)
 {
     ErrorType    = errorType;
     ErrorSummary = errorSummary;
     DomainError  = domainError;
     ErrorFields  = errorFields ?? new List <KeyValuePair <string, string> >();
     SystemError  = systemError ?? string.Empty;
 }
Ejemplo n.º 3
0
 private void OnCommandError(CommandErrorType errorType, CommandEventArgs args, Exception ex = null)
 => CommandErrored(this, new CommandErrorEventArgs(errorType, args, ex));
Ejemplo n.º 4
0
 private void OnCommandError(CommandErrorType errorType, CommandEventArgs args, Exception ex = null)
     => CommandErrored(this, new CommandErrorEventArgs(errorType, args, ex));
Ejemplo n.º 5
0
 public CommandErrorEventArgs(CommandErrorType errorType, CommandEventArgs baseArgs, Exception ex)
     : base(baseArgs.Message, baseArgs.Command, baseArgs.Args)
 {
     Exception = ex;
     ErrorType = errorType;
 }
 public CommandErrorEventArgs(CommandErrorType errorType, CommandEventArgs baseArgs, Client client, Exception ex)
     : base(baseArgs.Message, baseArgs.Command, client, baseArgs.Args)
 {
     Exception = ex;
     ErrorType = errorType;
 }
Ejemplo n.º 7
0
 private async Task OnCommandError(CommandErrorType errorType, CommandEventArgs args, Exception ex = null)
 => await _commandErrored.InvokeAsync(new CommandErrorEventArgs(errorType, args, ex)).ConfigureAwait(false);
Ejemplo n.º 8
0
 public CommandErrorEventArgs(CommandErrorType errorType, string error)
 {
     ErrorType = errorType;
     Error     = error;
 }
Ejemplo n.º 9
0
 private void RaiseCommandError(CommandErrorType errorType, CommandEventArgs args, Exception ex = null)
 {
     if (CommandError != null)
         CommandError(this, new CommandErrorEventArgs(errorType, args, ex));
 }
 public void CommandError(string topic, CommandErrorType code)
 {
     _logWrapper.LogError("failed to publish to" + topic);
 }
Ejemplo n.º 11
0
 protected virtual void OnCommandError(CommandErrorType errorType, string error)
 {
     CommandError?.Invoke(this, new CommandErrorEventArgs(errorType, error));
 }