Esempio n. 1
0
        public void Include([NotNull] ManagedExceptionVersion exceptionVersion)
        {
            Assert.ArgumentNotNull(exceptionVersion, nameof(exceptionVersion));
            Assert.ArgumentCondition(Uuid == exceptionVersion.LineageUuid,
                                     "not of this lineage");

            _exceptionObjects.Add(exceptionVersion);
        }
Esempio n. 2
0
        private void WriteValue([NotNull] ManagedExceptionVersion managedExceptionVersion,
                                IssueAttribute attribute,
                                [NotNull] IRowBuffer buffer)
        {
            int fieldIndex = GetFieldIndex(attribute);

            object rawValue = managedExceptionVersion.GetValue(attribute);

            buffer.Value[fieldIndex] = FormatValue(rawValue);
        }
        public ManagedExceptionVersion Clone()
        {
            var result = new ManagedExceptionVersion(ObjectID, LineageUuid, VersionUuid,
                                                     VersionImportOrigin, ImportOrigin,
                                                     VersionBeginDate, VersionEndDate);

            foreach (KeyValuePair <IssueAttribute, object> pair in _editableAttributes)
            {
                result._editableAttributes.Add(pair.Key, pair.Value);
            }

            return(result);
        }
Esempio n. 4
0
        public bool HasChange(
            [NotNull] ManagedExceptionVersion updateExceptionVersion,
            [NotNull] out ManagedExceptionVersion mergedExceptionVersion,
            [CanBeNull] out ManagedExceptionVersion replacedExceptionVersion,
            [NotNull] out IList <ExceptionAttributeConflict> conflicts)
        {
            conflicts = new List <ExceptionAttributeConflict>();

            ExceptionLineage lineage;

            if (!_lineages.TryGetValue(updateExceptionVersion.LineageUuid, out lineage))
            {
                // lineage not found -> all properties from update, no replaced rows
                mergedExceptionVersion   = updateExceptionVersion.Clone();
                replacedExceptionVersion = null;
                return(true);
            }

            ManagedExceptionVersion current = lineage.Current;

            if (current == null)
            {
                // there is no active exception in the lineage --> all properties from update, no replaced rows
                mergedExceptionVersion   = updateExceptionVersion.Clone();
                replacedExceptionVersion = null;
                return(true);
            }

            ManagedExceptionVersion original =
                lineage.GetVersion(updateExceptionVersion.VersionUuid);

            if (original == null)
            {
                // original exception no longer exists --> all properties from update, no replaced rows
                mergedExceptionVersion   = updateExceptionVersion.Clone();
                replacedExceptionVersion = current;
                return(true);
            }

            if (HasChange(updateExceptionVersion, current, original,
                          out mergedExceptionVersion,
                          out conflicts))
            {
                replacedExceptionVersion = current;
                return(true);
            }

            replacedExceptionVersion = null;
            return(false);
        }
Esempio n. 5
0
        public void AddExistingException([NotNull] ManagedExceptionVersion exceptionVersion)
        {
            Assert.ArgumentNotNull(exceptionVersion, nameof(exceptionVersion));

            ExceptionLineage lineage;

            if (!_lineages.TryGetValue(exceptionVersion.LineageUuid, out lineage))
            {
                lineage = new ExceptionLineage(exceptionVersion.LineageUuid);
                _lineages.Add(lineage.Uuid, lineage);
            }

            lineage.Include(exceptionVersion);
        }
Esempio n. 6
0
        public ManagedExceptionVersion CreateExceptionVersion([NotNull] IRow row)
        {
            var result = new ManagedExceptionVersion(
                row.OID,
                Assert.NotNull(GetGuid(row, _managedLineageUuidIndex)).Value,
                Assert.NotNull(GetGuid(row, _managedVersionUuidIndex)).Value,
                GetString(row, _managedVersionOriginIndex),
                GetString(row, _managedOriginIndex),
                GetDateTime(row, _managedVersionBeginDateIndex),
                GetDateTime(row, _managedVersionEndDateIndex));

            foreach (IssueAttribute attribute in _editableAttributes)
            {
                result.SetValue(attribute, GetValue(row, _fieldIndexes[attribute]));
            }

            return(result);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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));
        }
Esempio n. 9
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);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 10
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);
        }