Inhaltsverzeichnis

Use Case: Select an Attachment corresponding to a regular expression

In this HowTo, you will learn which conditions are necessary for implementing your own eBiss plugin. Below you can follow the implementation on the basis of a use case, In which we want to select only the attachments which are corresponding to a given regular expression.

Create the Jobstep class

To do this, first create a new project in Visual Studio with the settings:

You can find the complete project in your eBiss standard templates subdirectory, at: \StandardTemplates\PluginSample\eBiss.Plugin.Sample

Let's first create our Jobstep called MessageSelector. For this, our created class inherits from an abstract class ClientJobStepBase and implements the Run() method. Furthermore, the filter expression is declared and the property “FileNameFilter” is created and enhanced with the attribute [Browsable (true)]. The attribute ensures that the user is able to see the property on the GUI. Similarly, an event is assigned to the Jobstep, which is called OnMessageSelection and from the MessagesSelected type.

/// <summary>
/// Selects messages containing only one attachment with filename dummy.txt
/// </summary>
public class MessageSelector : ClientJobStepBase
{
   public event MessagesSelected OnMessageSelection;
   private string _attachmentName = "^dummy\\.txt$";
 
   [Browsable(true)]
   public string FileNameFilter
   {
       get { return _attachmentName; }
       set { _attachmentName = value; }
   }
[...]

Fig. 1: Jobstep Properties with Browsable Property FileNameFilter and Event OnMessageSelection

The Run method is then implemented and, in our case, logged sufficiently using our LogContext. Effectively, a list of messages is iterated and exactly one attachment is searched which corresponds to the given regular expression. This is then passed to the event OnMessageSelection and in our case delegated to another job.

public override JobStepResult Run()
{
    JobStepResult rc = JobStepResult.Ok;
    LogContext.Log(LogMsgType.Progress, "Select messages containing only one attachment that matches regular expression: " + FileNameFilter ?? "<NULL>");
 
    if (OnMessageSelection == null)
    {
        LogContext.Warning("OnMessageSelection is not connected to a target job step!");
    }
    else
    {
        System.Text.RegularExpressions.Regex regExp = new System.Text.RegularExpressions.Regex(FileNameFilter);
 
        List<IMessage> selectedMessages = new List<IMessage>();
        foreach (IMessage msg in Job.InputMessages)
        {
            if (msg.Attachments.Count == 1 && regExp.IsMatch(msg.Attachments[0].Filename))
            {
                selectedMessages.Add(msg);
            }
        }
        if (selectedMessages.Count == 0)
        {
            LogContext.Log(LogMsgType.Progress, "No message selected.");
        }
        else
        {
            LogContext.Log(LogMsgType.Progress, $"{selectedMessages.Count} message(s) selected.");
            Job.Delegate(OnMessageSelection, new MessageSelectionArgs(selectedMessages));
        }
    }
    LogContext.Debug("Exit with: " + rc.ToString());
    return rc;
}

Create your project and copy the .dll to the eBiss Plugin subdirectory. Once you have restarted the service, you will find your jobsteps in the Workflow Editor.

Fig. 2: Jobstep inside the Workflow-Editor

Create the jobstep resources

To do this, add another project in Visual Studio with the settings:

Add a Resouces File to your project. In these, the corresponding display names and descriptions for the properties of the newly created job step are defined. Now you can use <PropertyName> .Display.Description to set the tooltip, and with <PropertyName> .Display.Name ** the name corresponding to your language.

In our case, FileNameFilter.Display.Description and FileNameFilter.Display.Name. Same repeat for other languages.

Fig. 3: Resources

Create your project and copy the .dll to the eBiss directory. Once you have restarted the service, the display name and description for your job step should be taken from the resources.