public static IIssueRepository GetIssueRepository( [NotNull] string directoryFullPath, [NotNull] string gdbName, [CanBeNull] ISpatialReference spatialReference, IssueRepositoryType issueRepositoryType, double gridSize1 = 0d, double gridSize2 = 0d, double gridSize3 = 0d, bool addExceptionFields = false) { IFeatureWorkspace workspace = CreateDatabase(directoryFullPath, gdbName, issueRepositoryType); if (workspace == null) { return(null); } IIssueTableFieldManagement fields = GetFields(issueRepositoryType, addExceptionFields); Assert.NotNull(fields, "No field definition for repository type {0}", issueRepositoryType); var issueGdbCreator = new IssueGeodatabaseCreator(workspace, fields, spatialReference, gridSize1, gridSize2, gridSize3); return(issueGdbCreator.GetIssueRepository()); }
public void ExecuteVerification( [NotNull] string dataQualityXml, [NotNull] string specificationName, [NotNull] List <DataSource> dataSourceReplacements, [CanBeNull] AreaOfInterest areaOfInterest, [CanBeNull] string optionsXml, double tileSize, string outputDirectoryPath, IssueRepositoryType issueRepositoryType = IssueRepositoryType.FileGdb, bool ignoreConditionsForUnknownDatasets = true, ITrackCancel cancelTracker = null) { IList <XmlQualitySpecification> qualitySpecifications; XmlDataQualityDocument document = ReadXmlDocument(dataQualityXml, out qualitySpecifications); _msg.DebugFormat("Available specifications: {0}", StringUtils.Concatenate(qualitySpecifications.Select(s => s.Name), ", ")); XmlVerificationOptions verificationOptions = StringUtils.IsNotEmpty(optionsXml) ? VerificationOptionUtils.ReadOptionsXml(optionsXml) : null; IList <KeyValuePair <string, string> > properties = new List <KeyValuePair <string, string> >(); Directory.CreateDirectory(outputDirectoryPath); try { int errorCount; int warningCount; int exceptionCount; int unusedExceptionObjectCount; int rowCountWithStopConditions; bool fulfilled = Verify(document, specificationName, dataSourceReplacements, tileSize, outputDirectoryPath, issueRepositoryType, properties, verificationOptions, areaOfInterest, cancelTracker, ignoreConditionsForUnknownDatasets, out errorCount, out warningCount, out exceptionCount, out unusedExceptionObjectCount, out rowCountWithStopConditions); } catch (Exception) { StandaloneVerificationUtils.TryDeleteOutputDirectory(outputDirectoryPath); throw; } }
private bool Verify([NotNull] XmlDataQualityDocument document, [NotNull] string specificationName, [NotNull] IEnumerable <DataSource> dataSources, double tileSize, [NotNull] string directoryPath, IssueRepositoryType issureRepositoryType, [NotNull] IEnumerable <KeyValuePair <string, string> > properties, [CanBeNull] XmlVerificationOptions verificationOptions, [CanBeNull] AreaOfInterest areaOfInterest, [CanBeNull] ITrackCancel trackCancel, bool ignoreConditionsForUnknownDatasets, out int errorCount, out int warningCount, out int exceptionCount, out int unusedExceptionObjectCount, out int rowCountWithStopConditions) { try { QualitySpecification qualitySpecification; using (_msg.IncrementIndentation("Setting up quality specification")) { var modelFactory = new VerifiedModelFactory( CreateSimpleWorkspaceContext, new SimpleVerifiedDatasetHarvester()); var datasetOpener = new SimpleDatasetOpener(new MasterDatabaseDatasetContext()); var factory = new XmlBasedQualitySpecificationFactory(modelFactory, datasetOpener); qualitySpecification = factory.CreateQualitySpecification( document, specificationName, dataSources, ignoreConditionsForUnknownDatasets); } return(Verify(qualitySpecification, tileSize, directoryPath, issureRepositoryType, properties, verificationOptions, areaOfInterest, trackCancel, out errorCount, out warningCount, out exceptionCount, out unusedExceptionObjectCount, out rowCountWithStopConditions)); } finally { GC.Collect(); } }
public static IFeatureWorkspace CreateDatabase( [NotNull] string directoryFullPath, [NotNull] string gdbName, IssueRepositoryType issueRepositoryType) { if (issueRepositoryType != IssueRepositoryType.None && !Directory.Exists(directoryFullPath)) { Directory.CreateDirectory(directoryFullPath); } IWorkspaceName workspaceName = GetWorkspaceName(issueRepositoryType, directoryFullPath, gdbName); return(workspaceName == null ? null : (IFeatureWorkspace)WorkspaceUtils.OpenWorkspace(workspaceName)); }
private static IWorkspaceName GetWorkspaceName( IssueRepositoryType issueRepositoryType, [NotNull] string directoryPath, [NotNull] string gdbName) { switch (issueRepositoryType) { case IssueRepositoryType.None: return(null); case IssueRepositoryType.FileGdb: return(WorkspaceUtils.CreateFileGdbWorkspace(directoryPath, gdbName)); case IssueRepositoryType.Shapefiles: return(WorkspaceUtils.CreateShapefileWorkspace(directoryPath, gdbName)); default: throw new ArgumentOutOfRangeException(nameof(issueRepositoryType)); } }
private static IIssueTableFieldManagement GetFields( IssueRepositoryType issueRepositoryType, bool addExceptionFields) { switch (issueRepositoryType) { case IssueRepositoryType.None: return(null); case IssueRepositoryType.FileGdb: return(IssueTableFieldsFactory.GetIssueTableFields(addExceptionFields)); case IssueRepositoryType.Shapefiles: return(IssueTableFieldsFactory.GetIssueTableFields(addExceptionFields, useDbfFieldNames: true)); default: throw new ArgumentOutOfRangeException(nameof(issueRepositoryType)); } }
public static IIssueRepository GetIssueRepository( [NotNull] string gdbFullPath, [CanBeNull] ISpatialReference spatialReference, IssueRepositoryType issueRepositoryType) { Assert.ArgumentNotNullOrEmpty(gdbFullPath, nameof(gdbFullPath)); string directoryPath = Path.GetDirectoryName(gdbFullPath); Assert.NotNull(directoryPath, "Invalid full path to gdb (undefined directory): {0}", gdbFullPath); string gdbName = Path.GetFileName(gdbFullPath); Assert.NotNull(gdbName, "Invalid full path to gdb (undefined file name): {0}", gdbFullPath); return(GetIssueRepository(directoryPath, gdbName, spatialReference, issueRepositoryType)); }
public static bool IssueRepositoryExists( [NotNull] string directoryFullPath, [NotNull] string gdbName, IssueRepositoryType issueRepositoryType) { string fullPath = Path.Combine(directoryFullPath, gdbName); switch (issueRepositoryType) { case IssueRepositoryType.None: return(false); case IssueRepositoryType.FileGdb: return(WorkspaceUtils.FileGdbWorkspaceExists(fullPath)); case IssueRepositoryType.Shapefiles: return(WorkspaceUtils.ShapefileWorkspaceExists(fullPath)); default: throw new ArgumentOutOfRangeException(nameof(issueRepositoryType)); } }
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); }