public MainForm() { _presenter = new ChangeTracker(this); _mySettings = new MySettings(); InitializeComponent(); InitFormView(); CreateStatusBar(); }
public void ScanWorker() { MySettings settings = new MySettings(); _shouldStopScan = false; List<string> availableTables = new List<string>(); _view.Status("Scanner: Getting all tables list"); _view.Log("==================================================================="); using (var command = new SqlCommand(settings.GetAllTablesSql, _sqlConnection)) { try { using (var reader = command.ExecuteReader()) { while (reader.Read()) { if (_shouldStopScan) { SetScanIsCanceled(); return; } availableTables.Add(reader[0].ToString()); } } } catch(Exception e) { _view.LogError("Get All tables execution failed"); _view.LogError("QUERY: " + settings.GetAllTablesSql); _view.LogError(e.Message); } } _view.InitProgress(availableTables.Count); using (var command = new SqlCommand()) { command.Connection = _sqlConnection; foreach (var table in availableTables) { if (_shouldStopScan ) { SetScanIsCanceled(); return; } _view.Status("Scanning: " + table); _view.PerformStep(); command.CommandText = String.Format(settings.GetCheckSumSql, table); Int32? checksum = 0; try { checksum = command.ExecuteScalar() as Int32?; } catch (Exception e) { _view.LogError(e.Message + " TABLE " + table); _view.LogError("QUERY: " + settings.GetCheckSumSql); continue; } bool printchanged = false; if (!_lastTables.ContainsKey(table)) { _lastTables[table] = 0; } if (_lastTables[table] != checksum) { printchanged = true; _lastTables[table] = checksum; } if (printchanged) { _view.Log(table); } } IsScanInProgress = false; _view.Status("Ready"); _view.UpdateScanIsStopped(); } }
public void ScanWorker() { MySettings settings = new MySettings(); _shouldStopScan = false; List <string> availableTables = new List <string>(); _view.Status("Scanner: Getting all tables list"); _view.Log("==================================================================="); using (var command = new SqlCommand(settings.GetAllTablesSql, _sqlConnection)) { try { using (var reader = command.ExecuteReader()) { while (reader.Read()) { if (_shouldStopScan) { SetScanIsCanceled(); return; } availableTables.Add(reader[0].ToString()); } } } catch (Exception e) { _view.LogError("Get All tables execution failed"); _view.LogError("QUERY: " + settings.GetAllTablesSql); _view.LogError(e.Message); } } _view.InitProgress(availableTables.Count); using (var command = new SqlCommand()) { command.Connection = _sqlConnection; foreach (var table in availableTables) { if (_shouldStopScan) { SetScanIsCanceled(); return; } _view.Status("Scanning: " + table); _view.PerformStep(); command.CommandText = String.Format(settings.GetCheckSumSql, table); Int32?checksum = 0; try { checksum = command.ExecuteScalar() as Int32?; } catch (Exception e) { _view.LogError(e.Message + " TABLE " + table); _view.LogError("QUERY: " + settings.GetCheckSumSql); continue; } bool printchanged = false; if (!_lastTables.ContainsKey(table)) { _lastTables[table] = 0; } if (_lastTables[table] != checksum) { printchanged = true; _lastTables[table] = checksum; } if (printchanged) { _view.Log(table); } } IsScanInProgress = false; _view.Status("Ready"); _view.UpdateScanIsStopped(); } }