Esempio n. 1
0
 /// <summary>
 /// Invokes a stored procedure
 /// </summary>
 /// <param name="name">name of the stored procedure</param>
 /// <param name="prms">parameters object</param>
 public void Invoke(string name, object prms = null)
 {
     using (var cmd = _commandFactory.Create(name, prms, true))
     {
         Mapper.ExecuteNonQuery(cmd);
     }
 }
Esempio n. 2
0
        public IObservable <UniRx.Unit> Run()
        {
            IUnitData[] unitDatas = _unitSpawnSettings.GetUnits(_data.unitCommandData.UnitType);
            if (_data.unitCommandData.UnitIndex >= unitDatas.Length)
            {
                string errorMsg = string.Format("Unit Index not in unit datas range: {0}",
                                                _data.unitCommandData.UnitIndex);
                _logger.LogError(LoggedFeature.Units, errorMsg);
                return(Observable.Throw <UniRx.Unit>(new IndexOutOfRangeException(errorMsg)));
            }

            IUnitData unitData = unitDatas[(int)_data.unitCommandData.UnitIndex];

            // First, spawn the pets recursively.
            // We create commands that we execute directly, because
            // we don't want to treat these as standalone commands (they are only ever children of this command)
            IUnit[] pets = new IUnit[_data.unitCommandData.pets.Length];
            for (var i = 0; i < _data.unitCommandData.pets.Length; i++)
            {
                SpawnUnitData petSpawnUnitData =
                    new SpawnUnitData(_data.unitCommandData.pets[i], _data.tileCoords, _data.isInitialSpawn);
                ICommand petSpawnCommand =
                    _commandFactory.Create(typeof(SpawnUnitCommand), typeof(SpawnUnitData), petSpawnUnitData);
                petSpawnCommand.Run();
                pets[i] = _unitRegistry.GetUnit(_data.unitCommandData.pets[i].unitId);
            }

            // Now, spawn the unit itself.
            IUnit unit = _unitPool.Spawn(_data.unitCommandData.unitId, unitData, pets);

            _gridUnitManager.PlaceUnitAtTile(unit, _data.tileCoords);

            _logger.Log(LoggedFeature.Units, "Spawned: {0}. Id: {1}", unitData.Name, unit.UnitId);
            return(Observable.ReturnUnit());
        }
        public ConfirmationDialogViewModel(ICommandFactory commandFactory, IMessenger messenger)
        {
            this.messenger = messenger;

            OkButtonClick     = commandFactory.Create(OnOkButtonClick);
            CancelButtonClick = commandFactory.Create(OnCancelButtonClick, (o) => IsOkCancelMode);
        }
        public PasswordGenerationViewModel(
            ICommandFactory commandFactory,
            IMessenger messenger,
            IGenerator <string, PasswordGenerationParameters> generator)
        {
            this.messenger = messenger;
            this.generator = generator;

            ConfirmButtonClick  = commandFactory.Create(OnConfirmButtonClick);
            BackButtonClick     = commandFactory.Create(OnBackButtonClick);
            GenerateButtonClick = commandFactory.Create(OnGenerateButtonClick);

            LengthValues = new List <int>();
            PopulateLength();

            Parameters = new PasswordGenerationParameters
            {
                Length = LengthValues.Find(x => x == 16),
                IncludeSpecialCharacters   = false,
                IncludeNumericCharacters   = true,
                IncludeLowerCaseCharacters = true,
                IncludeUpperCaseCharacters = true,
                ExcludeSimilarCharacters   = true,
                ExcludeAmbiguousCharacters = true
            };
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Parameters)));
        }
Esempio n. 5
0
 public void AddBike(string name, decimal hourCost)
 {
     _commandFactory.Create <AddNewBikeCommandContext>().Execute(
         new AddNewBikeCommandContext()
     {
         HourCost = hourCost,
         Name     = name
     });
 }
        public AuthenticationViewModel(IUserService userService, ICommandFactory commandFactory, IMessenger messenger)
        {
            this.userService = userService;
            this.messenger   = messenger;

            RegisterButtonClick = commandFactory.Create(OnRegistrationButtonClick);
            LogInButtonClick    = commandFactory.Create(OnLogInButtonClick);

            AddValidation();
        }
        public AccountFormViewModel(IUserService userService, ICommandFactory commandFactory, IMessenger messenger)
        {
            this.userService = userService;
            this.messenger = messenger;

            SaveButtonClick = commandFactory.Create(OnSaveButtonClick);
            BackButtonClick = commandFactory.Create(OnBackButtonClick);
            GenerateButtonClick = commandFactory.Create(OnGenerateButtonClick);

            AddValidation();
        }
Esempio n. 8
0
        public void AddEmployee(AddEmployeeParameters parameters)
        {
            if (parameters.NewEmployee == null)
            {
                throw new InvalidParameterException();
            }

            var addEmployeeCommand = commandFactory.Create <AddEmployeeCommand>();

            addEmployeeCommand.Execute(parameters.NewEmployee, parameters.Dependents);
        }
        private void OnStateChangeRequested <T>(SetupSecurityRequestMessage <T> message)
        {
            BackButtonClick = commandFactory.Create((obj) =>
            {
                OnBackButtonClick(message);
            });

            ConfirmButtonClick = commandFactory.Create((obj) =>
            {
                OnConfirmButtonClick(message);
            });
        }
        public TResult Execute <TCriteria, TResult>(TCriteria criteria)
        {
            var command = _commandFactory.Create <ICommand <TCriteria, TResult> >();

            try
            {
                return(command.Execute(criteria));
            }
            finally
            {
                _commandFactory.Release(command);
            }
        }
Esempio n. 11
0
        public KeyChangeViewModel(IUserService userService, ICommandFactory commandFactory, IMessenger messenger)
        {
            this.userService = userService;
            this.messenger   = messenger;

            SaveButtonClick             = commandFactory.Create(OnSaveButtonClick);
            SecuritySettingsButtonClick = commandFactory.Create(OnSecuritySettingsButtonClick);
            BackButtonClick             = commandFactory.Create(OnBackButtonClick);

            storageProvider = new DefaultStorageProvider();

            AddValidation();
        }
        public SecuritySettingsViewModel(ICommandFactory commandFactory, IMessenger messenger, IViewModelFactory viewModelFactory)
        {
            this.commandFactory   = commandFactory;
            this.messenger        = messenger;
            this.viewModelFactory = viewModelFactory;

            storageProvider = new ConfigurableStorageProvider();

            RunOneSecondSetupButtonClick = commandFactory.Create(OnRunOneSecondSetupButtonClickAsync);
            RunTestButtonClick           = commandFactory.Create(OnRunTestButtonClick);

            SelectedEncryptionAlg = EncryptionAlgorithms.Aes256CbcHmacSha512;
            SelectedKdf           = KeyTransformations.Pbkdf2;
        }
Esempio n. 13
0
        public MainViewModel(
            IUserService userService,
            IViewModelFactory factory,
            ICommandFactory commandFactory,
            IMessenger messenger,
            IWindowStorage <ViewModelBase> windowStorage)
        {
            this.userService   = userService;
            this.factory       = factory;
            this.messenger     = messenger;
            this.windowStorage = windowStorage;

            CloseCommand         = commandFactory.Create(OnClose);
            QuitCommand          = commandFactory.Create(OnQuit);
            OpenCommand          = commandFactory.Create(OnOpen);
            StateChangedCommand  = commandFactory.Create(OnStateChanged);
            MenuButtonClick      = commandFactory.Create(OnHideMenu);
            SettingsButtonClick  = commandFactory.Create(OnSettingsClick);
            KeyChangeButtonClick = commandFactory.Create(OnKeyChangeClick);
            LogOutButtonClick    = commandFactory.Create(OnLogOut);

            OnChangeView(new SwitchViewMessage
            {
                NextView = typeof(AuthenticationViewModel)
            });
        }
Esempio n. 14
0
 public T Get(long id)
 {
     using (var cmd = _commandFactory.Create(SqlGenerator.GetSelectByIdQuery(), new { id }))
     {
         return(Mapper.GetObject <T>(cmd));
     }
 }
        public UserSettingsViewModel(
            IUserService userService,
            ICommandFactory commandFactory,
            IMessenger messenger,
            IStartupService startupService)
        {
            this.userService    = userService;
            this.messenger      = messenger;
            this.startupService = startupService;

            SaveButtonClick = commandFactory.Create(OnSaveButtonClick);
            BackButtonClick = commandFactory.Create(OnBackButtonClick);
            Settings        = new Settings(User.Settings);
        }
        public IObservable <Unit> Run()
        {
            IUnit unit = _unitRegistry.GetUnit(_data.unitId);

            if (unit == null)
            {
                _logger.LogError(LoggedFeature.Units,
                                 "MoveUnitSectionCommand called on unit not in registry: {0}",
                                 _data.unitId);
                return(Observable.Empty <Unit>());
            }

            uint?unitIndex = _unitDataIndexResolver.ResolveUnitIndex(unit.UnitData);

            if (unitIndex == null)
            {
                _logger.LogError(LoggedFeature.Units,
                                 "Failed to resolve unit index: {0}",
                                 _data.unitId);
                return(Observable.Empty <Unit>());
            }

            _despawnCommand =
                _commandFactory.Create <DespawnUnitCommand, DespawnUnitData>(new DespawnUnitData(_data.unitId));
            _despawnCommand.Run();

            var sectionLoadedSubject = new Subject <Unit>();
            var commandData          =
                new LoadMapSectionCommandData(_data.toSectionIndex, new LoadMapCommandData(_mapStoreId.index));
            ICommand loadMapSectionCommand =
                _commandFactory.Create <LoadMapSectionCommand, LoadMapSectionCommandData>(commandData);

            loadMapSectionCommand.Run().Subscribe(_ => {
                // We need to wait 1 frame in order to avoid race conditions between listeners on new section
                Observable.IntervalFrame(1).First().Subscribe(__ => {
                    IntVector2 entryTileCoords =
                        _entryTileFinder.GetEntryTile(_data.toSectionIndex, _data.fromSectionIndex);
                    // We don't spawn pets (which also are not despawn on despawn command)
                    var unitCommandData = new UnitCommandData(unit.UnitId, unitIndex.Value, unit.UnitData.UnitType);
                    var spawnUnitData   = new SpawnUnitData(unitCommandData, entryTileCoords, isInitialSpawn: false);
                    _spawnCommand       = _commandFactory.Create <SpawnUnitCommand, SpawnUnitData>(spawnUnitData);
                    _spawnCommand.Run();

                    sectionLoadedSubject.OnNext(Unit.Default);
                });
            });

            return(sectionLoadedSubject);
        }
Esempio n. 17
0
        public void AddEmployee_ShouldCreateAddEmployeeCommand()
        {
            var employeeController = GetEmployeeController();

            A.CallTo(() => fakeCommandFactory.Create <AddEmployeeCommand>()).Returns(new AddEmployeeCommand(A.Fake <IDapperHub>(), A.Fake <ICommandFactory>())
            {
                Execute = (employee, dependents) => {}
            });

            employeeController.AddEmployee(new AddEmployeeParameters {
                NewEmployee = new Employee(), Dependents = new List <Dependents>()
            });

            A.CallTo(() => fakeCommandFactory.Create <AddEmployeeCommand>()).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 18
0
        public void Execute_ShouldCallDapperBeginGetAllAndCommit()
        {
            var employeeCommand = GetAddEmployeeCommand();

            A.CallTo(() => fakeCommandFactory.Create <AddDependentsCommand>()).Returns(new AddDependentsCommand(A.Fake <IDapperHub>())
            {
                Execute = employee => { }
            });

            employeeCommand.Execute(A <Employee> ._, A <IEnumerable <Dependents> > ._);

            A.CallTo(() => fakeDapperHub.BeginTransaction()).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => fakeDapperHub.Insert(A <Employee> ._)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => fakeDapperHub.CommitTransaction()).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 19
0
        private void OnDragDrop(object sender, DragEventArgs dragEventArgs, ICommandFactory commandFactory)
        {
            //point they are dragged over
            var editor = ((Scintilla)sender);

            if (editor.ReadOnly)
            {
                return;
            }

            var clientPoint = editor.PointToClient(new Point(dragEventArgs.X, dragEventArgs.Y));
            //get where the mouse is hovering over
            int pos = editor.CharPositionFromPoint(clientPoint.X, clientPoint.Y);

            var command = commandFactory.Create(dragEventArgs);

            if (command == null)
            {
                return;
            }

            //if it has a Form give it focus
            var form = editor.FindForm();

            if (form != null)
            {
                form.Activate();
                editor.Focus();
            }

            editor.InsertText(pos, command.GetSqlString());
        }
Esempio n. 20
0
        public IDbCommand GetNewCommand(CommandType commandType = CommandType.Text)
        {
            var cmd = _commandFactory.Create();

            cmd.CommandType = commandType;
            return(cmd);
        }
Esempio n. 21
0
        private ICommand CreateTestRunnerCommand()
        {
            var commandArgs = _argumentsBuilder.BuildArguments();

            return(_commandFactory.Create(
                       $"dotnet-{_testRunner}",
                       commandArgs));
        }
Esempio n. 22
0
        public void Dispatch <TCommand>(TCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command),
                                                "Command can not be null.");
            }

            var commandFactory = _factory.Create <TCommand>();

            if (commandFactory == null)
            {
                throw new InvalidOperationException($"Handler {nameof(commandFactory)} can not be null");
            }

            commandFactory.Handle(command);
        }
Esempio n. 23
0
        private void OnDragEnter(object sender, DragEventArgs dragEventArgs, ICommandFactory commandFactory)
        {
            var command = commandFactory.Create(dragEventArgs);

            if (command != null)
            {
                dragEventArgs.Effect = DragDropEffects.Copy;
            }
        }
Esempio n. 24
0
    public static void Main(string[] argv)
    {
        // this is the only line that is really dependent of a specific
        // implementation.
        _commandFactory = new TheSpecificImplementationAssembly.CommandFactory();

        ICommand command = _commandFactory.Create("CreateUser");

        command.Execute();
    }
Esempio n. 25
0
 public int RunTests(DotnetTestParams dotnetTestParams)
 {
     return(_commandFactory.Create(
                _testRunnerNameResolver.ResolveTestRunner(),
                GetCommandArgs(dotnetTestParams),
                _framework,
                dotnetTestParams.Config)
            .Execute()
            .ExitCode);
 }
Esempio n. 26
0
        public async Task RunAsync()
        {
            var inputCommand = _commandFactory.Create("input");

            Console.WriteLine("[+] " + inputCommand.Name);
            var task = inputCommand.RunAsync(_commandFactory.CancellationTokenSource.Token);

            _tasks.Add(task);
            _commands.Add(inputCommand);
            _taskCommands.Add(task, inputCommand);

            while (_tasks.Count > 0)
            {
                task = await Task.WhenAny(_tasks);

                try
                {
                    string result = await task;
                    inputCommand = _taskCommands[task];
                    Console.WriteLine("[-] " + inputCommand.Name);

                    if (!string.IsNullOrEmpty(result))
                    {
                        Console.WriteLine("[=] " + result);
                    }

                    var commands = inputCommand.Continuations(result, _commandFactory);
                    foreach (var command in commands)
                    {
                        Console.WriteLine("[+] " + command.Name);
                        Task <string> runTask = command.RunAsync(_commandFactory.CancellationTokenSource.Token);
                        _tasks.Add(runTask);
                        _commands.Add(command);
                        _taskCommands.Add(runTask, command);
                    }

                    _tasks.Remove(task);
                    _commands.Remove(_taskCommands[task]);
                    _taskCommands.Remove(task);
                }
                catch (TaskCanceledException)
                {
                    var command = _taskCommands[task];
                    Console.WriteLine("[-] " + inputCommand.Name);
                    Console.WriteLine("[X] " + inputCommand.Name);
                    if (_commands.Contains(command))
                    {
                        _commands.Remove(command);
                    }
                    _tasks.Remove(task);
                    _taskCommands.Remove(task);
                }
            }
        }
Esempio n. 27
0
        public ProcessResponse Process(ProcessRequest request)
        {
            var response = new ProcessResponse();

            foreach (var command in _commandFactory.Create(request.CommandType))
            {
                response.Messages.Add(command.Process(request));
            }

            return(response);
        }
Esempio n. 28
0
        private object ConstructCommand(IOwinContext context)
        {
            var commandType = GetCommandType(context);
            var command     = commandFactory.Create(commandType, context.Environment);

            if (command == null)
            {
                throw new EmptyCommandBodyException(commandType);
            }

            return(command);
        }
Esempio n. 29
0
        public void Creates_listcommands_command_when_null_arguments_passed(ICommandFactory commandFactory,
                                                                            ICraneCommand craneCommand)
        {
            "Given I have a command factory"
            ._(() => commandFactory = ServiceLocator.Resolve <ICommandFactory>());

            "When I create a command with no arguments"
            ._(() => craneCommand = commandFactory.Create(null));

            "Then the command returned should be the list commands command"
            ._(() => craneCommand.Should().BeOfType <ListCommands>());
        }
Esempio n. 30
0
        private void Execute(List <string> args)
        {
            string commandName = string.Empty;

            if (args.Count >= 1 && Regex.IsMatch(args[0], "^[a-z]+$"))
            {
                commandName = args[0];
                args.RemoveAt(0); // Remove the argument we just used
            }

            // Attempt to find the command for the name
            CommandDescriptor commandDescriptor = commandRegistry.GetDescriptor(commandName, null);

            if (commandDescriptor == null)
            {
                throw new Exception(string.Format("Command '{0}' is not recognized.", commandName));
            }

            // Determine if this is a call for a sub command
            while (args.Count >= 1 && Regex.IsMatch(args[0], "^[a-z]+$"))
            {
                commandName = args[0];
                var subCommandDescriptor = commandRegistry.GetDescriptor(commandName, commandDescriptor);
                if (subCommandDescriptor == null)
                {
                    break;
                }

                commandDescriptor = subCommandDescriptor;
                args.RemoveAt(0); // Remove the argument we just used
            }

            // Create an instance of the required command
            ICommand command = commandFactory.Create(commandDescriptor.CommandType);

            // Parse the arguments and apply them to the command
            if (args.Count > 0)
            {
                foreach (IArgumentParser argumentParser in argumentParsers)
                {
                    argumentParser.Apply(args, command, commandDescriptor);
                }

                // Ensure that all the arguments have been parsed
                if (args.Count > 0)
                {
                    throw new Exception(string.Format("Unsupported argument '{0}'.", args[0]));
                }
            }

            // Execute the code of the command
            command.Execute();
        }