private static IEnumerable <IRow> TryGetRows( [NotNull] ITable table, [NotNull] ICollection <int> objectIDs) { if (objectIDs.Count == 0) { return(null); } const bool recycle = false; try { return(GdbQueryUtils.GetRowsByObjectIds(table, objectIDs, recycle)); } catch (Exception e) { _msg.WarnFormat( "Error getting involved rows for table {0}: {1} (see log for details)", DatasetUtils.GetName(table), e.Message); using (_msg.IncrementIndentation()) { _msg.DebugFormat("Object IDs of involved rows: {0}", StringUtils.Concatenate(objectIDs, ",")); LogTableDebugInfo(table); } _msg.WarnFormat("Trying again using alternative query method"); // try again using different fetch method (where clause) try { return(GdbQueryUtils.GetRowsInList(table, table.OIDFieldName, objectIDs, recycle)); } catch (Exception e2) { _msg.WarnFormat("Error getting involved rows for table {0}: {1}", DatasetUtils.GetName(table), e2.Message); using (_msg.IncrementIndentation()) { _msg.WarnFormat("Object IDs of involved rows: {0}", StringUtils.Concatenate(objectIDs, ",")); } return(null); } } }
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(); } }
// TODO: Is this a static Utils class? Or does each IAttributes implementation have // its specific AttributeHarvester? Or will there be a DatasetHarvester/ModelHarvester // that can create instances of this class (for the right IAttributes implementation) // in order to more loosely couple them with the domain classes? //private readonly IAttributes _attributeContainer; //public AttributeHarvester(IAttributes attributeContainer) //{ // _attributeContainer = attributeContainer; //} #region AttributedAssociation Attribute harvesting public static void HarvestAttributes([NotNull] AttributedAssociation attributedAssociation) { // TODO: support for configurator? attributedAssociation.ClearAttributeMaps(); using (_msg.IncrementIndentation( "Harvesting attributes for attributed association {0}", attributedAssociation.Name)) { const bool allowAlways = true; IRelationshipClass relationshipClass = ModelElementUtils.TryOpenFromMasterDatabase(attributedAssociation, allowAlways); Assert.NotNull(relationshipClass, "Relationship class not found in model master database: {0}", attributedAssociation.Name); var table = (ITable)relationshipClass; IList <IField> fields = DatasetUtils.GetFields(table); for (var fieldIndex = 0; fieldIndex < fields.Count; fieldIndex++) { IField field = fields[fieldIndex]; AddOrUpdateAttribute(attributedAssociation, field, fieldIndex); } DeleteAttributesNotInList(attributedAssociation, fields); attributedAssociation.ClearAttributeMaps(); } }
private static void LogVerificationDetails( [NotNull] QualityVerification verification) { _msg.Debug("Verified quality conditions:"); using (_msg.IncrementIndentation()) { List <QualityConditionVerification> sortedList = verification.ConditionVerifications.ToList(); sortedList.Sort((v1, v2) => string.Compare(v1.QualityCondition == null ? "<null>" : v1.QualityCondition.Name, v2.QualityCondition == null ? "<null>" : v2.QualityCondition.Name, StringComparison.CurrentCultureIgnoreCase)); foreach (QualityConditionVerification conditionVerification in sortedList) { LogConditionVerification(conditionVerification); } } _msg.Debug("Load times for verified datasets:"); using (_msg.IncrementIndentation()) { List <QualityVerificationDataset> sortedList = verification.VerificationDatasets.ToList(); sortedList.Sort((d1, d2) => string.Compare(d1.Dataset.Name, d2.Dataset.Name, StringComparison.CurrentCultureIgnoreCase)); foreach (QualityVerificationDataset verifiedDataset in sortedList) { LogVerificationDataset(verifiedDataset); } } }
private static void LogBeginVerification( [NotNull] QualitySpecification qualitySpecification, double tileSize, [CanBeNull] AreaOfInterest areaOfInterest) { using (_msg.IncrementIndentation("Begin quality verification")) { _msg.InfoFormat("Quality specification: {0}", qualitySpecification.Name); _msg.InfoFormat("Verification tile size: {0}", tileSize); if (areaOfInterest != null) { IGeometry testPerimeter = areaOfInterest.Geometry; if (testPerimeter.IsEmpty) { _msg.Warn("Test perimeter is empty"); } else { var envelope = testPerimeter as IEnvelope; string message; if (envelope == null) { Assert.ArgumentCondition(testPerimeter is IPolygon, "Unexpected test perimeter type: {0}; must be polygon or envelope", testPerimeter.GeometryType); envelope = testPerimeter.Envelope; message = string.Format("Polygon extent: {0} x {1}", envelope.Width, envelope.Height); } else { message = string.Format("Extent: {0} x {1}", envelope.Width, envelope.Height); } using (_msg.IncrementIndentation(message)) { _msg.InfoFormat("X-Min: {0}", envelope.XMin); _msg.InfoFormat("Y-Min: {0}", envelope.YMin); _msg.InfoFormat("X-Max: {0}", envelope.XMax); _msg.InfoFormat("Y-Max: {0}", envelope.YMax); } } } } }
/// <summary> /// Copies the entire content of the specified source directory to a given target directory path. /// </summary> /// <param name="source">The source directory.</param> /// <param name="target">The target director path.</param> /// <param name="overwriteFiles">if set to <c>true</c> any copied files that already exist in /// the target directory are overwritten. If the file exists and overwriteFiles is <c>false</c>, /// an <see cref="IOException"></see> is thrown.</param> public static void CopyDirectory([NotNull] DirectoryInfo source, [NotNull] DirectoryInfo target, bool overwriteFiles) { Assert.ArgumentNotNull(source, nameof(source)); Assert.ArgumentNotNull(target, nameof(target)); // Check if the target directory exists, if not, create it. if (!Directory.Exists(target.FullName)) { _msg.DebugFormat("Creating directory {0}", target.Name); Directory.CreateDirectory(target.FullName); } else { _msg.DebugFormat("Directory {0} already exists", target.Name); } using (_msg.IncrementIndentation()) { // Copy each file into it's new directory. foreach (FileInfo fileInfo in source.GetFiles()) { _msg.DebugFormat("Copying {0}", fileInfo.Name); string targetFilePath = Path.Combine(target.FullName, fileInfo.Name); fileInfo.CopyTo(targetFilePath, overwriteFiles); } // Copy each subdirectory using recursion. foreach (DirectoryInfo sourceSubdirectory in source.GetDirectories()) { var targetSubdirectory = new DirectoryInfo( Path.Combine(target.FullName, sourceSubdirectory.Name)); CopyDirectory(sourceSubdirectory, targetSubdirectory, overwriteFiles); } } }
private void ApplyFormState([NotNull] T formState, FormStateRestoreOption restoreOption) { _msg.VerboseDebugFormat("Applying form state for {0}", Form.Name); using (_msg.IncrementIndentation()) { switch (restoreOption) { case FormStateRestoreOption.OnlyLocation: ApplyLocation(formState); ApplyTopMost(formState); // don't apply size // don't apply window state ApplyInternalFormState(formState); break; case FormStateRestoreOption.KeepLocation: // don't apply location ApplyTopMost(formState); ApplySize(formState); ApplyWindowState(formState); ApplyInternalFormState(formState); break; case FormStateRestoreOption.Normal: ApplyLocation(formState); ApplyTopMost(formState); ApplySize(formState); ApplyWindowState(formState); ApplyInternalFormState(formState); break; default: throw new ArgumentException( string.Format("Unknown restore option: {0}", restoreOption)); } } }
public static void Import( [CanBeNull] string importWhereClause, [NotNull] IList <IObjectClass> targetExceptionClasses, [NotNull] IList <IObjectClass> importExceptionClasses, [NotNull] string importOriginValue, DateTime importDate) { IIssueTableFields importFields = GetImportFields(importExceptionClasses); IIssueTableFields targetFields = GetTargetFields(targetExceptionClasses); IDictionary <Guid, QualityConditionExceptions> targetExceptionsByConditionVersion; using (_msg.IncrementIndentation( "Reading existing exceptions in target workspace")) { targetExceptionsByConditionVersion = ReadTargetExceptions(targetExceptionClasses, targetFields); } var replacedExceptionObjects = new Dictionary <esriGeometryType, HashSet <int> >(); using (_msg.IncrementIndentation("Importing new exceptions from issue datasets...") ) { foreach (ITable importTable in importExceptionClasses.Cast <ITable>()) { using (_msg.IncrementIndentation("from {0}...", DatasetUtils.GetName(importTable))) { ITable targetTable = GetTargetTable(importTable, targetExceptionClasses); if (targetTable == null) { _msg.Warn( "No matching table in target workspace, ignoring import table"); continue; } var factory = new ExceptionObjectFactory( importTable, importFields, defaultStatus: ExceptionObjectStatus.Inactive); var newCount = 0; var updateCount = 0; var ignoredCount = 0; using (var writer = new ExceptionWriter(importTable, importFields, targetTable, targetFields)) { foreach (IRow row in GdbQueryUtils.GetRows(importTable, GetQueryFilter( importWhereClause), recycle: true)) { int matchCount; bool added = ImportException(row, importOriginValue, importDate, factory, targetExceptionsByConditionVersion, replacedExceptionObjects, writer, out matchCount); if (!added) { ignoredCount++; } else if (matchCount == 0) { newCount++; } else { updateCount++; } } } _msg.InfoFormat("{0:N0} exception(s) imported as new", newCount); _msg.InfoFormat("{0:N0} exception(s) imported as updates", updateCount); if (ignoredCount > 0) { _msg.InfoFormat("{0:N0} exception(s) ignored", ignoredCount); } } } } using (_msg.IncrementIndentation("Processing replaced exceptions...")) { foreach (ITable targetTable in targetExceptionClasses.Cast <ITable>()) { using (_msg.IncrementIndentation("Target table {0}...", DatasetUtils.GetName(targetTable))) { int fixedStatusCount; int updateCount = ProcessReplacedExceptions(targetTable, targetFields, replacedExceptionObjects, importDate, out fixedStatusCount); _msg.InfoFormat("{0:N0} replaced exception(s) updated", updateCount); if (fixedStatusCount > 0) { _msg.InfoFormat("Status value of {0:N0} old exception version(s) fixed", fixedStatusCount); } } } } }
private static void Execute([NotNull] IProcessingContext context, [NotNull] IProcessingFeedback feedback, [NotNull] IEnumerable <IGdbProcess> processes) { int current = 0, total = processes.Count(); try { foreach (IGdbProcess process in processes) { current += 1; if (feedback.CancellationPending) { throw new OperationCanceledException(); } ReportProcessStarting(feedback, process, current, total); if (process is IGroupGdbProcess) { feedback.CurrentGroup = process.Name; feedback.CurrentProcess = null; } else { feedback.CurrentGroup = null; feedback.CurrentProcess = process.Name; _msg.Debug(GetParameterDescription(process)); } try { DateTime startTime = DateTime.Now; using (_msg.IncrementIndentation()) { process.Execute(context, feedback); } TimeSpan duration = DateTime.Now - startTime; ReportProcessCompleted(feedback, process, duration); } catch (OperationCanceledException) { throw; // rethrow (but catch all other exceptions) } catch (Exception ex) { feedback.ReportError( string.Format("Error executing {0} {1}: {2}", process is IGroupGdbProcess ? "Process Group" : "GdbProcess", process.Name, ex.Message), ex); } } feedback.ReportCompleted(); } catch (OperationCanceledException) { feedback.ReportStopped(); } }