Exemplo n.º 1
0
 public CommandResult Handle(CommandDescriptor descriptor)
 {
     try
     {
         var commandType = _typeDiscoverer.GetCommandTypeByName(descriptor.GeneratedFrom);
         var command = (ICommand)_serializer.FromJson(commandType, descriptor.Command);
         command.Id = descriptor.Id;
         _commandContextConnectionManager.Register(Context.ConnectionId, command.Id);
         var commandResult = _commandCoordinator.Handle(command);
         return commandResult;
     }
     catch (Exception ex)
     {
         return new CommandResult { 
             Exception = ex, 
             ExceptionMessage = string.Format("Exception occured of type '{0}' with message '{1}'. StackTrace : {2}",ex.GetType().Name,ex.Message,ex.StackTrace)
         };
     }
 }
Exemplo n.º 2
0
        public CommandResult Handle(ICommand command)
        {
            var validationResults = new ObservableCollection<ValidationResult>();
            var commandValidationMessages = new ObservableCollection<string>();
            var commandResult = new CommandResult();
            commandResult.CommandName = command.Name;
            commandResult.ValidationResults = validationResults;
            commandResult.CommandValidationMessages = commandValidationMessages;

            if( !command.GetType().Equals(typeof(Command)) )
                CopyPropertyValuesToParameters(command);

            var descriptor = new CommandDescriptor
            {
                Id = Guid.NewGuid(),
                Name = command.Name,
                Command = _serializer.ToJson(command.Parameters),
                GeneratedFrom = command.GetType().FullName
            };
            _commands[descriptor.Id] = command;
            command.IsBusy = true;
            command.IsProcessing = true;
            _proxy.Handle(descriptor).ContinueWith(a =>
            {
                foreach (var commandValidationMessage in a.Result.CommandValidationMessages)
                    commandValidationMessages.Add(commandValidationMessage);
                foreach (var validationResult in a.Result.ValidationResults)
                    validationResults.Add(validationResult);

                commandResult.Exception = a.Result.Exception;
                commandResult.ExceptionMessage = a.Result.ExceptionMessage;

                command.IsBusy = false;

                if( command is INotifyCommandResultsReceived ) 
                    ((INotifyCommandResultsReceived)command).OnCommandResultsReceived(descriptor.Id, commandResult);
            });

            return commandResult;
        }