In Progress

  • This article applies to JobScheduler releases from 1.11.4 JS-1634 - Getting issue details... STATUS

Creating JobScheduler API Jobs using .NET

In addition to the programming languages natively supported by the JobScheduler API, JobScheduler can call .NET Objects with access on its API.

JobScheduler .NET API

The JobScheduler .NET API dlls are included in the lib\sos\com.sos-berlin.jobscheduler.engine.engine-taskserver-dotnet-<version>.jar file of a JobScheduler Windows Agent installation.

Extract lib\sos\com.sos-berlin.jobscheduler.engine.engine-taskserver-dotnet-<version>.jar to any location and find two dll files in the com\sos\scheduler\engine\taskserver\dotnet\dlls subdirectory:

  • com.sos-berlin.engine.engine-job-api-dotnet.dll
  • jni4net.n-0.8.8.0.dll

.

Setting up a project in Visual Studio

  • Create a new project of type "Class Library"
  • Choose .NET Framework 4
  • Add References:
    • Add Reference com.sos-berlin.engine.engine-job-api-dotnet.dll
    • Add Reference jni4net.n-0.8.8.0.dll
  • Create a Class to implement a JobScheduler job or a JobScheduler monitor

Job API

Implementing the job

JobScheduler will later try to find the .NET class as "namespace.classname".

Code for a simple c# job:

SampleJob
namespace JobSchedulerSamples
{
    using sos.spooler;

    public class SampleJob : Job_impl
    {
        #region Public Methods

        public override void spooler_close()
        {
            this.spooler_log.info(".NET spooler_close");
        }

        public override void spooler_exit()
        {
            this.spooler_log.info(".NET spooler_exit");
        }

        public override bool spooler_init()
        {
            const string method = ".NET spooler_init";
            this.spooler_log.info(method + ": spooler_task.id() = " + this.spooler_task.id());

            var taskParams = this.spooler_task.@params();
            if (taskParams != null)
            {
                var testParam = taskParams.value("test");
                if (!string.IsNullOrEmpty(testParam))
                {
                    this.spooler_log.info(method + ": test param = " + testParam);
                }
            }

            return true;
        }

        public override void spooler_on_error()
        {
            this.spooler_log.info(".NET spooler_on_error");
        }

        public override void spooler_on_success()
        {
            this.spooler_log.info(".NET spooler_on_success");
        }

        public override bool spooler_open()
        {
            this.spooler_log.info(".NET spooler_open");
            return true;
        }

        public override bool spooler_process()
        {
            this.spooler_log.info(".NET spooler_process");
            return this.spooler_task.order() != null;
        }

        #endregion
    }
}

 

Running the job

In JobScheduler the job for the above example is configured as follows:

SampleJob
<?xml version="1.0" encoding="ISO-8859-1"?>
<job  title="CSharp SampleJob" order="no" process_class="agent">
    <params>
        <param name="test" value="12345" />
    </params>
    <script language="dotnet" dotnet_class="JobSchedulerSamples.SampleJob" dll="dlls/JobSchedulerSamples.dll" />
    
    <run_time />
</job>

Monitor API

Implementing the monitor

JobScheduler will later try to find the .NET class as "namespace.classname".

Code for a simple c# monitor:

SampleMonitor
namespace JobSchedulerSamples
{
    using sos.spooler;

    public class SampleMonitor : Monitor_impl
    {
        #region Public Methods

        public override bool spooler_process_after(bool spoolerProcessResult)
        {
            this.spooler_log.info(".NET spooler_process_after");
            return spoolerProcessResult;
        }

        public override bool spooler_process_before()
        {
            this.spooler_log.info(".NET spooler_process_before");
            return true;
        }

        public override void spooler_task_after()
        {
            this.spooler_log.info(".NET spooler_task_after");
        }

        public override bool spooler_task_before()
        {
            this.spooler_log.info(".NET spooler_task_before");
            return true;
        }

        #endregion
    }
}

Running the monitor

In JobScheduler the monitor for the above example is configured as follows:

SampleMonitor
<?xml version="1.0" encoding="ISO-8859-1"?>
<job  title="CSharp SampleMonitor" order="no" process_class="agent">
    <params>
    </params>
    <script language="shell"><![CDATA[echo Hello, World]]></script>
    
    <monitor name="csharp_monitor" ordering="1"> 
        <script language="dotnet" dotnet_class="JobSchedulerSamples.SampleMonitor" dll="dlls/JobSchedulerSamples.dll" />
    </monitor>
 
    <run_time />
</job>

C# compiling on Windows without Visual Studio

For the both JobScheduler versions (x86 and x64) both .NET Framework x86 and .NET Framework x64 (see WINDOWS_NET_SDK_HOME below) can be used for compilation.

csharp_compilation.cmd
@echo off
rem --- Compiler Folder Location: x86 Windows ---
rem set WINDOWS_NET_SDK_HOME=C:\Windows\Microsoft.NET\Framework\v4.0.30319
rem --- Compiler Folder Location: x64 Windows ---
set WINDOWS_NET_SDK_HOME=C:\Windows\Microsoft.NET\Framework64\v4.0.30319

rem --- Compilation Dependencies: directory with the JobScheduler .NET API dlls (com.sos-berlin.engine.engine-job-api-dotnet.dll, jni4net.n-0.8.8.0.dll)
set REFERENCE_DIRECTORY=C:\Temp\samples\dependencies

rem --- Compilation Folder Location: directory with the .NET sources to compile
set SOURCE_DIRECTORY=C:\Temp\samples\sources

rem --- Compilation Output file
set OUTPUT_DLL=C:\Temp\samples\out\MySample.dll

%WINDOWS_NET_SDK_HOME%\csc.exe /nologo /t:library /out:"%OUTPUT_DLL%" /recurse:"%SOURCE_DIRECTORY%\*.*" /reference:"%REFERENCE_DIRECTORY%\com.sos-berlin.engine.engine-job-api-dotnet.dll";"%REFERENCE_DIRECTORY%\jni4net.n-0.8.8.0.dll"
echo %OUTPUT_DLL%

 

Samples

Download and extract JobSchedulerSamples.NET.zip

  • Copy dlls folder to the agent working directory (agent_home)
    • Unblock if necessary a downloaded dlls/JobSchedulerSamples.dll file to avoid security warnings. To unblock a file:
      • right-click it in Windows Explorer
      • choose Properties from the context menu
      • click the Unblock button in the lower right-hand corner of the resulting dialog
      • hit OK or Apply
  • Copy dotnet_samples folder to the master live directory (config/live)
    • Configure agent url in the agent.process_class.xml
  • Run samples