public void ReplicateData(string sFromDatabaseName, string ToDatabaseName) { // Create the target Database string sql = "CREATE DATABASE " + ToDatabaseName; USGDFramework.Data d = new USGDFramework.Data(); d.Exec(sql); string sSchema = ScriptDatabase(sFromDatabaseName, ToDatabaseName); sql = "USE " + ToDatabaseName; d.Exec(sql); d.Exec(sSchema); // For each table in Source database, insert a mirror image of data in the destination, that is NOT in the destination already. List <DataTable> lTables = GetSchemas(sFromDatabaseName); foreach (DataTable lTable in lTables) { string sTargetTable = ToDatabaseName + "..[" + lTable.Name + "]"; string sSourceTable = sFromDatabaseName + "..[" + lTable.Name + "]"; string sSourceFields = GetDelimitedFieldList(lTable, false); string sTargetFields = GetDelimitedFieldList(lTable, true); string sInsert = "INSERT INTO " + sTargetTable + " (" + sSourceFields + ")"; string sFrom = "SELECT " + sSourceFields + " FROM " + sSourceTable + " WHERE ID NOT IN (Select ID from " + sTargetTable + ")"; string sSQL = sInsert + "\r\n" + sFrom; d.Exec(sSQL); } }
public static object Housecleaning(string sNetworkID, HttpServerUtility server, HttpApplicationState ha, bool bForce) { try { if (string.IsNullOrEmpty(sNetworkID)) { sNetworkID = "test"; } //Once every minute or so, perform housecleaning string sClean = AppCache("lastcleaning" + sNetworkID, ha); DateTime dtClean = default(DateTime); if (Strings.Len(sClean) > 0) { dtClean = Convert.ToDateTime(sClean); } double dtSecs = DateAndTime.DateDiff(DateInterval.Second, dtClean, DateTime.Now); string sDt8 = AppCache("lastscan" + sNetworkID, ha); DateTime dt8 = default(DateTime); if (Strings.Len(sDt8) > 0) { dt8 = Convert.ToDateTime(sDt8); } double dt8Secs = DateAndTime.DateDiff(DateInterval.Second, dt8, DateTime.Now); string sHealth = GetHealth(sNetworkID); if (dt8Secs > 180) { AppCache("lastscan" + sNetworkID, DateTime.Now.ToString(), server, ha); lock (myLock) { if (sHealth != "HEALTH_DOWN") { ScanBlocksForPoolBlocksSolved(sNetworkID, bForce); } } } if (dtSecs > 60 || bForce) { lock (myLock) { AppCache("lastcleaning" + sNetworkID, DateTime.Now.ToString(), server, ha); string sql = "exec UpdatePool '' "; mPD.Exec(sql); // Verify all solutions VerifySolutions(sNetworkID); //Clear out old Work records (networkid does not matter as old is old) check to see if any blocks are solved if (clsStaticHelper.LogLimiter() > 970) { RewardUpvotedLetterWriters(); } return(true); } } return(true); } catch (Exception ex) { clsStaticHelper.Log("HOUSECLEANING ERR: " + ex.Message); return(false); } }