Exemplo n.º 1
0
        public string GetString([NotNull] IRow errorRow,
                                [NotNull] AttributeRole role)
        {
            const bool roleIsOptional = false;

            return(Assert.NotNull(GetString(errorRow, role, roleIsOptional)));
        }
Exemplo n.º 2
0
        internal string GetFieldName([NotNull] AttributeRole attributeRole)
        {
            // TODO: Consider implementing a configuration consistency check at the beginning

            string fieldName = null;

            foreach (IssueDatasetWriter issueWriter in GetIssueWriters())
            {
                if (fieldName == null)
                {
                    fieldName = issueWriter.GetAttribute(attributeRole).Name;
                }
                else if (!fieldName.Equals(
                             issueWriter.GetAttribute(attributeRole).Name,
                             StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidConfigurationException(
                              string.Format(
                                  "The field with role '{0}' must have the same name in all issue tables.",
                                  attributeRole));
                }
            }

            Assert.NotNull(fieldName, "Field for role '{0}' not found in issue datasets",
                           attributeRole);

            return(fieldName);
        }
Exemplo n.º 3
0
        public void WriteValue([NotNull] IRowBuffer rowBuffer,
                               [NotNull] AttributeRole role,
                               [CanBeNull] string text)
        {
            int fieldIndex = GetFieldIndex(role);

            WriteTextValue(text, rowBuffer, fieldIndex);
        }
Exemplo n.º 4
0
        public void WriteValue([NotNull] IRowBuffer rowBuffer,
                               [NotNull] AttributeRole role,
                               [CanBeNull] object value)
        {
            int fieldIndex = GetFieldIndex(role);

            rowBuffer.set_Value(fieldIndex, value ?? DBNull.Value);
        }
Exemplo n.º 5
0
        protected object GetValue([NotNull] AttributeRole role, bool roleIsOptional)
        {
            int?index = GetFieldIndex(role, _fieldIndexCache, roleIsOptional);

            return(index == null
                                       ? null
                                       : _object.Value[index.Value]);
        }
Exemplo n.º 6
0
        protected string GetString([NotNull] AttributeRole role)
        {
            object value = GetValue(role);

            return(value is DBNull
                                       ? null
                                       : (string)value);
        }
Exemplo n.º 7
0
        protected string GetDisplayValue([NotNull] AttributeRole role)
        {
            // don't call in tight loops
            int    index = GetFieldIndex(role, _fieldIndexCache);
            object value = GdbObjectUtils.GetDisplayValue(_object, index);

            // NOTE: explicit cast to string results in exception if the domain code could not be resolved
            return(Convert.ToString(value));
        }
Exemplo n.º 8
0
        private IField GetField([NotNull] IFields fields,
                                AttributeRole role,
                                out int fieldIndex)
        {
            string name = _fieldNames[role];

            fieldIndex = fields.FindField(name);

            return(fields.Field[fieldIndex]);
        }
Exemplo n.º 9
0
        public static int GetFieldIndex([NotNull] ITable table,
                                        [NotNull] Attribute attribute,
                                        [CanBeNull] IFieldIndexCache fieldIndexCache = null)
        {
            AttributeRole attributeRole = (attribute as ObjectAttribute)?.Role;

            return
                (fieldIndexCache?.GetFieldIndex(table, attribute.Name, attributeRole) ??
                 GetFieldIndex(table, attribute.Name, attributeRole));
        }
Exemplo n.º 10
0
        private int GetFieldIndex([NotNull] AttributeRole role, bool roleIsOptional)
        {
            int fieldIndex;

            if (!_fieldIndexesByRole.TryGetValue(role, out fieldIndex))
            {
                fieldIndex = GetFieldIndexCore(role, roleIsOptional);
                _fieldIndexesByRole.Add(role, fieldIndex);
            }

            return(fieldIndex);
        }
Exemplo n.º 11
0
            public int GetFieldIndex([NotNull] string fieldName, [CanBeNull] AttributeRole role)
            {
                int fieldIndex;

                if (!_fieldIndexes.TryGetValue(fieldName, out fieldIndex))
                {
                    fieldIndex = AttributeUtils.GetFieldIndex(_table, fieldName, role);
                    _fieldIndexes.Add(fieldName, fieldIndex);
                }

                return(fieldIndex);
            }
Exemplo n.º 12
0
        public int GetFieldIndex(ITable table, string fieldName, AttributeRole role)
        {
            FieldIndexes fieldIndexes;

            if (!_fieldIndexesByTable.TryGetValue(table, out fieldIndexes))
            {
                fieldIndexes = new FieldIndexes(table);
                _fieldIndexesByTable.Add(table, fieldIndexes);
            }

            return(fieldIndexes.GetFieldIndex(fieldName, role));
        }
Exemplo n.º 13
0
        private int GetFieldIndex([NotNull] AttributeRole role,
                                  [CanBeNull] IFieldIndexCache fieldIndexCache)
        {
            const bool roleIsOptional = false;
            int?       result         = GetFieldIndex(role, fieldIndexCache, roleIsOptional);

            if (result == null)
            {
                throw new InvalidOperationException("field index expected");
            }

            return(result.Value);
        }
Exemplo n.º 14
0
        protected bool?GetBoolean([NotNull] AttributeRole role)
        {
            object value = GetValue(role);

            if (value == null || value is DBNull)
            {
                return(null);
            }

            const int trueValue = 1;

            return(Equals(value, trueValue));
        }
Exemplo n.º 15
0
        public static string ToString(this AttributeRole attributeRole)
        {
            switch (attributeRole)
            {
            case AttributeRole.Dimension:
                return("Dimension");

            case AttributeRole.Measure:
                return("Measure");

            default:
                return("Unknown type");
            }
        }
Exemplo n.º 16
0
        public int GetFieldLength([NotNull] AttributeRole role)
        {
            int length;

            if (!_fieldLengthByRole.TryGetValue(role, out length))
            {
                IField field = Table.Fields.Field[GetFieldIndex(role)];

                length = field.Length;

                _fieldLengthByRole.Add(role, length);
            }

            return(length);
        }
Exemplo n.º 17
0
        private ObjectAttribute GetAttribute([NotNull] AttributeRole attributeRole,
                                             bool roleIsOptional)
        {
            // TODO: Test if there are uow problems here
            ObjectAttribute attribute = _issueObjectDataset.GetAttribute(attributeRole);

            if (attribute != null || roleIsOptional)
            {
                return(attribute);
            }

            throw new InvalidConfigurationException(
                      string.Format("Attribute role {0} does not exist in {1}",
                                    attributeRole, _issueObjectDataset.Name));
        }
Exemplo n.º 18
0
        public string GetString([NotNull] IRow errorRow,
                                [NotNull] AttributeRole role,
                                bool roleIsOptional)
        {
            int fieldIndex = GetFieldIndex(role, roleIsOptional);

            if (fieldIndex < 0)
            {
                return(null);
            }

            object obj = errorRow.Value[fieldIndex];

            return(obj == null || obj is DBNull
                                       ? string.Empty
                                       : Convert.ToString(obj));
        }
Exemplo n.º 19
0
        public static int GetFieldIndex([NotNull] ITable table,
                                        [NotNull] string fieldName,
                                        [CanBeNull] AttributeRole attributeRole)
        {
            // TODO search first based on name, or first based on role?

            if (Equals(attributeRole, AttributeRole.Shape))
            {
                var featureClass = table as IFeatureClass;
                if (featureClass != null)
                {
                    return(table.FindField(featureClass.ShapeFieldName));
                }
            }
            else if (Equals(attributeRole, AttributeRole.ShapeArea))
            {
                var featureClass = table as IFeatureClass;
                if (featureClass != null)
                {
                    IField areaField = DatasetUtils.GetAreaField(featureClass);
                    if (areaField != null)
                    {
                        return(table.FindField(areaField.Name));
                    }
                }
            }
            else if (Equals(attributeRole, AttributeRole.ShapeLength))
            {
                var featureClass = table as IFeatureClass;
                if (featureClass != null)
                {
                    IField lengthField = DatasetUtils.GetLengthField(featureClass);
                    if (lengthField != null)
                    {
                        return(table.FindField(lengthField.Name));
                    }
                }
            }
            else if (Equals(attributeRole, AttributeRole.ObjectID))
            {
                return(table.FindField(table.OIDFieldName));
            }

            return(table.FindField(fieldName));
        }
Exemplo n.º 20
0
        private int GetFieldIndexCore([NotNull] AttributeRole role, bool roleIsOptional)
        {
            ObjectAttribute attribute = GetAttribute(role, roleIsOptional);

            if (attribute == null)
            {
                return(-1);
            }

            int fieldIndex = AttributeUtils.GetFieldIndex(Table, attribute, _fieldIndexCache);

            if (fieldIndex >= 0 || roleIsOptional)
            {
                return(fieldIndex);
            }

            throw new ArgumentException(string.Format("Field {0} not found", attribute.Name));
        }
Exemplo n.º 21
0
        private void Write([NotNull] IFeature feature,
                           AttributeRole role,
                           [CanBeNull] object value)
        {
            Assert.ArgumentNotNull(feature, nameof(feature));

            int    fieldIndex;
            IField field = GetField(feature.Fields, role, out fieldIndex);

            if (value == null || value is DBNull)
            {
                if (field.IsNullable)
                {
                    feature.Value[fieldIndex] = DBNull.Value;
                }

                return;
            }

            if (field.Type != esriFieldType.esriFieldTypeString)
            {
                feature.Value[fieldIndex] = value;
                return;
            }

            var stringValue = value as string;

            Assert.NotNull(stringValue, "Unexpected value for text field: {0}", value);

            bool requiresTrim = stringValue.Length > field.Length;

            if (requiresTrim)
            {
                _msg.WarnFormat("Text is too long for field '{0}', cutting off: {1}",
                                field.Name, stringValue);
            }

            string writeValue = requiresTrim
                                                    ? stringValue.Substring(0, field.Length)
                                                    : stringValue;

            feature.Value[fieldIndex] = writeValue;
        }
Exemplo n.º 22
0
        private int?GetFieldIndex([NotNull] AttributeRole role,
                                  [CanBeNull] IFieldIndexCache fieldIndexCache,
                                  bool roleIsOptional)
        {
            ObjectAttribute attribute = _dataset.GetAttribute(role);

            if (attribute == null)
            {
                if (roleIsOptional)
                {
                    return(null);
                }

                throw new ArgumentException(
                          string.Format("Dataset [{0}] has no attribute role [{1}]",
                                        _dataset.Name, role), nameof(role));
            }

            return(AttributeUtils.GetFieldIndex(_object.Class, attribute, fieldIndexCache));
        }
 protected string GetFieldName([NotNull] AttributeRole attributeRole)
 {
     return(IssueDatasets.GetFieldName(attributeRole));
 }
Exemplo n.º 24
0
        protected void SetValue([NotNull] AttributeRole role, [CanBeNull] object value)
        {
            int index = GetFieldIndex(role, _fieldIndexCache);

            _object.set_Value(index, value ?? DBNull.Value);
        }
Exemplo n.º 25
0
 public T?Get <T>([NotNull] IRow errorRow,
                  [NotNull] AttributeRole role) where T : struct
 {
     return(GdbObjectUtils.ReadRowValue <T>(errorRow, GetFieldIndex(role)));
 }
Exemplo n.º 26
0
        protected object GetValue([NotNull] AttributeRole role)
        {
            const bool roleIsOptional = false;

            return(GetValue(role, roleIsOptional));
        }
Exemplo n.º 27
0
 public bool HasAttribute([NotNull] AttributeRole attributeRole)
 {
     return(_issueObjectDataset.GetAttribute(attributeRole) != null);
 }
Exemplo n.º 28
0
        public ObjectAttribute GetAttribute([NotNull] AttributeRole attributeRole)
        {
            const bool roleIsOptional = false;

            return(Assert.NotNull(GetAttribute(attributeRole, roleIsOptional)));
        }
Exemplo n.º 29
0
        private int GetFieldIndex([NotNull] AttributeRole role)
        {
            const bool roleIsOptional = false;

            return(GetFieldIndex(role, roleIsOptional));
        }
Exemplo n.º 30
0
 public int GetFieldIndex(IObjectClass objectClass,
                          string fieldName,
                          AttributeRole role)
 {
     return(GetFieldIndex((ITable)objectClass, fieldName, role));
 }