Exercise outline

The goal of this exercise is to show how a new plugin can be developed using the Delta Shell SDK. The Delta Shell SDK NuGet package will be used in order to make a quick start.

Create a new C# project

Start Visual Studio 2012 and create a new C# project (File | New | Project...) by configuring the project wizard as shown in the following image:



Afterwards, a solution should be created with a structure as shown in the following image:



The default class named Class1.cs can be removed.

Add the Delta Shell SDK to the project using NuGet

A Visual Studio extension called NuGet will be used to add the Delta Shell SDK to the newly created project.

General information about NuGet can be found at http://docs.nuget.org/.

Information on how to install NuGet as a Visual Studio extension can be found at http://docs.nuget.org/docs/start-here/installing-nuget.

Since Visual Studio 2012 NuGet is installed by default. However you have to make sure that it is updated to the latest version by checking the Extension and Updates window (click TOOLS | Extensions and Updates... | Updates | Visual Studio Gallery). When previous version is used - installing Delta Shell SDK package might result in the following error:


Open the NuGet package manager (right click the solution | Manage NuGet Packages for Solution...) and search for the Delta Shell SDK like shown in the following image:



After installing the Delta Shell SDK, the volume model project will end up looking like this:

Actions performed by the NuGet package

In order to quickly start developing plugins, the Delta Shell NuGet SDK package performed a couple of important actions (which otherwise should have been performed manually).

First of all, some new files are added to the project:

  • PluginInfo.cs

    The code in this file registers the C# project as a Delta Shell plugin:

       using Mono.Addins;
    
       [assembly: Addin]
       [assembly: AddinDependency("DeltaShellApplication", "1.0")]
       

    The contents of the code snippet above are related to the use of Mono.Addins for extending Delta Shell logic with plugin logic.

    Information on the Mono.Addins extension model can be found here: http://monoaddins.codeplex.com/documentation.

  • ApplicationPlugin.cs

    The code in this file registers an application plugin to Delta Shell:

        using DelftTools.Shell.Core;
        using Mono.Addins;
    
        namespace DeltaShell.Plugins.VolumeModel
        {
            [Extension(typeof(IPlugin))]
            public class ApplicationPlugin : DelftTools.Shell.Core.ApplicationPlugin
            {
                public override string Name
                {
                    get { return "<Type name of your plugin here>"; }
                }
    
                public override string Description
                {
                    get { return "<Type short description of plugin>"; }
                }
    
                public override string Version
                {
                    get { return "1.0"; }
                }
            }
        }
       

    The aspect [Extension(typeof(IPlugin))] is necessary for marking the created class as a plugin class.

    The class is derived from the ApplicationPlugin base class in order to automatically implement some basic application plugin logic.

  • GuiPlugin.cs

    The code in this file registers a gui plugin to Delta Shell:

        using DelftTools.Shell.Core;
        using Mono.Addins;
    
        namespace DeltaShell.Plugins.VolumeModel
        {
            [Extension(typeof(IPlugin))]
            public class GuiPlugin : DelftTools.Shell.Gui.GuiPlugin
            {
                public override string Name
                {
                    get { return "<Type name of your gui plugin here>"; }
                }
    
                public override string Description
                {
                    get { return "<Type short description of plugin>"; }
                }
    
                public override string Version
                {
                    get { return "1.0"; }
                }
            }
        }
      

    The aspect [Extension(typeof(IPlugin))] is necessary for marking the created class as a plugin class.

    The class is derived from the GuiPlugin base class in order to automatically implement some basic gui plugin logic.

In the second place, references to the Delta Shell SDK are added to the project:

  • DelftTools.Controls
  • DelftTools.Controls.Swf
  • DelftTools.Functions
  • DelftTools.Hydro
  • DelftTools.Shell.Core
  • DelftTools.Shell.Gui
  • DelftTools.Shell.Gui.Swf
  • DelftTools.Units
  • DelftTools.Utils
  • Fluent
  • GeoAPI
  • GeoAPI.Extensions
  • Mono.Addins
  • NetTopologySuite
  • NetTopologySuite.Extensions
  • SharpMap.Api
  • SharpMap
  • SharpMap.Extensions
  • SharpMap.UI

Third, some project properties are set (right click on the project in the solution | Properties):

  • The Post-build event command line property (in the Build Events tab) is set to:

    if not exist "$(SolutionDir)packages\DeltaShell.1.0.0\delta-shell\plugins\$(ProjectName)" md "$(SolutionDir)packages\DeltaShell.1.0.0\delta-shell\plugins\$(ProjectName)"
    copy /Y "$(TargetPath)" "$(SolutionDir)packages\DeltaShell.1.0.0\delta-shell\plugins\$(ProjectName)"
    
    This post-build event results in copying the project output files to a dedicated plugin folder inside the Delta Shell package.

  • The Start action property (in the Debug tab) is set to the external program packages\DeltaShell.1.0.0\delta-shell\bin\DeltaShell.Gui.exe.

Finally, a folder called packages is added to the file system. This folder contains the Delta Shell package (as well as the NuGet packages configuration file for the solution):



The delta-shell folder highlighted above is all you need to provide to end users when distributing Delta Shell with your plugin(s).

Adapt the created application plugin class

Rename the ApplicationPlugin.cs file to VolumeModelApplicationPlugin.cs and adapt the contents as shown below.

While renaming the file, don't perform a rename of all project references to the code element ApplicationPlugin:

using DelftTools.Shell.Core;
using Mono.Addins;

namespace DeltaShell.Plugins.VolumeModel
{
    [Extension(typeof(IPlugin))]
    public class VolumeModelApplicationPlugin : ApplicationPlugin
    {
        public override string Name
        {
            get { return "Volume model application"; }
        }

        public override string Description
        {
            get { return "Application plugin of the volume model application"; }
        }

        public override string Version
        {
            get { return "1.0"; }
        }
    }
}

Adapt the created gui plugin class

Rename the GuiPlugin.cs file to VolumeModelGuiPlugin.cs and adapt the contents as shown below.

While renaming the file, don't perform a rename of all project references to the code element GuiPlugin:

using DelftTools.Shell.Core;
using DelftTools.Shell.Gui;
using Mono.Addins;

namespace DeltaShell.Plugins.VolumeModel
{
    [Extension(typeof(IPlugin))]
    public class VolumeModelGuiPlugin : GuiPlugin
    {
        public override string Name
        {
            get { return "Volume model application (UI)"; }
        }

        public override string Description
        {
            get { return "Gui plugin of the volume model application"; }
        }

        public override string Version
        {
            get { return "1.0"; }
        }
    }
}

Exercise results

Run the application and open the About window (File | Help | About). Ensure both the application plugin and the gui plugin are visible in the overview of loaded plugins:






  • No labels