Exemple #1
0
        public void CanGetAttributes()
        {
            const string dsName = "TOPGIS.TLM_DATASET";
            DdxModel     m      = CreateModel();

            ObjectDataset ds = m.AddDataset(CreateObjectDataset(dsName));

            ObjectAttribute oa1 = ds.AddAttribute(
                new ObjectAttribute("field1", FieldType.Text));
            ObjectAttribute oa2 = ds.AddAttribute(
                new ObjectAttribute("field2", FieldType.Text));

            oa1.ReadOnlyOverride = false;
            oa2.ReadOnlyOverride = true;

            CreateSchema(m);

            UnitOfWork.NewTransaction(
                delegate
            {
                AssertUnitOfWorkHasNoChanges();

                IList <Dataset> list = Repository.Get(dsName);
                Assert.AreEqual(1, list.Count);
                var result = list[0] as VectorDataset;

                Assert.IsNotNull(result);
                Assert.AreEqual(dsName, result.Name);
                Assert.AreEqual(2, ds.Attributes.Count);
                Assert.AreEqual(2, (new List <ObjectAttribute>(ds.GetAttributes())).Count);

                ObjectAttribute field1 = ds.GetAttribute("field1");
                ObjectAttribute field2 = ds.GetAttribute("field2");
                Assert.IsNotNull(field1, "field1");
                Assert.IsNotNull(field2, "field2");

                Assert.IsFalse(field1.ReadOnly);
                Assert.IsTrue(field2.ReadOnly);
            });
        }
Exemple #2
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));
        }