Esempio n. 1
0
        public ICommand CreateCommand(string commandName, IEngine engine)
        {
            ICommand command = null;

            Commands name;

            bool isValidCommandName = System.Enum.TryParse(commandName, out name);

            if (!isValidCommandName)
            {
                throw new ArgumentException("Invalid command name!");
            }

            switch (name)
            {
            case Commands.Add:
                command = new AddCommand(engine);
                break;

            case Commands.Create:
                command = new CreateCommand(engine);
                break;

            case Commands.Remove:
                command = new RemoveCommand(engine);
                break;

            case Commands.Print:
                command = new PrintCommand(engine);
                break;
            }

            return(command);
        }
 private void OnSelectedAccountChanged()
 {
     _accountDetailsViewModel.Account = SelectedAccount;
     CurrentViewModel = _accountDetailsViewModel;
     EditCommand.RaiseCanExecuteChanged();
     RemoveCommand.RaiseCanExecuteChanged();
 }
 public CodeGenerationMigrationAppService(
     AddCommand addCommand,
     RemoveCommand removeCommand)
 {
     _addCommand    = addCommand;
     _removeCommand = removeCommand;
 }
Esempio n. 4
0
    public void Run(string[] args)
    {
        ProjectCommandLineApplication userJwts = new(_reporter)
        {
            Name = "dotnet user-jwts"
        };

        userJwts.HelpOption("-h|--help");

        // dotnet user-jwts list
        ListCommand.Register(userJwts);
        // dotnet user-jwts create
        CreateCommand.Register(userJwts);
        // dotnet user-jwts print ecd045
        PrintCommand.Register(userJwts);
        // dotnet user-jwts remove ecd045
        RemoveCommand.Register(userJwts);
        // dotnet user-jwts clear
        ClearCommand.Register(userJwts);
        // dotnet user-jwts key
        KeyCommand.Register(userJwts);

        // Show help information if no subcommand/option was specified.
        userJwts.OnExecute(() => userJwts.ShowHelp());

        try
        {
            userJwts.Execute(args);
        }
        catch (Exception ex)
        {
            _reporter.Error(ex.Message);
        }
    }
}
Esempio n. 5
0
        private void btnRemove_Click(object sender, EventArgs e)//button remove
        {
            if (root == null)
            {
                return;
            }
            if (nodeSelected == null)
            {
                return;
            }
            if (nodeSelected.getID() == 0)
            {
                return;
            }
            TreeNode[] nodeTreeviewEdit = root.Nodes.Find(nodeSelected.getID().ToString(), true);
            var        macro            = new MacroCommand();

            remove = new RemoveCommand(ref mapNode, nodeSelected, ref root, nodeTreeviewEdit[0], this);
            macro.Add(remove);
            Manager.Execute(macro);



            mainTreeView.Nodes.Clear();
            mainTreeView.Nodes.Add(root);
            root.Expand();

            mainTreeView.SelectedNode = root;
        }
Esempio n. 6
0
 /// <summary>
 /// Check the commands' enabled state
 /// </summary>
 private void CheckCommands()
 {
     RunCommand.RaiseCanExecuteChanged();
     RemoveCommand.RaiseCanExecuteChanged();
     RunReportCommand.RaiseCanExecuteChanged();
     RunExportCommand.RaiseCanExecuteChanged();
 }
Esempio n. 7
0
        public void AddTwoRemoveOneCorrectly_WhenUsingRemoveCommand(IProduct product1, IProduct product2)
        {
            // Arrange
            var addProduct1Command = new AddCommand(_ProductList, product1);

            _productInvoker.AddCommand("addproduct1", addProduct1Command);

            var addProduct2Command = new AddCommand(_ProductList, product2);

            _productInvoker.AddCommand("addproduct2", addProduct2Command);

            var removeProduct2Command = new RemoveCommand(_ProductList, product2);

            _productInvoker.AddCommand("removeproduct2", removeProduct2Command);

            // Act
            _productInvoker.InvokeCommand("addproduct1");
            _productInvoker.InvokeCommand("addproduct2");
            _productInvoker.InvokeCommand("removeproduct2");

            // Assert
            _ProductList.Products.Should().NotBeNullOrEmpty()
            .And
            .HaveCount(1)
            .And
            .OnlyHaveUniqueItems()
            .And
            .NotContain(product2)
            .And
            .Contain(product1);
        }
Esempio n. 8
0
        public void InsertLink(string s, Link link)
        {
            _nextInputInline = null;

            if (!_selection.IsEmpty)
            {
                var index  = _selection.Offset;
                var remove = new RemoveCommand(_target, _selection.Offset, _selection.Length);
                _executor.Execute(remove);
                ReflectExecutedRange(remove);
            }

            var inserting = default(Run);

            if (_nextInputInline != null)
            {
                inserting        = _nextInputInline;
                inserting.Text   = s;
                inserting.Link   = link;
                _nextInputInline = null;
            }
            else
            {
                inserting = new Run(s, link);
            }

            var insert = new InsertInlineCommand(_target, _caretIndex, inserting);

            _executor.Execute(insert);
            ReflectExecutedRange(insert);
        }
Esempio n. 9
0
        // --- insert ---
        public void Insert(string s)
        {
            if (!_selection.IsEmpty)
            {
                var index = _selection.Offset;
                var cmd   = new RemoveCommand(_target, _selection.Offset, _selection.Length);
                _executor.Execute(cmd);
                ReflectExecutedRange(cmd);
            }

            if (_nextInputInline != null)
            {
                _nextInputInline.Text = s;
                var cmd = new InsertInlineCommand(_target, _caretIndex, _nextInputInline);
                _executor.Execute(cmd);
                ReflectExecutedRange(cmd);
                _nextInputInline = null;
            }
            else
            {
                var cmd = new InsertStringCommand(_target, _caretIndex, s);
                _executor.Execute(cmd);
                ReflectExecutedRange(cmd);
            }
        }
Esempio n. 10
0
        public void CallsRemoveWhenRemoveCommand()
        {
            RemoveCommand removeCommand = new RemoveCommand();

            _controllerFixture.Controller.Execute(removeCommand);
            _controllerFixture.Remove.Verify(x => x.Execute(It.IsAny <string>()), Times.Once);
        }
Esempio n. 11
0
        private string InterpredCommand(string[] data, string commandName)
        {
            Command addCmd    = new AddCommand(data, repository, unitFactory);
            Command reportcmd = new ReportCommand(data, repository, unitFactory);
            Command removecmd = new RemoveCommand(data, repository, unitFactory);
            string  result    = string.Empty;

            if (commandName == "fight")
            {
                Environment.Exit(0);
            }
            switch (commandName)
            {
            case "add":
                return(addCmd.Execute());

            case "report":
                return(reportcmd.Execute());

            case "fight":
                Environment.Exit(0);
                break;

            case "retire":
                return(removecmd.Execute());

            default:
                throw new InvalidOperationException("Invalid command!");
            }
            return(result);
        }
Esempio n. 12
0
        //删除
        public virtual async Task <Unit> Handle(RemoveCommand <TEntity> message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                await NotifyValidationErrorsAsync(message);

                return(await Task.FromResult(new Unit()));
            }

            if (await ExistsByIdAsync(message.Id))
            {
                await CommandRepository.RemoveAsync(message.Id);
            }
            else
            {
                //通过领域事件发布 错误 通知
                await Bus.RaiseEvent(new DomainNotification(DomainHandlerType.Remove, DomainNotificationType.Error, "", $"{typeof(TEntity).Name} 不存在该Id {message.Id}!", message.Id));

                return(await Task.FromResult(new Unit()));
            }

            if (await CommitAsync())
            {
                //通过领域事件发布 通知
                await Bus.RaiseEvent(new DomainNotification(DomainHandlerType.Remove, DomainNotificationType.Success, "", $"{typeof(TEntity).Name} 删除成功", message.Id));
            }
            return(await Task.FromResult(new Unit()));
        }
 private void OnRemove(object sender, RoutedEventArgs e)
 {
     if (RemoveCommand != null && RemoveCommandParametr != null)
     {
         RemoveCommand.Execute(RemoveCommandParametr);
     }
 }
        /// <summary>
        /// Initialize the view model.
        /// </summary>
        /// <param name="config">AdcpSubsystemConfig for this view model.</param>
        /// <param name="configVM">Adcp Configuration view model.</param>
        public AdcpSubsystemConfigurationViewModel(AdcpSubsystemConfig config, AdcpConfigurationViewModel configVM)
            : base(string.Format("Subsystem Configuration {0}", config.ToString()))
        {
            ConfigKey = config.ToString();
            ConfigVM  = configVM;

            // Initialize values
            _events = IoC.Get <IEventAggregator>();
            _pm     = IoC.Get <PulseManager>();

            // Get the predictor from the selected project subsystem configuration
            // Create the VM
            //Predictor = config.Predictor as AdcpPredictor;
            //Predictor = _pm.SelectedProject.Configuration.SubsystemConfigDict[ConfigKey].Predictor as AdcpPredictor;
            CalcPrediction();
            RangeVM = new AdcpRangePlannerViewModel(PredictedProfileRange, PredictedBottomRange);

            // Update the properties with the latest values
            UpdateProperties();

            // Remove configuration command
            RemoveCommand = ReactiveCommand.Create();
            RemoveCommand.Subscribe(_ => OnRemoveCommand());

            // Edit the configuration command
            EditCommand = ReactiveCommand.Create();
            EditCommand.Subscribe(param => OnEditCommand(param));
        }
Esempio n. 15
0
        // ReSharper restore NotAccessedField.Local

        public CodeExplorerViewModel(
            RubberduckParserState state,
            RemoveCommand removeCommand,
            IConfigProvider <GeneralSettings> generalSettingsProvider,
            IConfigProvider <WindowSettings> windowSettingsProvider,
            IUiDispatcher uiDispatcher,
            IVBE vbe,
            ITemplateProvider templateProvider,
            ICodeExplorerSyncProvider syncProvider)
        {
            _state = state;
            _state.StateChanged       += HandleStateChanged;
            _state.ModuleStateChanged += ParserState_ModuleStateChanged;

            _externalRemoveCommand   = removeCommand;
            _generalSettingsProvider = generalSettingsProvider;
            _windowSettingsProvider  = windowSettingsProvider;
            _uiDispatcher            = uiDispatcher;
            _vbe = vbe;
            _templateProvider = templateProvider;

            CollapseAllSubnodesCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCollapseNodes, EvaluateCanSwitchNodeState);
            ExpandAllSubnodesCommand   = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteExpandNodes, EvaluateCanSwitchNodeState);
            ClearSearchCommand         = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteClearSearchCommand);
            if (_externalRemoveCommand != null)
            {
                RemoveCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRemoveCommand, _externalRemoveCommand.CanExecute);
            }

            OnPropertyChanged(nameof(Projects));

            SyncCodePaneCommand = syncProvider.GetSyncCommand(this);
            // Force a call to EvaluateCanExecute
            OnPropertyChanged(nameof(SyncCodePaneCommand));
        }
Esempio n. 16
0
        public void TestNullSourceFilePath()
        {
            string        src = null;
            RemoveCommand rmc = new RemoveCommand(src);

            Assert.Throws <ArgumentNullException>(() => rmc.Execute());
        }
Esempio n. 17
0
        private static bool RunCommands()
        {
            ICommand cmd = new HelpCommand();

            if (!string.IsNullOrEmpty(ArgSettings.Help))
            {
                cmd = new HelpCommand();
            }
            else if (ArgSettings.List)
            {
                cmd = new ListCommand();
            }
            else if (ArgSettings.Remove)
            {
                cmd = new RemoveCommand();
            }
            else if (ArgumentsHelper.IsValidUri(ArgSettings.Source) &&
                     ArgumentsHelper.IsValidUri(ArgSettings.Destination) &&
                     ArgumentsHelper.IsValidAzureConnection(ArgSettings.SourceConnection))
            {
                cmd = new CopyCommand();
            }
            else if (ArgumentsHelper.IsValidUri(ArgSettings.Source) &&
                     ArgumentsHelper.IsValidFileSystemPath(ArgSettings.Destination))
            {
                cmd = new DownloadCommand();
            }
            else if (ArgumentsHelper.IsValidFileSystemPath(ArgSettings.Source) &&
                     ArgumentsHelper.IsValidUri(ArgSettings.Destination))
            {
                cmd = new UploadCommand();
            }

            return(cmd.Execute());
        }
 private void RemoveState()
 {
     _numberOfStates--;
     _triggerStateDataModels.Remove(_triggerStateDataModels.Last());
     ObservableTriggerStates.Refresh();
     RemoveCommand.RaiseCanExecuteChanged();
 }
        public void It_should_run_and_remove_a_FeatureBit()
        {
            // Arrange
            var sb = new StringBuilder();

            SystemContext.ConsoleWriteLine = s => sb.Append(s);
            var opts = new RemoveOptions {
                Name = "foo"
            };
            var repo = Substitute.For <IFeatureBitsRepo>();

            repo.GetByNameAsync("foo").Returns(Task.FromResult((IFeatureBitDefinition) new CommandFeatureBitDefintion {
                Name = "foo", Id = 5
            }));
            repo.RemoveAsync(Arg.Any <IFeatureBitDefinition>());
            var it = new RemoveCommand(opts, repo);

            // Act
            var result = it.RunAsync().Result;

            // Assert
            result.Should().Be(0);
            repo.Received().GetByNameAsync("foo");
            repo.Received().RemoveAsync(Arg.Any <IFeatureBitDefinition>());
            sb.ToString().Should().Be("Feature bit removed.");
        }
 private void AddState()
 {
     _numberOfStates++;
     _triggerStateDataModels.Add(new TriggerStateDataModel(_avalibleSignals, _numberOfStates));
     ObservableTriggerStates.Refresh();
     RemoveCommand.RaiseCanExecuteChanged();
 }
        /// <summary>
        /// Add a input file.
        /// </summary>
        /// <param name="file">The path of the file</param>
        public async Task AddInputFile(string file)
        {
            switch (OutOfProcessHelper.TestSourceFile(file))
            {
            //File is corrupt pdf.
            case OutOfProcessHelper.SourceTestResult.Unreadable:
                //Tell the user the pdf is corrupt.
                Application.Current.Dispatcher.BeginInvoke(new Action(() => ((MetroWindow)Application.Current.MainWindow).ShowMessageAsync("The file " + Path.GetFileName(file) + " could not be opened as a PDF or image", "Some thing went wrong when opening " + Path.GetFileName(file))));
                break;

            //File is a valid pdf.
            case OutOfProcessHelper.SourceTestResult.Ok:
                //Add the pdf to the ListBox.
                Application.Current.Dispatcher.Invoke(new Action(() => Files.Add(new PDFItem(file, null))));
                break;

            //File is a image (maybe not valid!).
            case OutOfProcessHelper.SourceTestResult.Image:
                break;
            }
            //Update Commands
            Application.Current.Dispatcher.Invoke(() => MergeCommand.RaiseCanExecuteChanged());
            MoveUpCommand.RaiseCanExecuteChanged();
            MoveDownCommand.RaiseCanExecuteChanged();
            Application.Current.Dispatcher.Invoke(() => RemoveCommand.RaiseCanExecuteChanged());
        }
Esempio n. 22
0
 public ModuleManagementInstallerAppService(
     AddCommand addCommand,
     RemoveCommand removeCommand)
 {
     _addCommand    = addCommand;
     _removeCommand = removeCommand;
 }
        public MainWindowViewModel(IMainWindowModel model)
        {
            if (model is null)
            {
                return;
            }

            _disposables = new CompositeDisposable();
            _model       = model;
            if (_model is IDisposable disposableModel)
            {
                _disposables.Add(disposableModel);
            }

            StartupShortcuts = _model.StartupShortcuts
                               .Select(x => x?.Select(i => new ShortcutForDisplay(i)).ToList())
                               .ToReadOnlyReactivePropertySlim(new List <ShortcutForDisplay>())
                               .AddTo(_disposables);

            AddCommand
            .Subscribe(AddShortcut)
            .AddTo(_disposables);

            RemoveCommand
            .Subscribe(RemoveShortcut)
            .AddTo(_disposables);

            OpenExplorerCommand
            .Subscribe(OpenExplorer)
            .AddTo(_disposables);
        }
Esempio n. 24
0
        public void TestNonexistentFileRemoval()
        {
            string        fileSource = Path.Combine(TestConstants.TestDirectory, "a");
            RemoveCommand rmc        = new RemoveCommand(fileSource);

            Assert.DoesNotThrow(() => rmc.Execute());
        }
Esempio n. 25
0
        public void TestInvalidSourceFilePath()
        {
            string        src = TestConstants.TestDirectory + "/\0.txt";
            RemoveCommand rmc = new RemoveCommand(src);

            Assert.Throws <ArgumentException>(() => rmc.Execute());
        }
Esempio n. 26
0
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation
        #region Package Members

        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            await base.InitializeAsync(cancellationToken, progress);

            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Transform
                var menuCommandId  = new CommandID(GuidList.guidConfigurationTransformCmdSet, (int)PkgCmdIDList.cmdidAddConfigTransforms);
                var oleMenuCommand = new OleMenuCommand(MenuItemCallback, null, BeforeQueryStatus, menuCommandId);
                mcs.AddCommand(oleMenuCommand);

                // Preview
                var previewCommandId      = new CommandID(GuidList.guidConfigurationTransformCmdSet, (int)PkgCmdIDList.cmdidPreviewConfigTransforms);
                var previewOleMenuCommand = new OleMenuCommand(PreviewMenuItemCallback, null, PreviewBeforeQueryStatus, previewCommandId);
                mcs.AddCommand(previewOleMenuCommand);

                // Remove
                RemoveCommand.Create(this, GuidList.ProjectMenuGroupCmdSet, (int)PkgCmdIDList.RemoveCommandId);
            }
        }
        public IEnumerable <ICommand> GetCommands()
        {
            var commands = new List <ICommand>();

            foreach (var line in ReadLines())
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                ICommand command = null;
                switch (line.Split()[0])
                {
                case "ADD":
                    command = new AddCommand(line);
                    break;

                case "REMOVE":
                    command = new RemoveCommand(line);
                    break;

                case "QUERY":
                    command = new QueryCommand(line);
                    break;
                }
                if (command != null)
                {
                    commands.Add(command);
                }
            }
            return(commands);
        }
Esempio n. 28
0
 protected override void OnPropertyChanged(string propertyName)
 {
     base.OnPropertyChanged(propertyName);
     if (propertyName == "CanSave")
     {
         SaveCommand.RaiseCanExecuteChanged();
     }
     else if (propertyName == "CanCancel")
     {
         CancelCommand.RaiseCanExecuteChanged();
     }
     else if (propertyName == "CanDelete")
     {
         DeleteCommand.RaiseCanExecuteChanged();
     }
     else if (propertyName == "CanRemove")
     {
         RemoveCommand.RaiseCanExecuteChanged();
     }
     else if (propertyName == "CanAddNew")
     {
         AddCommand.RaiseCanExecuteChanged();
     }
     else if (propertyName == "IsBusy")
     {
         RefreshCommands();
     }
 }
Esempio n. 29
0
        private static async Task <int> RunRemoveAndReturnExitCode(RemoveOptions opts)
        {
            var repo   = GetCorrectRepository(opts);
            var cmd    = new RemoveCommand(opts, repo);
            int result = await cmd.RunAsync();

            return(result);
        }
        public void It_can_be_created()
        {
            var opts = new RemoveOptions();
            var repo = Substitute.For <IFeatureBitsRepo>();
            var it   = new RemoveCommand(opts, repo);

            it.Should().NotBeNull();
        }
Esempio n. 31
0
        public PortfolioViewModel(IStockQuoteProvider quoteProvider)
        {
            _quoteProvider = quoteProvider;
            _stockModels = new ObservableCollection<StockModel>();
            _stockModels.Add(new StockModel("MSFT", _quoteProvider));

            _addCommand = new AddCommand(this);
            _removeCommand = new RemoveCommand(this);
        }
Esempio n. 32
0
 public static void GenerateAndRunTestCases(string command, int itemIdToChange, string expectedResultMessage, string message)
 {
     GGList originalList = new GGList();
     AddOriginalDataToList(originalList);
     GGList expectedList = new GGList();
     CreateExpectedList(expectedList, itemIdToChange);
     RemoveCommand rmCommand = new RemoveCommand();
     GGResult actualResult = rmCommand.Execute(command, originalList);
     Assert.AreEqual(expectedList, originalList, message);
     Assert.AreEqual(expectedResultMessage, actualResult.GetNotice(), "result message");
 }