Data Mining

Download Free Data Mining Source Code In C/C++, C#, Visual Basic, Visual Basic.NET, Java,
and other programming languages
Welcome to Data Mining Sign in | Join | Help
in Search

Data Mining Source Code Newsletter

Announcing The Data Mining Source Code Newsletter!

Subscribe By Email | Subscribe By RSS Feed

Creating Custom ASP.NET Jobs For Background Processing On Single or MultipleThreads

Last post 09-21-2005, 20:29 by michael jeong. 5 replies.
Sort Posts: Previous Next
  •  04-10-2005, 5:21 4526

    Creating Custom ASP.NET Jobs For Background Processing On Single or MultipleThreads

    1. Introduction:

    This article describes how to create a custom ASP.NET like DTS job that can run on a single thread or multiple threads in the background.

    The source code used in this demonstration is taking from a custom mailing list job for http://www.kdkeys.net/lists . Please download it and use it freely in your applications.

    This ASP.NET Job was created using the extensible components architected for a popular ASP.NET application known as CommunityServer. You can download this application under an open source license that allows you to modify the code while giving credits to the application provider TelligentSystems.

    2. Creating An ASP.NET Background Job:

    Creating a customized job (like a SQL Server DTS Job) for tasks that can be processed using background threads in ASP.NET involves working with 4 or 5 components in Community Server.

    1. CommunityServer.Config xml file
    2. IJob interface in CommunityServer.Configuration namesapce
    3. A Job abstract class that implements the IJob interface (MailingListJob)
    4. A Job class that inherits the Job abstract class (ForumsMailingListJob)
    5. An abstract class that defines the method which will be invoked when the job runs (MailingList)
    6. A class that implements the method that will be invoked when the job runs(ForumsMailingList)
    7. A Jobs and Job class provided by CommunityServer that will manage the invocation, scheduling instantiation, threading of all asp.net jobs.
    8. A SiteSettingsManager class

    3. CommunityServer.Config

    CommunityServer.Config file contains a 'Jobs' configurations section for setting up new jobs or changing the behavior of existing jobs. The can be singleThread or multi-threaded. The sample mailing list asp.net job can be added using the configurations settings below. 

    4. IJob Interface

    This interface is a type in CommunityServer.Configuration namespace and is the interface implemented by all ASP.NET Jobs. It includes an Execute(XmlNode node) method. You will have to inherit from this interface to create a custom asp.net job.

    namespace CommunityServer.Configuration{

       public interface IJob{

             void Execute(XmlNode node); }

    }

    5. Custom Job Abstract Class

    Create an abstract class that will implement the IJob interface and serve as the base class for your custom asp.net job. The custom Job abstract class will be a member of the your namespace. I used KDKEYS.ASPNET.JOBS as the namespace for the Mailing List job.

    a.) namespace KDKEYS.ASPNET.JOBS{

          public abstract class MailingListJob: IJob{

                public MailingListJob(){}

          }

    }

    Create an abstract method that returns the current application implementation of the Custom Job. See an example below.

    b.) protected abstract MailingList CurrentMailingList{

                get;

    }

    c.) Create a method which runs the custom ASP.NET job when invoked by theSiteSettingsListIterator delegate with a SettingsID parameter.

    protected void CreateLists(int settingsID){

          CurrentMailingList.CreateLists(settingsID);

    }

    The Execute(XmlNode node) method implements IJob.Execute by calling the SiteSettingsManager.IterateSiteSettings method.

    d.) public void Execute(XmlNode node){

          SiteSettingsManager.IterateSettings(new, SiteSettingsListIterator(this.CreateLists));

    }

    6. Custom Job Concrete Class

    Create a class that derives from your abstract custom jobs class. This is the class that would be instantiated in your application to execute the custom job class. I created a  ForumsMailingListJob class that inherits from the abstract KDKEYS.ASPNET.JOBS.MailingListJob class. Please refer to the example below:

    namespace KDKEYS.ASPNET.JOBS{

    public class ForumsMailingListJob : MailingListJob

          public ForumsMailingListJob(){}

          ForumMailingList fml = null;

          protected override MailingList CurrentMailingList{

                get{

                      if (fml == null)

                            fml = new ForumMailingList();

                            return fml;

                   }

          }

    7.  Abstract Class Defines Work Done By ASP.NET Job

    Create an abstract class that defines the methods that will be executed to do some processing. Since the custom asp.net job I implemented finds out what mailing list you belong to and sends you periodic scheduled news update, I created an abstract class named  mailing list with one method that is used to create mailing lists(s) for a website as in the code snippet below:

    public abstract class MailingList {
          public abstract void CreateLists (int settingsID);

    }

    8.  lmplement  A Class That Does Work

    Inherit from the abstract class above and implement the abstract member which executes and does some work when the custom asp.net job runs. I created a ForumsMailingList class which derives from the abstract MailingList class and implements the CreateLists method.

    public abstract class ForumsMailingList {
          public override void CreateLists (int settingsID){

            SqlDataProvider provider = new SqlDataProvider();

             provider.KDKEYSGroupsGetDigestMessage(settingsID);

             provider = null;

          }

    }

    9.  Job and Jobs:: The Missing Link?

    You may be asking at this point, 'What Is The Object That Instantiates A Job From CommunityServer.Config?', the answer is the Jobs object.  It holds a single instance of al the jobs that it activated on the web server, where each active jobis represented by a Job object. The Jobs class Starts a Job, Stops A Job, manages the threading and scheduling of jobs and uses the System.Threading.Timer class and a callback to invoke active asp.net jobs. The code goes like this:

    singleTimer = new Timer(new TimerCallback(call_back),null,Interval, Interval);

    10.  SiteSettingsManager.IterateSettings

    You do not have to implement this method, however, you need to call it in the abstract custom job class. The methods enables you to iterate through all the settingsID available.

    11. Threading and Execution Concerns

    What about scheduling your asp.net job so that it runs every x minutes, background pooling, thread management and other concerns? Community Server's components will handle all that for you. CommunityServer uses the same architecture and components that I illustrated above to manage a default set of asp.net jobs for emailing, indexing content for its custom search algorithm, updating site statistics, managing pictures and other asp.net jobs.

    12. Conclusion

    In this article I have shown how you can take advantage of a popular and available ASP.NET application to create customized ASP.NET jobs that can processed on a background thread(s).  I also demonstrated the ease and speed with which you can create scheduled processes without a lot of coding.

    13. About The Author

    Kingsley Tagbo is an freelance writer and consultant.

    You can reach him via his blogs at http://www.kdkeys.net/blogs/kingsleytagbo or http://www.kdkeys.net/blogs/kingsley.tagbo



    Sign-up For Data Mining Source Code Newsletter

  •  08-02-2005, 0:16 5706 in reply to 4526

    Re: Creating Custom ASP.NET Jobs For Background Processing On Single or MultipleThreads

    This was a very interesting and potentially very useful article which unfortunatly does not detail how to implement this in the user controls for CommunityServer. Is there a follow up to this post detailing how to implement a subscription page like you have at http://www.kdkeys.net/lists/ ?

    Thanks for your help.

    Simon

  •  08-02-2005, 0:38 5708 in reply to 5706

    Re: Creating Custom ASP.NET Jobs For Background Processing On Single or MultipleThreads

    Not really, this article was meant to demonstrate how to create a custom community server asp.net job and not a list manager Smile [:)]


    Sign-up For Data Mining Source Code Newsletter

  •  08-02-2005, 0:54 5710 in reply to 5708

    Sad [:(] Re: Creating Custom ASP.NET Jobs For Background Processing On Single or MultipleThreads

    Thats a real shame. I have been waiting for almost 12 months for a solution like this for my nfp community server installation but unfortunatly my c# skills are still limited and I am not sure where to even begin implementing a solution like you have implemented in your installation . I don't suppose you would ever consider extending the article to give an insight in how to achieve this.

    Thanks for a great resource, I think I will learn alot from your community.

    Simon

  •  08-02-2005, 1:03 5714 in reply to 5710

    Re: Creating Custom ASP.NET Jobs For Background Processing On Single or MultipleThreads

    I waited for about 3 years, back then community server was called Forums 1.0. I wish it had been included in the recent builds of Community Server, however, the entire solution was created using one and only one SQL Server stored procedure, no C# code Surprise [:O]

    It is still being evolved and I am adding new functionality now as we type.



    Sign-up For Data Mining Source Code Newsletter

  •  09-21-2005, 20:29 6028 in reply to 5714

    Cool [H] Re: Creating Custom ASP.NET Jobs For Background Processing On Single or MultipleThreads

    I really impressed this interesting way.
    But I cant find storedprocedure "kdkeys_Groups_GetDigestMessage".
    Can I see that prodedure how to work?

Announcing The Data Mining Source Code Newsletter!

Subscribe By Email | Subscribe By RSS Feed