Jump to: navigation, search

Use Customizable Commands

DevGuide2.png Purpose: To provide information about the customizable commands available in the Interaction Workspace.

Before You Start

Creating a Command

The command system is based on the chain of command (or chain of responsibility) design pattern. The following example illustrates how to create your own commands by using Genesys best practices. For each new command, create a class which implements the IElementOfCommand interface. After creating the command, you must add it to a chain of command in your module (see Creating a New Module). The custom command created in the following step-by-step example displays a confirmation dialog before executing the ReleaseCall command. 1. Create the elementary command class: [C#]

// File: CustomCommand.cs
namespace Genesyslab.Desktop.Modules.ExtensionSample.CustomCommand
  // Custom command which prompts a confirmation dialog before executing the ReleaseCall command
  class BeforeReleaseCallCommand : IElementOfCommand
    readonly IObjectContainer container;
    ILogger log;
    public BeforeReleaseCallCommand(IObjectContainer container)
      this.container = container;
      // Initialize the trace system
      this.log = container.Resolve<ILogger>();
      // Create a child trace section
      this.log = log.CreateChildLogger("BeforeReleaseCallCommand");
    public string Name { get; set; }
    public bool Execute(IDictionary<string, object> parameters, IProgressUpdater progress)
      // To go to the main thread
      if (Application.Current.Dispatcher != null && !Application.Current.Dispatcher.CheckAccess())
        object result = Application.Current.Dispatcher.Invoke(DispatcherPriority.Send, 
                                      new ExecuteDelegate(Execute), parameters, progress);
        return (bool)result;
        // Get the parameter
        IInteractionVoice interactionVoice = parameters["CommandParameter"] as IInteractionVoice;
        // Prompt the alert dialog
        return MessageBox.Show("Do you really want to release this call?\r\nThe call",
          "Release the call?", MessageBoxButton.YesNo) == MessageBoxResult.No;
    delegate bool ExecuteDelegate(IDictionary<string, object> parameters, IProgressUpdater progressUpdater);

2. Create the chain of command in the Module initialization by using the CommandManager:

// File: ExtensionSampleModule.cs
ICommandManager commandManager = container.Resolve<ICommandManager>();
// Add a command before the release call
// Method 1:
commandManager.CommandsByName["InteractionVoiceReleaseCall"].Insert(0, new CommandActivator() {
    CommandType = typeof(BeforeReleaseCallCommand), Name = "BeforeReleaseCall" });
// Method 2 (recommended):
commandManager.InsertCommandToChainOfCommandBefore("InteractionVoiceReleaseCall", "ReleaseCall", 
  new CommandActivator() { CommandType = typeof(BeforeReleaseCallCommand), Name = "BeforeReleaseCall" });

3. You can add several commands to a chain of command. The order of execution follows the order in which the commands are added. BeforeReleaseCallCommand is executed before ReleaseCallCommand, for example: [C#]

     new List<CommandActivator>()
       new CommandActivator() { CommandType = typeof(BeforeReleaseCallCommand), Name = "BeforeReleaseCall" }, 
       new CommandActivator() { CommandType = typeof(ReleaseCallCommand), Name = "ReleaseCall" }

4. Finally, execute the chain of command by using parameters, as shown in the following example (defined here: Command list): [C#]

IDictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("CommandParameter", interaction);
parameters.Add("Reasons", reasons);
parameters.Add("Extensions", extensions);

Inserting a Command in a Chain

Each element of command is unique across the given chain. You can use the ICOmmandManager.InsertCommandToChainOfCommandAfter() method to insert your command after a specific command by passing its name. The following code snippet shows how to insert the element of command "CloseSample" in the chain of command "BundleClose" after the element of command "IsPossibleToClose":

commandManager.InsertCommandToChainOfCommandAfter("BundleClose", "IsPossibleToClose", new List<CommandActivator>() 
      new CommandActivator()
        CommandType = typeof(CloseSampleCommand), Name = "CloseSample"

Multiple Commands and Overlapping

When you pass several commands to a given chain, they share the parameters which have identical names. This can lead to over-lapping issues when you execute the command. To by-pass this issue, make sure that your parameters are correct before your application executes the command. For instance, consider using the Command1 and Command2 of MyChain:

Chain of Command Default commands Parameters
MyChain Command1
  • Parameter1: IInteractionChat
  • Parameter2: KeyValueCollection
  • Parameter1: IInteractionChat
  • Parameter3: KeyValueCollection
  • IInteractionChat: Genesyslab.Desktop.Modules.OpenMedia.Model.Interactions.Chat.IInteractionChat
  • KeyValueCollection: Genesyslab.Enterprise.Commons.Collections.KeyValueCollection

When you execute MyChain, you must pass all the parameters of Command1 and Command2. Parameter1 is shared amongst Command1 and Command2.

IDictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("Parameter1", interaction);
parameters.Add("Parameter2", reasons);
parameters.Add("Parameter3", extensions);

Read Next

Resultset next.png Customize Views and Regions category:Customizable Commands

This page was last edited on February 27, 2013, at 16:12.


Comment on this article:

blog comments powered by Disqus