用于多个客户端数据库和FTP帐户的通用Windows服务
我必须构建一个从n个客户端数据库获取数据的Windows服务,将结果集转换为XLS格式并将其发送到客户端的相应(客户端特定)FTP帐户指定的时间间隔,用于多个客户端数据库和FTP帐户的通用Windows服务
下面是放置它的另一种方式: 相同的Windows服务将连接到多个数据库,将文件发送到不同的FTP帐户,并根据连接到的客户端数据库以不同的时间间隔运行。
我的问题是,我应该如何设计它,以便它可以灵活处理多个场景并且更具可配置性。
这个背后的基本思想是最大限度地减少新客户端要求相同服务时的实施时间。
我正在考虑以下想法,其中可以将单个客户端设置为单独的工作线程。我知道这种方法有些严重错误,但似乎无法找出最佳方法。
这里的部分代码:
private static void Main(string[] args)
{
// Initialize the first worker thread.
NewUserThread newUserThread = new NewUserThread();
// Specify properties of this worker thread.
newUserThread.Name = "New User Check";
newUserThread.Delay = 0;
newUserThread.Interval = 2 * 60 * 1000;
// Initialize the second worker thread.
UserUpdateThread userUpdateThread = new UserUpdateThread();
// Specify properties of this worker thread.
userUpdateThread.Name = "User Update Check";
userUpdateThread.Delay = 30 * 1000;
userUpdateThread.Interval= 5 * 60 * 1000;
// Initialize the first Windows service objects.
WindowsService userCheckService = new WindowsService();
userCheckService.ServiceName = UserCheckServiceName;
// Initialize the second Windows service objects.
WindowsService emailService = new WindowsService();
emailService.ServiceName = EmailServiceName;
// Add services to an array.
ServiceBase[] services = new ServiceBase[]
{
userCheckService,
emailService,
};
// Launch services.
SendFiles("Launching services...");
Run(services, args);
}
internal static void (string message, params object[] args)
{
// Call to DB
// Convert dataset to XLS
// Send to FTP
}
让我知道,如果我没有做任何意义,我很开放,探索一种全新的方法。
代码示例将有所帮助。
非常感谢!
那么我会写架构的东西,以便应用程序在将来保持可扩展性。
特征码用于:依赖注入
做一个接口名为IDatabaseSources和实现接口的不同datasourceclasses
您IDatabaseSource接口的样品的方法是连接(),FetchData()。当您在已实现的类中编写connect方法时,将从web.config中获取连接字符串。
公共类的SqlDataSource:IDatabaseSources {将在接口中定义的所有方法}
公共类SQLDataSource2:IDatabaseSources {将在接口中定义的所有方法}
做一个接口名为IFTPSources并实现不同类中的接口。
您的IDatabaseSource接口的示例方法是Connect(),SendData()。当您在已实现的类中编写connect方法时,从web.config中获取FTP信息。
公共类FTPSource1:IFTPSources {将在接口中定义的所有方法}
公共类FTPSource2:IFTPSources {将在接口中定义的所有方法}
此外,这些依赖项应按照您的调度程序注入到windows服务中
虽然如果有10个FTP目标,那么您将拥有10个FTP源类。是的,它增加了许多班级,但这就是单一职责原则,加上你将能够维护/扩展应用程序的方式。
嗨,首席,由于我必须履行的项目的一些要求,我无法使用此设置,但我觉得这是一个很好的体系结构,我会记住另一个项目。 +1 – Learner 2013-02-20 18:47:04