示例#1
0
        public void Write([NotNull] IRow importExceptionRow,
                          DateTime importDate,
                          [NotNull] string originValue,
                          Guid lineageGuid,
                          string versionOriginValue,
                          string statusValue)
        {
            if (_insertCursor == null)
            {
                _insertCursor  = _targetTable.Insert(true);
                _rowBuffer     = _targetTable.CreateRowBuffer();
                _featureBuffer = _rowBuffer as IFeatureBuffer;
            }

            IRowBuffer buffer = Assert.NotNull(_rowBuffer);

            TransferAttributes(importExceptionRow, buffer);

            WriteText(buffer, _originFieldIndex, originValue);
            buffer.Value[_versionBeginDateFieldIndex] = importDate;
            buffer.Value[_versionEndDateFieldIndex]   = DBNull.Value;
            buffer.Value[_versionUuidFieldIndex]      = GetNewVersionUuid();
            WriteText(buffer, _versionOriginFieldIndex, versionOriginValue);
            buffer.Value[_lineageUuidFieldIndex] =
                ExceptionObjectUtils.FormatGuid(lineageGuid);
            buffer.Value[_statusFieldIndex] = statusValue;

            if (_featureBuffer != null)
            {
                _featureBuffer.Shape = ((IFeature)importExceptionRow).ShapeCopy;
            }

            _insertCursor?.InsertRow(buffer);
        }
        public void SetValue(IssueAttribute attribute, [CanBeNull] object value)
        {
            if (attribute == IssueAttribute.ExceptionStatus)
            {
                // normalize the status value
                value = ExceptionObjectUtils.GetNormalizedStatus(value as string);
            }

            _editableAttributes[attribute] = value;
        }
示例#3
0
        public void CanGetInvolvedRowsKeyFastEnough()
        {
            var involvedRows = new List <InvolvedRow>
            {
                new InvolvedRow("Table2", 100),
                new InvolvedRow("Table1", 1000),
                new InvolvedRow("Table2", 200)
            };

            AssertFastEnough(() => ExceptionObjectUtils.GetKey(involvedRows), 10000, 0.1);
        }
示例#4
0
        private static void AssertEqualKeys([NotNull] ICollection <InvolvedRow> involvedRows)
        {
            string involvedRowsKey = ExceptionObjectUtils.GetKey(involvedRows);

            string involvedTablesKey = ExceptionObjectUtils.GetKey(
                IssueUtils.GetInvolvedTables(involvedRows));

            Console.WriteLine(@"Involved rows key:   [{0}]", involvedRowsKey);
            Console.WriteLine(@"Involved tables key: [{0}]", involvedTablesKey);

            Assert.AreEqual(involvedRowsKey, involvedTablesKey);
        }
示例#5
0
        private static object FormatValue(object rawValue)
        {
            if (rawValue == null)
            {
                return(DBNull.Value);
            }

            if (rawValue is Guid)
            {
                return(ExceptionObjectUtils.FormatGuid((Guid)rawValue));
            }

            return(rawValue);
        }
示例#6
0
        public void CanIgnoreInvolvedRowTable()
        {
            var involvedRows = new List <InvolvedRow>
            {
                new InvolvedRow("Table2", 100),
                new InvolvedRow("Table1", 1000),
                new InvolvedRow("Table2", 200)
            };

            string key = ExceptionObjectUtils.GetKey(involvedRows, t => t == "Table1");

            Console.WriteLine(key);

            Assert.AreEqual("Table2:100:200;", key);
        }
示例#7
0
 private static XmlExceptionObject CreateException(
     [NotNull] ExceptionObject exceptionObject,
     int usageCount)
 {
     return(new
            XmlExceptionObject
     {
         Id = exceptionObject.Id,
         ShapeType = Escape(ExceptionObjectUtils.GetShapeTypeText(
                                exceptionObject.ShapeType)),
         IssueCode = Escape(exceptionObject.IssueCode),
         InvolvedObjects = Escape(exceptionObject.InvolvedTablesText),
         UsageCount = usageCount
     });
 }
示例#8
0
        public void Write([NotNull] IRow updateExceptionRow,
                          DateTime updateDate,
                          [NotNull] ManagedExceptionVersion managedExceptionVersion,
                          [NotNull] string originValue,
                          [NotNull] string versionOriginValue,
                          [CanBeNull] string versionImportStatus)
        {
            Assert.ArgumentNotNull(updateExceptionRow, nameof(updateExceptionRow));
            Assert.ArgumentNotNull(managedExceptionVersion, nameof(managedExceptionVersion));
            Assert.ArgumentNotNullOrEmpty(originValue, nameof(originValue));
            Assert.ArgumentNotNullOrEmpty(versionOriginValue, nameof(versionOriginValue));

            if (_insertCursor == null)
            {
                _insertCursor  = _targetTable.Insert(true);
                _rowBuffer     = _targetTable.CreateRowBuffer();
                _featureBuffer = _rowBuffer as IFeatureBuffer;
            }

            IRowBuffer buffer = Assert.NotNull(_rowBuffer);

            TransferAttributes(updateExceptionRow, buffer);

            WriteText(buffer, _originFieldIndex, originValue);
            buffer.Value[_versionBeginDateFieldIndex] = updateDate;
            buffer.Value[_versionEndDateFieldIndex]   = DBNull.Value;           // even if 'Inactive'
            buffer.Value[_versionUuidFieldIndex]      = GetNewVersionUuid();
            WriteText(buffer, _versionOriginFieldIndex, versionOriginValue);
            buffer.Value[_lineageUuidFieldIndex] =
                ExceptionObjectUtils.FormatGuid(managedExceptionVersion.LineageUuid);
            WriteText(buffer, _versionImportStatusIndex, versionImportStatus);

            foreach (IssueAttribute attribute in managedExceptionVersion.EditableAttributes)
            {
                WriteValue(managedExceptionVersion, attribute, buffer);
            }

            if (_featureBuffer != null)
            {
                _featureBuffer.Shape = ((IFeature)updateExceptionRow).ShapeCopy;
            }

            _insertCursor?.InsertRow(buffer);
        }
示例#9
0
        private static string FormatOriginValue(
            [NotNull] string updateOriginValue,
            [CanBeNull] ManagedExceptionVersion replacedExceptionVersion)
        {
            var origins = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
            {
                updateOriginValue
            };

            if (replacedExceptionVersion != null)
            {
                foreach (string replacedOrigin in
                         ExceptionObjectUtils.ParseOrigins(replacedExceptionVersion.ImportOrigin))
                {
                    origins.Add(replacedOrigin);
                }
            }

            return(ExceptionObjectUtils.FormatOrigins(origins));
        }
示例#10
0
        public void CanIgnoreInvolvedTable()
        {
            var involvedTables = new List <InvolvedTable>
            {
                new InvolvedTable("Table1",
                                  new[]
                {
                    new OIDRowReference(100)
                }),
                new InvolvedTable("Table2",
                                  new[]
                {
                    new OIDRowReference(200),
                    new OIDRowReference(100)
                }),
            };

            string key = ExceptionObjectUtils.GetKey(involvedTables, t => t == "Table1");

            Console.WriteLine(key);

            Assert.AreEqual("Table2:100:200;", key);
        }
示例#11
0
        private static bool ImportException(
            [NotNull] IRow row, [NotNull] string importOriginValue, DateTime importDate,
            [NotNull] ExceptionObjectFactory factory,
            [NotNull]
            IDictionary <Guid, QualityConditionExceptions> targetExceptionsByConditionVersion,
            [NotNull] IDictionary <esriGeometryType, HashSet <int> > replacedExceptionObjects,
            [NotNull] ExceptionWriter writer,
            out int matchCount)
        {
            ExceptionObject exceptionObject = factory.CreateExceptionObject(row);

            matchCount = 0;

            // import only active exceptions
            if (exceptionObject.Status != ExceptionObjectStatus.Active)
            {
                return(false);
            }

            var matchingLineageUuids = new DistinctValues <Guid>();

            var origins = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
            {
                importOriginValue
            };

            foreach (ExceptionObject matchingExceptionObject in GetMatchingExceptionObjects(
                         targetExceptionsByConditionVersion,
                         exceptionObject))
            {
                // add to Uuids of matching exceptions (usually, should be unique)
                if (matchingExceptionObject.ManagedLineageUuid != null)
                {
                    // also if matching exception is inactive
                    // --> lineage of inactive exceptions may be continued (resurrection of inactive exceptions)
                    matchingLineageUuids.Add(matchingExceptionObject.ManagedLineageUuid.Value);

                    // NOTE: consider *preferring* active exceptions, only if none: resurrect inactive exception lineage
                }

                // include the origin values of active replaced exceptions
                // Note: not for resurrected exceptions (inactive/with end date -> active)
                if (matchingExceptionObject.ManagedVersionEndDate == null)
                {
                    foreach (string replacedOrigin in
                             ExceptionObjectUtils.ParseOrigins(matchingExceptionObject.ManagedOrigin))
                    {
                        origins.Add(replacedOrigin);
                    }
                }

                matchCount++;

                AddToReplacedExceptionObjects(matchingExceptionObject, replacedExceptionObjects);
            }

            writer.Write(row,
                         importDate,
                         ExceptionObjectUtils.FormatOrigins(origins),
                         GetLineageUuid(matchingLineageUuids),
                         versionOriginValue: importOriginValue,
                         statusValue: "Active");

            return(true);
        }
示例#12
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);
                            }
                        }
                    }
                }
            }
        }
示例#13
0
        private bool HasChange([NotNull] ManagedExceptionVersion update,
                               [NotNull] ManagedExceptionVersion current,
                               [NotNull] ManagedExceptionVersion original,
                               [NotNull] out ManagedExceptionVersion merged,
                               [NotNull] out IList <ExceptionAttributeConflict> conflicts)
        {
            merged = update.Clone();

            var changedAttributes = new List <IssueAttribute>();

            conflicts = new List <ExceptionAttributeConflict>();

            if (update.Status == ExceptionObjectStatus.Active &&
                current.Status == ExceptionObjectStatus.Active)
            {
                // 1: update: active; current: active --> update of active exception
                // --> update attributes regularly
            }
            else if (update.Status == ExceptionObjectStatus.Inactive &&
                     current.Status == ExceptionObjectStatus.Active)
            {
                // 2: update: inactive; current: active --> "deletion" of active exception
                // --> update attributes regularly
            }
            else if (update.Status == ExceptionObjectStatus.Active &&
                     current.Status == ExceptionObjectStatus.Inactive)
            {
                // 3: update: active; current: inactive
                if (original.Status == ExceptionObjectStatus.Active)
                {
                    // set to inactive by previous import
                    // --> ignore
                    _msg.DebugFormat(
                        "Exception ({0}) was set to inactive by previous update, ignore update (OID: {1})",
                        ExceptionObjectUtils.FormatGuid(current.LineageUuid), update.ObjectID);
                    return(false);
                }

                // resurrection
                return(true);
                // --> ignore, no change
            }
            else if (update.Status == ExceptionObjectStatus.Inactive &&
                     current.Status == ExceptionObjectStatus.Inactive)
            {
                // 4: update: inactive; current: inactive
                // --> update attributes regularly
                _msg.DebugFormat(
                    "Exception ({0}) was set to inactive by previous update, ignore update (OID: {1})",
                    ExceptionObjectUtils.FormatGuid(current.LineageUuid), update.ObjectID);
            }

            foreach (IssueAttribute attribute in _editableAttributes)
            {
                object newValue      = update.GetValue(attribute);
                object currentValue  = current.GetValue(attribute);
                object originalValue = original.GetValue(attribute);

                if (Equals(newValue, originalValue) || Equals(newValue, currentValue))
                {
                    // the value was not changed in the update, or it is equal to the current value
                    merged.SetValue(attribute, currentValue);
                }
                else
                {
                    // different from current, changed in update
                    changedAttributes.Add(attribute);

                    merged.SetValue(attribute, newValue);

                    if (!Equals(currentValue, originalValue))
                    {
                        // also changed in current --> conflict
                        conflicts.Add(CreateConflict(attribute,
                                                     newValue, currentValue, originalValue,
                                                     update.LineageUuid,
                                                     original.VersionUuid));
                    }
                }
            }

            return(changedAttributes.Count > 0);
        }
示例#14
0
 private static string GetNewVersionUuid()
 {
     return(ExceptionObjectUtils.FormatGuid(Guid.NewGuid()));
 }