Ejemplo n.º 1
0
        private static IEnumerable <IRow> GetReferencingRows(
            [NotNull] ReferencedTableInfo referencedTableInfo,
            [NotNull] ReferencingTableInfo referencingTableInfo)
        {
            const bool recycle     = true;
            const int  maxKeyCount = 20;

            if (referencedTableInfo.KeySet.Count <= maxKeyCount)
            {
                return(GdbQueryUtils.GetRowsInList(
                           referencingTableInfo.Table,
                           referencingTableInfo.ForeignKeyFieldName,
                           referencedTableInfo.KeySet, recycle,
                           referencingTableInfo.Filter));
            }

            var queryFilter =
                new QueryFilterClass
            {
                WhereClause = string.Format("{0} IS NOT NULL",
                                            referencingTableInfo.ForeignKeyFieldName)
            };

            return(GdbQueryUtils.GetRows(referencingTableInfo.Table, queryFilter,
                                         recycle));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private static IList <ConstraintNode> GetConstraints(
            [NotNull] ITable constraintsTable,
            [CanBeNull] string filterExpression,
            [NotNull] string constraintField,
            [CanBeNull] string constraintDescriptionField,
            bool invertCondition)
        {
            var result = new List <ConstraintNode>();

            int constraintIndex = constraintsTable.FindField(constraintField);

            Assert.True(constraintIndex >= 0, "Field {0} not found in table {1}",
                        constraintField, DatasetUtils.GetName(constraintsTable));

            int descriptionIndex = -1;

            if (StringUtils.IsNotEmpty(constraintDescriptionField))
            {
                descriptionIndex = constraintsTable.FindField(constraintDescriptionField);
                Assert.True(descriptionIndex >= 0,
                            "Field {0} not found in table {1}",
                            constraintDescriptionField, DatasetUtils.GetName(constraintsTable));
            }

            IQueryFilter filter = CreateQueryFilter(filterExpression, constraintField,
                                                    constraintDescriptionField);

            const bool recycling = true;

            foreach (IRow row in GdbQueryUtils.GetRows(constraintsTable, filter, recycling))
            {
                var constraint = row.Value[constraintIndex] as string;

                if (constraint == null || constraint.Trim().Length == 0)
                {
                    continue;
                }

                string constraintDescription =
                    descriptionIndex >= 0
                                                ? row.Value[descriptionIndex] as string
                                                : null;

                result.Add(
                    CreateConstraintNode(constraint, constraintDescription, invertCondition));
            }

            return(result);
        }
Ejemplo n.º 4
0
        private static ExceptionUpdateDetector GetUpdateDetector(
            [NotNull] ITable targetTable,
            [NotNull] ManagedExceptionVersionFactory targetExceptionVersionFactory,
            [NotNull] IEnumerable <IssueAttribute> editableAttributes)
        {
            var result = new ExceptionUpdateDetector(editableAttributes);

            foreach (IRow targetRow in GdbQueryUtils.GetRows(targetTable, recycle: true))
            {
                result.AddExistingException(
                    targetExceptionVersionFactory.CreateExceptionVersion(targetRow));
            }

            return(result);
        }
Ejemplo n.º 5
0
        private static Dictionary <int, IRow> GetFirstNRows(ITable table, int count)
        {
            var dic = new Dictionary <int, IRow>(count);

            foreach (IRow row in GdbQueryUtils.GetRows(table, false))
            {
                dic.Add(row.OID, row);
                if (dic.Count >= count)
                {
                    break;
                }
            }

            return(dic);
        }
Ejemplo n.º 6
0
        protected virtual IEnumerable <Row> GetRowsCore([NotNull] ISourceClass sourceClass, [CanBeNull] QueryFilter filter, bool recycle)
        {
            Table table = OpenFeatureClass(sourceClass);

            if (table == null)
            {
                yield break;
            }

            // Todo daro: check recycle
            foreach (Feature feature in GdbQueryUtils.GetRows <Feature>(
                         table, filter, recycle))
            {
                yield return(feature);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Ensures that the list of reserved names is ready.
        /// </summary>
        private void EnsureReservedNames()
        {
            if (_reservedNames != null)
            {
                return;
            }

            int    nameFieldIndex;
            int    reasonFieldIndex;
            int    validNameFieldIndex;
            string subFields = GetLookupSubFields(out nameFieldIndex,
                                                  out reasonFieldIndex,
                                                  out validNameFieldIndex);

            var queryFilter = new QueryFilterClass
            {
                SubFields   = subFields,
                WhereClause = GetConstraint(_reservedNamesTable)
            };

            _reservedNames = new List <ReservedName>();

            const bool recycle = true;

            foreach (
                IRow row in GdbQueryUtils.GetRows(_reservedNamesTable, queryFilter,
                                                  recycle))
            {
                var name = row.get_Value(nameFieldIndex) as string;

                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }

                string reason = reasonFieldIndex >= 0
                                                        ? row.get_Value(reasonFieldIndex) as string
                                                        : null;
                string validName = validNameFieldIndex >= 0
                                                           ? row.get_Value(validNameFieldIndex) as string
                                                           : null;

                _reservedNames.Add(new ReservedName(name, reason, validName));
            }
        }
            private IEnumerable <FieldSpecification> ReadFieldSpecifications(
                [NotNull] ITable table)
            {
                int nameFieldIndex       = table.FindField("ATTRIBUTE");
                int typeStringFieldIndex = table.FindField("FIELDTYPE_ARCGIS");
                int aliasFieldIndex      = table.FindField("ALIAS");
                int accessTypeFieldIndex = table.FindField("FIELDTYPE_ACCESS");

                const bool recycle = true;

                foreach (IRow row in GdbQueryUtils.GetRows(table, GetQueryFilter(), recycle))
                {
                    var name = row.Value[nameFieldIndex] as string;

                    Console.WriteLine(name);
                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }

                    object type       = row.Value[typeStringFieldIndex];
                    var    typeString = type as string;

                    if (string.IsNullOrEmpty(typeString))
                    {
                        throw new InvalidConfigurationException(
                                  string.Format("Expected type is undefined: '{0}'", type));
                    }

                    var           alias        = row.Value[aliasFieldIndex] as string;
                    esriFieldType expectedType = GetFieldType(typeString);

                    var accessTypeString = row.Value[accessTypeFieldIndex] as string;

                    int length = expectedType == esriFieldType.esriFieldTypeString
                                                             ? GetTextLength(accessTypeString)
                                                             : -1;

                    yield return
                        (new FieldSpecification(name, expectedType, length, alias, null, true));
                }
            }
Ejemplo n.º 9
0
        public void CanGetRelated()
        {
            IFeatureWorkspace  ws = OpenTestWorkspace();
            IRelationshipClass rc =
                ws.OpenRelationshipClass("TOPGIS_TLM.TLM_STRASSE_NAME");

            NUnit.Framework.Assert.AreEqual(rc.Cardinality,
                                            esriRelCardinality.esriRelCardinalityOneToMany);

            int count = 0;

            foreach (IRow row in GdbQueryUtils.GetRows((ITable)rc.OriginClass, false))
            {
                var             obj      = (IObject)row;
                IList <IObject> features = GdbQueryUtils.GetRelatedObjectList(obj, new[] { rc });
                count += features.Count;
            }

            NUnit.Framework.Assert.Greater(count, 0);
        }
Ejemplo n.º 10
0
        private int ExecuteGeometry([CanBeNull] IGeometry geometry)
        {
            EnsureKeySet();

            if (!(_table is IFeatureClass))
            {
                geometry = null;
            }

            IQueryFilter filter = TestUtils.CreateFilter(geometry, AreaOfInterest,
                                                         GetConstraint(0), _table, null);

            const bool recycle    = true;
            int        errorCount = 0;

            foreach (IRow row in GdbQueryUtils.GetRows(_table, filter, recycle))
            {
                errorCount += VerifyRow(row);
            }

            return(errorCount);
        }
Ejemplo n.º 11
0
        public void Can_instantiate_IssueItem()
        {
            var definition =
                _geodatabase.GetDefinition <FeatureClassDefinition>(_issuePointsFeatureClassName);

            var reader = new AttributeReader(definition,
                                             Attributes.IssueCode,
                                             Attributes.IssueCodeDescription,
                                             Attributes.InvolvedObjects,
                                             Attributes.QualityConditionName,
                                             Attributes.TestName,
                                             Attributes.TestDescription,
                                             Attributes.TestType,
                                             Attributes.IssueSeverity,
                                             Attributes.IsStopCondition,
                                             Attributes.Category,
                                             Attributes.AffectedComponent,
                                             Attributes.Url,
                                             Attributes.DoubleValue1,
                                             Attributes.DoubleValue2,
                                             Attributes.TextValue,
                                             Attributes.IssueAssignment,
                                             Attributes.QualityConditionUuid,
                                             Attributes.QualityConditionVersionUuid,
                                             Attributes.ExceptionStatus,
                                             Attributes.ExceptionNotes,
                                             Attributes.ExceptionCategory,
                                             Attributes.ExceptionOrigin,
                                             Attributes.ExceptionDefinedDate,
                                             Attributes.ExceptionLastRevisionDate,
                                             Attributes.ExceptionRetirementDate,
                                             Attributes.ExceptionShapeMatchCriterion);

            foreach (Feature feature in GdbQueryUtils.GetRows <Feature>(_issuePoints))
            {
                var item = new IssueItem(0, feature);
                break;
            }
        }
Ejemplo n.º 12
0
        public void OrderByGuidFileGdb()
        {
            IFeatureWorkspace featureWs =
                WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetArealeFileGdbPath());
            ITable table = DatasetUtils.OpenTable(featureWs, "TLM_NUTZUNGSAREAL");

            IQueryFilter queryFilter = new QueryFilterClass();

            var queryFilterDef = (IQueryFilterDefinition)queryFilter;

            queryFilterDef.PostfixClause = "ORDER BY UUID";

            foreach (IRow row in GdbQueryUtils.GetRows(table, queryFilter, true))
            {
                object value = row.get_Value(1);

                Assert.False(value == DBNull.Value, "Empty UUID field");

                var currentGuid = new Guid((string)value);

                Console.WriteLine(currentGuid);
            }
        }
Ejemplo n.º 13
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
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);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
        internal static IKeySet ReadKeySet([NotNull] ITable table,
                                           [NotNull] string keyField,
                                           [CanBeNull] string whereClause,
                                           esriFieldType keyFieldType,
                                           int keyFieldIndex)
        {
            Assert.ArgumentNotNull(table, nameof(table));
            Assert.ArgumentNotNullOrEmpty(keyField, nameof(keyField));

            Stopwatch       watch       = null;
            MemoryUsageInfo memoryUsage = null;

            if (_msg.IsVerboseDebugEnabled)
            {
                watch       = _msg.DebugStartTiming();
                memoryUsage = new MemoryUsageInfo();
                memoryUsage.Refresh();
            }

            IKeySet result = CreateKeySet(keyFieldType);

            var queryFilter = new QueryFilterClass
            {
                SubFields   = keyField,
                WhereClause = whereClause
            };
            string tableName = DatasetUtils.GetName(table);

            const bool recycle = true;

            foreach (IRow row in GdbQueryUtils.GetRows(table, queryFilter, recycle))
            {
                object key = row.Value[keyFieldIndex];

                if (key == DBNull.Value || key == null)
                {
                    continue;
                }

                // TODO handle errors (e.g. invalid guid strings)
                bool added = result.Add(key);

                if (!added)
                {
                    _msg.VerboseDebugFormat(
                        "Ignored duplicate key found in field '{0}' in table '{1}': {2}",
                        keyField, tableName, key);
                }
            }

            if (watch != null)
            {
                _msg.DebugStopTiming(watch,
                                     "Reading {0:N0} {1} keys from field '{2}' in table '{3}'",
                                     result.Count, keyFieldType, keyField,
                                     DatasetUtils.GetName(table));
                _msg.DebugFormat("Memory usage of keys: {0}", memoryUsage);
            }

            return(result);
        }
Ejemplo n.º 16
0
        internal static ITupleKeySet ReadTupleKeySet(
            [NotNull] ITable table,
            [NotNull] ICollection <string> keyFields,
            [CanBeNull] string whereClause,
            [NotNull] IList <esriFieldType> keyFieldTypes,
            [NotNull] IList <int> keyFieldIndices)
        {
            Assert.ArgumentNotNull(table, nameof(table));
            Assert.ArgumentNotNull(keyFields, nameof(keyFields));
            Assert.ArgumentNotNull(keyFieldTypes, nameof(keyFieldTypes));
            Assert.ArgumentNotNull(keyFieldIndices, nameof(keyFieldIndices));

            Stopwatch       watch       = null;
            MemoryUsageInfo memoryUsage = null;

            if (_msg.IsVerboseDebugEnabled)
            {
                watch       = _msg.DebugStartTiming();
                memoryUsage = new MemoryUsageInfo();
                memoryUsage.Refresh();
            }

            var fieldIndices = new List <int>();

            foreach (string keyField in keyFields)
            {
                int fieldIndex = table.FindField(keyField);
                Assert.True(fieldIndex >= 0, "field '{0}' not found in table {1}",
                            keyField, DatasetUtils.GetName(table));
                fieldIndices.Add(fieldIndex);
            }

            ITupleKeySet result = new TupleKeySet();

            IQueryFilter queryFilter = GetQueryFilter(keyFields, whereClause);

            string keyFieldsString = StringUtils.Concatenate(keyFields, ",");
            string tableName       = DatasetUtils.GetName(table);

            const bool recycle = true;

            foreach (IRow row in GdbQueryUtils.GetRows(table, queryFilter, recycle))
            {
                Tuple tuple = ReadTuple(row, fieldIndices);

                bool added = result.Add(tuple);

                if (!added)
                {
                    _msg.DebugFormat(
                        "Ignored duplicate value combination found in fields '{0}' in table '{1}': {2}",
                        keyFieldsString, tableName, tuple);
                }
            }

            if (watch != null)
            {
                _msg.DebugStopTiming(watch,
                                     "Reading {0:N0} keys from fields '{1}' in table '{2}'",
                                     result.Count, queryFilter.SubFields,
                                     DatasetUtils.GetName(table));
                _msg.DebugFormat("Memory usage of keys: {0}", memoryUsage);
            }

            return(result);
        }
Ejemplo n.º 17
0
        public void CanCreateGdbFeatureClassWithBackingDataset()
        {
            IWorkspace ws = TestUtils.OpenUserWorkspaceOracle();

            const string tlmStrasse = "TOPGIS_TLM.TLM_STRASSE";

            IFeatureClass realFeatureClass = DatasetUtils.OpenFeatureClass(ws, tlmStrasse);

            var rowCache = GdbQueryUtils.GetRows((ITable)realFeatureClass, false)
                           .Take(100)
                           .ToList();

            Assert.AreEqual(100, rowCache.Count);

            GdbTable tableWithBackingData =
                new GdbFeatureClass(41, "TESTABLE", esriGeometryType.esriGeometryPoint,
                                    "Test table",
                                    table => new InMemoryDataset(table, rowCache));

            IFeatureClass featureClassWithBackingData = (IFeatureClass)tableWithBackingData;

            Assert.AreEqual(41, featureClassWithBackingData.ObjectClassID);
            Assert.AreEqual("TESTABLE", DatasetUtils.GetName(featureClassWithBackingData));
            Assert.AreEqual("Test table",
                            DatasetUtils.GetAliasName(featureClassWithBackingData));
            Assert.AreEqual(esriGeometryType.esriGeometryPoint,
                            featureClassWithBackingData.ShapeType);

            Assert.False(featureClassWithBackingData.HasOID);
            Assert.Null(featureClassWithBackingData.OIDFieldName);

            for (int i = 0; i < realFeatureClass.Fields.FieldCount; i++)
            {
                featureClassWithBackingData.AddField(realFeatureClass.Fields.Field[i]);
            }

            Assert.AreEqual("OBJECTID", featureClassWithBackingData.OIDFieldName);
            Assert.AreEqual("SHAPE", featureClassWithBackingData.ShapeFieldName);

            Assert.AreEqual(100, GdbQueryUtils.Count(featureClassWithBackingData, ""));

            IQueryFilter queryFilter = GdbQueryUtils.CreateQueryFilter("OBJECTID");

            queryFilter.WhereClause = "OBJECTID < 0";

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(featureClassWithBackingData, queryFilter));

            var backingDataset = tableWithBackingData.BackingDataset as InMemoryDataset;

            Assert.NotNull(backingDataset);

            backingDataset.AllRows.Add(new GdbRow(1, tableWithBackingData));

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(featureClassWithBackingData, queryFilter));

            queryFilter.WhereClause = "OBJECTID >= 0";

            Assert.AreEqual(101,
                            GdbQueryUtils.Count(featureClassWithBackingData, queryFilter));
        }
Ejemplo n.º 18
0
        public static IEnumerable <AllowedError> GetAllowedErrors(
            [NotNull] IssueDatasetWriter issueWriter,
            [CanBeNull] IGeometry areaOfInterest,
            [NotNull] ISpatialFilter spatialFilter,
            [NotNull] AllowedErrorFactory allowedErrorFactory)
        {
            Assert.ArgumentNotNull(issueWriter, nameof(issueWriter));
            Assert.ArgumentNotNull(spatialFilter, nameof(spatialFilter));
            Assert.ArgumentNotNull(allowedErrorFactory, nameof(allowedErrorFactory));

            Stopwatch watch = _msg.DebugStartTiming();

            ITable       errorTable = issueWriter.Table;
            IQueryFilter filter;

            var errorFeatureClass = errorTable as IFeatureClass;

            if (errorFeatureClass != null)
            {
                if (areaOfInterest != null)
                {
                    spatialFilter.Geometry      = areaOfInterest;
                    spatialFilter.GeometryField = errorFeatureClass.ShapeFieldName;
                    spatialFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
                }

                filter = spatialFilter;
            }
            else
            {
                filter = new QueryFilterClass
                {
                    WhereClause = spatialFilter.WhereClause,
                    SubFields   = spatialFilter.SubFields
                };
            }

            var addedAllowedErrorsCount = 0;
            var readRowCount            = 0;

            const bool recycling = true;

            foreach (IRow row in GdbQueryUtils.GetRows(errorTable, filter, recycling))
            {
                readRowCount++;
                AllowedError allowedError =
                    allowedErrorFactory.CreateAllowedError(issueWriter, row);

                if (allowedError == null)
                {
                    continue;
                }

                addedAllowedErrorsCount++;

                yield return(allowedError);
            }

            _msg.DebugStopTiming(watch,
                                 "Collected {0} allowed error(s) based on {1} row(s) read from {2}",
                                 addedAllowedErrorsCount, readRowCount,
                                 issueWriter.DatasetName);
        }