async Task <TestResultCoordinator.TestOperationResult> GetTwinAsync() { try { Twin twin = await this.registryManager.GetTwinAsync(Settings.Current.DeviceId, this.moduleId); if (twin == null) { Logger.LogError($"Twin was null for {this.moduleId}"); return(null); } var twinTestResult = new TwinTestResult() { TrackingId = this.trackingId, Properties = twin.Properties.Reported }; return(new TestResultCoordinator.TestOperationResult( this.Source, TestOperationResultType.Twin.ToString(), twinTestResult.ToString(), twin.LastActivityTime.HasValue ? twin.LastActivityTime.Value : DateTime.UtcNow)); } catch (Exception e) { Logger.LogError(e, $"Failed to get twin for {this.moduleId}"); return(null); } }
Option<TwinTestResult> GetTwinTestResult(TestOperationResult current) { if (!current.Type.Equals(TestOperationResultType.Twin.ToString(), StringComparison.OrdinalIgnoreCase)) { Option.None<TwinTestResult>(); } TwinTestResult twinTestResult = JsonConvert.DeserializeObject<TwinTestResult>(current.Result); return Option.Some(twinTestResult); }
async Task SendReportAsync(string source, StatusCode statusCode, TwinCollection details, string exception = "") { var result = new TwinTestResult() { Operation = statusCode.ToString(), Properties = details, ErrorMessage = exception, TrackingId = this.trackingId }; Logger.LogDebug($"Sending report {result.ToString()}"); await ModuleUtil.ReportStatus(this.trcClient, Logger, source, result.ToString(), TestOperationResultType.Twin.ToString()); }
Option <TwinTestResult> GetTwinTestResult(TestOperationResult current) { if (!current.Type.Equals(TestOperationResultType.Twin.ToString(), StringComparison.OrdinalIgnoreCase)) { Option.None <TwinTestResult>(); } Logger.LogDebug($"Deserializing for source {current.Source} result: {current.Result} {current.Type}"); TwinTestResult twinTestResult = JsonConvert.DeserializeObject <TwinTestResult>(current.Result); return(Option.Some(twinTestResult)); }
async Task SendReportAsync(string source, StatusCode statusCode, TwinCollection details, string exception = "") { var result = new TwinTestResult(source, DateTime.UtcNow) { Operation = statusCode.ToString(), Properties = details, ErrorMessage = exception, TrackingId = this.trackingId }; Logger.LogDebug($"Sending report {result.GetFormattedResult()}"); await ModuleUtil.ReportTestResultAsync(this.testResultReportingClient, Logger, result); }
static List <(long, TestOperationResult)> GetStoreData(string source, string resultType, IEnumerable <string> resultValues, int start = 0) { var storeData = new List <(long, TestOperationResult)>(); int count = start; foreach (string value in resultValues) { var tc = new Microsoft.Azure.Devices.Shared.TwinCollection(); var values = value.Split(";"); foreach (var item in values) { tc[item] = "1"; } var twinTestResult = new TwinTestResult(source, DateTime.UtcNow) { Properties = tc }; storeData.Add((count, twinTestResult.ToTestOperationResult())); count++; } return(storeData); }