private Task <Workspace> WithAnalysisProgressReportingAsync(int numSpecsTotal, Task <Workspace> task)
        {
            var counter = m_frontEndStatistics.SpecTypeChecking;

            return(TaskUtilities.AwaitWithProgressReportingAsync(
                       task,
                       EvaluationProgressReportingPeriod,
                       (elapsed) =>
            {
                m_logger.FrontEndWorkspaceAnalysisPhaseProgress(FrontEndContext.LoggingContext, counter.Count, numSpecsTotal);
                NotifyProgress(WorkspaceProgressEventArgs.Create(ProgressStage.Analysis, counter.Count, numSpecsTotal));
            },
                       reportImmediately: false));
        }
Esempio n. 2
0
        public void AwaitPreciseNumberOfSuccessfulReports(int taskTimeMilliseconds, int reportPeriodMilliseconds, bool reportImmediately, bool reportAtEnd, int numberOfReports)
        {
            int i            = 0;
            int successValue = 42;

            var result = TaskUtilities.AwaitWithProgressReportingAsync(
                task: TestTask(TimeSpan.FromMilliseconds(taskTimeMilliseconds), successValue),
                period: TimeSpan.FromMilliseconds(reportPeriodMilliseconds),
                action: (time) => Interlocked.Increment(ref i),
                reportImmediately: reportImmediately,
                reportAtEnd: reportAtEnd).GetAwaiter().GetResult();

            XAssert.AreEqual(successValue, result);
            XAssert.AreEqual(numberOfReports, i);
        }
        private async Task <bool> WithConversionProgressReportingAsync(int totalSpecs, Task <bool[]> task)
        {
            var counter = m_frontEndStatistics.SpecConversion;
            var results = await TaskUtilities.AwaitWithProgressReportingAsync(
                task,
                period : EvaluationProgressReportingPeriod,
                action : (elapsed) =>
            {
                m_logger.FrontEndConvertPhaseProgress(FrontEndContext.LoggingContext, counter.Count, totalSpecs);
                NotifyProgress(WorkspaceProgressEventArgs.Create(ProgressStage.Conversion, counter.Count, totalSpecs));
            },
                reportImmediately : false);

            return(results.All(t => t));
        }
        private Task <Workspace> WithWorkspaceProgressReportingAsync(int?numSpecs, Task <Workspace> task)
        {
            var numParseTotal = numSpecs?.ToString(CultureInfo.InvariantCulture) ?? "?";

            var counter = m_frontEndStatistics.SpecBinding;

            return(TaskUtilities.AwaitWithProgressReportingAsync(
                       task,
                       EvaluationProgressReportingPeriod,
                       (elapsed) =>
            {
                m_logger.FrontEndWorkspacePhaseProgress(FrontEndContext.LoggingContext, counter.Count, numParseTotal);
                NotifyProgress(WorkspaceProgressEventArgs.Create(ProgressStage.Parse, counter.Count, numSpecs));
            },
                       reportImmediately: false)
                   );
        }
Esempio n. 5
0
        public void AwaitFailure()
        {
            int    i             = 0;
            string exceptionText = "Boom";

            try
            {
                var result = TaskUtilities.AwaitWithProgressReportingAsync(
                    task: Task.Run(() => TestMethod(exceptionText)),
                    period: TimeSpan.FromHours(24),
                    action: (time) => Interlocked.Increment(ref i),
                    reportImmediately: false,
                    reportAtEnd: false).GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                XAssert.AreEqual(exceptionText, e.GetLogEventMessage());
                XAssert.AreEqual(0, i);
                return;
            }

            XAssert.Fail("Should have thrown an exception");
        }