private static void RunTests(List<ITestRuleSupplier> testTypesList) { foreach (ITestRuleSupplier ts in testTypesList) { Logger.TraceWriteLine(string.Format("Running cleaning for {0} tests", ts.Name)); Logger.TraceIndent(); CleansingManager cm = new CleansingManager(ts); cm.cleanData(null); if (ts.TestCurrentState()) { Logger.TraceWriteLine("The test suceeded."); } else { Logger.TraceWriteLine("The test failed."); } Logger.TraceUnindent(); } }
/// <summary> /// Initializes the cleaning process /// </summary> /// <remarks> /// Connects to the database and creates <see cref="CleansingManager"/> /// </remarks> public void InitFlow() { m_sqlUtils = new MySqlNativeClientUtils(DBUsername, DBPassword, DBName, HostName); SqlUtils.Connect(); Logger.TraceWriteLine(string.Format("Connected to {0}/{1}@{2} - {3}", DBUsername, DBPassword, DBName, HostName)); // TODO Demo m_cleansingManager = new CleansingManager(new PaperRuleProvider(SqlUtils)); m_cleansingManager = new CleansingManager(new OfflineCleaningRuleProvider(SqlUtils)); // remove previous run data try { Logger.TraceWriteLine("Truncating table " + TableConstants.ScoredFacts); SqlUtils.TruncateTable(TableConstants.ScoredFacts); Logger.TraceWriteLine("Truncating table " + TableConstants.UserScores); SqlUtils.TruncateTable(TableConstants.UserScores); } catch (MySqlException) { Logger.TraceWriteLine(string.Format("Tables {0} and {1} do not exit", TableConstants.ScoredFacts, TableConstants.UserScores)); } }
public void thread_main() { try { DateTime timestamp = DateTime.MinValue; DatabaseCleaningManager dcm = new DatabaseCleaningManager(); dcm.ParseArgs(m_args.Skip(1).ToArray()); dcm.InitFlow(); int iteration = 0; CleansingManager offline = new CleansingManager(new OfflineCleaningRuleProvider(dcm.SqlUtils)); while (m_exit_thread == false) { Logger.DebugWrite(string.Format("Thread is going to sleep at {0}...", DateTime.Now.ToLongTimeString())); Thread.Sleep(1000); Logger.DebugWriteLine(string.Format("back at {0}", DateTime.Now.ToLongTimeString())); if (m_exit_thread) break; DateTime cur = DateTime.Now; #if (!FREQUENT) object res = dcm.SqlUtils.ExecuteScalar(string.Format( "select count(*) from itemsmentions where time > timestamp('{0}')", timestamp.ToString("s"))); long num = (long)res; if (num > 0) #endif { if (0 == iteration++ % 10) // 2 minutes { // full cleanup timestamp = DateTime.Now; Logger.DebugWriteLine("Full cleaning"); offline.cleanData(null); } else { // incremental cleanup #if (FREQUENT) // test code object res = dcm.SqlUtils.ExecuteScalar(string.Format( "select count(*) from itemsmentions where time > timestamp('{0}')", timestamp.ToString("s"))); long num = (long)res; if (num == 0) continue; #endif Logger.TraceWriteLine("Incremental cleaning"); timestamp = cur; CleansingManager online = new CleansingManager(new OnlineCleaningRuleProvider(dcm.SqlUtils)); online.cleanData(null); //offline.cleanData(null); } } } } catch (Exception ex) { DCF.Common.Logger.TraceWriteLine("Caught exception " + ex.Message); } }
public void init() { m_sqlUtils = new MySqlNativeClientUtils(DBUsername, DBPassword, DBName, HostName); SqlUtils.Connect(); Logger.TraceWriteLine(string.Format("Connected to {0}/{1}@{2} - {3}", DBUsername, DBPassword, DBName, HostName)); m_supplier = new XmlRuleSupplier(SqlUtils); m_supplier.parseFile(m_filename); m_cleansingManager = new CleansingManager(m_supplier); }