Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

In the simplest case your extension has no parameters. However, it may be useful to change the behavior of your extension from one project to the other.

The screenshot below, shows an extension with a parameter and which can be edited individually per project:

For example, if your extension copies translated files then the parameter may be the target directory and the Beebox administrator can change the path from one project to the next.

Adding parameters starts with implementing the three methods below:

  • ParameterHelp property: Must return a help text. If null then the system assumes that there are no parameters.
  • ParameterDefault property: Returns your parameter default value (null or something else). This default value can then be changed in the project settings.
  • ValidateParameter() method: This method is called when a user changes the parameter value in a project. Return an error message if the value is not ok.
     
Sample code:
		/// <summary>
		/// Gets optional help description (not html!) of the configuration parameter.
		/// By returning a non-null value, you explicitly tell the Beebox that this extension has a configurable parameter.
		/// </summary>
		public override string ParameterHelp 
		{ 
			get { return "Fill in a filter type, either one of 'alpha', 'beta' or 'gamma'."; } 
		}
 
 
 
		/// <summary>
		/// Gets the default value of the parameter. Default can be changed by user.
		/// </summary>
		public override string ParameterDefault { get { return "alpha"; } }
 
 
 
		/// <summary>
		/// Validates the user parameters.
		/// Return null if ok, otherwise return an error text.
		/// </summary>
		/// <param name="parameter">The parameter edited by a user.</param>
		/// <returns>Null: parameter is ok. Otherwise return an error message.</returns>
		public override string ValidateParameter(string parameter)
		{
			try
			{
				if (parameter != "alpha" && parameter != "beta" && parameter != "gamma") 
					return "Wrong parameter value!";
				else
					return null;
			}
			catch (Exception e) { return "The parameter is not correct."; }
		}

 

The last step is to process the configuration parameter passed to the main method of each extension. Example:

public override bool IsMatch(Segment segment, IExtensionConfiguration configuration)

 

This interface has a Parameter property. It is null if the default parameter was not changed in the project that triggered your extension. A typical code would look like this:

public override bool IsMatch(Segment segment, IExtensionConfiguration configuration)
{
	// Get parameter. 
	// If null then the default value was not edited in the current Beebox project.
 
	var parameter = configuration.Parameter ?? ParameterDefault;
    if (parameter == "alpha") 
    {
       ....
    }

 

 

 

  • No labels