public void Target_Command_CallCount_Is_Zero_After_Initialization_Of_CommandBinder() { var source = new MockEventSource(); var target = new MockViewModelWithAction(); var binder = new CommandBinder<MockEventArgs>(source, "MockEvent", target.Command); binder.Bind(); Assert.AreEqual(0, target.Command.CallCount); }
public void Source_Is_Enabled_When_Target_ICommand_CanExecute_Is_True_During_Initialization() { var source = new MockEventSource(); var target = new MockViewModelWithAction(); var binder = new CommandBinder<MockEventArgs>(source, "MockEvent", target.Command); binder.Bind(); Assert.IsTrue(source.IsEnabled); }
protected override void ExecuteAfterBindings() { InjectorBinder.Bind <Queries>().To <Queries>().ToSingleton(); InjectorBinder.Bind <Database>().To <Database>().ToSingleton(); CommandBinder.Bind <StartApp>() .To <StartModules>() .InSequence(); }
public void Target_Command_Is_Executed_When_Source_Event_Is_Raised_And_Command_Is_Enabled() { var source = new MockEventSource(); var target = new MockViewModelWithAction(); var binder = new CommandBinder<MockEventArgs>(source, "MockEvent", target.Command); binder.Bind(); source.RaiseMockEvent("foo"); Assert.AreEqual(1, target.Command.CallCount); }
protected override void ExecuteAfterBindings() { InjectorBinder.Bind <ProjectsHolder>().To <ProjectsHolder>().ToSingleton(); InjectorBinder.Bind <Queries>().To <Queries>().ToSingleton(); CommandBinder.Bind <StartApp>() .To <SetupCommand>() .InSequence(); }
public void Source_Is_Disabled_When_Target_Command_Becomes_Disabled() { var source = new MockEventSource(); var target = new MockViewModelWithAction(); var binder = new CommandBinder<MockEventArgs>(source, "MockEvent", target.Command); target.Command.MaxCalls = 1; binder.Bind(); source.RaiseMockEvent("foo"); Assert.IsFalse(source.IsEnabled); }
private void CreateAndBindCommands() { _fillStructurePopupOpenCommand = new Command(miFillFromSchema_Click); _subscriptions.Add(CommandBinder.Bind(miFillFromSchema, _fillStructurePopupOpenCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.FillStructure, x => miFillFromSchema.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiAddStructureItem, _controller.AddStructureItemCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddStructureItem, x => tsmiAddStructureItem.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsbStructureAdd, _controller.AddStructureItemCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddStructureItem, x => tsbStructureAdd.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsbStructureDelete, _controller.DeleteStructureItemCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.DeleteStructureItem, x => tsbStructureDelete.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiDeleteStructureItem, _controller.DeleteStructureItemCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.DeleteStructureItem, x => tsmiDeleteStructureItem.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsbMetadataLoadAll, _controller.LoadContainerCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.LoadEntireContainer, x => tsbMetadataLoadAll.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsbMetadataDelete, _controller.DeleteMetadataItemCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.DeleteMetadataItem, x => tsbMetadataDelete.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiDeleteSchema, _controller.DeleteMetadataItemCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.DeleteMetadataItem, x => tsmiDeleteSchema.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(miAddLinkedServer, _controller.AddLinkedServerCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddServer, x => miAddLinkedServer.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiAddLinkedServer, _controller.AddLinkedServerCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddServer, x => tsmiAddLinkedServer.Visible = x)); _subscriptions.Add(CommandBinder.Bind(miAddDatabase, _controller.AddDatabaseCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddDatabase, x => miAddDatabase.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiAddDatabase, _controller.AddDatabaseCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddDatabase, x => tsmiAddDatabase.Visible = x)); _subscriptions.Add(CommandBinder.Bind(miAddSchema, _controller.AddSchemaCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddSchema, x => miAddSchema.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiAddSchema, _controller.AddSchemaCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddSchema, x => tsmiAddSchema.Visible = x)); _subscriptions.Add(CommandBinder.Bind(miAddPackage, _controller.AddPackageCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddPackage, x => miAddPackage.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiAddPackage, _controller.AddPackageCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddPackage, x => tsmiAddPackage.Visible = x)); _subscriptions.Add(CommandBinder.Bind(miAddTable, _controller.AddTableCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddTable, x => miAddTable.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiAddTable, _controller.AddTableCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddTable, x => tsmiAddTable.Visible = x)); _subscriptions.Add(CommandBinder.Bind(miAddView, _controller.AddViewCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddView, x => miAddView.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiAddView, _controller.AddViewCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddView, x => tsmiAddView.Visible = x)); _subscriptions.Add(CommandBinder.Bind(miAddProcedure, _controller.AddProcedureCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddProcedure, x => miAddProcedure.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiAddProcedure, _controller.AddProcedureCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddProcedure, x => tsmiAddProcedure.Visible = x)); _subscriptions.Add(CommandBinder.Bind(miAddSynonym, _controller.AddSynonymCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddSynonym, x => miAddSynonym.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiAddSynonym, _controller.AddSynonymCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddSynonym, x => tsmiAddSynonym.Visible = x)); _subscriptions.Add(CommandBinder.Bind(miAddField, _controller.AddFieldCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddField, x => miAddField.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiAddField, _controller.AddFieldCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddField, x => tsmiAddField.Visible = x)); _subscriptions.Add(CommandBinder.Bind(miAddForeignKey, _controller.AddForeignKeyCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddForeignKey, x => miAddForeignKey.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiAddForeignKey, _controller.AddForeignKeyCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.AddForeignKey, x => tsmiAddForeignKey.Visible = x)); _subscriptions.Add(CommandBinder.Bind(byNameToolStripMenuItem, _controller.SortSchemaByNameCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.SortByName, x => byNameToolStripMenuItem.Visible = x)); _subscriptions.Add(CommandBinder.Bind(byTypeToolStripMenuItem, _controller.SortSchemaByTypeCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.SortByType, x => byTypeToolStripMenuItem.Visible = x)); _subscriptions.Add(CommandBinder.Bind(tsmiMoveToTopContainer, _controller.MoveUpSchemaCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.MoveToTop, x => tsmiMoveToTopContainer.Visible = x)); _subscriptions.Add(CommandBinder.Bind(tsmiMoveToBotContainer, _controller.MoveDownSchemaCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.MoveToBottom, x => tsmiMoveToBotContainer.Visible = x)); _subscriptions.Add(CommandBinder.Bind(tsmiSortStructureByName, _controller.SortStructureByNameCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.SortByName, x => tsmiSortStructureByName.Visible = x)); _subscriptions.Add(CommandBinder.Bind(tsmiSortStructureByType, _controller.SortStructureByTypeCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.SortByType, x => tsmiSortStructureByType.Visible = x)); _subscriptions.Add(CommandBinder.Bind(tsmiMoveStructureToTop, _controller.MoveUpStructureCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.MoveToTop, x => tsmiMoveStructureToTop.Visible = x)); _subscriptions.Add(CommandBinder.Bind(tsmiMoveStructureToBot, _controller.MoveDownStructureCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.MoveToBottom, x => tsmiMoveStructureToBot.Visible = x)); _subscriptions.Add(CommandBinder.Bind(miClear, _controller.ClearSchemaCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.ClearChildItems, x => miClear.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(miStructureClear, _controller.ClearStructureCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.ClearChildItems, x => miStructureClear.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(miStructureLoadAll, _controller.CreateStructureChildsCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.CreateChildStructure, x => miStructureLoadAll.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(miLoadAll, _controller.LoadSchemaChildsCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.LoadChildItems, x => miLoadAll.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiConnectAndLoad, _controller.ConnectAndLoadCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.ConnectAndLoadChilds, x => tsmiConnectAndLoad.Enabled = x)); _subscriptions.Add(ActiveQueryBuilder.View.WinForms.Images.Common.Add.Subscribe(x => tsddbAdd.Image = x)); }
protected override void ExecuteAfterBindings() { InjectorBinder.Bind <ProjectsHolder>().To <ProjectsHolder>().ToSingleton(); InjectorBinder.Bind <Queries>().To <Queries>().ToSingleton(); InjectorBinder.Bind <XmlDataLoader>().To <XmlDataLoader>().ToSingleton(); CommandBinder.Bind <StartApp>() .To <CleanUpCommand>() .To <SetupCommand>() .To <ConvertToXElementCommand>() .InSequence(); }
protected override void ExecuteAfterBindings() { InjectorBinder.Bind <EntityFactory>().To <EntityFactory>().ToSingleton(); InjectorBinder.Bind <IEntityManager>().To <EntityManager>().ToSingleton(); InjectorBinder.Bind <World>().To <World>().ToSingleton(); InjectorBinder.Bind <EntityMoving>().ToSingleton(); InjectorBinder.Bind <EntityAttacking>().ToSingleton(); InjectorBinder.Bind <EntityHealing>().ToSingleton(); CommandBinder.Bind <StartApp>() .To <SetupEntityVariantsCommand>() .To <CreateEnvironmentCommand>() .To <CreateRandomEntitiesCommand>() .InSequence(); }
private void BindCommands() { _addIncludeCommand = new Command(tsbAdd_Click); _addExcludeCommand = new Command(tsbAddExclude_Click); _deleteIncludeCommand = new Command(tsbDelete_Click); _deleteExcludeCommand = new Command(tsbDeleteExclude_Click); _editIncludeCommand = new Command(tsbEditInclude_Click); _editExcludeCommand = new Command(tsbEditExclude_Click); _subscriptions.Add(CommandBinder.Bind(tsbAddInclude, _addIncludeCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.Add, x => tsbAddInclude.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsbAddExclude, _addExcludeCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.Add, x => tsbAddExclude.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsbDeleteInclude, _deleteIncludeCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.Delete, x => tsbDeleteInclude.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsbDeleteExclude, _deleteExcludeCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.Delete, x => tsbDeleteExclude.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsbEditInclude, _editIncludeCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.Edit, x => tsbEditInclude.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsbEditExclude, _editExcludeCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.Edit, x => tsbEditExclude.Enabled = x)); }
private void BindCommands() { _addIncludeCommand = new Command(tsbAdd_Click); _addExcludeCommand = new Command(tsbAddExclude_Click); _deleteIncludeCommand = new Command(tsbDelete_Click); _deleteExcludeCommand = new Command(tsbDeleteExclude_Click); _editIncludeCommand = new Command(tsbEditInclude_Click); _editExcludeCommand = new Command(tsbEditExclude_Click); _subscriptions.Add(CommandBinder.Bind(MenuItemIncludeAdd, _addIncludeCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.Add, x => MenuItemIncludeAdd.IsEnabled = x, false)); _subscriptions.Add(CommandBinder.Bind(MenuItemExcludeAdd, _addExcludeCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.Add, x => MenuItemExcludeAdd.IsEnabled = x, false)); _subscriptions.Add(CommandBinder.Bind(MenuItemIncludeRemove, _deleteIncludeCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.Delete, x => MenuItemIncludeRemove.IsEnabled = x, false)); _subscriptions.Add(CommandBinder.Bind(MenuItemExcludeRemove, _deleteExcludeCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.Delete, x => MenuItemExcludeRemove.IsEnabled = x, false)); _subscriptions.Add(CommandBinder.Bind(MenuItemIncludeEdit, _editIncludeCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.Edit, x => MenuItemIncludeEdit.IsEnabled = x, false)); _subscriptions.Add(CommandBinder.Bind(MenuItemExcludeEdit, _editExcludeCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.Edit, x => MenuItemExcludeEdit.IsEnabled = x, false)); }
public ModelingDesigner() { this._blocks = new BlockControlCollection(); this._relations = new BlockRelationCollection(); this._blocks.CollectionChanged += OnBlocksChanged; this._relations.CollectionChanged += OnRelationsChanged; //默认添加几个命令。 CommandBinder.Bind <DeleteBlockCommand>(this); CommandBinder.Bind <SelectAllCommand>(this); CommandBinder.Bind <OpenODMLCommand>(this); CommandBinder.Bind <SaveODMLCommand>(this); CommandBinder.Bind <RestoreODMLCommand>(this); CommandBinder.Bind <HideRelationCommand>(this); //CommandBinder.Bind<ToggleHiddenRelationsCommand>(this);//不易用。 }
private void CreateAndBindCommands() { _importContainerCommand = new Command(btnImportMetadataFromXml_Click); _exportContainerCommand = new Command(btnExportMetadataToXml_Click); _importStructureCommand = new Command(btnImportStructureFromXml_Click); _exportStructureCommand = new Command(btnExportStructureToXml_Click); _previewCommand = new Command(BtnPreview_Click); _stopLoadingCommand = new Command(metadataEditorControl.StopLoading); _subscriptions.Add(CommandBinder.Bind(tsmiExportContainer, _exportContainerCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.ExportContainer, x => tsmiExportContainer.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiImportContainer, _importContainerCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.ImportContainer, x => tsmiImportContainer.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiExportStructure, _exportStructureCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.ExportStructure, x => tsmiExportStructure.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(tsmiImportStructure, _importStructureCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.ImportStructure, x => tsmiImportStructure.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(btnPreview, _previewCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.Preview, x => btnPreview.Enabled = x)); _subscriptions.Add(CommandBinder.Bind(btnStop, _stopLoadingCommand, ActiveQueryBuilder.View.WinForms.Commands.MetadataEditor.StopLoading, x => btnStop.Enabled = x)); }
public static T Bind <T>(IEnumerable <string> args, Action <Configurator> action) where T : CommandSettings, new() { // Configure var configurator = new Configurator(null); action(configurator); // Parse command tree. var parser = new CommandTreeParser(CommandModelBuilder.Build(configurator)); var result = parser.Parse(args); // Bind the settings to the tree. CommandSettings settings = new T(); CommandBinder.Bind(result.Tree, ref settings, new TypeResolverAdapter(null)); // Return the settings. return((T)settings); }
private static Task <int> Execute( CommandTree leaf, CommandTree tree, CommandContext context, ITypeResolver resolver, IConfiguration configuration) { // Bind the command tree against the settings. var settings = CommandBinder.Bind(tree, leaf.Command.SettingsType, resolver); configuration.Settings.Interceptor?.Intercept(context, settings); // Create and validate the command. var command = leaf.CreateCommand(resolver); var validationResult = command.Validate(context, settings); if (!validationResult.Successful) { throw CommandRuntimeException.ValidationFailed(validationResult); } // Execute the command. return(command.Execute(context, settings)); }
private void CreateAndBindCommands() { _subscriptions.Add( ActiveQueryBuilder.Core.Localization.MetadataEditor.DatabaseSchemaCaption.Subscribe(x => LabelHeaderDatabase.Text = x)); _subscriptions.Add( ActiveQueryBuilder.Core.Localization.MetadataEditor.MetadataStructureCaption.Subscribe(x => LabelHeaderMeatdaStructure.Text = x)); _subscriptions.Add( ActiveQueryBuilder.Core.Localization.MetadataEditor.PropertiesBarCaption.Subscribe(x => LabelHeaderProperties.Text = x)); _subscriptions.Add( ActiveQueryBuilder.Core.Localization.MetadataEditor.GroupByServer.Subscribe(x => CheckBoxByServer.Content = x)); _subscriptions.Add( ActiveQueryBuilder.Core.Localization.MetadataEditor.GroupByDatabase.Subscribe(x => CheckBoxByDatabase.Content = x)); _subscriptions.Add( ActiveQueryBuilder.Core.Localization.MetadataEditor.GroupBySchema.Subscribe(x => CheckBoxBySchema.Content = x)); _subscriptions.Add( ActiveQueryBuilder.Core.Localization.MetadataEditor.GroupByTypes.Subscribe(x => CheckBoxByTypes.Content = x)); _subscriptions.Add( ActiveQueryBuilder.Core.Localization.MetadataEditor.GenerateObjects.Subscribe(x => CheckBoxGenerateObjects.Content = x)); _subscriptions.Add( ActiveQueryBuilder.Core.Localization.MetadataEditor.StructureWillBeCleared.Subscribe(x => TextBlockWarning.Text = x)); _subscriptions.Add(ActiveQueryBuilder.Core.Localization.Common.Proceed.Subscribe(x => ButtonProceed.Content = x)); _subscriptions.Add(ActiveQueryBuilder.Core.Localization.Common.Cancel.Subscribe(x => ButtonCancel.Content = x)); _subscriptions.Add(CommandBinder.Bind(MenuItemMetadataLoadAll, _controller.LoadContainerCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.LoadEntireContainer, x => MenuItemMetadataLoadAll.IsEnabled = x, false)); _subscriptions.Add(CommandBinder.Bind(MenuItemDatabaseDelete, _controller.DeleteMetadataItemCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.DeleteMetadataItem, x => MenuItemDatabaseDelete.IsEnabled = x, false)); _subscriptions.Add(CommandBinder.Bind(MenuItemMetadataStructureAdd, _controller.AddStructureItemCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddStructureItem, x => MenuItemMetadataStructureAdd.IsEnabled = x, false)); _subscriptions.Add(CommandBinder.Bind(MenuItemMetadataStructureDelete, _controller.DeleteStructureItemCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.DeleteMetadataItem, x => MenuItemMetadataStructureDelete.IsEnabled = x, false)); _fillStructurePopupOpenCommand = new Command(MenuItemMetadataStructureFillFromSchema_OnClick); _subscriptions.Add(CommandBinder.Bind(MenuItemAddLinkedServer, _controller.AddLinkedServerCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddServer, x => MenuItemAddLinkedServer.IsEnabled = x)); _subscriptions.Add(CommandBinder.Bind(MenuItemAddDatabase, _controller.AddDatabaseCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddDatabase, x => MenuItemAddDatabase.IsEnabled = x)); _subscriptions.Add(CommandBinder.Bind(MenuItemAddSchema, _controller.AddSchemaCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddSchema, x => MenuItemAddSchema.IsEnabled = x)); _subscriptions.Add(CommandBinder.Bind(MenuItemAddPackage, _controller.AddPackageCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddPackage, x => MenuItemAddPackage.IsEnabled = x)); _subscriptions.Add(CommandBinder.Bind(MenuItemAddTable, _controller.AddTableCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddTable, x => MenuItemAddTable.IsEnabled = x)); _subscriptions.Add(CommandBinder.Bind(MenuItemAddView, _controller.AddViewCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddView, x => MenuItemAddView.IsEnabled = x)); _subscriptions.Add(CommandBinder.Bind(MenuItemAddProcedure, _controller.AddProcedureCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddProcedure, x => MenuItemAddProcedure.IsEnabled = x)); _subscriptions.Add(CommandBinder.Bind(MenuItemAddSynonym, _controller.AddSynonymCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddSynonym, x => MenuItemAddSynonym.IsEnabled = x)); _subscriptions.Add(CommandBinder.Bind(MenuItemAddField, _controller.AddFieldCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddField, x => MenuItemAddField.IsEnabled = x)); _subscriptions.Add(CommandBinder.Bind(MenuItemAddForeignKey, _controller.AddForeignKeyCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddForeignKey, x => MenuItemAddForeignKey.IsEnabled = x)); _subscriptions.Add(CommandBinder.Bind(MenuItemMetadataStructureFillFromSchema, _fillStructurePopupOpenCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.FillStructure, x => MenuItemMetadataStructureFillFromSchema.IsEnabled = x)); Loaded += (sender, args) => { _controller.UpdateStructureCommands(); _controller.UpdateContainerCommands(); }; }
private void MetadataStructureTree_OnValidateItemContextMenu(object sender, MetadataStructureItemMenuEventArgs e) { _contextMenuSubscriptions = new CompositeDisposable(); var menu = e.Menu; menu.ClearItems(); var contextMenuItemStructureAddItem = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemStructureAddItem, _controller.AddStructureItemCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddStructureItem, x => contextMenuItemStructureAddItem.IsEnabled = x)); var contextMenuItemStructureDelete = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemStructureDelete, _controller.DeleteStructureItemCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.DeleteStructureItem, x => contextMenuItemStructureDelete.IsEnabled = x)); var contextMenuItemStructureCreateChild = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemStructureCreateChild, _controller.CreateStructureChildsCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.CreateChildStructure, x => contextMenuItemStructureCreateChild.IsEnabled = x)); var contextMenuItemStructureClearChild = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemStructureClearChild, _controller.ClearStructureCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.ClearChildItems, x => contextMenuItemStructureClearChild.IsEnabled = x)); var contextSubMenuItemStructureSort = (MenuItem)menu.AddSubMenu(""); _subscriptions.Add( ActiveQueryBuilder.Core.Localization.MetadataEditor.Sort.Subscribe(x => contextSubMenuItemStructureSort.Header = x)); var contextSubMenuItemStructureSortByName = (MenuItem)((ICustomSubMenu)contextSubMenuItemStructureSort).AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextSubMenuItemStructureSortByName, _controller.SortStructureByNameCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.SortByName, x => contextSubMenuItemStructureSortByName.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextSubMenuItemStructureSortByTypeAndName = (MenuItem)((ICustomSubMenu)contextSubMenuItemStructureSort).AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextSubMenuItemStructureSortByTypeAndName, _controller.SortStructureByTypeCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.SortByType, x => contextSubMenuItemStructureSortByTypeAndName.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemStructureMoveToTop = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemStructureMoveToTop, _controller.MoveUpStructureCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.MoveToTop, x => contextMenuItemStructureMoveToTop.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemStructureMoveToBottom = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemStructureMoveToBottom, _controller.MoveDownStructureCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.MoveToBottom, x => contextMenuItemStructureMoveToBottom.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); menu.Closing += Menu_Closing; }
private void DatabaseSchemaTree_OnValidateItemContextMenu(object sender, MetadataStructureItemMenuEventArgs e) { _contextMenuSubscriptions = new CompositeDisposable(); var menu = e.Menu; menu.ClearItems(); if (OpenContainerLoadFormIfNotConnected && (_sqlContext.MetadataProvider == null || !_sqlContext.MetadataProvider.Connected)) { var contextMenuItemSchemaConnectAndLoad = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaConnectAndLoad, _controller.ConnectAndLoadCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.ConnectAndLoadChilds, x => contextMenuItemSchemaConnectAndLoad.IsEnabled = x)); } if (!(OpenContainerLoadFormIfNotConnected && (_sqlContext.MetadataProvider == null || !_sqlContext.MetadataProvider.Connected))) { var contextMenuItemSchemaLoadChildDatabase = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaLoadChildDatabase, _controller.LoadSchemaChildsCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.LoadChildItems, x => contextMenuItemSchemaLoadChildDatabase.IsEnabled = x)); } var contextMenuItemSchemaDelete = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaDelete, _controller.DeleteMetadataItemCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.DeleteMetadataItem, x => contextMenuItemSchemaDelete.IsEnabled = x)); var contextMenuItemSchemaClearChild = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaClearChild, _controller.ClearSchemaCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.ClearChildItems, x => contextMenuItemSchemaClearChild.IsEnabled = x)); menu.AddSeparator(); var contextMenuItemSchemaAddLinkedServer = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaAddLinkedServer, _controller.AddLinkedServerCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddServer, x => contextMenuItemSchemaAddLinkedServer.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemSchemaAddDatabase = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaAddDatabase, _controller.AddDatabaseCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddDatabase, x => contextMenuItemSchemaAddDatabase.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemSchemaAddSchema = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaAddSchema, _controller.AddSchemaCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddSchema, x => contextMenuItemSchemaAddSchema.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemSchemaAddPackage = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaAddPackage, _controller.AddPackageCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddPackage, x => contextMenuItemSchemaAddPackage.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemSchemaAddTable = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaAddTable, _controller.AddTableCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddTable, x => contextMenuItemSchemaAddTable.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemSchemaAddView = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaAddView, _controller.AddViewCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddView, x => contextMenuItemSchemaAddView.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemSchemaAddProcedure = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaAddProcedure, _controller.AddProcedureCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddProcedure, x => contextMenuItemSchemaAddProcedure.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemSchemaAddSynonym = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaAddSynonym, _controller.AddSynonymCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddSynonym, x => contextMenuItemSchemaAddSynonym.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemSchemaAddField = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaAddField, _controller.AddFieldCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddField, x => contextMenuItemSchemaAddField.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemSchemaAddForeignKey = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaAddForeignKey, _controller.AddForeignKeyCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.AddForeignKey, x => contextMenuItemSchemaAddForeignKey.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextSubMenuItemSchemaSort = (MenuItem)menu.AddSubMenu(""); _subscriptions.Add( ActiveQueryBuilder.Core.Localization.MetadataEditor.Sort.Subscribe(x => contextSubMenuItemSchemaSort.Header = x)); var contextSubMenuItemSchemaSortByName = (MenuItem)((ICustomSubMenu)contextSubMenuItemSchemaSort).AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextSubMenuItemSchemaSortByName, _controller.SortSchemaByNameCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.SortByName, x => contextSubMenuItemSchemaSortByName.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextSubMenuItemSchemaSortByTypeAndName = (MenuItem)((ICustomSubMenu)contextSubMenuItemSchemaSort).AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextSubMenuItemSchemaSortByTypeAndName, _controller.SortSchemaByTypeCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.SortByType, x => contextSubMenuItemSchemaSortByTypeAndName.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemSchemaMoveToTop = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaMoveToTop, _controller.MoveUpSchemaCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.MoveToTop, x => contextMenuItemSchemaMoveToTop.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); var contextMenuItemSchemaMoveToBottom = (MenuItem)menu.AddItem("", null, false, false, null, null); _subscriptions.Add(CommandBinder.Bind(contextMenuItemSchemaMoveToBottom, _controller.MoveDownSchemaCommand, ActiveQueryBuilder.View.WPF.Commands.Descriptions.MetadataEditor.MoveToBottom, x => contextMenuItemSchemaMoveToBottom.Visibility = x ? Visibility.Visible : Visibility.Collapsed)); _controller.UpdateContainerCommands(); menu.Closing += Menu_Closing; }
private async ValueTask <int> RunAsync(ApplicationSchema applicationSchema, CommandInput commandInput) { // Handle debug directive if (IsDebugModeEnabled(commandInput)) { await PromptDebuggerAsync(); } // Handle preview directive if (IsPreviewModeEnabled(commandInput)) { _console.Output.WriteCommandInput(commandInput); return(0); } // Try to get the command schema that matches the input var commandSchema = applicationSchema.TryFindCommand(commandInput.CommandName) ?? applicationSchema.TryFindDefaultCommand() ?? FallbackDefaultCommand.Schema; // Activate command instance var commandInstance = commandSchema == FallbackDefaultCommand.Schema ? new FallbackDefaultCommand() // bypass activator : (ICommand)_typeActivator.CreateInstance(commandSchema.Type); // Assemble help context var helpContext = new HelpContext( Metadata, applicationSchema, commandSchema, commandSchema.GetValues(commandInstance) ); // Handle help option if (ShouldShowHelpText(commandSchema, commandInput)) { _console.Output.WriteHelpText(helpContext); return(0); } // Handle version option if (ShouldShowVersionText(commandSchema, commandInput)) { _console.Output.WriteLine(Metadata.Version); return(0); } // Starting from this point, we may produce exceptions that are meant for the // end user of the application (i.e. invalid input, command exception, etc). // Catch these exceptions here, print them to the console, and don't let them // propagate further. try { // Bind and execute command _commandBinder.Bind(commandInput, commandSchema, commandInstance); await commandInstance.ExecuteAsync(_console); return(0); } catch (CliFxException ex) { _console.Error.WriteException(ex); if (ex.ShowHelp) { _console.Output.WriteLine(); _console.Output.WriteHelpText(helpContext); } return(ex.ExitCode); } }