Software

Samay Enterprise .NET Scheduler – Replace Windows Service & Tasks for your Background Jobs

  • By
  • September 27, 2012

.NET Scheduler
Introduction
As a .NET developer you must have run into situations where you need to run tasks and jobs in the background at fixed schedules. The most common methods to get this done is creating Windows Services or using the Windows Task Scheduler. However, developing and controlling them is both time consuming and needs developer intervention for tweaking the minutest settings. Samay .NET Enterprise Scheduler fills in this requirement by providing all the infrastructure needed to run the simplest to the most complicated tasks. Background
In this tutorial, we will go through how easy it is to create a Job and Task for Samay. You can now write generic Tasks in your favorite .NET language like C# or VB.net which take in parameters from a friendly interface which an admin can customize without changing any code.Samay has a very easy to use Administration User Interface which lets you quickly see a list of Jobs & their configurations. There is a TimeLine interface to give you a Visual representation of you Jobs Schedule and find an appropriate time to schedule Jobs so as to distribute the load on the system resources. It also has a powerful logging interface to see what is going on inside the Samay Engine.Your First Task:
We will create a very simple task in C# which takes in Two Numbers, and performs one of the four possible operation on them (Plus, Minus, Multiply, Divide). We will also create a Test Harness so that we can test our task thoroughly before deploying it to the Samay Engine. Of course, this is for illustration purposes only and Samay supports any complex logic code you can write in .NET!

Creating the Task:
Open Visual Studio 2010. Create a new Visual Studio Project, ‘Class Library’ (C#) and name it ‘Task_Operations’. Rename ‘Class1.cs’ to ‘Task_Operations.cs’. Add a Reference to ‘SamaySharedLib’ and a ‘using Technisient;’ in your source file.Inherit from ‘TaskBase’ class and override the ‘Run’ method. Here is how the C# code looks now:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Technisient;

namespace Task_Operations
{
public class Task_Operations:TaskBase
{
public override object Run(object input)
{
//your logic
return null;
}
}
}

Now, we will start with actual logic of the Task. We need three parameters – the two numbers to work on and the operation to be performed on them. Lets define three properties and set the attribute ‘SamayParameter’ on them. Setting this attribute will expose the properties in the Samay Admin interface. To show a dropdown, we use enum for operation. Then we write the logic in the ‘Run’ method. When this method is executed in the engine, the properties will be automatically be initialized by the Samay Engine.Complete C# Source code:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Technisient;

namespace Task_Operations
{
public class Task_Operations : TaskBase
{
public override object Run(object input)
{
//your logic
decimal answer = 0;

switch (Operation)
{
case Ops.Add:
answer = Number1 + Number2;
break;
case Ops.Subtract:
answer = Number1 – Number2;
break;
case Ops.Multiple:
answer = Number1 * Number2;
break;
case Ops.Divide:
answer = Number1 / Number2;
break;
default:
break;
}

return answer;
//can return null if you are not doing any Task Chaining or
//the next Tasks does not require any input from previous Task.
}

[SamayParameter(LabelText = "Number 1",
Help = "First Number", IsRequired = true, Index = 1)]
public long Number1 { get; set; }

[SamayParameter(LabelText = "Number 2",
Help = "Second Number", IsRequired = true, Index = 3)]
public long Number2 { get; set; }

[SamayParameter(LabelText = "Operation", DefaultValue = "Add",
Help = "Operation to be performed", IsRequired = true, Index = 2)]
public Ops Operation { get; set; }

public enum Ops { Add, Subtract, Multiple, Divide }
}
}

Thats as easy as it gets!

Please click here to see the entire tutorial:
http://www.dotnetscheduler.com/content/getting-started-0
Here we cover in detail the following topics including the User Interface for jobs and tasks:

  • SamayParameter
  • Logging
  • Task Chaining
  • Task Configuration Interface

No Comments Found

Leave a Reply