我必須構建一個從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
}
讓我知道,如果我沒有做任何意義,我很開放,探索一種全新的方法。
代碼示例將有所幫助。
非常感謝!
嗨,首席,由於我必須履行的項目的一些要求,我無法使用此設置,但我覺得這是一個很好的體系結構,我會記住另一個項目。 +1 – Learner 2013-02-20 18:47:04