Beispiel #1
0
        private static BackgroundVerificationService CreateVerificationService(
            IBackgroundVerificationInputs backgroundVerificationInputs,
            ConcurrentBag <IssueMsg> issueCollection,
            Action <VerificationResponse> writeAction, ITrackCancel trackCancel)
        {
            var qaService = new BackgroundVerificationService(
                backgroundVerificationInputs.DomainTransactions,
                backgroundVerificationInputs.DatasetLookup)
            {
                CustomErrorFilter = backgroundVerificationInputs.CustomErrorFilter
            };

            var currentProgress = new VerificationProgressMsg();

            qaService.IssueFound +=
                (sender, args) =>
                issueCollection.Add(CreateIssueProto(args, backgroundVerificationInputs));

            qaService.Progress += (sender, args) =>
                                  SendProgress(
                sender, args, issueCollection,
                currentProgress, writeAction, trackCancel);

            return(qaService);
        }
Beispiel #2
0
        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;
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        private static void UpdateSubProgress([NotNull] VerificationResponse responseMsg,
                                              [NotNull] SubResponse subResponse)
        {
            VerificationProgressMsg progressMsg = responseMsg.Progress;

            if (progressMsg == null)
            {
                return;
            }

            if (subResponse.Status != ServiceCallStatus.Running &&
                subResponse.Status != ServiceCallStatus.Finished)
            {
                subResponse.CancellationMessage = progressMsg.Message;
            }

            // TODO: More stuff? Box?
            subResponse.ProgressTotal   = progressMsg.OverallProgressTotalSteps;
            subResponse.ProgressCurrent = progressMsg.OverallProgressCurrentStep;

            if (progressMsg.CurrentBox != null)
            {
                subResponse.CurrentBox = progressMsg.CurrentBox;
            }
        }
Beispiel #6
0
 private static void SetMessageFromCondition(VerificationProgressMsg progressMsg,
                                             VerificationProgressEventArgs e)
 {
     progressMsg.Message =
         e.ProgressType == VerificationProgressType.ProcessNonCache
                                 ? ((QualityCondition)e.Tag).Name
                                 : string.Empty;
 }
Beispiel #7
0
        private static void UpdateServiceProgress(
            IQualityVerificationProgressTracker serviceProgress,
            VerificationResponse messageProto)
        {
            // No access to COM objects here (we're on the background thread!)

            serviceProgress.ErrorCount += messageProto.Issues.Count(i => !i.Allowable);

            serviceProgress.WarningCount += messageProto.Issues.Count(i => i.Allowable);

            VerificationProgressMsg progressMsg = messageProto.Progress;

            if (progressMsg == null)
            {
                return;
            }

            serviceProgress.ProgressType = (VerificationProgressType)progressMsg.ProgressType;
            serviceProgress.ProgressStep = (VerificationProgressStep)progressMsg.ProgressStep;

            serviceProgress.ProcessingMessage =
                progressMsg.ProcessingStepMessage;

            if (progressMsg.OverallProgressTotalSteps > 0)
            {
                serviceProgress.OverallProgressTotalSteps =
                    progressMsg.OverallProgressTotalSteps;
            }

            serviceProgress.OverallProgressCurrentStep =
                progressMsg.OverallProgressCurrentStep;

            if (progressMsg.DetailedProgressTotalSteps > 0)
            {
                serviceProgress.DetailedProgressTotalSteps =
                    progressMsg.DetailedProgressTotalSteps;
            }

            serviceProgress.DetailedProgressCurrentStep =
                progressMsg.DetailedProgressCurrentStep;

            if (progressMsg.CurrentBox != null &&
                progressMsg.CurrentBox.XMax > 0 &&
                progressMsg.CurrentBox.YMax > 0)
            {
                serviceProgress.CurrentTile = new EnvelopeXY(
                    progressMsg.CurrentBox.XMin, progressMsg.CurrentBox.YMin,
                    progressMsg.CurrentBox.XMax, progressMsg.CurrentBox.YMax);
            }

            serviceProgress.StatusMessage = progressMsg.Message;

            serviceProgress.RemoteCallStatus = (ServiceCallStatus)messageProto.ServiceCallStatus;
        }
Beispiel #8
0
        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;
        }
Beispiel #9
0
        private static bool UpdateParallelProgress(VerificationProgressMsg currentProgress,
                                                   VerificationProgressEventArgs e)
        {
            SetOverallStep(currentProgress, e);

            if (e.CurrentBox != null)
            {
                currentProgress.CurrentBox =
                    ProtobufGeometryUtils.ToEnvelopeMsg(e.CurrentBox);
            }

            return(true);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        private static void LogProgress(VerificationProgressMsg progressMsg)
        {
            if (progressMsg == null)
            {
                return;
            }

            _msg.VerboseDebug($"{DateTime.Now} - {progressMsg}");

            _msg.DebugFormat(
                "Received service progress of type {0}/{1}: {2} / {3}",
                (VerificationProgressType)progressMsg.ProgressType,
                (VerificationProgressStep)progressMsg.ProgressStep,
                progressMsg.OverallProgressCurrentStep,
                progressMsg.OverallProgressTotalSteps);
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        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);
                }
            }
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
 private static void ResetOverallStep([NotNull] VerificationProgressMsg progressMsg)
 {
     progressMsg.OverallProgressCurrentStep = 0;
     progressMsg.OverallProgressTotalSteps  = 10;
 }
Beispiel #16
0
 private static void ResetDetailStep([NotNull] VerificationProgressMsg progressMsg)
 {
     progressMsg.DetailedProgressCurrentStep = 0;
     progressMsg.DetailedProgressTotalSteps  = 10;
 }
Beispiel #17
0
 private static void SetDetailStep([NotNull] VerificationProgressMsg progressMsg,
                                   [NotNull] VerificationProgressEventArgs e)
 {
     progressMsg.DetailedProgressCurrentStep = e.Current + 1;
     progressMsg.DetailedProgressTotalSteps  = e.Total;
 }