c# - Generic Windows Service for multiple client databases and FTP accounts -
i have build windows service grabs info n number of client databases, convert result set xls format , send corresponding (client specific) ftp business relationship @ client specified interval,
here's way of putting it: same windows service connect multiple databases, sends files different ftp accounts , runs @ different intervals based on client db connected to.
my question is, how should design it's flexible handle multiple scenarios , more configurable.
the basic thought behind minimize implementation time in future when new client asks same service.
i considering next thought individual client can set separate worker thread. know terribly wrong approach can't seem figure out best way.
here's partial code:
private static void main(string[] args) { // initialize first worker thread. newuserthread newuserthread = new newuserthread(); // specify properties of worker thread. newuserthread.name = "new user check"; newuserthread.delay = 0; newuserthread.interval = 2 * 60 * 1000; // initialize sec worker thread. userupdatethread userupdatethread = new userupdatethread(); // specify properties of worker thread. userupdatethread.name = "user update check"; userupdatethread.delay = 30 * 1000; userupdatethread.interval= 5 * 60 * 1000; // initialize first windows service objects. windowsservice usercheckservice = new windowsservice(); usercheckservice.servicename = usercheckservicename; // initialize sec windows service objects. windowsservice emailservice = new windowsservice(); emailservice.servicename = emailservicename; // add together services array. servicebase[] services = new servicebase[] { usercheckservice, emailservice, }; // launch services. sendfiles("launching services..."); run(services, args); } internal static void (string message, params object[] args) { // phone call db // convert dataset xls // send ftp }
let me know if not making sense , open explore new approach.
code sample help.
thanks in advance!
well gonna write architecting stuff application stays extensible in future.
pattern used: dependency injection
make interface named idatabasesources , implement interface in different datasourceclasses
a sample method idatabasesource interface connect(),fetchdata(). when programme connect method in implemented classes fetch connection string web.config.
public class sqldatasource:idatabasesources { have methods defined in interface}
public class sqldatasource2:idatabasesources{ have methods defined in interface}
make interface named iftpsources , implement interface in different classes.
a sample method idatabasesource interface connect(),senddata(). when programme connect method in implemented classes fetch ftp info web.config.
public class ftpsource1:iftpsources{ have methods defined in interface}
public class ftpsource2:iftpsources{ have methods defined in interface}
further these dependency's should injected in windows service per scheduler
although if there 10 ftp destinations you'll have 10 ftp source class. yes increases number of classes that's single responsibility principle plus way you'll able maintain/extend application.
c# .net multithreading windows-services
No comments:
Post a Comment