Exemplo n.º 1
0
 protected override bool WriteIssueMapDocument(QualitySpecification qualitySpecification,
                                               IIssueRepository issueRepository,
                                               IIssueStatisticsTable issueStatisticsTable,
                                               IList <IObjectClass> verifiedObjectClasses,
                                               XmlVerificationReport verificationReport,
                                               IFeatureClass aoiFeatureClass)
 {
     // No op: Writing mxds is not supported here.
     return(false);
 }
        public static List <string> WriteHtmlReports(
            [NotNull] QualitySpecification qualitySpecification,
            [NotNull] string directory,
            [NotNull] IssueStatistics issueStatistics,
            [NotNull] XmlVerificationReport verificationReport,
            [NotNull] string verificationReportFileName,
            [CanBeNull] string defaultReportTemplatePath = null,
            [CanBeNull] XmlVerificationOptions options   = null,
            [CanBeNull] string issueGdbPath = null,
            [CanBeNull] IList <string> issueMapFilePaths = null,
            [CanBeNull] IList <string> qualitySpecificationReportFilePaths = null)
        {
            string defaultTemplateDirectory =
                VerificationOptionUtils.GetDefaultTemplateDirectory(options);

            var reportDefinitions = new List <HtmlReportDefinition>();

            foreach (XmlHtmlReportOptions reportOptions in
                     VerificationOptionUtils.GetHtmlReportOptions(
                         options, defaultReportTemplatePath))
            {
                HtmlReportDefinition reportDefinition =
                    VerificationOptionUtils.GetReportDefinition(reportOptions,
                                                                defaultReportTemplatePath,
                                                                defaultTemplateDirectory);
                if (!File.Exists(reportDefinition.TemplatePath))
                {
                    _msg.WarnFormat("Template file does not exist: {0}",
                                    reportOptions.TemplatePath);
                    continue;
                }

                reportDefinitions.Add(reportDefinition);
            }

            List <string> filePaths =
                reportDefinitions.Select(d => Path.Combine(directory, d.FileName))
                .ToList();

            foreach (HtmlReportDefinition reportDefinition in reportDefinitions)
            {
                WriteHtmlReport(qualitySpecification, directory,
                                reportDefinition,
                                issueStatistics, verificationReport,
                                verificationReportFileName,
                                issueGdbPath,
                                issueMapFilePaths,
                                filePaths,
                                qualitySpecificationReportFilePaths);
            }

            return(filePaths);
        }
        private static void WriteHtmlReport(
            [NotNull] QualitySpecification qualitySpecification,
            [NotNull] string directory,
            [NotNull] HtmlReportDefinition reportDefinition,
            [NotNull] IssueStatistics issueStatistics,
            [NotNull] XmlVerificationReport verificationReport,
            [NotNull] string verificationReportFileName,
            [CanBeNull] string issueGdbPath,
            [CanBeNull] IEnumerable <string> issueMapFilePaths,
            [NotNull] IEnumerable <string> htmlReportFileNames,
            [CanBeNull] IEnumerable <string> qualitySpecificationReportFilePaths)
        {
            Assert.ArgumentNotNull(reportDefinition, nameof(reportDefinition));
            Assert.ArgumentCondition(File.Exists(reportDefinition.TemplatePath),
                                     "Template file does not exist: {0}",
                                     reportDefinition.TemplatePath);

            string reportFilePath = Path.Combine(directory, reportDefinition.FileName);

            _msg.DebugFormat("Preparing html report model");
            var reportModel = new HtmlReportModel(qualitySpecification,
                                                  issueStatistics,
                                                  verificationReport,
                                                  directory,
                                                  verificationReportFileName,
                                                  issueGdbPath,
                                                  issueMapFilePaths,
                                                  htmlReportFileNames,
                                                  qualitySpecificationReportFilePaths,
                                                  reportDefinition);

            _msg.DebugFormat("Rendering html report based on template {0}",
                             reportDefinition.TemplatePath);

            LiquidUtils.RegisterSafeType <HtmlReportModel>();
            LiquidUtils.RegisterSafeType <HtmlTexts>();

            string output = LiquidUtils.Render(
                reportDefinition.TemplatePath,
                new KeyValuePair <string, object>("report", reportModel),
                new KeyValuePair <string, object>("text", new HtmlTexts()));

            _msg.DebugFormat("Writing html report to {0}", reportFilePath);
            FileSystemUtils.WriteTextFile(output, reportFilePath);

            _msg.InfoFormat("Html report written to {0}", reportFilePath);
        }
        private bool Verify([NotNull] QualitySpecification qualitySpecification,
                            double tileSize,
                            [NotNull] string directory,
                            IssueRepositoryType issueRepositoryType,
                            [NotNull] IEnumerable <KeyValuePair <string, string> > properties,
                            [CanBeNull] XmlVerificationOptions verificationOptions,
                            [CanBeNull] AreaOfInterest areaOfInterest,
                            [CanBeNull] ITrackCancel trackCancel,
                            out int errorCount,
                            out int warningCount,
                            out int exceptionCount,
                            out int unusedExceptionObjectCount,
                            out int rowCountWithStopConditions)
        {
            Model primaryModel = StandaloneVerificationUtils.GetPrimaryModel(qualitySpecification);

            Assert.NotNull(primaryModel, "no primary model found for quality specification");

            // TODO disable quality conditions based on primaryModel and DatasetTestParameterValue.UsedAsReferenceData?
            // TODO this would probably require an explicit identification of the primary data source
            XmlVerificationReportBuilder xmlReportBuilder = GetReportBuilder();
            var statisticsBuilder = new IssueStatisticsBuilder();

            var datasetsCollector = new InvolvedDatasetsCollector();

            var service = new StandaloneQualityVerificationService(
                new MultiReportBuilder(xmlReportBuilder,
                                       statisticsBuilder,
                                       datasetsCollector),
                (context) => new SimpleDatasetOpener(context));

            // This context excludes geometric networks, terrains, topology, etc.:
            var datasetContext  = new MasterDatabaseDatasetContext();
            var datasetResolver =
                new QualityConditionObjectDatasetResolver(
                    new MasterDatabaseWorkspaceContextLookup());

            string issueWorkspaceName =
                VerificationOptionUtils.GetIssueWorkspaceName(verificationOptions);
            string verificationReportFileName =
                VerificationOptionUtils.GetXmlReportFileName(verificationOptions);

            ISpatialReference spatialReference =
                primaryModel.SpatialReferenceDescriptor?.SpatialReference;

            var  issueGdbWritten = false;
            bool fulfilled;

            List <string> htmlReportFilePaths;
            List <string> specificationReportFilePaths;
            string        gdbPath = null;

            Func <IObjectDataset, string> getKeyField =
                StandaloneVerificationUtils.GetKeyFieldLookupFunction(verificationOptions);

            ExceptionObjectRepository exceptionObjectRepository =
                StandaloneVerificationUtils.PrepareExceptionRepository(
                    qualitySpecification, datasetContext, datasetResolver, areaOfInterest,
                    verificationOptions);

            using (IIssueRepository issueRepository =
                       ExternalIssueRepositoryUtils.GetIssueRepository(
                           directory, issueWorkspaceName, spatialReference, issueRepositoryType,
                           addExceptionFields: true))
            {
                fulfilled = service.Verify(qualitySpecification, datasetContext, datasetResolver,
                                           issueRepository, exceptionObjectRepository, tileSize,
                                           getKeyField,
                                           areaOfInterest, trackCancel,
                                           out errorCount,
                                           out warningCount,
                                           out rowCountWithStopConditions);

                if (issueRepository != null)
                {
                    issueGdbWritten = true;

                    gdbPath = ((IWorkspace)issueRepository.FeatureWorkspace).PathName;

                    _msg.InfoFormat("Issues written to {0}", gdbPath);

                    issueRepository.CreateIndexes(GetForSubProcess(trackCancel),
                                                  ignoreErrors: true);
                }

                using (_msg.IncrementIndentation("Documenting verification results..."))
                {
                    XmlVerificationReport verificationReport = GetVerificationReport(
                        xmlReportBuilder, qualitySpecification, properties);

                    string verificationReportPath = Path.Combine(directory,
                                                                 verificationReportFileName);
                    XmlUtils.Serialize(verificationReport, verificationReportPath);

                    _msg.InfoFormat("Verification report written to {0}", verificationReportPath);

                    IssueStatistics issueStatistics = statisticsBuilder.IssueStatistics;

                    if (issueRepository != null)
                    {
                        var issueStatisticsWriter =
                            new IssueStatisticsWriter(issueRepository.FeatureWorkspace);

                        issueStatisticsWriter.WriteStatistics(issueStatistics);

                        if (spatialReference != null &&
                            areaOfInterest != null &&
                            !areaOfInterest.IsEmpty)
                        {
                            var aoiWriter =
                                new AreaOfInterestWriter(issueRepository.FeatureWorkspace);
                            aoiWriter.WriteAreaOfInterest(areaOfInterest, spatialReference);
                        }
                    }

                    specificationReportFilePaths =
                        StandaloneVerificationUtils.WriteQualitySpecificationReport(
                            qualitySpecification, directory, _qualitySpecificationTemplatePath,
                            verificationOptions);

                    htmlReportFilePaths = StandaloneVerificationUtils.WriteHtmlReports(
                        qualitySpecification, directory, issueStatistics, verificationReport,
                        verificationReportFileName, _htmlReportTemplatePath, verificationOptions,
                        issueGdbWritten ? gdbPath : null,
                        null, specificationReportFilePaths);
                }
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();

            if (htmlReportFilePaths.Count > 0)
            {
                using (_msg.IncrementIndentation(htmlReportFilePaths.Count == 1
                                                                         ? "Html report:"
                                                                         : "Html reports:"))
                {
                    foreach (string path in htmlReportFilePaths)
                    {
                        _msg.Info(path);
                    }
                }
            }

            if (specificationReportFilePaths.Count > 0)
            {
                using (_msg.IncrementIndentation(specificationReportFilePaths.Count == 1
                                                                         ? "Quality specification report:"
                                                                         : "Quality specification reports:"))
                {
                    foreach (string path in specificationReportFilePaths)
                    {
                        _msg.Info(path);
                    }
                }
            }

            if (exceptionObjectRepository != null)
            {
                IExceptionStatistics stats = exceptionObjectRepository.ExceptionStatistics;
                exceptionCount             = stats.ExceptionCount;
                unusedExceptionObjectCount = stats.UnusedExceptionObjectCount;
            }
            else
            {
                exceptionCount             = 0;
                unusedExceptionObjectCount = 0;
            }

            return(fulfilled);
        }
Exemplo n.º 5
0
        public HtmlReportModel(
            [NotNull] QualitySpecification qualitySpecification,
            [NotNull] IIssueStatistics statistics,
            [NotNull] XmlVerificationReport verificationReport,
            [NotNull] string outputDirectoryPath,
            [NotNull] string verificationReportName,
            [CanBeNull] string issueGeodatabasePath,
            [CanBeNull] IEnumerable <string> issueMapFilePaths,
            [NotNull] IEnumerable <string> htmlReportFileNames,
            [CanBeNull] IEnumerable <string> qualitySpecificationReportFilePaths,
            [NotNull] IHtmlDataQualityCategoryOptionsProvider categoryOptionsProvider)
        {
            Assert.ArgumentNotNull(qualitySpecification, nameof(qualitySpecification));
            Assert.ArgumentNotNull(statistics, nameof(statistics));
            Assert.ArgumentNotNull(verificationReport, nameof(verificationReport));
            Assert.ArgumentNotNullOrEmpty(outputDirectoryPath, nameof(outputDirectoryPath));
            Assert.ArgumentNotNullOrEmpty(verificationReportName,
                                          nameof(verificationReportName));
            Assert.ArgumentNotNull(categoryOptionsProvider, nameof(categoryOptionsProvider));

            _verificationReport = verificationReport;
            HtmlReportFiles     =
                htmlReportFileNames.Select(
                    fileName =>
                    new OutputFile(
                        Path.Combine(outputDirectoryPath, fileName)))
                .ToList();
            IssueMapFiles = issueMapFilePaths?.Select(path => new OutputFile(path))
                            .ToList() ?? new List <OutputFile>();
            QualitySpecificationReportFiles =
                qualitySpecificationReportFilePaths?.Select(path => new OutputFile(path))
                .ToList() ?? new List <OutputFile>();

            Properties               = new NameValuePairs(GetProperties(verificationReport.Properties));
            QualitySpecification     = qualitySpecification.Name;
            VerificationWasCancelled = verificationReport.Cancelled;
            HasVerificationExtent    = verificationReport.TestExtent != null;

            if (verificationReport.TestExtent != null)
            {
                VerificationExtentString = HtmlReportUtils.FormatExtent(
                    verificationReport.TestExtent);
            }

            if (verificationReport.AreaOfInterest != null)
            {
                AreaOfInterest = HtmlReportUtils.GetAreaOfInterest(
                    verificationReport.AreaOfInterest);
            }

            OutputDirectoryPath        = outputDirectoryPath;
            OutputDirectoryName        = Assert.NotNull(Path.GetFileName(outputDirectoryPath));
            OutputDirectoryRelativeUrl = HtmlReportUtils.GetRelativeUrl(string.Empty);
            OutputDirectoryAbsoluteUrl = outputDirectoryPath;

            VerificationReportName = verificationReportName;
            VerificationReportUrl  = HtmlReportUtils.GetRelativeUrl(verificationReportName);

            if (IssueMapFiles.Count > 0)
            {
                OutputFile issueMapFile = IssueMapFiles[0];

                MapDocumentName = issueMapFile.FileName;
                MapDocumentUrl  = issueMapFile.Url;
            }

            IssueGeodatabaseName = Path.GetFileName(issueGeodatabasePath);

            List <HtmlReportDataQualityCategory> categories =
                HtmlReportUtils.GroupByCategories(
                    statistics,
                    new HtmlReportDataQualityCategoryComparer(),
                    new HtmlReportQualityConditionComparer(),
                    new HtmlReportIssueGroupComparer(),
                    GetTestIdentifier,
                    categoryOptionsProvider,
                    out _issueGroups);

            CategoriesWithIssues = categories.Where(c => c.IssueGroups.Count > 0).ToList();
            RootCategories       = categories.Where(c => c.IsRoot).ToList();

            HasWarnings = statistics.WarningCount > 0;
            HasErrors   = statistics.ErrorCount > 0;
            HasIssues   = !HasWarnings && !HasErrors;

            IssueCount = HtmlReportUtils.Format(statistics.WarningCount +
                                                statistics.ErrorCount);
            WarningCount   = HtmlReportUtils.Format(statistics.WarningCount);
            ErrorCount     = HtmlReportUtils.Format(statistics.ErrorCount);
            ExceptionCount = HtmlReportUtils.Format(statistics.ExceptionCount);

            TimeSpan t = TimeSpan.FromSeconds(verificationReport.ProcessingTimeSeconds);

            ProcessingTime = HtmlReportUtils.FormatTimeSpan(t);
        }