コード例 #1
0
        private static IEnumerable <string> GetFieldNames(
            [NotNull] IIssueTableFields issueTableFields,
            [NotNull] ITable table,
            [NotNull] IEnumerable <IssueAttribute> attributes)
        {
            yield return(table.OIDFieldName);

            var featureClass = table as IFeatureClass;

            if (featureClass != null)
            {
                yield return(featureClass.ShapeFieldName);
            }

            foreach (IssueAttribute attribute in attributes)
            {
                string name = issueTableFields.GetName(attribute, optional: true);

                if (name == null)
                {
                    // no field definition
                    continue;
                }

                if (table.FindField(name) < 0)
                {
                    // field does not exist in table
                    continue;
                }

                yield return(name);
            }
        }
コード例 #2
0
        public ManagedExceptionVersionFactory(
            [NotNull] ITable table,
            [NotNull] IIssueTableFields fields,
            [NotNull] IEnumerable <IssueAttribute> editableAttributes) :
            base(table, fields)
        {
            Assert.ArgumentNotNull(editableAttributes, nameof(editableAttributes));

            _editableAttributes = editableAttributes.ToList();

            _managedLineageUuidIndex      = GetIndex(IssueAttribute.ManagedExceptionLineageUuid);
            _managedVersionBeginDateIndex =
                GetIndex(IssueAttribute.ManagedExceptionVersionBeginDate);
            _managedVersionEndDateIndex =
                GetIndex(IssueAttribute.ManagedExceptionVersionEndDate);
            _managedVersionUuidIndex   = GetIndex(IssueAttribute.ManagedExceptionVersionUuid);
            _managedVersionOriginIndex =
                GetIndex(IssueAttribute.ManagedExceptionVersionOrigin);
            _managedOriginIndex = GetIndex(IssueAttribute.ManagedExceptionOrigin);

            // editable attributes
            foreach (IssueAttribute attribute in _editableAttributes)
            {
                _fieldIndexes.Add(attribute, GetIndex(attribute));
            }
        }
コード例 #3
0
        private static IDictionary <Guid, QualityConditionExceptions> ReadTargetExceptions(
            [NotNull] IList <IObjectClass> targetExceptionClasses,
            [NotNull] IIssueTableFields fields)
        {
            Assert.ArgumentNotNull(targetExceptionClasses, nameof(targetExceptionClasses));
            Assert.ArgumentCondition(targetExceptionClasses.Count > 0, "no exception classes");

            var result = new Dictionary <Guid, QualityConditionExceptions>();

            foreach (ITable targetTable in targetExceptionClasses.Cast <ITable>())
            {
                var factory = new ExceptionObjectFactory(
                    targetTable, fields,
                    defaultStatus: ExceptionObjectStatus.Inactive,
                    includeManagedExceptionAttributes: true);

                foreach (IRow row in GdbQueryUtils.GetRows(targetTable, recycle: true))
                {
                    ExceptionObject exceptionObject = factory.CreateExceptionObject(row);

                    Guid qconVersionUuid = exceptionObject.QualityConditionVersionUuid;

                    QualityConditionExceptions exceptions;
                    if (!result.TryGetValue(qconVersionUuid, out exceptions))
                    {
                        exceptions = new QualityConditionExceptions(qconVersionUuid, null);
                        result.Add(qconVersionUuid, exceptions);
                    }

                    exceptions.Add(exceptionObject);
                }
            }

            return(result);
        }
コード例 #4
0
        public IssueRepository([NotNull] IssueRowWriter rowWriter,
                               [NotNull] IEnumerable <IssueFeatureWriter> featureWriters,
                               [NotNull] IIssueTableFields fields,
                               [NotNull] IFeatureWorkspace featureWorkspace)
        {
            Assert.ArgumentNotNull(rowWriter, nameof(rowWriter));
            Assert.ArgumentNotNull(featureWriters, nameof(featureWriters));
            Assert.ArgumentNotNull(fields, nameof(fields));
            Assert.ArgumentNotNull(featureWorkspace, nameof(featureWorkspace));

            FeatureWorkspace = featureWorkspace;
            _rowWriter       = rowWriter;
            _featureWriters  = featureWriters.ToList();

            _issueWritersByGeometryType = GetIssueWritersByGeometryType(rowWriter,
                                                                        _featureWriters);

            _issueDatasets = GetIssueDatasets(rowWriter, _featureWriters, fields);

            if (_featureWriters.Count > 0)
            {
                _spatialReference =
                    SpatialReferenceUtils.GetUniqueSpatialReference(
                        GetSpatialReferences(_featureWriters),
                        comparePrecisionAndTolerance: true,
                        compareVerticalCoordinateSystems: true);
            }
        }
コード例 #5
0
 public ExceptionFeatureClass([NotNull] IFeatureClass featureClass,
                              [NotNull] IIssueTableFields fields,
                              int exceptionCount)
     : base(featureClass, fields, exceptionCount)
 {
     FeatureClass = featureClass;
 }
コード例 #6
0
        private static void LogConflicts(
            [NotNull] ICollection <ExceptionAttributeConflict> conflicts,
            [NotNull] IIssueTableFields fields)
        {
            if (conflicts.Count == 0)
            {
                return;
            }

            _msg.WarnFormat("{0} attribute conflict(s) exist:", conflicts.Count);

            using (_msg.IncrementIndentation())
            {
                foreach (ExceptionAttributeConflict conflict in conflicts)
                {
                    _msg.WarnFormat("- {0}:", fields.GetName(conflict.Attribute));

                    using (_msg.IncrementIndentation())
                    {
                        _msg.WarnFormat("- original value: {0}", conflict.OriginalValue);
                        _msg.WarnFormat("- new value: {0}", conflict.UpdateValue);
                        _msg.WarnFormat("- previous value (overwritten): {0}",
                                        conflict.CurrentValue);
                        _msg.WarnFormat("- origin of previous value: {0}",
                                        conflict.CurrentValueOrigin);
                        _msg.WarnFormat("- import date of previous value: {0}",
                                        conflict.CurrentValueImportDate);
                    }
                }
            }
        }
コード例 #7
0
        private static IDictionary <int, int> GetFieldIndexMap(
            [NotNull] ITable importTable, [NotNull] IIssueTableFields importFields,
            [NotNull] ITable targetTable, [NotNull] IIssueTableFields targetFields)
        {
            var result = new Dictionary <int, int>();

            var mappedTargetIndices = new HashSet <int>();

            foreach (IssueAttribute issueAttribute in EnumUtils.GetList <IssueAttribute>())
            {
                int importIndex = importFields.GetIndex(issueAttribute, importTable,
                                                        optional: true);
                if (importIndex < 0)
                {
                    continue;
                }

                int targetIndex = targetFields.GetIndex(issueAttribute, targetTable,
                                                        optional: true);
                if (targetIndex < 0)
                {
                    continue;
                }

                result.Add(importIndex, targetIndex);
                mappedTargetIndices.Add(targetIndex);
            }

            // map additional attributes, if field name and type are equal and if target field is editable
            int importFieldCount = importTable.Fields.FieldCount;

            for (var importIndex = 0; importIndex < importFieldCount; importIndex++)
            {
                if (result.ContainsKey(importIndex))
                {
                    // already mapped
                    continue;
                }

                IField importField = importTable.Fields.Field[importIndex];

                if (!CanTransfer(importField.Type))
                {
                    continue;
                }

                int targetIndex = GetMatchingTargetFieldIndex(importField, targetTable);

                if (targetIndex < 0 || mappedTargetIndices.Contains(targetIndex))
                {
                    // target field already mapped to an import field
                    continue;
                }

                result.Add(importIndex, targetIndex);
            }

            return(result);
        }
コード例 #8
0
 private static string FormatConflict([NotNull] ExceptionAttributeConflict conflict,
                                      [NotNull] IIssueTableFields fields)
 {
     return(string.Format("{0} ({1} [{2}])",
                          fields.GetName(conflict.Attribute),
                          FormatConflictValue(conflict),
                          conflict.CurrentValueOrigin));
 }
コード例 #9
0
        protected ExceptionObjectFactoryBase([NotNull] ITable table,
                                             [NotNull] IIssueTableFields fields)
        {
            Assert.ArgumentNotNull(table, nameof(table));
            Assert.ArgumentNotNull(fields, nameof(fields));

            _table  = table;
            _fields = fields;
        }
コード例 #10
0
ファイル: IssueDataset.cs プロジェクト: sungaoyong/ProSuite
        protected IssueDataset([NotNull] IssueWriter issueWriter,
                               [NotNull] IIssueTableFields fields)
        {
            Assert.ArgumentNotNull(issueWriter, nameof(issueWriter));
            Assert.ArgumentNotNull(fields, nameof(fields));

            _issueWriter = issueWriter;
            Fields       = fields;
        }
コード例 #11
0
        public IssueGeodatabaseCreator([NotNull] IFeatureWorkspace featureWorkspace,
                                       [NotNull] IIssueTableFieldManagement fields,
                                       [CanBeNull] ISpatialReference spatialReference,
                                       double gridSize1 = 0d,
                                       double gridSize2 = 0d,
                                       double gridSize3 = 0d)
        {
            Assert.ArgumentNotNull(featureWorkspace, nameof(featureWorkspace));
            Assert.ArgumentNotNull(fields, nameof(fields));

            _featureWorkspace = featureWorkspace;
            _fields           = fields;

            _rowWriter = CreateRowWriter(IssueDatasetUtils.RowClassName, featureWorkspace,
                                         fields, LocalizableStrings.IssuesStandaloneTableName);

            if (spatialReference != null)
            {
                var spatialReferenceCopy =
                    (ISpatialReference)((IClone)spatialReference).Clone();
                if (!spatialReferenceCopy.HasZPrecision())
                {
                    SpatialReferenceUtils.SetZDomain(spatialReferenceCopy,
                                                     -10000, 100000,
                                                     0.0001, 0.001);
                }

                _featureWriters.Add(
                    CreateFeatureWriter(
                        IssueDatasetUtils.PolygonClassName, featureWorkspace, fields,
                        esriGeometryType.esriGeometryPolygon,
                        spatialReferenceCopy, gridSize1, gridSize2, gridSize3,
                        LocalizableStrings.RawIssuesLayerName_Polygon));

                _featureWriters.Add(
                    CreateFeatureWriter(
                        IssueDatasetUtils.PolylineClassName, featureWorkspace, fields,
                        esriGeometryType.esriGeometryPolyline,
                        spatialReferenceCopy, gridSize1, gridSize2, gridSize3,
                        LocalizableStrings.RawIssuesLayerName_Polyline));

                _featureWriters.Add(
                    CreateFeatureWriter(
                        IssueDatasetUtils.MultipointClassName, featureWorkspace, fields,
                        esriGeometryType.esriGeometryMultipoint,
                        spatialReferenceCopy, gridSize1, gridSize2, gridSize3,
                        LocalizableStrings.RawIssuesLayerName_Multipoint));

                _featureWriters.Add(
                    CreateFeatureWriter(
                        IssueDatasetUtils.MultiPatchClassName, featureWorkspace, fields,
                        esriGeometryType.esriGeometryMultiPatch,
                        spatialReferenceCopy, gridSize1, gridSize2, gridSize3,
                        LocalizableStrings.RawIssuesLayerName_MultiPatch));
            }
        }
コード例 #12
0
        protected ExceptionDataset([NotNull] IObjectClass objectClass,
                                   [NotNull] IIssueTableFields fields,
                                   int exceptionCount)
        {
            Assert.ArgumentNotNull(objectClass, nameof(objectClass));
            Assert.ArgumentNotNull(fields, nameof(fields));

            ObjectClass    = objectClass;
            Fields         = fields;
            ExceptionCount = exceptionCount;
        }
コード例 #13
0
        private static string FormatConflicts(
            [NotNull] ICollection <ExceptionAttributeConflict> conflicts,
            [NotNull] IIssueTableFields fields)
        {
            if (conflicts.Count == 0)
            {
                return(null);
            }

            return(string.Format(
                       LocalizableStrings.ImportExceptionsFunctionBase_FormatConflicts,
                       StringUtils.Concatenate(conflicts,
                                               c => FormatConflict(c, fields),
                                               ",")));
        }
コード例 #14
0
        public ExceptionWriter([NotNull] ITable importTable,
                               [NotNull] IIssueTableFields importFields,
                               [NotNull] ITable targetTable,
                               [NotNull] IIssueTableFields targetFields)
        {
            Assert.ArgumentNotNull(importTable, nameof(importTable));
            Assert.ArgumentNotNull(importFields, nameof(importFields));
            Assert.ArgumentNotNull(targetTable, nameof(targetTable));
            Assert.ArgumentNotNull(targetFields, nameof(targetFields));

            _targetTable  = targetTable;
            _targetFields = targetFields;

            _lineageUuidFieldIndex = targetFields.GetIndex(
                IssueAttribute.ManagedExceptionLineageUuid, targetTable);
            _versionBeginDateFieldIndex = targetFields.GetIndex(
                IssueAttribute.ManagedExceptionVersionBeginDate, targetTable);
            _versionEndDateFieldIndex = targetFields.GetIndex(
                IssueAttribute.ManagedExceptionVersionEndDate, targetTable);
            _versionUuidFieldIndex = targetFields.GetIndex(
                IssueAttribute.ManagedExceptionVersionUuid, targetTable);
            _versionOriginFieldIndex = targetFields.GetIndex(
                IssueAttribute.ManagedExceptionVersionOrigin, targetTable);

            _originFieldIndex = targetFields.GetIndex(
                IssueAttribute.ManagedExceptionOrigin, targetTable);
            _statusFieldIndex = targetFields.GetIndex(
                IssueAttribute.ExceptionStatus, targetTable);
            _versionImportStatusIndex = targetFields.GetIndex(
                IssueAttribute.ManagedExceptionVersionImportStatus, targetTable);

            _fieldLengths = GetFieldLengths(targetTable);

            var importFeatureClass = importTable as IFeatureClass;
            var targetFeatureClass = targetTable as IFeatureClass;

            if (importFeatureClass != null)
            {
                Assert.NotNull(targetFeatureClass);

                ValidateSpatialReferences(targetFeatureClass, importFeatureClass);
            }

            _targetFieldIndicesByImportFieldIndex = GetFieldIndexMap(importTable, importFields,
                                                                     targetTable,
                                                                     targetFields);
        }
コード例 #15
0
        private static IList <IIssueDataset> GetIssueDatasets(
            [NotNull] IssueRowWriter rowWriter,
            [NotNull] IEnumerable <IssueFeatureWriter> featureWriters,
            [NotNull] IIssueTableFields fields)
        {
            var result = new List <IIssueDataset>
            {
                new IssueTable(rowWriter, fields)
            };

            foreach (IssueFeatureWriter featureWriter in featureWriters)
            {
                result.Add(new IssueFeatureClass(featureWriter, fields));
            }

            return(result);
        }
コード例 #16
0
        public IssueAttributeWriter([NotNull] ITable table,
                                    [NotNull] IIssueTableFields fields) : base(table)
        {
            Assert.ArgumentNotNull(table, nameof(table));
            Assert.ArgumentNotNull(fields, nameof(fields));

            _issueDescriptionFieldIndex = fields.GetIndex(IssueAttribute.IssueDescription,
                                                          table);
            _issueCodeFieldIndex            = fields.GetIndex(IssueAttribute.IssueCode, table);
            _issueCodeDescriptionFieldIndex =
                fields.GetIndex(IssueAttribute.IssueCodeDescription, table);
            _involvedObjectsFieldIndex =
                fields.GetIndex(IssueAttribute.InvolvedObjects, table);
            _qualityConditionFieldIndex = fields.GetIndex(IssueAttribute.QualityConditionName,
                                                          table);
            _testTypeFieldIndex        = fields.GetIndex(IssueAttribute.TestType, table);
            _testNameFieldIndex        = fields.GetIndex(IssueAttribute.TestName, table);
            _testDescriptionFieldIndex =
                fields.GetIndex(IssueAttribute.TestDescription, table);
            _issueSeverityFieldIndex     = fields.GetIndex(IssueAttribute.IssueSeverity, table);
            _stopConditionFieldIndex     = fields.GetIndex(IssueAttribute.IsStopCondition, table);
            _categoryFieldIndex          = fields.GetIndex(IssueAttribute.Category, table);
            _affectedComponentFieldIndex = fields.GetIndex(IssueAttribute.AffectedComponent,
                                                           table);
            _urlFieldIndex = fields.GetIndex(IssueAttribute.Url, table);

            // optional fields
            _doubleValue1FieldIndex = fields.GetIndex(
                IssueAttribute.DoubleValue1,
                table, optional: true);
            _doubleValue2FieldIndex = fields.GetIndex(
                IssueAttribute.DoubleValue2,
                table, optional: true);
            _textValueFieldIndex = fields.GetIndex(
                IssueAttribute.TextValue,
                table, optional: true);

            _qualityConditionUuidFieldIndex = fields.GetIndex(
                IssueAttribute.QualityConditionUuid,
                table, optional: true);
            _qualityConditionVersionUuidFieldIndex = fields.GetIndex(
                IssueAttribute.QualityConditionVersionUuid,
                table, optional: true);
        }
コード例 #17
0
        public static bool IsUpdateWorkspace([NotNull] IFeatureWorkspace workspace)
        {
            IIssueTableFields fields =
                IssueTableFieldsFactory.GetIssueTableFields(
                    addExceptionFields: true,
                    useDbfFieldNames: WorkspaceUtils.IsShapefileWorkspace((IWorkspace)workspace),
                    addManagedExceptionFields: true);

            var requiredAttributes = new[]
            {
                IssueAttribute.ManagedExceptionLineageUuid,
                IssueAttribute.ManagedExceptionVersionUuid
            };

            return(IssueRepositoryUtils.GetIssueObjectClasses(workspace)
                   .Cast <ITable>()
                   .All(tbl => requiredAttributes.All(
                            att => HasField(
                                tbl, att, fields))));
        }
コード例 #18
0
        public void Configure([NotNull] ITable table,
                              [NotNull] ITableFields tableFields,
                              [NotNull] IIssueTableFields fields)
        {
            Assert.ArgumentNotNull(table, nameof(table));
            Assert.ArgumentNotNull(tableFields, nameof(tableFields));
            Assert.ArgumentNotNull(fields, nameof(fields));

            foreach (KeyValuePair <IssueAttribute, XmlFieldOptions> pair in _fieldOptionsByRole)
            {
                int fieldIndex = fields.GetIndex(pair.Key, table, optional: true);
                if (fieldIndex < 0)
                {
                    _msg.DebugFormat(
                        "No field with role {0} found in {1}; field configuration ignored",
                        pair.Key, DatasetUtils.GetName(table));
                    continue;
                }

                var fieldInfo = (IFieldInfo3)tableFields.FieldInfo[fieldIndex];

                Configure(fieldInfo, pair.Value);
            }

            foreach (KeyValuePair <string, XmlFieldOptions> pair in _fieldOptionsByName)
            {
                int fieldIndex = table.FindField(pair.Key);
                if (fieldIndex < 0)
                {
                    _msg.DebugFormat("Field not found in {0}: {1}; field configuration ignored",
                                     DatasetUtils.GetName(table),
                                     pair.Key);
                    continue;
                }

                var fieldInfo = (IFieldInfo3)tableFields.FieldInfo[fieldIndex];

                Configure(fieldInfo, pair.Value);
            }
        }
コード例 #19
0
        private static int ProcessReplacedExceptions(
            [NotNull] ITable targetTable,
            [NotNull] IIssueTableFields targetFields,
            [NotNull] IDictionary <esriGeometryType, HashSet <int> > replacedExceptionObjects,
            DateTime importDate,
            out int fixedStatusCount)
        {
            esriGeometryType shapeType = GetShapeType(targetTable);

            HashSet <int> replacedOids;

            if (!replacedExceptionObjects.TryGetValue(shapeType, out replacedOids))
            {
                // no replaced exception objects for this shape type
                fixedStatusCount = 0;
                return(0);
            }

            return(ProcessReplacedExceptions(targetTable, targetFields,
                                             importDate, replacedOids,
                                             out fixedStatusCount));
        }
コード例 #20
0
        public ExceptionObjectFactory(
            [NotNull] ITable table,
            [NotNull] IIssueTableFields fields,
            [CanBeNull] IAlternateKeyConverterProvider alternateKeyConverterProvider = null,
            ShapeMatchCriterion defaultShapeMatchCriterion = ShapeMatchCriterion.EqualEnvelope,
            ExceptionObjectStatus defaultStatus            = ExceptionObjectStatus.Active,
            [CanBeNull] IGeometry areaOfInterest           = null,
            bool includeManagedExceptionAttributes         = false) : base(table, fields)
        {
            _alternateKeyConverterProvider = alternateKeyConverterProvider;
            _defaultShapeMatchCriterion    = defaultShapeMatchCriterion;
            _defaultStatus  = defaultStatus;
            _areaOfInterest = areaOfInterest;

            _tableSupportsNullValues =
                !WorkspaceUtils.IsShapefileWorkspace(DatasetUtils.GetWorkspace(table));

            _featureClass = table as IFeatureClass;
            _shapeType    = _featureClass?.ShapeType;

            _xyTolerance = _featureClass == null
                                               ? (double?)null
                                               : GetXyTolerance(_featureClass);

            _uuidIndex                = GetIndex(IssueAttribute.QualityConditionUuid);
            _versionUuidIndex         = GetIndex(IssueAttribute.QualityConditionVersionUuid);
            _issueCodeIndex           = GetIndex(IssueAttribute.IssueCode);
            _affectedComponentIndex   = GetIndex(IssueAttribute.AffectedComponent);
            _involvedObjectsIndex     = GetIndex(IssueAttribute.InvolvedObjects);
            _shapeMatchCriterionIndex = GetIndex(IssueAttribute.ExceptionShapeMatchCriterion,
                                                 optional: true);
            _exceptionStatusIndex = GetIndex(IssueAttribute.ExceptionStatus, optional: true);

            _doubleValue1Index = GetIndex(IssueAttribute.DoubleValue1, optional: true);
            _doubleValue2Index = GetIndex(IssueAttribute.DoubleValue2, optional: true);
            _textValueIndex    = GetIndex(IssueAttribute.TextValue, optional: true);

            _exceptionCategoryIndex = GetIndex(IssueAttribute.ExceptionCategory,
                                               optional: true);

            if (includeManagedExceptionAttributes)
            {
                // get managed exception attribute field indexes
                _managedOriginIndex = GetIndex(IssueAttribute.ManagedExceptionOrigin,
                                               optional: true);
                _managedLineageUuidIndex = GetIndex(IssueAttribute.ManagedExceptionLineageUuid,
                                                    optional: true);
                _managedVersionBeginDateIndex =
                    GetIndex(IssueAttribute.ManagedExceptionVersionBeginDate,
                             optional: true);
                _managedVersionEndDateIndex =
                    GetIndex(IssueAttribute.ManagedExceptionVersionEndDate,
                             optional: true);
                _managedVersionUuidIndex = GetIndex(IssueAttribute.ManagedExceptionVersionUuid,
                                                    optional: true);
                _managedVersionImportOriginIndex = GetIndex(
                    IssueAttribute.ManagedExceptionVersionOrigin,
                    optional: true);
            }

            _fieldNames = GetFieldNames(fields, table,
                                        GetIssueAttributes(includeManagedExceptionAttributes))
                          .ToList();
        }
コード例 #21
0
 public IssueTable([NotNull] IssueRowWriter issueWriter,
                   [NotNull] IIssueTableFields fields)
     : base(issueWriter, fields)
 {
     _issueWriter = issueWriter;
 }
コード例 #22
0
ファイル: ExceptionTable.cs プロジェクト: sungaoyong/ProSuite
 public ExceptionTable([NotNull] IObjectClass objectClass,
                       [NotNull] IIssueTableFields fields,
                       int exceptionCount)
     : base(objectClass, fields, exceptionCount)
 {
 }
コード例 #23
0
        private static int ProcessReplacedExceptions(
            [NotNull] ITable targetTable,
            [NotNull] IIssueTableFields targetFields,
            DateTime importDate,
            [NotNull] ICollection <int> replacedOids,
            out int fixedStatusCount)
        {
            fixedStatusCount = 0;
            int statusFieldIndex = targetFields.GetIndex(IssueAttribute.ExceptionStatus,
                                                         targetTable);
            int versionEndDateFieldIndex =
                targetFields.GetIndex(IssueAttribute.ManagedExceptionVersionEndDate, targetTable);

            ICursor cursor = targetTable.Update(null, Recycling: true);

            var updateCount = 0;

            const string statusInactive = "Inactive";

            try
            {
                for (IRow row = cursor.NextRow();
                     row != null;
                     row = cursor.NextRow())
                {
                    object oldEndDate         = row.Value[versionEndDateFieldIndex];
                    bool   oldVersionIsClosed = !(oldEndDate == null || oldEndDate is DBNull);
                    string oldStatus          = (row.Value[statusFieldIndex] as string)?.Trim();

                    var anyChanges = false;

                    if (replacedOids.Contains(row.OID))
                    {
                        if (!statusInactive.Equals(oldStatus, StringComparison.OrdinalIgnoreCase))
                        {
                            // the row status is different from "Inactive" --> set to "Inactive"
                            row.Value[statusFieldIndex] = statusInactive;
                            anyChanges = true;
                        }

                        if (!oldVersionIsClosed)
                        {
                            // the row does not have an end date set --> set importDate as end date
                            row.Value[versionEndDateFieldIndex] = importDate;
                            anyChanges = true;
                        }

                        if (anyChanges)
                        {
                            updateCount++;
                        }
                    }
                    else
                    {
                        // fix status if not 'inactive' for a closed version
                        if (oldVersionIsClosed &&
                            !statusInactive.Equals(oldStatus, StringComparison.OrdinalIgnoreCase))
                        {
                            row.Value[statusFieldIndex] = statusInactive;

                            anyChanges = true;
                            fixedStatusCount++;
                        }
                    }

                    if (anyChanges)
                    {
                        cursor.UpdateRow(row);
                    }
                }
            }
            finally
            {
                ComUtils.ReleaseComObject(cursor);
            }

            return(updateCount);
        }
コード例 #24
0
        public static void Update(
            [CanBeNull] string whereClause,
            [NotNull] IList <IObjectClass> targetExceptionClasses,
            [NotNull] IList <IObjectClass> updateExceptionClasses,
            [NotNull] string updateOriginValue,
            DateTime updateDate,
            bool requireOriginalVersionExists = true)
        {
            IIssueTableFields updateFields = GetUpdateFields(updateExceptionClasses);
            IIssueTableFields targetFields = GetTargetFields(targetExceptionClasses);

            var editableAttributes = new[]
            {
                IssueAttribute.ExceptionStatus,
                IssueAttribute.ExceptionCategory,
                IssueAttribute.ExceptionNotes,
                IssueAttribute.ExceptionOrigin,
                IssueAttribute.ExceptionDefinitionDate,
                IssueAttribute.ExceptionLastRevisionDate,
                IssueAttribute.ExceptionRetirementDate,
                IssueAttribute.IssueAssignment
            };

            using (_msg.IncrementIndentation(
                       "Updating exceptions based on exported exception datasets..."))
            {
                foreach (ITable updateTable in updateExceptionClasses.Cast <ITable>())
                {
                    using (_msg.IncrementIndentation("from {0}...",
                                                     DatasetUtils.GetName(updateTable)))
                    {
                        ITable targetTable = GetTargetTable(updateTable, targetExceptionClasses);
                        if (targetTable == null)
                        {
                            _msg.Warn(
                                "No matching table in target workspace, ignoring import table");
                            continue;
                        }

                        var targetExceptionFactory = new ManagedExceptionVersionFactory(
                            targetTable, targetFields, editableAttributes);
                        var updateExceptionFactory = new ManagedExceptionVersionFactory(
                            updateTable, updateFields, editableAttributes);

                        ExceptionUpdateDetector updateDetector = GetUpdateDetector(
                            targetTable,
                            targetExceptionFactory,
                            editableAttributes);

                        var replacedOids = new HashSet <int>();

                        var updatedRowsCount       = 0;
                        var rowsWithConflictsCount = 0;

                        using (var exceptionWriter = new ExceptionWriter(updateTable, updateFields,
                                                                         targetTable, targetFields))
                        {
                            foreach (IRow updateRow in GdbQueryUtils.GetRows(
                                         updateTable, GetQueryFilter(whereClause), recycle: true))
                            {
                                ManagedExceptionVersion updateExceptionVersion =
                                    updateExceptionFactory.CreateExceptionVersion(updateRow);

                                ManagedExceptionVersion            mergedException;
                                ManagedExceptionVersion            replacedExceptionVersion;
                                IList <ExceptionAttributeConflict> conflicts;

                                if (updateDetector.HasChange(updateExceptionVersion,
                                                             out mergedException,
                                                             out replacedExceptionVersion,
                                                             out conflicts))
                                {
                                    if (replacedExceptionVersion == null)
                                    {
                                        string message = string.Format(
                                            "Exception version {0} not found in lineage {1} (target table: {2})",
                                            ExceptionObjectUtils.FormatGuid(
                                                updateExceptionVersion.VersionUuid),
                                            ExceptionObjectUtils.FormatGuid(
                                                updateExceptionVersion.LineageUuid),
                                            DatasetUtils.GetName(targetTable));

                                        if (requireOriginalVersionExists)
                                        {
                                            throw new InvalidDataException(message);
                                        }

                                        _msg.WarnFormat(
                                            "{0}. Creating new version with attributes from update row.",
                                            message);
                                    }

                                    updatedRowsCount++;

                                    string versionImportStatus;
                                    if (conflicts.Count == 0)
                                    {
                                        versionImportStatus = null;
                                    }
                                    else
                                    {
                                        versionImportStatus =
                                            FormatConflicts(conflicts, targetFields);

                                        rowsWithConflictsCount++;

                                        LogConflicts(conflicts, targetFields);
                                    }

                                    exceptionWriter.Write(updateRow, updateDate, mergedException,
                                                          FormatOriginValue(updateOriginValue,
                                                                            replacedExceptionVersion),
                                                          updateOriginValue, versionImportStatus);

                                    if (replacedExceptionVersion != null)
                                    {
                                        replacedOids.Add(replacedExceptionVersion.ObjectID);
                                    }
                                }
                            }
                        }

                        _msg.InfoFormat("{0:N0} exception(s) updated", updatedRowsCount);
                        if (rowsWithConflictsCount > 0)
                        {
                            _msg.WarnFormat("{0:N0} exception(s) with conflicts",
                                            rowsWithConflictsCount);
                        }

                        if (replacedOids.Count > 0)
                        {
                            int fixedStatusCount;
                            int updateCount = ProcessReplacedExceptions(targetTable, targetFields,
                                                                        updateDate, replacedOids,
                                                                        out fixedStatusCount);

                            _msg.DebugFormat("{0:N0} replaced exception version(s) updated",
                                             updateCount);
                            if (fixedStatusCount > 0)
                            {
                                _msg.WarnFormat(
                                    "Status value of {0:N0} old exception version(s) fixed",
                                    fixedStatusCount);
                            }
                        }
                    }
                }
            }
        }
コード例 #25
0
        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);
                        }
                    }
                }
            }
        }
コード例 #26
0
 private static bool HasField([NotNull] ITable table,
                              IssueAttribute attribute,
                              [NotNull] IIssueTableFields fields)
 {
     return(fields.GetIndex(attribute, table, optional: true) >= 0);
 }
コード例 #27
0
 public IssueFeatureClass([NotNull] IssueFeatureWriter issueWriter,
                          [NotNull] IIssueTableFields fields)
     : base(issueWriter, fields)
 {
     _issueWriter = issueWriter;
 }