Click or drag to resize

Custom Checkers

This chapter deals with self-created Checker dlls. You can use your own Checkers to monitor any process or state that only you know about. Vishnu already offers some standard checkers, but sooner or later you will want to create your own Checkers with special functions. However, to create your own DLLs, you need basic knowledge of a DotNet-language, e.g. C#.

ImportantImportant

Nevertheless, you can get started with C# using a Vishnu-Visual Studio-extension even without any programming knowledge. At the push of a button, an executable test project with your own new Checker will be generated.

the demo job

This is what the demo job for your Custom Checkers looks like:

User Checker Demo

This is the associated JobDescription.xml:

JobDescription.xml
<?xml version="1.0" encoding="utf-8"?>
<JobDescription>
  <LogicalName>UserCheckerDemo</LogicalName>
  <LogicalExpression>Predecessor AND UserChecker</LogicalExpression>
  <Checkers type="array">
    <Checker>
      <LogicalName>Predecessor</LogicalName>
      <PhysicalPath>TrueFalseExceptionChecker.dll</PhysicalPath>
      <Parameters>False:True:Exception|10|Predecessor: Hello World</Parameters>
      <Trigger>
        <PhysicalPath>TimerTrigger.dll</PhysicalPath>
        <Parameters>P:3|P:15</Parameters>
      </Trigger>
    </Checker>
    <Checker>
      <LogicalName>UserChecker</LogicalName>
      <PhysicalPath>Plugin\UserChecker.dll</PhysicalPath>
      <Trigger>
        <Reference>True</Reference>
        <Parameters>Predecessor</Parameters>
      </Trigger>
    </Checker>
  </Checkers>
</JobDescription>
Hinweis  Note

A quick reminder: the start job can be set via Configuration and parameters.

the demo project - created quickly

Using the Visual Studio extension Vishnu_UserChecker_VSIX.vsix (install by double-clicking), you can add a C# project template for your Custom Checkers to Visual Studio.

Vishnu User Checker VSIX

This project template can then be used later for a new project:

Vishnu User Checker VSIX select

A project folder with a checker project and a test project is generated.

AchtungAttention

During the generation of the projects, two error messages appear stating that not all required packages could be added to the project. However, these are not true and can be ignored.

User Checker Solution
Hinweis  Note

The UserChecker and the test project are immediately buildable and the UserChecker could be used with the implemented demo functionality as Vishnu-checker.

Here is the output of the test project:

User Checker Demo Run
the demo project - Details

The UserChecker class in the project generated by the project template (see above) contains the Work method as the main processing logic. Here you can incorporate your business-specific processing logic:

Work' method in the UserChecker class
    ...
private bool? Work(TreeEvent source)
{
    // As an example, an additional parameter is set here via the passed TreeEvent
    // from the result of an assumed predecessor checker.
    // However, this part is not required for most checkers.
    string demoInterestingPredecessorHello = zero;
    if (source?.Results?.ContainsKey("Predecessor") == true)
    {
        object returnObject = source.Results["Predecessor"ReturnObject;
        demoInterestingPredecessorHello = GenericPropertyGetter.GetProperty<string>(
            returnObject, "DefaultResultProperty");
    }
    else
    {
        if (source?.Environment?.ContainsKey("Predecessor") == true)
        {
            object returnObject = source.Environment["Predecessor"ReturnObject;
            demoInterestingPredecessorHello = GenericPropertyGetter.GetProperty<string>(
                returnObject, "DefaultResultProperty");
        }
        // Depending on the requirements, an exception can be thrown here.
        //else
        //{
        // throw new ApplicationException(
        // "UserChecker: DemoInterestingPredecessor was not found!");
        //}
    }

    // This is followed by the actual checker processing, which returns an extended boolean.
    // of this checker and also fills a return object with additional information if necessary.
    // The return can be completely independent of Results or Environment; is only relevant here for
    // the demo is coded dependent.
    // TODO: you can implement your own processing here.
    if (!String.IsNullOrEmpty(demoInterestingPredecessorHello))
    {
        this._returnObject = demoInterestingPredecessorHello;
        return true;
    }
    else
    {
        this._returnObject = "no Predecessor-Result found!";
        return false;
    }
}
    ...
Hinweis  Note

As you can see in the example, access to the Vishnu environment is also possible. However, this is rarely necessary in practice.

See also