Creating Job Scheduler API Jobs using C# and .NET
In addition to the programming languages natively supported by the JobScheduler API, JobScheduler can call COM Objects with access on its API.
This technique can be used to create C# jobs.
Setting up a project in Visual Studio
- Create a new project of type "Class Library"
- Choose .NET Framework 4 or higher
- In the project properties go to Application->Assembly Information and check "Make assembly COM-Visible"
- In the project properties go to Build and check "Register for COM interop"
- In the project properties go to Signing and check "Sign the assembly"
- Create a Class to implement the job
- Run Visual Studio as Administrator to enable it to register the assembly on your machine
Implementing the job
JobScheduler will later try to find the com class as "namespace.classname". This combined name may not be longer than 40 characters.
Code for a simple c# job:
- the dynamic keyword is used to avoid reflection code
- the dynamic keyword requires .NET 4
- in spooler_set_context the Job Scheduler objects are assigned to local properties
Please refer to these documentations how to use the API: [http://www.sos-berlin.com/doc/en/scheduler.doc/api/api.xml]
The example Visual Studio Project can be downloaded here: http://www.sos-berlin.com/download/scheduler/CSharpSampleJob.zip
Running the job
In JobScheduler the job for the above example is configured as follows:
Registering the assembly
In order for JobScheduler to find your COM Class, the assembly needs to be registered.
From an administrator command line:
Debugging the job
In order to debug the job in visual studio
- In the project properties->Debug choose "Start external program" and insert the path to scheduler.exe
- Copy the command line arguments from the definition of the "SOS JobScheduler" Service and paste them into the "Command line arguments" of the project
- Set the Scheduler home directory as the working directory in the debug options
edit your scheduler.xml and change the "process_classes" element to: