Is there a newer way to accomplish what this article recommends?

74 views Asked by At

I like the idea of this Agent Service that allows me to add jobs without affecting existing code, but the article is pretty old. Has something come along since 2005 that would be a better way of accomplishing the same thing?

I am limited to .Net, but I can use any version of the framework.

http://visualstudiomagazine.com/articles/2005/05/01/create-a-net-agent.aspx

Edit: Here is a summary of what I'm trying to do

Have a .Net service that can read a configuration file to dynamically load DLLs to perform tasks.

The service has a dynamic object loader that maps XML to classes in the DLLs to perform the tasks.

An example of the xml file and the class it maps is below. Basically, the service can read the Job from the xml, instantiate an instance of the CustomerAttendeeCreateNotificationWorker and call the Run() method. As a developer, I can make any number of these classes and implement whatever I want in the Run() method. Also note that the entry for "CustomerAttendanceNotificationTemplateName" gets assigned to a property with the same name on the instantiated object.

<?xml version="1.0" encoding="utf-8"?>
<Manager type="Task.RemotingManager, TaskClasses">
    <Jobs type="Task.TaskJob, TaskBase" Name="CustomerAttendeeCreateNotificationWorker Worker">
        <Worker type="TaskWorkers.CustomerAttendeeCreateNotificationWorker, TaskWorkers"
            Description="Inserts records into NotificationQueue for CustomerAttendees"
                CustomerAttendanceNotificationTemplateName ="CustomerAttendanceNotificationTemplateName"
            />
        <Schedulers type="Task.FixedIntervalScheduler, TaskClasses"
            DaysOfWeek="Everyday"
            Frequency="00:05:00"
            StartTime="00:00:00"
            EndTime="23:55:00"
            />
    </Jobs>
    <Jobs type="Task.TaskJob, TaskBase" Name="SendNotificationWorker Worker">
        <Worker type="TaskWorkers.SendNotificationWorker, TaskWorkers"
            Description="Sends messages from NotificationQueue"
            />
        <Schedulers type="Task.FixedIntervalScheduler, TaskClasses"
            DaysOfWeek="Everyday"
            Frequency="00:05:00"
            StartTime="00:00:00"
            EndTime="23:55:00"
            />
    </Jobs>/>
</Manager>
/// <summary>
///     The customer attendee create notification worker.
/// </summary>
[Serializable]
public class CustomerAttendeeCreateNotificationWorker : TaskWorker
{
    #region Constants

    /// <summary>
    ///     The stat e_ critical.
    /// </summary>
    private const int StateCritical = 1;

    /// <summary>
    ///     The stat e_ ok.
    /// </summary>
    private const int StateOk = 0;

    #endregion

    #region Fields

    /// <summary>
    ///     The customer notification setting name.
    /// </summary>
    private string customerAttendanceNotificationTemplateName;

    #endregion

    #region Public Properties

    /// <summary>
    ///     The customer notification setting name.
    /// </summary>
    public string CustomerAttendanceNotificationTemplateName
    {
        get
        {
            return this.customerAttendanceNotificationTemplateName;
        }

        set
        {
            this.customerAttendanceNotificationTemplateName = value;
        }
    }

    /// <summary>
    /// Gets or sets the logger.
    /// </summary>
    public ILogger Logger { get; set; }

    #endregion

    #region Public Methods and Operators

    /// <summary>
    ///     The run.
    /// </summary>
    /// <returns>
    ///     The <see cref="TaskResult" />.
    /// </returns>
    public override TaskResult Run()
    {
        StringBuilder errorStringBuilder = new StringBuilder();
        string errorLineTemplate = "Time: {0} Database: {1} Error Message: {2}" + Environment.NewLine;
        bool isError = false;
        IUnitOfWork configUnitOfWork = new GenericUnitOfWork<DCCShowConfigContext>();
        TradeshowService tradeshowService = new TradeshowService(configUnitOfWork);

        List<Tradeshow> tradeshows = tradeshowService.GetAll().Where(t => t.Status == "OPEN").ToList();
        string connectionStringTemplate = ConfigurationManager.ConnectionStrings["DCCTradeshow"].ConnectionString;
        int customerNotificationSettingGroupId = Convert.ToInt32(ConfigurationManager.AppSettings["NotificationSettingGroupId"]);

        foreach (Tradeshow tradeshow in tradeshows)
        {
            try
            {
                string connectionString = string.Format(connectionStringTemplate, tradeshow.DbName);
                IUnitOfWork unitOfWork = new TradeshowUnitOfWork(connectionString);

                NotificationService notificationService = new NotificationService(unitOfWork);
                notificationService.InsertCustomerAttendanceNotifications(tradeshow.TradeshowId, customerNotificationSettingGroupId, this.customerAttendanceNotificationTemplateName);
            }
            catch (Exception exception)
            {
                isError = true;
                errorStringBuilder.AppendLine(string.Format(errorLineTemplate, DateTime.Now, tradeshow.DbName, exception.Message));
            }
        }

        TaskResult result;
        if (isError)
        {
            result = new TaskResult(StateOk, TaskResultStatus.Exception, "Errors Occured", errorStringBuilder.ToString());
        }
        else
        {
            result = new TaskResult(StateOk, TaskResultStatus.Ok,"All Good", "All Good");
        }

        return result;
    }

    #endregion
}`
0

There are 0 answers