Learner
Learner

Reputation: 4004

Generic Windows Service for multiple client databases and FTP accounts

I have to build a windows service that grabs data from n number of client databases, convert the result set to XLS format and send it to corresponding (client specific) FTP account at client specified interval,

Here's another way of putting it: Same Windows Service will connect to multiple databases, sends files to different FTP accounts and runs at different intervals based on which client DB it is connected to.

My question is, how should I design it so that it's flexible to handle multiple scenarios and is more configurable.

The basic idea behind this is to minimize the implementation time in future when a new client asks for the same service.

I am considering the following idea where an individual client can be set to a separate worker thread. I know something is terribly wrong with this approach but can't seem to figure out the best way.

Here's the partial code:

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
    }

Let me know if I am not making any sense and I am open to explore a completely new approach.

Code sample will help.

Thanks all in advance!

Upvotes: 0

Views: 692

Answers (1)

Chief
Chief

Reputation: 914

Well i am gonna write the architecting stuff so that the application stays extensible in future.

Pattern Used: Dependency Injection

Make a Interface named IDatabaseSources and implement the interface in the different datasourceclasses

A sample method for your IDatabaseSource interface would be Connect(),FetchData(). When you program the connect method in the implemented classes fetch the connection string from web.config.

public class SQLDataSource:IDatabaseSources { will have all the methods defined in the interface}

public class SQLDataSource2:IDatabaseSources{ will have all the methods defined in the interface}

Make a interface named IFTPSources and implement the interface in the different classes.

A sample method for your IDatabaseSource interface would be Connect(),SendData(). When you program the connect method in the implemented classes fetch the FTP information from web.config.

public class FTPSource1:IFTPSources{ will have all the methods defined in the interface}

public class FTPSource2:IFTPSources{ will have all the methods defined in the interface}

Further these dependency's should be injected in the windows service as per your scheduler

Although if there are 10 FTP destinations then you'll have 10 FTP source class. Yes it increases number of classes but that's what single responsibility principle is plus that way you'll be able to maintain/extend the application.

Upvotes: 1

Related Questions