Implement Custom Fetch Actions
You can implement custom fetch actions in a ConnectorLib .NET connector.
Action | Description | Method to override |
---|---|---|
action=Fetch&FetchAction=MyAction
|
Perform custom fetch actions on a repository. |
|
To implement a custom fetch action, override the CustomFetch
method on the ConnectorBase
interface.
The
method is passed the name of the fetch action that was called in the request. The name is always in upper case, because action names are case-insensitive. You can use the CustomFetch
method to handle as many fetch action names as necessary, however the action names CustomFetch
SYNCHRONIZE
, COLLECT
, HOLD
, and so on, are reserved by the connector for the standard fetch actions.
The CustomFetch
method is also passed an ICustomFetchTask
object. To obtain a request object that provides the action parameters included in the request, access the property Request
on this object.
Other resources, including a collection of identifiers and an ingester, are available through the ICustomFetchTask
object. You can use these in your implementation of the custom fetch action.
The
method can run many times for a single request; each time it is passed a different CustomFetch
I
CustomFetchTask
instance. The number of times that the
method runs is determined as follows:CustomFetch
- The
method runs for each distinct configuration file section name embedded in the identifiers (provided by theCustomFetch
identifiers
oridentifiersXML
action parameters) or included in the request (using theconfigsection
ortasksections
parameters). Theconfigsection
parameter accepts a single name. Thetasksections
parameter accepts a comma-separated list of names. - If no configuration file sections are provided by identifiers or by the
configsection
ortasksections
parameters, then thecustomFetch
method runs one time for each task listed in the[FetchTasks]
section of the configuration file. -
If no fetch tasks are configured in the connector's configuration file, the
customFetch
method does not run and the following warning is written to the connector's logs:WARNING: Custom fetch action is not associated with any task configuration sections, no tasks will be executed
Your code must use the parameters from the request to perform the action and populate the action response.
To obtain the response object, access the property Response
on the ICustomFetchTask
object. Set the value of XML elements in the response by calling the method SetValue
on the response object. The arguments for this method are the name to use for the new element, and a value.
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
method should return CustomFetch
false
only if the fetch action name is not supported. In all other cases, return true
. If another failure occurs then throw an exception from the
method, giving the reason for the failure.CustomFetch
The following sample code shows how a custom fetch action might be implemented for a basic connector.
This example provides action=fetch&FetchAction=echo
. The action writes a message to the connector's customfetch
log. The response to the action returns the action parameters that were set in the request, and the reference of each document that was processed. Your users can retrieve the response for an asynchronous action such as Fetch
through the QueueInfo
action.
override public bool CustomFetch(String action, ICustomFetchTask task) { if (action != "ECHO") return false; task.Log.WriteLine(LogLevel.Always, "Custom Fetch action " + action + " called"); task.Response.SetValue("token", task.Response.Token); foreach (String param in task.Request.Parameters) { task.Response.SetValue("parameters/" + param, task.Request[param]); } int refIndex = 0; foreach (IDocInfo docInfo in task.Docs) { task.Response.SetValue("documents/reference[" + (refIndex++) + "]", docInfo.Identifier.Reference); } return true; }