private void buttonAddMissing_Click(object sender, EventArgs e)
        {
            var commandCollector = new CommandCollector {
                Path = CommandExecutor.Path
            };                                                                         // Represent all changes in a single undo step

            try
            {
                using (var handler = new GuiTaskHandler(this))
                    CheckDigest(handler, commandCollector);
            }
            #region Error handling
            catch (OperationCanceledException)
            {
                return;
            }
            catch (ArgumentException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (IOException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (UnauthorizedAccessException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (WebException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (NotSupportedException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
                return;
            }
            #endregion

            finally
            {
                var command = commandCollector.BuildComposite();
                if (CommandExecutor == null)
                {
                    command.Execute();
                }
                else
                {
                    CommandExecutor.Execute(command);
                }
            }

            _labelUpdateHint.Visible = false;
        }
Esempio n. 2
0
    private async Task <IActionResult> ProcessCommandAsync(IDurableClient durableClient, ICommand command, IAsyncCollector <ICommand> commandQueue, IAsyncCollector <string> commandMonitor, ILogger log)
    {
        var commandHandler   = commandHandlers.FirstOrDefault(handler => handler.CanHandle(command));
        var commandCollector = new CommandCollector(commandQueue, command);

        if (commandHandler is null)
        {
            return(new BadRequestResult());
        }
        else
        {
            ICommandResult commandResult = null;

            try
            {
                await commandAuditWriter
                .WriteAsync(command)
                .ConfigureAwait(false);

                if (commandHandler.Orchestration)
                {
                    _ = await durableClient
                        .StartNewAsync(nameof(CommandOrchestration), command.CommandId.ToString(), command)
                        .ConfigureAwait(false);

                    commandResult = await durableClient
                                    .GetCommandResultAsync(command)
                                    .ConfigureAwait(false);
                }
                else
                {
                    commandResult = await commandHandler
                                    .HandleAsync(command, commandCollector, null, log ?? NullLogger.Instance)
                                    .ConfigureAwait(false);

                    if (!commandResult.RuntimeStatus.IsFinal())
                    {
                        commandResult.RuntimeStatus = CommandRuntimeStatus.Completed;
                    }
                }

                if (commandResult is null)
                {
                    throw new NullReferenceException($"Unable to resolve result information for command {command.CommandId}");
                }
            }
            catch (Exception exc)
            {
                commandResult ??= command.CreateResult();
                commandResult.Errors.Add(exc);

                // there are some edge cases that affect our action result
                // by returning specific result objects / status codes:

                switch (exc)
                {
                case NotImplementedException notImplementedException:

                    // indicates something in the command's payload can't be processed

                    return(new BadRequestResult());

                case NotSupportedException notSupportedException:

                    // indicates a duplicate command (identified by id)

                    return(new System.Web.Http.ConflictResult());
                }
            }
            finally
            {
                if (commandResult.RuntimeStatus.IsFinal())
                {
                    await commandAuditWriter
                    .WriteAsync(command, commandResult)
                    .ConfigureAwait(false);
                }
                else
                {
                    await commandMonitor
                    .AddAsync(command.CommandId.ToString())
                    .ConfigureAwait(false);
                }
            }

            return(CreateCommandResultResponse(commandResult));
        }
    }
 protected virtual bool HasData()
 {
     return(CommandCollector.All().Any());
 }
Esempio n. 4
0
 public void Save()
 {
     //do not use AddCommand here as we only want to save the table without notifying any change events
     //since all changed were performed already
     CommandCollector.AddCommand(_parameterTask.SetParameterFomula(_tableParameter, EditedFormula));
 }