static List <(long, TestOperationResult)> GetStoreData( string source, IEnumerable <string> resultValues, IEnumerable <DateTime> resultDates, IEnumerable <string> resultOperations, int start = 0) { var storeData = new List <(long, TestOperationResult)>(); int count = start; for (int i = 0; i < resultValues.Count(); i++) { var networkControllerStatus = (NetworkControllerStatus)Enum.Parse(typeof(NetworkControllerStatus), resultValues.ElementAt(i)); var networkControllerOperation = (NetworkControllerOperation)Enum.Parse(typeof(NetworkControllerOperation), resultOperations.ElementAt(i)); var networkControllerTestResult = new NetworkControllerTestResult( source, resultDates.ElementAt(i)) { NetworkControllerStatus = networkControllerStatus, NetworkControllerType = NetworkControllerType.Offline, Operation = networkControllerOperation }; storeData.Add((count, networkControllerTestResult.ToTestOperationResult())); count++; } return(storeData); }
private void ValidateNetworkControllerTestResults() { if (this.testResultsValidated) { return; } for (int i = 0; i < this.networkControllerTestResults.Count; i += 2) { NetworkControllerTestResult curr = this.networkControllerTestResults[i]; if (!NetworkControllerOperation.SettingRule.Equals(curr.Operation)) { throw new InvalidOperationException("Expected SettingRule."); } if (!NetworkControllerOperation.RuleSet.Equals(this.networkControllerTestResults[i + 1].Operation)) { throw new InvalidOperationException("Test result SettingRule found with no RuleSet found after."); } if (!curr.NetworkControllerStatus.Equals(this.networkControllerTestResults[i + 1].NetworkControllerStatus)) { throw new InvalidOperationException("Test result SettingRule and following RuleSet do not match NetwokControllerStatuses"); } } this.testResultsValidated = true; }
public (NetworkControllerStatus networkControllerStatus, bool isWithinTolerancePeriod, TimeSpan delay) GetNetworkControllerStatusAndWithinToleranceAt(DateTime statusTime) { this.ValidateNetworkControllerTestResults(); // the time between when the test results finish and the network controller comes up var delay = TimeSpan.Zero; // Return network controller status at given time NetworkControllerStatus networkControllerStatus = this.initialNetworkControllerStatus; bool isWithinTolerancePeriod = false; for (int i = 0; i < this.networkControllerTestResults.Count; i += 2) { NetworkControllerTestResult curr = this.networkControllerTestResults[i]; if (statusTime <= curr.CreatedAt) { break; } networkControllerStatus = curr.NetworkControllerStatus; NetworkControllerTestResult next = this.networkControllerTestResults[i + 1]; isWithinTolerancePeriod = statusTime > curr.CreatedAt && statusTime <= next.CreatedAt.Add(this.tolerancePeriod); delay = statusTime.Subtract(curr.CreatedAt); } return(networkControllerStatus, isWithinTolerancePeriod, delay); }
static Option <NetworkControllerTestResult> GetNetworkControllerTestOperationResult(TestOperationResult current) { if (!current.Type.Equals(TestOperationResultType.Network.ToString(), StringComparison.OrdinalIgnoreCase)) { return(Option.None <NetworkControllerTestResult>()); } Logger.LogDebug($"Deserializing for source {current.Source} result: {current.Result} {current.Type}"); NetworkControllerTestResult networkControllerTestResult = JsonConvert.DeserializeObject <NetworkControllerTestResult>(current.Result); return(Option.Some(networkControllerTestResult)); }
public Task ReportNetworkStatusAsync(NetworkControllerOperation operation, NetworkControllerStatus networkControllerStatus, NetworkControllerType networkControllerType, bool success = true) { var testResult = new NetworkControllerTestResult(this.moduleId, DateTime.UtcNow) { Operation = operation.ToString(), OperationStatus = success ? "Success" : "Failed", NetworkControllerType = networkControllerType, NetworkControllerStatus = networkControllerStatus, TrackingId = this.trackingId }; return(ModuleUtil.ReportTestResultAsync(this.testResultReportingClient, Log, testResult)); }
public (NetworkControllerStatus networkControllerStatus, bool isWithinTolerancePeriod) GetNetworkControllerStatusAndWithinToleranceAt(DateTime statusTime) { this.ValidateNetworkControllerTestResults(); // Return network controller status at given time NetworkControllerStatus networkControllerStatus = this.initialNetworkControllerStatus; bool isWithinTolerancePeriod = false; for (int i = 0; i < this.networkControllerTestResults.Count; i += 2) { NetworkControllerTestResult curr = this.networkControllerTestResults[i]; if (statusTime <= curr.CreatedAt) { break; } networkControllerStatus = curr.NetworkControllerStatus; NetworkControllerTestResult next = this.networkControllerTestResults[i + 1]; isWithinTolerancePeriod = statusTime > curr.CreatedAt && statusTime <= next.CreatedAt.Add(this.tolerancePeriod); } return(networkControllerStatus, isWithinTolerancePeriod); }