private void ReportProgress(Control c, AtalLoggerDataRetrievalCycleState state, string msg) { var m = new MethodInvoker(() => { OnProgress.Invoke(this, new ProgressEventArgs(state, msg)); }); c.Invoke(m); }
private void Cycle(object o) { try { Control c = (Control)o; InnerCycle(c); } finally { State = AtalLoggerDataRetrievalCycleState.Idle; } }
public void Start(Control c) { lock (this) { //busy ? if (State != AtalLoggerDataRetrievalCycleState.Idle) { throw new InvalidOperationException("Nog bezig met uitlezen logger..."); } State = AtalLoggerDataRetrievalCycleState.FindingLogger; } //database checked and ok ? CheckDatabase(); if (!databaseOk) { throw new Exception("Database niet gevonden. Metingen kunnen niet opgeslagen worden."); } new Thread(Cycle).Start(c); //next steps to be done in separate thread }
private void InnerCycle(Control c) { //STEP 1. Look for logger - 5 sec var logger = DetectLogger(); State = AtalLoggerDataRetrievalCycleState.ReadingLoggerInfo; ReportProgress(c, state, "Uitlezen logger : serienummer & aantal metingen."); //STEP 2. Get details from logger. var details = logger.GetDetailsFromDevice(); ReportProgress(c, state, string.Format("Uitlezen logger : {0} heeft {1} metingen", details.SerialNumber, details.NumberOfSamples)); if (details.NumberOfSamples == 0) { throw new Exception("Geen metingen op de logger beschikbaar."); } State = AtalLoggerDataRetrievalCycleState.ReadingLoggerSamples; Thread.Sleep(1000); ReportProgress(c, state, string.Format("Uitlezen logger : 0 van {0} uitgelezen", details.NumberOfSamples)); //STEP 3. Read samples from logger. var totalRead = 0; logger.GetSamplesFromDevice(details.NumberOfSamples, i => { totalRead += i; ReportProgress(c, state, string.Format("Uitlezen logger : {0} van {1} uitgelezen", totalRead, details.NumberOfSamples)); }, false); //TODO : support for debug dump... //STEP 4. Store the samples in the database. }
public ProgressEventArgs(AtalLoggerDataRetrievalCycleState state, string msg) { State = state; Message = msg; }