How to: Create and Install a Simple Custom Command
This topic shows how to create an add-in in Visual Studio and install it in Microsoft code name “Quadrant”. This is the fourth and last topic in the "Quadrant" Advanced Customization Tutorial.
Caution:
|
|---|
| This tutorial assumes that you have already completed the How to: Create a Database from "M" in "Quadrant" tutorial, which creates the PetShop database in an instance of SQL Server by using Microsoft code name “M”. |
To create an add-in by using Visual Studio
-
Navigate to the ViewProductsSample folder.
-
Open ViewProductsSample.csproj in Visual Studio.
-
In Solution Explorer, double-click ViewProductsSample.cs.
-
Replace the
CommandHandlersclass in ViewProductsSample.cs with the following code.The
CanExecutemethod enables the command only when the active database session is MSPetShop4. TheExecutemethod uses the object model in “Quadrant” to open a workpad that displays the Product table from the MSPetShop4 database.public static class CommandHandlers { public static void Execute(object sender, ExecutedRoutedEventArgs args) { WorkpadServices.AddWorkpad("dbo2.Product", ApplicationServices.Instance.LastActiveSession.Id, true); } public static void CanExecute(object sender, CanExecuteRoutedEventArgs args) { args.CanExecute = false; if (ApplicationServices.Instance.ActiveDatabase.Name == "MSPetShop4") { args.CanExecute = true; } } } -
In Solution Explorer, double-click Extensions.m. Paste the following code into the file.
The
Microsoft.Quadrantmodule instantiates a model for the ViewProducts command. TheMicrosoft.Quadrant.Shell.Menumodule creates a Menu item in the View menu in “Quadrant”.module Microsoft.Quadrant{ import Microsoft.Quadrant; Commands { StackTraceCommand { Name => 'ViewProducts', Execute => 'Execute, Samples.CommandHandlers, ViewProductsSample', CanExecute => 'CanExecute, Samples.CommandHandlers, ViewProductsSample', }, } } module Microsoft.Quadrant.Shell.Menu { MenuItems { Import_MenuItem { OwnerMenuGroup => MenuGroups.Refresh_MenuGroup, Order => 3, ExtentName => "MenuButtons", .MenuButtons { { MenuItem => Import_MenuItem, DisplayText => 'Products', AutomationId => 'qs:ViewProducts', Command => 'ViewProducts' } } }, } } -
In Solution Explorer, right-click the ViewProductsSample project and select Build to compile the project.
To install the add-in in “Quadrant”
-
In “Quadrant”, on the Data menu, click Install Addin….
-
Browse to the ViewProductsSample directory, then navigate to bin\Debug\. Select ViewProductsSample.dll and click Open.
-
Click OK in the add-in install success dialog.
-
To verify that the add-in has been successfully installed, locate Products on the View menu.
-
If Products is unavailable, MSPetShop4 is not an active session. On the View menu, click Explorer, and then click MSPetShop4. The database opens in a new workpad.
-
Now click Products on the View menu. A new workpad will open, displaying the Products table from the MSPetShop4 database.
Caution: