Export (0) Print
Expand All

How to: Create and Install a Simple Custom Command

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

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.

Ee698913.Warning(en-us,VS.85).gif 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

  1. Navigate to the ViewProductsSample folder.

  2. Open ViewProductsSample.csproj in Visual Studio.

  3. In Solution Explorer, double-click ViewProductsSample.cs.

  4. Replace the CommandHandlers class in ViewProductsSample.cs with the following code.

    The CanExecute method enables the command only when the active database session is MSPetShop4. The Execute method 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;
                }
            }
        }
    
    
  5. In Solution Explorer, double-click Extensions.m. Paste the following code into the file.

    The Microsoft.Quadrant module instantiates a model for the ViewProducts command. The Microsoft.Quadrant.Shell.Menu module 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'
                    }
                }
            },        
           
        }
    }
    
    
  6. In Solution Explorer, right-click the ViewProductsSample project and select Build to compile the project.

To install the add-in in “Quadrant”

  1. In “Quadrant”, on the Data menu, click Install Addin….

  2. Browse to the ViewProductsSample directory, then navigate to bin\Debug\. Select ViewProductsSample.dll and click Open.

  3. Click OK in the add-in install success dialog.

  4. To verify that the add-in has been successfully installed, locate Products on the View menu.

  5. 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.

  6. Now click Products on the View menu. A new workpad will open, displaying the Products table from the MSPetShop4 database.

See Also


Show:
© 2014 Microsoft