private void MakePrimaryStatRequest()
        {
            _uiStateController.IncUiLock();

            _uiThreadInvoker.Dispatch(() => DataAvailable = false);
            _primaryStatRequestCommand.Execute(null);
        }
示例#2
0
        /// <summary>
        /// Executes a CommandChain from the beginning.
        /// </summary>
        /// <param name="commandChain"></param>
        /// <param name="onlyIFinallyCommands">indicates errors, if true only finally commands are executed. If an finally command throws an exceptions, remaining finally commands are still executed.</param>
        protected virtual void Execute(IList <ICommandContainer> commandChain, bool onlyIFinallyCommands, CommandRegistryFinishedCallback registryFinishedCallback = null)
        {
            if (commandChain.Count < 1)
            {
                String error = "It is not allowed to call execute with a command-chain of size zero.";
                Log.Error(error);
                throw new ArgumentException(error);
            }
            ICommandContainer commandContainer = commandChain[0];

            if (onlyIFinallyCommands)
            {
                if (!(commandContainer.Command is IFinallyCommand))
                {
                    ExecuteRecursion(commandChain, onlyIFinallyCommands, registryFinishedCallback);
                    return;
                }
            }
            ICommand command          = commandContainer.Command;
            Object   commandParameter = commandContainer.CommandParameter;

            if ((command is IAsyncCommand) || ((command is CommandRegistry) && ((CommandRegistry)command).IsAsync))
            {
                // The command works asynchronously, thus we must wait until all operations initiated by the command
                // are finished, before we can go on with the next command.
                // Therefore, we acquire a unique Id to identify the async command and we associate the index of the
                // following command with this index.
                IAsyncCommand asyncCommand = (IAsyncCommand)command;

                long processSequenceId = AcquireCommand();

                // The async command is called with the NextCommand delegate:
                asyncCommand.Execute(commandParameter, delegate(bool success)
                {
                    //commandChain, processSequenceId and onlyIFinallyCommands are stored (closure).
                    AsyncExecuteRecursion(commandChain, processSequenceId, success, onlyIFinallyCommands, registryFinishedCallback);
                });
                return;
            }

            // The command works synchronously, thus we can directly proceed with the next command:
            try
            {
                command.Execute(commandParameter);
            }
            catch (Exception ex)
            {
                Log.Warn("Execution of the command '" + command.GetType().Name + "' with parameter '" + commandParameter.GetType().Name + "' lead to the following exception: " + ex);
                onlyIFinallyCommands = true;
            }
            ExecuteRecursion(commandChain, onlyIFinallyCommands, registryFinishedCallback);
        }
示例#3
0
        public static async Task ExecuteAsync(this IAsyncCommand command, object parameter, bool throwOnError = false)
        {
            command.Execute(parameter);
            var task = command.Task;

            if (task != null)
            {
                try
                {
                    await task;
                }
                catch (Exception)
                {
                    if (throwOnError)
                    {
                        throw;
                    }
                }
            }
        }
示例#4
0
        /// <inheritdoc cref="IAsyncCommandMediary.CommandAsync{TContext,TResult}"/>
        public virtual Task <TResult> CommandAsync <TContext, TResult>(IAsyncCommand <TContext, TResult> command, TContext context, CancellationToken cancellationToken = default)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(Decorator.Decorate(GetOperationName(command, nameof(command.Execute)), () => command.Execute(context, cancellationToken)));
        }