External command user interface

To allow Site Manager users to maintain the configuration of an External command job more easily you can implement a user interface that hides the key-value pairs from the user. The Site Manager's Scheduler plugin contains an interface ISchedulerActionSetupControlProvider that you can implement which will embed a UserControl into the Parameters tab where you can customize how you want your users to set up the job.

 

ISchedulerActionSetupControlProvider

This interface is located in the assembly LSOne.ViewPlugins.Scheduler.dll.

 

The interface provides a UserControl and the parameter dictionary required to configure a ISchedulerAction external command plugin.

 

The order in which the Site Manager calls the methods are:

  1. InitializeParameters
  2. CreateSetupControl
  3. DataIsModified
  4. GetParameters

 

ISchedulerActionSetupControlProvider methods

Description

void InitializeParameters(Dictionary<string, string> parameters)

Initializes the dictionary in parameters with default values if they are not present. This method should add and initialize all the default key/value pairs if they do not exist.

parameters: The current setup parameter values.

UserControl CreateSetupControl(IConnectionManagerentry, Dictionary<string, string> parameters)

Creates an instance of the setup control and passes a connection to the database to it.

entry: The connection to the database.

parameters: The current setup parameter values.

Dictionary<string, string> GetParemeters() Creates and returns the parameter dictionary based on the configuration on the control. This is called if DataIsModified returns true.
void DataIsModified() Goes through the current configuration of the setup-control and returns true if the configuration has changed from when CreateSetupControl was called. If this returns true then the function GetParemeters is called.

Implementing the interface

Based on the external command that was set up Implementing external commands, we can add a user interface that lets the user enter values for Param1 and Param2. This is a very simple implementation but should give you the general idea of how you can add a simple UI on top of your external commands.

1: Add a setup control provider class to your existing external command project

In order for the Site Manager to load your implementation, it needs to be contained within the same assembly as your ISchedulerAction external command implementation. When you open the job view for an External command job, the Site Manager will scan the selected assembly for an implementation of ISchedulerActionSetupControlProvider. If an implementor is found it is instantiated and the control embedded into the view.

 

Below is a sample implementation. Note that the SetupControl implementation is shown in step 2.

class SetupControlProvider : ISchedulerActionSetupControlProvider
{
	private SetupControl setupControl;

	public void InitializeParameters(Dictionary<string, string> parameters)
	{
		if (!parameters.ContainsKey("Param1"))
		{
			parameters.Add("Param1", "");
		}

		if (!parameters.ContainsKey("Param2"))
		{
			parameters.Add("Param2", "");
		}
	}

	public System.Windows.Forms.UserControl CreateSetupControl(IConnectionManager entry, Dictionary<string, string> parameters)
	{            
		setupControl = new SetupControl();
		setupControl.Init(parameters);

		return setupControl;
	}

	public Dictionary<string, string> GetParemeters()
	{
		return setupControl.GetParameters();
	}

	public bool DataIsModified()
	{
		return setupControl.DataIsModified();
	}
}

2: Add the user control

Add a UserControl to your solution and name the it SetupControl.

Design:

Implementation:

public partial class SetupControl : UserControl
{

	private Dictionary<string, string> parameters;

	public SetupControl()
	{
		InitializeComponent();

		parameters = new Dictionary<string, string>();
	}

	/// <summary>
	/// Populates the dictionary with the current values from the user interface and returns the modified dictionary.
	/// </summary>
	/// <returns></returns>
	public Dictionary<string, string> GetParameters()
	{
		parameters["Param1"] = tbParam1.Text;
		parameters["Param2"] = tbParam2.Text;

		return parameters;
	}

	/// <summary>
	/// Returns true if the data in the UI is different from the original parameters supplied in <see cref="Init"/>
	/// </summary>
	/// <returns></returns>
	public bool DataIsModified()
	{
		if (parameters["Param1"] != tbParam1.Text) return true;

		if (parameters["Param2"] != tbParam2.Text) return true;

		return false;
	}

	/// <summary>
	/// Initializes the data on the control.
	/// </summary>
	/// <param name="parameters">The current setup parameter values.</param>
	public void Init(Dictionary<string, string> parameters)
	{
		this.parameters = parameters;

		tbParam1.Text = parameters["Param1"];
		tbParam2.Text = parameters["Param2"];
	}
}

Deploying the user interface

The assembly is deployed in the same manner as described Implementing external commands. To view your user interface we need to open our External command job again after the updated assembly has been deployed. Go to ToolsØReplicationØJobs and open your job. You should now see your user interface instead of the key-value list that was there before implementing theISchedulerActionSetupControlProvider interface:

The assembly needs to exist on the same machine as the Site Manager for the UI to load. If you are viewing the job from a remote machine the control will not be embedded in the view and the user will see the key-value setup list instead.