public ReportedPropertyUpdater(RegistryManager registryManager, ModuleClient moduleClient, ITwinTestResultHandler reporter, TwinState twinState) { this.registryManager = registryManager; this.moduleClient = moduleClient; this.reporter = reporter; this.twinState = twinState; }
public DesiredPropertiesValidator(RegistryManager registryManager, ModuleClient moduleClient, TwinEventStorage storage, ITwinTestResultHandler resultHandler, TwinState twinState) { this.registryManager = registryManager; this.moduleClient = moduleClient; this.storage = storage; this.resultHandler = resultHandler; this.twinState = twinState; }
public ReportedPropertyOperation(RegistryManager registryManager, ModuleClient moduleClient, AnalyzerClient analyzerClient, TwinEventStorage storage, TwinState twinState) { this.registryManager = registryManager; this.moduleClient = moduleClient; this.analyzerClient = analyzerClient; this.storage = storage; this.twinState = twinState; }
public DesiredPropertyOperation(RegistryManager registryManager, ModuleClient moduleClient, AnalyzerClient analyzerClient, TwinEventStorage storage, TwinState twinState) { this.registryManager = registryManager; this.moduleClient = moduleClient; this.analyzerClient = analyzerClient; this.storage = storage; this.twinState = twinState; this.moduleClient.SetDesiredPropertyUpdateCallbackAsync(this.OnDesiredPropertyUpdateAsync, storage); }
public static async Task <TwinAllOperationsInitializer> CreateAsync(RegistryManager registryManager, ModuleClient moduleClient, ITwinTestResultHandler resultHandler, TwinEventStorage storage) { try { TwinState initializedState; Twin twin = await registryManager.GetTwinAsync(Settings.Current.DeviceId, Settings.Current.TargetModuleId); Dictionary <string, DateTime> reportedPropertyUpdates = await storage.GetAllReportedPropertiesUpdatedAsync(); Dictionary <string, DateTime> desiredPropertyUpdates = await storage.GetAllDesiredPropertiesUpdatedAsync(); if (reportedPropertyUpdates.Count == 0 && desiredPropertyUpdates.Count == 0 && (await storage.GetAllDesiredPropertiesReceivedAsync()).Count == 0) { Logger.LogInformation("No existing storage detected. Initializing new module twin for fresh run."); // reset desired properties Twin desiredPropertyResetTwin = await registryManager.ReplaceTwinAsync(Settings.Current.DeviceId, Settings.Current.TargetModuleId, new Twin(), twin.ETag); await TwinTesterUtil.ResetTwinReportedPropertiesAsync(moduleClient, desiredPropertyResetTwin); await Task.Delay(TimeSpan.FromSeconds(10)); // give enough time for reported properties reset to reach cloud twin = await registryManager.GetTwinAsync(Settings.Current.DeviceId, Settings.Current.TargetModuleId); initializedState = new TwinState { ReportedPropertyUpdateCounter = 0, DesiredPropertyUpdateCounter = 0, TwinETag = twin.ETag, LastTimeOffline = DateTime.MinValue }; } else { Logger.LogInformation("Existing storage detected. Initializing reported / desired property update counters."); initializedState = new TwinState { ReportedPropertyUpdateCounter = GetNewPropertyCounter(reportedPropertyUpdates), DesiredPropertyUpdateCounter = GetNewPropertyCounter(desiredPropertyUpdates), TwinETag = twin.ETag, LastTimeOffline = DateTime.MinValue, LastTimeOfEdgeRestart = DateTime.MinValue }; } Logger.LogInformation($"Start state of module twin: {JsonConvert.SerializeObject(twin, Formatting.Indented)}"); return(new TwinAllOperationsInitializer(registryManager, moduleClient, resultHandler, storage, initializedState)); } catch (Exception e) { throw new Exception($"Shutting down module. Initialization failure: {e}"); } }
public DesiredPropertiesValidator(RegistryManager registryManager, ModuleClient moduleClient, TwinEventStorage storage, ITwinTestResultHandler resultHandler, TwinState twinState) { this.registryManager = registryManager; this.moduleClient = moduleClient; this.storage = storage; this.resultHandler = resultHandler; this.twinState = twinState; moduleClient.SetConnectionStatusChangesHandler((status, reason) => { Logger.LogInformation($"Detected change in connection status:{Environment.NewLine}Changed Status: {status} Reason: {reason}"); if (status == ConnectionStatus.Disconnected_Retrying) { this.twinState.LastTimeOfEdgeRestart = DateTime.UtcNow; } }); }
public static async Task <TwinCloudOperationsInitializer> CreateAsync(RegistryManager registryManager, ITwinTestResultHandler resultHandler) { try { TwinState initializedState; Twin twin = await registryManager.GetTwinAsync(Settings.Current.DeviceId, Settings.Current.TargetModuleId); initializedState = new TwinState { TwinETag = twin.ETag }; Logger.LogInformation($"Start state of module twin: {JsonConvert.SerializeObject(twin, Formatting.Indented)}"); return(new TwinCloudOperationsInitializer(registryManager, resultHandler, initializedState)); } catch (Exception e) { throw new Exception($"Shutting down module. Initialization failure: {e}"); } }
public static async Task <TwinEdgeOperationsInitializer> CreateAsync(RegistryManager registryManager, ModuleClient moduleClient, ITwinTestResultHandler reporter) { try { TwinState initializedState; Twin twin = await registryManager.GetTwinAsync(Settings.Current.DeviceId, Settings.Current.ModuleId); // reset properties Twin desiredPropertyResetTwin = await registryManager.ReplaceTwinAsync(Settings.Current.DeviceId, Settings.Current.ModuleId, new Twin(), twin.ETag); initializedState = new TwinState { TwinETag = desiredPropertyResetTwin.ETag }; Logger.LogInformation($"Start state of module twin: {JsonConvert.SerializeObject(twin, Formatting.Indented)}"); return(new TwinEdgeOperationsInitializer(registryManager, moduleClient, reporter, initializedState)); } catch (Exception e) { throw new Exception($"Shutting down module. Initialization failure: {e}"); } }
TwinCloudOperationsInitializer(RegistryManager registryManager, ITwinTestResultHandler resultHandler, TwinState twinState) { this.desiredPropertyUpdater = new DesiredPropertyUpdater(registryManager, resultHandler, twinState); }
protected bool ExceedFailureThreshold(TwinState twinState, DateTime twinUpdateTime) { DateTime comparisonPoint = twinUpdateTime > twinState.LastTimeOffline ? twinUpdateTime : twinState.LastTimeOffline; return(DateTime.UtcNow - comparisonPoint > Settings.Current.TwinUpdateFailureThreshold); }
public DesiredPropertyUpdater(RegistryManager registryManager, ITwinTestResultHandler resultHandler, TwinState twinState) { this.registryManager = registryManager; this.resultHandler = resultHandler; this.twinState = twinState; }
TwinAllOperationsInitializer(RegistryManager registryManager, ModuleClient moduleClient, ITwinTestResultHandler resultHandler, TwinEventStorage storage, TwinState twinState) { this.reportedPropertyUpdater = new ReportedPropertyUpdater(registryManager, moduleClient, resultHandler, twinState); this.desiredPropertyUpdater = new DesiredPropertyUpdater(registryManager, resultHandler, twinState); this.desiredPropertyReceiver = new DesiredPropertyReceiver(registryManager, moduleClient, resultHandler); this.reportedPropertiesValidator = new ReportedPropertiesValidator(registryManager, moduleClient, storage, resultHandler, twinState); this.desiredPropertiesValidator = new DesiredPropertiesValidator(registryManager, moduleClient, storage, resultHandler, twinState); }
TwinEdgeOperationsInitializer(RegistryManager registryManager, ModuleClient moduleClient, ITwinTestResultHandler reporter, TwinState initializedState) { this.reportedPropertyUpdater = new ReportedPropertyUpdater(registryManager, moduleClient, reporter, initializedState); this.desiredPropertiesReceiver = new DesiredPropertyReceiver(registryManager, moduleClient, reporter); }
bool ShouldExpectDesiredPropertyCallback(TwinState twinState, DateTime twinUpdateTime) { return((twinUpdateTime - twinState.LastTimeOfEdgeRestart).Duration() > Settings.Current.EdgeHubRestartFailureTolerance); }
private TwinOperator(RegistryManager registryManager, ModuleClient moduleClient, AnalyzerClient analyzerClient, TwinEventStorage storage, TwinState twinState) { this.reportedPropertyOperation = new ReportedPropertyOperation(registryManager, moduleClient, analyzerClient, storage, twinState); this.desiredPropertyOperation = new DesiredPropertyOperation(registryManager, moduleClient, analyzerClient, storage, twinState); }