public void TestHealth(bool userInitiated) { lock (_locker) { string error = null; string warning = null; string misc = null; if (!_running) { error += "Restarting protocol \"" + _name + "\"..."; try { Stop(); Start(); } catch (Exception ex) { error += ex.Message + "..."; } if (_running) error += "restarted protocol." + Environment.NewLine; else error += "failed to restart protocol." + Environment.NewLine; } if (_running) { if (_localDataStore == null) error += "No local data store present on protocol." + Environment.NewLine; else if (_localDataStore.TestHealth(ref error, ref warning, ref misc)) { error += "Restarting local data store..."; try { _localDataStore.Restart(); } catch (Exception ex) { error += ex.Message + "..."; } if (!_localDataStore.Running) error += "failed to restart local data store." + Environment.NewLine; } if (_remoteDataStore == null) error += "No remote data store present on protocol." + Environment.NewLine; else if (_remoteDataStore.TestHealth(ref error, ref warning, ref misc)) { error += "Restarting remote data store..."; try { _remoteDataStore.Restart(); } catch (Exception ex) { error += ex.Message + "..."; } if (!_remoteDataStore.Running) error += "failed to restart remote data store." + Environment.NewLine; } foreach (Probe probe in _probes) if (probe.Enabled) { if (probe.TestHealth(ref error, ref warning, ref misc)) { error += "Restarting probe \"" + probe.GetType().FullName + "\"..."; try { probe.Restart(); } catch (Exception ex) { error += ex.Message + "..."; } if (!probe.Running) error += "failed to restart probe \"" + probe.GetType().FullName + "\"." + Environment.NewLine; } else { // keep track of successful system-initiated health tests. this tells use how consistently the probe is running. if (!userInitiated) lock (probe.SuccessfulHealthTestTimes) { probe.SuccessfulHealthTestTimes.Add(DateTime.Now); probe.SuccessfulHealthTestTimes.RemoveAll(healthTestTime => healthTestTime < ParticipationHorizon); } } } } _mostRecentReport = new ProtocolReportDatum(DateTimeOffset.UtcNow, error, warning, misc, this); SensusServiceHelper.Get().Logger.Log("Protocol report:" + Environment.NewLine + _mostRecentReport, LoggingLevel.Normal, GetType()); SensusServiceHelper.Get().Logger.Log("Storing protocol report locally.", LoggingLevel.Normal, GetType()); _localDataStore.AddNonProbeDatum(_mostRecentReport); if (!_localDataStore.UploadToRemoteDataStore && _forceProtocolReportsToRemoteDataStore) { SensusServiceHelper.Get().Logger.Log("Local data aren't pushed to remote, so we're copying the report datum directly to the remote cache.", LoggingLevel.Normal, GetType()); _remoteDataStore.AddNonProbeDatum(_mostRecentReport); } } }
public void ResetForSharing() { _randomTimeAnchor = DateTime.MinValue; _storageDirectory = null; _mostRecentReport = null; foreach (Probe probe in _probes) { probe.ResetForSharing(); // reset enabled status of probes to the original values. probes can be disabled when the protocol is started (e.g., if the user cancels out of facebook login.) probe.Enabled = probe.OriginallyEnabled; } if (_localDataStore != null) _localDataStore.ClearForSharing(); if (_remoteDataStore != null) _remoteDataStore.ClearForSharing(); }