示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
                        }
                    }
                }
            }
        }