CommandServer.Contracts 1.0.0

dotnet add package CommandServer.Contracts --version 1.0.0
NuGet\Install-Package CommandServer.Contracts -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CommandServer.Contracts" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CommandServer.Contracts --version 1.0.0
#r "nuget: CommandServer.Contracts, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CommandServer.Contracts as a Cake Addin
#addin nuget:?package=CommandServer.Contracts&version=1.0.0

// Install CommandServer.Contracts as a Cake Tool
#tool nuget:?package=CommandServer.Contracts&version=1.0.0

Command Server Contracts

This package supplies the interface required to add a new Command Server command handler extension for Visual Studio

    /// <summary>
    /// Command dispatch which plugs into the Command Server plug in
    /// </summary>
    public interface ICommandServerDispatch
    {
        
        string Name { get; }

        /// <summary>
        /// Can this implementation process the command. Implementations are selected using the following rule
        /// 1 Select the implementation which name forms part of the command and can handle the the command
        /// 2 Select he first implementation in the pipeline which says it can handle the command
        /// </summary>
        /// <param name="commandId">The command id to be handled</param>
        /// <returns>True if the CommandServerDispatch can handle the payload.</returns>
        Boolean CanProcess(string  commandId);
        
        /// <summary>
        /// Process the command and return any results. Most commands will not return any results.
        /// </summary>
        /// <param name="payload">JSON representation of the command</param>
        /// <returns>JSON representation of the result</returns>
        Task<CommandServerResult> Process(JObject payload);

    }
}

Description

  • To add a class into the Command Server you need to create a Visual Studio extension which implements ICommandServerDispatch
  • The extension needs to be signify that it is a MEF Component
  • The extension needs to implement the interface above.
  • The extension needs to mark the implementation as exported via MEF

The example below is a minimum implementation which reports the command has handled to the Command Server output window without actually doing any other processing.

Export(typeof(ICommandServerDispatch))]
public class CursorlessCommandHandler: ICommandServerDispatch
{
    public string Name { get; } = "cursorless";

    public bool CanProcess(
        string commandId) => commandId == "cursorless.command";
   

    public Task<CommandServerResult> Process(
        JObject payload)
    {
        ///The first parameter of the CommandServerResult will be logged in the Command Server output window.
        ///The second parameter is any data to write to the response file
        return Task.FromResult(new CommandServerResult("Handled by cursorless command handler",
            CommandServerResult.None));
    }
}
  • A command sent to the command server will be handled by zero or one command handlers
  • In the event that multiple handlers say they can handle a command:
    • We select the first command handler which has its name as part of the command.
    • This should stop 'catch all' command handlers from stealing your commands.
Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 190 8/14/2022