2013-02-14 31 views
0

我必須構建一個從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

那麼我會寫架構的東西,以便應用程序在將來保持可擴展性。

特徵碼用於:依賴注入

做一個接口名爲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源類。是的,它增加了許多班級,但這就是單一職責原則,加上你將能夠維護/擴展應用程序的方式。

+0

嗨,首席,由於我必須履行的項目的一些要求,我無法使用此設置,但我覺得這是一個很好的體系結構,我會記住另一個項目。 +1 – Learner 2013-02-20 18:47:04

相關問題