c# - Disabling Database Writes for a Dry Run -
i have windows service inherits marshalbyrefobject.
while running, service receive file then:
read info database do calculations write result databasei want implement function, let's phone call testrun(), can called remotely will:
for obvious reasons, want testrun() utilize same calculation code regular service, littered updatedatabase() calls.
here simplified version of have:
static bool commitchanges = true; public calcresult testrun() { seek { commitchanges = false; homecoming processdata(); } { commitchanges = true; } } private calcresult processdata() { datamodel info = querydata(); //note: docalculations() calls bunch of other functions complex // objects many of create multiple calls updatedatabase(). calcresult result = docalculations(datamodel); homecoming result; } private void updatedatabase(calcresult result) { if(commitchanges) { //write info database } } the problem i'm pretty sure if calls testrun() while service processing data, it's possible of real info might not written database.
what improve way disable queries test run using boolean flag?
you add together optional argument processdata.
public calcresult testrun() { homecoming processdata(writetodatabase: false); } private calcresult processdata(bool writetodatabase = true) { datamodel info = querydata(); calcresult result = docalculations(datamodel); if (writetodatabase) updatedatabase(result); homecoming result; } private void updatedatabase(calcresult result) { //write info database } c# multithreading remoting
No comments:
Post a Comment