C# 是否有更新的方法来实现本文所推荐的功能?

C# 是否有更新的方法来实现本文所推荐的功能?,c#,.net,xml,c#-5.0,C#,.net,Xml,C# 5.0,我喜欢这个代理服务的想法,它允许我在不影响现有代码的情况下添加作业,但这篇文章已经很老了。自2005年以来,是否出现了一些更好的方式来完成同样的事情 我仅限于.Net,但我可以使用框架的任何版本 编辑:这里是我试图做的一个总结 拥有一个.Net服务,该服务可以读取配置文件以动态加载DLL以执行任务 该服务有一个动态对象加载器,它将XML映射到DLL中的类以执行任务 下面是xml文件及其映射的类的示例。基本上,该服务可以从xml中读取作业,实例化CustomerAtendeeCreateNoti

我喜欢这个代理服务的想法,它允许我在不影响现有代码的情况下添加作业,但这篇文章已经很老了。自2005年以来,是否出现了一些更好的方式来完成同样的事情

我仅限于.Net,但我可以使用框架的任何版本

编辑:这里是我试图做的一个总结

拥有一个.Net服务,该服务可以读取配置文件以动态加载DLL以执行任务

该服务有一个动态对象加载器,它将XML映射到DLL中的类以执行任务

下面是xml文件及其映射的类的示例。基本上,该服务可以从xml中读取作业,实例化CustomerAtendeeCreateNotificationWorker的实例并调用Run()方法。作为一名开发人员,我可以创建任意数量的此类,并在Run()方法中实现我想要的任何东西。还要注意,“CustomerAttendanceNotificationTemplateName”的条目被分配给实例化对象上具有相同名称的属性

<?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>

/>
//
///客户与会者将创建通知工作人员。
/// 
[可序列化]
公共类CustomerAttendeeCreateNotificationWorker:TaskWorker
{
#区域常数
/// 
///该统计数据至关重要。
/// 
private const int StateCritical=1;
/// 
///统计数据还可以。
/// 
私有常量int StateOk=0;
#端区
#区域字段
/// 
///客户通知设置名称。
/// 
私有字符串customerAttendanceNotificationTemplateName;
#端区
#区域公共财产
/// 
///客户通知设置名称。
/// 
公共字符串CustomerAttendanceNotificationTemplateName
{
得到
{
返回此.customerAttendanceNotificationTemplateName;
}
设置
{
this.customerAttendanceNotificationTemplateName=值;
}
}
/// 
///获取或设置记录器。
/// 
公共ILogger记录器{get;set;}
#端区
#区域公共方法和运算符
/// 
///跑步。
/// 
/// 
///这个。
/// 
公共覆盖任务结果运行()
{
StringBuilder errorStringBuilder=新建StringBuilder();
string errorLineTemplate=“时间:{0}数据库:{1}错误消息:{2}”+Environment.NewLine;
bool-isError=false;
IUnitOfWork configUnitOfWork=新的GenericUnitOfWork();
TradeshowService TradeshowService=新的TradeshowService(configUnitOfWork);
List tradeshows=tradeshowService.GetAll()。其中(t=>t.Status==“OPEN”).ToList();
字符串connectionStringTemplate=ConfigurationManager.ConnectionStrings[“DCCTradeshow”]。ConnectionString;
int customerNotificationSettingGroupId=Convert.ToInt32(ConfigurationManager.AppSettings[“NotificationSettingGroupId]”);
foreach(贸易展中的贸易展)
{
尝试
{
string connectionString=string.Format(connectionStringTemplate,tradeshow.DbName);
IUnitOfWork unitOfWork=新展会unitOfWork(connectionString);
NotificationService NotificationService=新的NotificationService(工作单元);
notificationService.InsertCustomerAttentications通知(tradeshow.TradeshowId、customerNotificationSettingGroupId、this.customerAttendanceNotificationTemplateName);
}
捕获(异常)
{
isError=真;
AppendLine(string.Format(errorLineTemplate,DateTime.Now,tradeshow.DbName,exception.Message));
}
}
任务结果;
如果(isError)
{
结果=新的TaskResult(StateOk,TaskResultStatus.Exception,“出错”,errorStringBuilder.ToString());
}
其他的
{
结果=新任务结果(StateOk,TaskResultStatus.Ok,“一切正常”,“一切正常”);
}
返回结果;
}
#端区
}`

你能在你的问题中总结一下那篇文章的相关观点吗?关于堆栈溢出的问题应该是自包含的,如果外部链接最终破坏了您的问题,那么您的问题将毫无意义。Frédéric Hamidi感谢您的反馈。我已经更新了帖子。
/// <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
}`