Пример #1
0
        public HomeViewModel(INavigationService navigationService,
                             ICommandFactory commandFactory)
        {
            this.navigationService = navigationService;

            NavigateToRecipesCommand     = commandFactory.CreateCommand(NavigateToRecipes);
            NavigateToIngredientsCommand = commandFactory.CreateCommand(NavigateToIngredients);
        }
Пример #2
0
        public RecipeListViewModel(RecipesFacade recipesFacade,
                                   ICommandFactory commandFactory,
                                   INavigationService navigationService)
        {
            this.recipesFacade     = recipesFacade;
            this.navigationService = navigationService;

            NavigateToDetailCommand = commandFactory.CreateCommand <Guid>(NavigateToDetail);
            NavigateToAddCommand    = commandFactory.CreateCommand(NavigateToAdd);
        }
Пример #3
0
        public RecipeViewModel(ISessionStateManager sessionStateManager, IViewModelRepository viewModelRepository, ICommandFactory commandFactory)
        {
            _sessionStateManager = sessionStateManager ?? throw new ArgumentNullException(nameof(sessionStateManager));
            _viewModelRepository = viewModelRepository ?? throw new ArgumentNullException(nameof(viewModelRepository));
            _commandFactory      = commandFactory ?? throw new ArgumentNullException(nameof(commandFactory));

            RetrieveIngredientsCommand = _commandFactory.CreateCommand(this, RetrieveIngredients);
            RemoveIngredientsCommand   = _commandFactory.CreateCommand(this, RemoveIngredients);
            AddIngredientCommand       = _commandFactory.CreateCommand(this, AddIngredient);
        }
Пример #4
0
        public IngredientListViewModel(IngredientsFacade ingredientsFacade,
                                       ICommandFactory commandFactory,
                                       INavigationService navigationService)
        {
            this.ingredientsFacade = ingredientsFacade;
            this.navigationService = navigationService;

            NavigateToDetailCommand = commandFactory.CreateCommand <Guid>(NavigateToDetail);
            NavigateToAddCommand    = commandFactory.CreateCommand(NavigateToAdd);
        }
Пример #5
0
 public IngredientEditViewModel(Guid?viewModelParameter,
                                IngredientsFacade ingredientsFacade,
                                ICommandFactory commandFactory,
                                INavigationService navigationService)
     : base(viewModelParameter)
 {
     this.ingredientsFacade = ingredientsFacade;
     this.navigationService = navigationService;
     CancelCommand          = commandFactory.CreateCommand(Cancel);
     SaveCommand            = commandFactory.CreateCommand(Save);
 }
Пример #6
0
        public IngredientDetailViewModel(Guid viewModelParameter,
                                         IngredientsFacade ingredientsFacade,
                                         ICommandFactory commandFactory,
                                         INavigationService navigationService)
            : base(viewModelParameter)
        {
            this.ingredientsFacade = ingredientsFacade;
            this.navigationService = navigationService;

            DeleteCommand         = commandFactory.CreateCommand(Delete);
            NavigateToEditCommand = commandFactory.CreateCommand(NavigateToEdit);
        }
Пример #7
0
        private void inputProvider_OnHover(object sender, EventArgs e)
        {
            var command = commandFactory.CreateCommand(CommandType.Hover);

            communicator.ExecuteCommand(command);
            if (OnCommandProcessed != null)
            {
                OnCommandProcessed(this, new ProcessedCommandArgs {
                    CommandType = CommandType.Hover
                });
            }
        }
Пример #8
0
        public RecipeDetailViewModel(Guid viewModelParameter,
                                     RecipesFacade recipesFacade,
                                     ICommandFactory commandFactory,
                                     INavigationService navigationService)
            : base(viewModelParameter)
        {
            this.recipesFacade     = recipesFacade;
            this.commandFactory    = commandFactory;
            this.navigationService = navigationService;

            DeleteCommand         = commandFactory.CreateCommand(Delete);
            NavigateToEditCommand = commandFactory.CreateCommand(NavigateToEdit);
        }
Пример #9
0
        public MainViewModel(ICommandFactory commandFactory)
        {
            _rootFolder = Folder = new FolderTree(null, "/:", this);

            PathFolders             = "/:";
            StartNameFolder         = "Папка";
            CreateRealFolderCommand = commandFactory.CreateCommand(CreateRealDirectory);
            HomeFolderCommand       = commandFactory.CreateCommand(o =>
            {
                Folder      = _rootFolder;
                PathFolders = _rootFolder.Name;
            });
        }
Пример #10
0
        /// <summary> Execute une requête SQL de type INSERT, UPDATE ou DELETE
        /// </summary>
        public bool ExecuteNonQuery()
        {
            DbCommand dbCommand = _commandFactory.CreateCommand(CommandType.Text);

            try
            {
                dbCommand.ExecuteNonQuery();
                return(true);
            }
            catch (Exception e)
            {
                ProcessException(e);
                return(false);
            }
        }
 public DerDieDasViewModel(ICommandFactory commandFactory, IDerDieDasTest derDieDasTest)
 {
     ParamValidator.EnsureParametersAreValid(new NullValidatorWithValue<ICommandFactory>(() => commandFactory, commandFactory),
                                             new NullValidatorWithValue<IDerDieDasTest>(() => derDieDasTest, derDieDasTest));
     _derDieDasTest = derDieDasTest;
     SpecifiedPlural = string.Empty;
     AllAvailableTests = new ObservableCollection<Test>();
     _submitCommand = commandFactory.CreateCommand(DoSubmit, CanSubmit);
     _restartTestCommand = commandFactory.CreateCommand(DoRestart, CanRestart);
     _aUmlaut = commandFactory.CreateCommand(DoAUmlaut, CanAUmlaut);
     _oUmlaut = commandFactory.CreateCommand(DoOUmlaut, CanOUmlaut);
     _uUmlaut = commandFactory.CreateCommand(DoUUmlaut, CanUUmlaut);
     _derDieDasTest.StartTest(new List<string>());
     LoadAvailableTests();
 }
Пример #12
0
        /// <summary>
        /// Tries to get the command given by its name and prints its help string to the output
        /// </summary>
        /// <param name="cmdName">Name of the command</param>
        private void PrintCommandHelp(string cmdName)
        {
            var cmd = commandFactory.CreateCommand(cmdName);

            if (cmd == null)
            {
                throw new InvalidCommandParameterException(
                          "help",
                          string.Format("The given command ({0}) does no exist", cmdName));
            }
            else
            {
                output.Message(cmd.Help);
                output.Message(GlobalParameters);
            }
        }
Пример #13
0
        public RecipeEditViewModel(Guid?viewModelParameter,
                                   RecipesFacade recipesFacade,
                                   IngredientsFacade ingredientsFacade,
                                   ICommandFactory commandFactory,
                                   INavigationService navigationService)
            : base(viewModelParameter)
        {
            this.recipesFacade     = recipesFacade;
            this.ingredientsFacade = ingredientsFacade;
            this.navigationService = navigationService;

            AddIngredientCommand    = commandFactory.CreateCommand(AddIngredient);
            RemoveIngredientCommand = commandFactory.CreateCommand <Guid>(RemoveIngredient);
            SaveCommand             = commandFactory.CreateCommand(Save);
            CancelCommand           = commandFactory.CreateCommand(Cancel);
        }
Пример #14
0
 public LineViewModel(IPointViewModel start, IPointViewModel finish,
     Action<PointTransit<ILineViewModel>> insertAction, ICommandFactory commandFactory)
 {
     Start = start;
     Finish = finish;
     InsertCommand = commandFactory.CreateCommand(o => insertAction(((PointTransit) o).Cast<ILineViewModel>()));
 }
Пример #15
0
        private void FillCollection <T>(ICollection <T> collection, PropertyMappings mappings) where T : new()
        {
            using (DbCommand command = commandFactory.CreateCommand())
            {
                IEntityAdapter adapter = new EntityAdapter(command)
                {
                    MissingPropertyMappingAction = MissingPropertyMappingAction.Ignore
                };

                if (mappings != null && mappings.Count > 0)
                {
                    adapter.Options.Mappings.Add(mappings);
                }
                adapter.FillCollection(collection);
            }
        }
Пример #16
0
        // Magic, do not touch!
        public ICommand ParseCommand(string fullCommand)
        {
            var commandName = fullCommand.Split(' ')[0];
            var command     = fact.CreateCommand(commandName);

            return(command);
        }
Пример #17
0
        public async Task <IActionResult> Post([FromBody] Command command)
        {
            var interpretation = _commandInterpreter.Interpret(command.CommandText);
            var commandInfo    = new CommandInfo
            {
                Command   = interpretation.Command,
                Subject   = interpretation.Subject,
                Modifiers = interpretation.Modifiers
            };
            var concreteCommand  = _commandFactory.CreateCommand(commandInfo);
            var validationResult = concreteCommand.Validate();

            if (!validationResult.IsValid)
            {
                return(Ok(new CommandExecutionResult
                {
                    Content = new DocumentPlainContent {
                        PlainText = validationResult.ValidationMessage
                    },
                    Type = CommandExecutionResultType.Warning
                }));
            }
            var result = await concreteCommand.ExecuteAsync();

            return(Ok(Convert(result)));
        }
        public bool RunResetNetworkCommand()
        {
            var success = false;

            try
            {
                var executableCommand = _factory.CreateCommand("resetnetwork");
                var executableResult  = executableCommand.Execute("nohostname");
                _logger.Log(executableResult.Output.Value());
                success = true;
            }
            catch (InvalidCommandException exception)
            {
                _logger.Log(exception.Message);
            }
            catch (UnsuccessfulCommandExecutionException exception)
            {
                var result = (ExecutableResult)exception.Data["result"];
                var output = "";
                var error  = "";
                if (result.Output != null && !string.IsNullOrEmpty(result.Output.Value()))
                {
                    output = ", Output:" + result.Output.Value();
                }
                if (result.Error != null && !string.IsNullOrEmpty(result.Error.Value()))
                {
                    error = ", Error:" + result.Error.Value();
                }

                _logger.Log(string.Format("{0}{1}{2}", exception.Message, output, error));
            }

            return(success);
        }
Пример #19
0
        public RegisterOrganisationViewModel(ISessionStateManager sessionStateManager, ICommandFactory commandFactory)
        {
            _sessionStateManager = sessionStateManager ?? throw new ArgumentNullException(nameof(_sessionStateManager));
            _commandFactory      = commandFactory ?? throw new ArgumentNullException(nameof(commandFactory));

            RegisterCommand = _commandFactory.CreateCommand(this, RegisterOrganisation);
        }
Пример #20
0
        public override IMenu ExecuteCommand()
        {
            if (CurrentOption.IsField)
            {
                string fieldInput =
                    " " + this.forumReader.ReadLine(CurrentOption.Position.Left + 1, CurrentOption.Position.Top);

                this.Buttons[currentIndex] = this.labelFactory.CreateButton(fieldInput, CurrentOption.Position,
                                                                            CurrentOption.IsHidden, CurrentOption.IsField);
                return(this);
            }

            try
            {
                string   commandName = string.Join("", CurrentOption.Text.Split());
                ICommand command     = commandFactory.CreateCommand(commandName);
                IMenu    view        = command.Execute(UsernameInput, PasswordInput);

                return(view);
            }
            catch (Exception e)
            {
                error = true;
                Open();

                return(this);
            }
        }
Пример #21
0
        /// <summary>
        /// Runs the application
        /// </summary>
        public void Run()
        {
            for (; ;)
            {
                try
                {
                    // Get command
                    _output.WriteLine(InsertCommand);
                    var message = _input.ReadLine();

                    // Log inserted command
                    _logger.LogInformation(string.Format(LogInsertedCommand, message));

                    // Execute command
                    var command = _commandFactory.CreateCommand(message);
                    command.Execute(_robot);
                }
                catch (InvalidCommandException ex)
                {
                    _logger.LogWarning(ex.Message);
                    _output.WriteLine(ex.Message);
                }
                catch (RobotException ex)
                {
                    _logger.LogWarning(ex.Message);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, ex.Message);
                    throw;
                }
            }
        }
Пример #22
0
        public override IMenu ExecuteCommand()
        {
            ICommand command = null;

            int actualIndex = this.currentPage * 10 + this.currentIndex;

            if (currentIndex > 0 && currentIndex <= 10)
            {
                command = commandFactory.CreateCommand("ViewCategoryMenu");
            }
            else
            {
                command = commandFactory.CreateCommand(string.Join("", this.CurrentOption.Text.Split()));
            }

            return(command.Execute(actualIndex.ToString()));
        }
Пример #23
0
        public override IMenu ExecuteCommand()
        {
            string   commandName = string.Join("", this.CurrentOption.Text.Split()) + "Menu";
            ICommand command     = commandFactory.CreateCommand(commandName);
            IMenu    view        = command.Execute();

            return(view);
        }
Пример #24
0
        public override IMenu ExecuteCommand()
        {
            var commandName = string.Join("", this.CurrentOption.Text.Split());
            var command     = commandFactory.CreateCommand(commandName);
            var menu        = command.Execute(this.postId.ToString());

            return(menu);
        }
Пример #25
0
        public ICommand ParseCommand(string fullCommand, ICommandFactory commandFactory)
        {
            Guard.WhenArgument(commandFactory, "Command factory in command parser cannot be null.").IsNull().Throw();
            Guard.WhenArgument(fullCommand, "Command`s name cannot be null or empty.").IsNullOrEmpty().Throw();
            string commandName = fullCommand.Split()[0];

            return(commandFactory.CreateCommand(commandName));
        }
Пример #26
0
        public void RunApplication()
        {
            var addNewCustomer = new AddNewCustomer {
                Name = "CustoerName1", Password = "******"
            };

            commandFactory.CreateCommand <AddNewCustomer>()
            .Execute(addNewCustomer);
        }
        private void ProcessCommand(Command command)
        {
            var removeMessageFromXenStore = true;

            try
            {
                var executableCommand = _factory.CreateCommand(command.name);
                ExecutableResult executableResult;

                if (hasPrePostCommandAttribute(executableCommand))
                {
                    executableResult = new PreAndPostCommandAttribute(_logger).Execute(executableCommand, command);
                }
                else
                {
                    executableResult = executableCommand.Execute(command.value);
                }

                WriteToXenStore(command.key, new Json <object>().Serialize(new { returncode = executableResult.ExitCode, message = executableResult.Output.Value() }));
            }
            catch (InvalidCommandException exception)
            {
                WriteToXenStore(command.key, new Json <object>().Serialize(new { returncode = "1", message = exception.Message }));
            }
            catch (UnsuccessfulCommandExecutionException exception)
            {
                var result = (ExecutableResult)exception.Data["result"];
                var output = "";
                var error  = "";
                if (result.Output != null && !string.IsNullOrEmpty(result.Output.Value()))
                {
                    output = ", Output:" + result.Output.Value();
                }
                if (result.Error != null && !string.IsNullOrEmpty(result.Error.Value()))
                {
                    error = ", Error:" + result.Error.Value();
                }
                WriteToXenStore(command.key, new Json <object>().Serialize(new
                {
                    returncode = result.ExitCode,
                    message    = exception.Message +
                                 output + error
                }));
            }
            catch (Exception ex)
            {
                removeMessageFromXenStore = false;
                _logger.Log(String.Format("Exception was : {0}\nStackTrace Was: {1}", ex.Message, ex.StackTrace));
            }
            finally
            {
                if (removeMessageFromXenStore)
                {
                    _store.Remove(command.key);
                }
            }
        }
Пример #28
0
        public override IMenu ExecuteCommand()
        {
            string   commandName = string.Join("", this.CurrentOption.Text.Split());
            ICommand command     = commandFactory.CreateCommand(commandName);
            IMenu    menu        = command.Execute(this.postId.ToString());

            this.viewEngine.ResetBuffer();

            return(menu);
        }
Пример #29
0
        //----------------------------------------------------------------//

        public async Task RunTask(TaskBase taskBase, IDbConnection connection)
        {
            bool isSuccess = await Task.Run(() => taskBase.SafeExecute(connection));

            if (isSuccess)
            {
                _commandFactory.CreateCommand <ITaskInfoCommand>(connection)
                .Update(taskBase.taskInfo);
            }
        }
Пример #30
0
        public ICommand ParseCommand(string fullCommand)
        {
            Guard.WhenArgument(fullCommand, "Full command").IsNullOrWhiteSpace().Throw();

            var commandTokens = fullCommand.Split();
            var commandName   = commandTokens[0].ToLower();

            var command = commandFactory.CreateCommand(commandName);

            return(command);
        }
        public RegisterRecipeViewModel(IViewModelRepository viewModelRepository, ISessionStateManager sessionStateManager, ICommandFactory commandFactory)
        {
            _viewModelRepository = viewModelRepository ?? throw new ArgumentNullException(nameof(viewModelRepository));
            _sessionStateManager = sessionStateManager ?? throw new ArgumentNullException(nameof(sessionStateManager));
            _commandFactory      = commandFactory ?? throw new ArgumentNullException(nameof(commandFactory));

            SeasonSelectionModelManager    = new ViewModelManager <SelectionViewModel <Season> >(CreateSeasonSelectionViewModel());
            IngredientTypeSelectionManager = new ViewModelManager <SelectionViewModel <IngredientCharacteristics> >(CreateIngredientCharacteristicSelectionViewModel());

            RegisterRecipeCommand = _commandFactory.CreateCommand(this, RegisterRecipe);
        }
        public string Read(string args)
        {
            string[] parts       = args.Split();
            string   commandType = parts[0];

            string[] commandArgs = parts.Skip(1).ToArray();

            ICommand command = commandFactory.CreateCommand(commandType);

            return(command.Execute(commandArgs));
        }
Пример #33
0
        private void SetCommandFromFactory(ICommandFactory commandFactory)
        {
            this.updatePriority = PriorityItem.CommandFactory;

            if (commandFactory == null || CommandProvider == null) {
                return;
            }

            if (CommandProvider.CommandFactories.Any((f) => AreCommandFactoriesEqual(f, commandFactory))) {
                this.updatePriority = PriorityItem.None;

                this.allowPropertyBehaviours = false;

                try {
                    var command = commandFactory.CreateCommand();
                    commandFactory.PopulateCommand(command, CommandProvider);

                    Command = command;
                } finally {
                    this.allowPropertyBehaviours = true;
                }
            }
        }
Пример #34
0
 public PointViewModel(double x, double y, 
     Action<IPointViewModel> deleteAction, ICommandFactory commandFactory) :
     base(x, y)
 {
     DeleteCommand = commandFactory.CreateCommand(() => deleteAction(this));
 }