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 DesiredPropertiesValidator(RegistryManager registryManager, ModuleClient moduleClient, TwinEventStorage storage, ITwinTestResultHandler resultHandler, TwinTestState twinTestState) { this.registryManager = registryManager; this.moduleClient = moduleClient; this.storage = storage; this.resultHandler = resultHandler; this.twinTestState = twinTestState; }
public TwinAllOperationsResultHandler(Uri reportUrl, TwinEventStorage storage, string moduleId) { this.testResultReportingClient = new TestResultReportingClient { BaseUrl = reportUrl.AbsoluteUri }; this.moduleId = moduleId; this.storage = storage; }
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 TwinAllOperationsResultHandler(Uri analyzerClientUri, TwinEventStorage storage, string moduleId) { this.analyzerClient = new AnalyzerClient() { BaseUrl = analyzerClientUri.AbsoluteUri }; this.moduleId = moduleId; this.storage = storage; }
async Task OnDesiredPropertyUpdateAsync(TwinCollection desiredProperties, object userContext) { TwinEventStorage storage = (TwinEventStorage)userContext; foreach (dynamic twinUpdate in desiredProperties) { KeyValuePair <string, object> pair = (KeyValuePair <string, object>)twinUpdate; await this.storage.AddDesiredPropertyReceivedAsync(pair.Key); } }
static async Task <ITwinTestInitializer> GetTwinAllOperationsInitializer(RegistryManager registryManager, Uri analyzerClientUri) { ModuleClient moduleClient = await ModuleUtil.CreateModuleClientAsync( Settings.Current.TransportType, ModuleUtil.DefaultTimeoutErrorDetectionStrategy, ModuleUtil.DefaultTransientRetryStrategy, Logger); TwinEventStorage storage = new TwinEventStorage(); storage.Init(Settings.Current.StoragePath, new SystemEnvironment(), Settings.Current.StorageOptimizeForPerformance); var resultHandler = new TwinAllOperationsResultHandler(analyzerClientUri, storage, Settings.Current.ModuleId); return(await TwinAllOperationsInitializer.CreateAsync(registryManager, moduleClient, resultHandler, storage)); }
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; } }); }
static async Task Main() { Logger.LogInformation($"Starting twin tester with the following settings:\r\n{Settings.Current}"); try { RegistryManager registryManager = RegistryManager.CreateFromConnectionString(Settings.Current.ServiceClientConnectionString); ModuleClient moduleClient = await ModuleUtil.CreateModuleClientAsync( Settings.Current.TransportType, ModuleUtil.DefaultTimeoutErrorDetectionStrategy, ModuleUtil.DefaultTransientRetryStrategy, Logger); await moduleClient.OpenAsync(); AnalyzerClient analyzerClient = new AnalyzerClient { BaseUrl = Settings.Current.AnalyzerUrl.AbsoluteUri }; TwinEventStorage storage = new TwinEventStorage(); storage.Init(Settings.Current.StoragePath, new SystemEnvironment(), Settings.Current.StorageOptimizeForPerformance); TwinOperator twinOperator = await TwinOperator.CreateAsync(registryManager, moduleClient, analyzerClient, storage); twinOperator.Start(); (CancellationTokenSource cts, ManualResetEventSlim completed, Option <object> handler) = ShutdownHandler.Init(TimeSpan.FromSeconds(5), Logger); await cts.Token.WhenCanceled(); completed.Set(); handler.ForEach(h => GC.KeepAlive(h)); Logger.LogInformation("TwinTester exiting."); } catch (Exception ex) { Logger.LogError($"Error occurred during twin test setup.\r\n{ex}"); } }
public static async Task <TwinAllOperationsInitializer> CreateAsync(RegistryManager registryManager, ModuleClient moduleClient, ITwinTestResultHandler resultHandler, TwinEventStorage storage) { try { TwinTestState 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 TwinTestState(twin.ETag); } else { Logger.LogInformation("Existing storage detected. Initializing reported / desired property update counters."); initializedState = new TwinTestState( GetNewPropertyCounter(reportedPropertyUpdates), GetNewPropertyCounter(desiredPropertyUpdates), twin.ETag, DateTime.MinValue, DateTime.MinValue, 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}"); } }
TwinAllOperationsInitializer(RegistryManager registryManager, ModuleClient moduleClient, ITwinTestResultHandler resultHandler, TwinEventStorage storage, TwinTestState twinTestState) { this.registryManager = registryManager; this.twinTestState = twinTestState; this.reportedPropertyUpdater = new ReportedPropertyUpdater(moduleClient, resultHandler, twinTestState.ReportedPropertyUpdateCounter); this.desiredPropertyUpdater = new DesiredPropertyUpdater(registryManager, resultHandler, twinTestState); this.desiredPropertyReceiver = new DesiredPropertyReceiver(moduleClient, resultHandler); this.reportedPropertiesValidator = new ReportedPropertiesValidator(registryManager, moduleClient, storage, resultHandler, twinTestState); this.desiredPropertiesValidator = new DesiredPropertiesValidator(registryManager, moduleClient, storage, resultHandler, twinTestState); moduleClient.SetConnectionStatusChangesHandler((status, reason) => { Logger.LogInformation($"Detected change in connection status:{Environment.NewLine}Changed Status: {status} Reason: {reason}"); if (status == ConnectionStatus.Disconnected_Retrying) { this.twinTestState.EdgeHubLastStopped = DateTime.UtcNow; } else if (status == ConnectionStatus.Connected) { this.twinTestState.EdgeHubLastStarted = DateTime.UtcNow; } }); }
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); }
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); }