private static void UpdateNonContainerProgress(VerificationProgressMsg currentProgress, VerificationProgressEventArgs e) { VerificationProgressStep newProgressStep = ToVerificationStep(e.ProgressStep); if (currentProgress.ProgressType != (int)e.ProgressType) { // First non-container progress ResetOverallStep(currentProgress); currentProgress.Message = string.Empty; currentProgress.ProcessingStepMessage = string.Empty; } if (newProgressStep == VerificationProgressStep.DataLoading) { SetOverallStep(currentProgress, e); ResetDetailStep(currentProgress); currentProgress.Message = $"Loading {((IDataset) e.Tag).Name}"; } else if (newProgressStep == VerificationProgressStep.Testing) { SetDetailStep(currentProgress, e); currentProgress.Message = ((QualityCondition)e.Tag).Name; } currentProgress.ProgressStep = (int)newProgressStep; }
private static bool IsPriorityProgress(VerificationProgressEventArgs args, VerificationProgressMsg currentProgress, ConcurrentBag <IssueMsg> issueCollection) { if (args.ProgressType == VerificationProgressType.Error && issueCollection.Count < 10) { return(false); } if (args.ProgressType == VerificationProgressType.ProcessParallel) { // TODO: Work out better overall progress steps return(true); } if (currentProgress.ProgressType != (int)args.ProgressType) { return(true); } if (!IsRelevantStep(args.ProgressStep)) { return(false); } return(currentProgress.ProgressStep != (int)args.ProgressStep); }
private static bool UpdateProgress(VerificationProgressMsg currentProgress, VerificationProgressEventArgs e) { if (e.ProgressType == VerificationProgressType.PreProcess) { currentProgress.ProcessingStepMessage = e.Tag as string ?? string.Empty; SetOverallStep(currentProgress, e); } else if (e.ProgressType == VerificationProgressType.ProcessNonCache) { UpdateNonContainerProgress(currentProgress, e); } else if (e.ProgressType == VerificationProgressType.ProcessContainer) { if (!UpdateContainerProgress(currentProgress, e)) { return(false); } } else if (e.ProgressType == VerificationProgressType.ProcessParallel) { if (!UpdateParallelProgress(currentProgress, e)) { return(false); } } currentProgress.ProgressType = (int)e.ProgressType; return(true); }
private static void SetMessageFromCondition(VerificationProgressMsg progressMsg, VerificationProgressEventArgs e) { progressMsg.Message = e.ProgressType == VerificationProgressType.ProcessNonCache ? ((QualityCondition)e.Tag).Name : string.Empty; }
internal static void LogProgress([NotNull] VerificationProgressEventArgs args) { if (_msg.IsVerboseDebugEnabled) { LogProgressVerbose(args); } else if (_msg.IsDebugEnabled) { LogProgressDebug(args); } }
private static void SetOverallStep([NotNull] VerificationProgressMsg progressMsg, [NotNull] VerificationProgressEventArgs e) { if (e.Total == 0) { // no update return; } progressMsg.OverallProgressCurrentStep = e.Current + 1; progressMsg.OverallProgressTotalSteps = e.Total; }
private static void LogProgressVerbose( [NotNull] VerificationProgressEventArgs args) { string message = args.ProgressType != VerificationProgressType.Error ? string.Format("{0} {1}, Step {2} of {3}: {4}", args.ProgressType, args.ProgressStep, args.Current, args.Total, TranslateTag(args)) : string.Format("{0} #{1}", args.ProgressType, args.Current); _msg.Debug(message); }
private static bool UpdateParallelProgress(VerificationProgressMsg currentProgress, VerificationProgressEventArgs e) { SetOverallStep(currentProgress, e); if (e.CurrentBox != null) { currentProgress.CurrentBox = ProtobufGeometryUtils.ToEnvelopeMsg(e.CurrentBox); } return(true); }
private void OnProgress([NotNull] VerificationProgressEventArgs args) { TestExecutionUtils.LogProgress(args); if (Progress != null) { if (args.CurrentBox != null && _testPerimeter != null) { args.SetSpatialReference(_testPerimeter.SpatialReference); } Progress(this, args); } }
private static void SendProgress(VerificationProgressEventArgs args, ConcurrentBag <IssueMsg> issueCollection, VerificationProgressMsg currentProgress, Action <VerificationResponse> writeAction) { if (!IsPriorityProgress(args, currentProgress, issueCollection) && DateTime.Now - _lastProgressTime < TimeSpan.FromSeconds(1)) { return; } _lastProgressTime = DateTime.Now; WriteProgressAndIssues(args, issueCollection, currentProgress, writeAction); }
private static object TranslateTag([NotNull] VerificationProgressEventArgs args) { object tag = args.Tag; var dataset = tag as IDataset; if (dataset != null) { return(dataset.Name); } var row = tag as TestRow; return(row?.DataReference.GetDescription() ?? tag); }
private static void SendProgress( object sender, VerificationProgressEventArgs args, ConcurrentBag <IssueMsg> issueCollection, VerificationProgressMsg currentProgress, Action <VerificationResponse> writeAction, ITrackCancel trackCancel) { if (trackCancel != null && !trackCancel.Continue()) { _msg.Debug("Cancelling..."); ((QualityVerificationServiceBase)sender).Cancel(); return; } SendProgress(args, issueCollection, currentProgress, writeAction); }
private static void WriteProgressAndIssues( VerificationProgressEventArgs e, ConcurrentBag <IssueMsg> issues, VerificationProgressMsg currentProgress, Action <VerificationResponse> writeAction) { VerificationResponse response = new VerificationResponse { ServiceCallStatus = (int)ServiceCallStatus.Running }; if (!UpdateProgress(currentProgress, e) && issues.Count == 0) { return; } response.Progress = currentProgress; //List<IssueMsg> sentIssues = new List<IssueMsg>(issues.Count); while (issues.TryTake(out IssueMsg issue)) { response.Issues.Add(issue); } _msg.DebugFormat("Sending {0} errors back to client...", issues.Count); try { writeAction(response); } catch (InvalidOperationException ex) { // For example: System.InvalidOperationException: Only one write can be pending at a time _msg.VerboseDebug("Error sending progress to the client", ex); // The issues would be lost, so put them back into the collection foreach (IssueMsg issue in response.Issues) { issues.Add(issue); } } }
private static void SetDetailStep([NotNull] VerificationProgressMsg progressMsg, [NotNull] VerificationProgressEventArgs e) { progressMsg.DetailedProgressCurrentStep = e.Current + 1; progressMsg.DetailedProgressTotalSteps = e.Total; }
public void Execute(IEnumerable <ITest> tests, AreaOfInterest areaOfInterest, CancellationTokenSource cancellationTokenSource) { Assert.NotNull(QualitySpecification, "QualitySpecification has not been initialized."); Assert.NotNull(TestAssembler, "TestAssembler has not been initialized."); StartVerification(QualityVerification); CancellationTokenSource = cancellationTokenSource; IList <IList <QualityCondition> > qcGroups = TestAssembler.BuildQualityConditionGroups(tests.ToList(), areaOfInterest, FilterTableRowsUsingRelatedGeometry, _originalRequest.MaxParallelProcessing); foreach (IList <QualityCondition> qcGroup in qcGroups) { if (qcGroup.Count == 0) { continue; } VerificationRequest subRequest = CreateSubRequest(_originalRequest, QualitySpecification, qcGroup); SubResponse subResponse = new SubResponse(); Task <bool> task = Task.Run( async() => await VerifyAsync(_qaClient, subRequest, subResponse, CancellationTokenSource), CancellationTokenSource.Token); // Process the messages even though the foreground thread is blocking/busy processing results task.ConfigureAwait(false); _tasks.Add(Assert.NotNull(task), subResponse); Thread.Sleep(50); } while (_tasks.Count > 0) { if (TryTakeCompletedRun(_tasks, out Task <bool> task, out SubResponse subResponse)) { ProcessFinalResult(task, subResponse); _msg.InfoFormat("Remaining work unit verifications: {0}", _tasks.Count); } else { // Process intermediate errors (might need de-duplication or other manipulation in the future) bool reportProgress = false; foreach (SubResponse response in _tasks.Values) { if (DrainIssues(response)) { reportProgress = true; } if (UpdateOverallProgress(response)) { reportProgress = true; } } if (reportProgress) { var eventArgs = new VerificationProgressEventArgs( VerificationProgressType.ProcessParallel, OverallProgressCurrent, OverallProgressTotal); eventArgs.Tag = "TODO"; Progress?.Invoke(this, eventArgs); } } Thread.Sleep(100); } EndVerification(QualityVerification); }
private static bool UpdateContainerProgress(VerificationProgressMsg currentProgress, VerificationProgressEventArgs e) { VerificationProgressStep newProgressStep = ToVerificationStep(e.ProgressStep); switch (newProgressStep) { case VerificationProgressStep.TileProcessing: // New tile: SetOverallStep(currentProgress, e); ResetDetailStep(currentProgress); currentProgress.CurrentBox = ProtobufGeometryUtils.ToEnvelopeMsg(e.CurrentBox); break; case VerificationProgressStep.DataLoading: //SetOverallStep(currentProgress, e); SetDetailStep(currentProgress, e); currentProgress.ProcessingStepMessage = "Loading data"; currentProgress.Message = ((IDataset)e.Tag).Name; break; case VerificationProgressStep.Testing: if (currentProgress.ProgressStep != (int)newProgressStep) { // First time ResetDetailStep(currentProgress); currentProgress.ProcessingStepMessage = "Testing rows"; } double relativeProgress = ((double)e.Current - currentProgress.DetailedProgressCurrentStep) / e.Total; if (relativeProgress > 0.05) { SetDetailStep(currentProgress, e); var testRow = e.Tag as TestRow; currentProgress.Message = testRow?.DataReference.DatasetName; } else { return(false); } break; case VerificationProgressStep.TileCompleting: SetDetailStep(currentProgress, e); currentProgress.ProcessingStepMessage = "Completing tile"; currentProgress.Message = ((QualityCondition)e.Tag).Name; break; } currentProgress.ProgressStep = (int)newProgressStep; string message = e.Tag as string; CallbackUtils.DoWithNonNull(message, s => currentProgress.Message = s); return(true); }
private static void LogProgressDebug(VerificationProgressEventArgs args) { switch (args.ProgressType) { case VerificationProgressType.PreProcess: _msg.DebugFormat("Preprocessing: {0}", args.Tag); break; case VerificationProgressType.ProcessNonCache: switch (args.ProgressStep) { case Step.ITestProcessing: var qualityCondition = args.Tag as QualityCondition; _msg.DebugFormat("Processing non-container test: {0}", qualityCondition == null ? args.Tag : qualityCondition.Name); break; case Step.DataLoading: var dataset = args.Tag as IDataset; if (dataset != null) { _msg.DebugFormat("Loading data: {0}", dataset.Name); } break; } break; case VerificationProgressType.ProcessContainer: switch (args.ProgressStep) { case Step.ITestProcessing: var qualityCondition = args.Tag as QualityCondition; _msg.DebugFormat("Processing standalone test: {0}", qualityCondition == null ? args.Tag : qualityCondition.Name); break; case Step.DataLoading: var dataset = args.Tag as IDataset; _msg.DebugFormat("Loading data: {0}", dataset == null ? args.Tag : dataset.Name); break; case Step.TileProcessing: if (args.CurrentBox != null) { double xMin; double yMin; double xMax; double yMax; args.CurrentBox.QueryCoords(out xMin, out yMin, out xMax, out yMax); string format = xMax < 400 ? "Verifying tile {0} of {1}, (extent: {2:N6}, {3:N6}, {4:N6}, {5:N6})" : "Verifying tile {0} of {1}, (extent: {2:N2}, {3:N2}, {4:N2}, {5:N2})"; _msg.DebugFormat(format, args.Current + 1, args.Total, xMin, yMin, xMax, yMax); } break; case Step.TileProcessed: if (args.Current > 0) { _msg.DebugFormat("Processed tile {0} of {1}", args.Current, args.Total); } break; } break; case VerificationProgressType.Error: break; default: throw new ArgumentOutOfRangeException(); } }