You can implement custom actions in a ConnectorLib .NET connector.
| Action | Description | Method to override |
|---|---|---|
action=MyAction
|
Perform custom actions on a repository. | Custom
|
To implement a custom action, override the Custom method on the ConnectorBase interface.
The method is passed the name of the action that was called in the request. The name is always in upper case, because action names are case-insensitive. You can use the Customcustom method to handle as many action names as necessary, however the action names FETCH, VIEW, GETURI, GETSTATUS, and so on, are reserved by the connector for the standard actions.
The Custom method is also passed an ICustomTask object. This provides access to a request object that provides all of the action parameters. You can obtain the request object by accessing the property Request on the ICustomTask object.
All actions require a configuration file section name for the action to run. For a synchronous custom action, this is taken from the configsection parameter in the request (for example MyActionSection in the request action=MyAction&configsection=MyActionSection). If configsection is not set the connector uses the value of the sectionname parameter. If neither of these action parameters are set the connector uses the section name Default. In this case, the connector logs the following warning:
WARNING: Custom action is not associated with a configuration section, using [Default] section
The section name is available through the ICustomTask object. Standard operations that read the configuration file use the correct section automatically.
Your code must use the parameters from the request to perform the action and populate the action response. Response on the ICustomTask object. You can then call the method SetValue(name, value) on the response object to add an XML element and value to the response.
You can add attributes and nested elements to the action response using XPath-like expressions with element indexes. For example:
Response.SetValue("document[0]/metadata[7]/@name", "MyField");
Your implementation of the custom method should return false only if the action name is not supported. In all other cases, return true. If another failure occurs then throw an exception from the custom method, giving the reason for the failure.
The following sample code shows how a custom action might be implemented for a basic connector.
override public bool Custom(String action, ICustomTask task)
{
if (action != "ECHO")
return false;
task.Log.WriteLine(LogLevel.Always, "Custom action " + task.Request.Action + " called");
foreach (String param in task.Request.Parameters)
{
task.Response.SetValue(param, task.Request[param]);
}
return true;
}
|
|