private string GetDomainName([NotNull] string fieldName)
        {
            IObjectClass objectClass = ConfiguratorUtils.OpenFromDefaultDatabase(Dataset);

            int    fieldIndex = objectClass.FindField(fieldName);
            IField field      = objectClass.Fields.Field[fieldIndex];

            IDomain domain = field.Domain;

            return(domain == null
                                       ? "No Domain"
                                       : domain.Name);
        }
예제 #2
0
        private static void GetSubtypes([NotNull] IObjectDataset objectDataset,
                                        [CanBeNull] out string field,
                                        [CanBeNull] out IList <Subtype> subtypes)
        {
            IObjectClass objectClass = ConfiguratorUtils.OpenFromDefaultDatabase(objectDataset);
            var          s           = (ISubtypes)objectClass;

            field = s.SubtypeFieldName;

            subtypes = string.IsNullOrEmpty(field)
                                           ? null
                                           : DatasetUtils.GetSubtypes(objectClass);
        }
        protected virtual Dictionary <string, FieldValues> GetFieldNamesCore()
        {
            IObjectClass objectClass = ConfiguratorUtils.OpenFromDefaultDatabase(Dataset);

            var subs = (ISubtypes)objectClass;

            var fieldNames = new Dictionary <string, FieldValues>();

            // get coded value domains
            int          iSub  = subs.SubtypeFieldIndex;
            IObjectClass table = objectClass;

            IFields fields     = table.Fields;
            int     fieldCount = fields.FieldCount;

            for (var fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++)
            {
                if (fieldIndex == iSub && _subtypes == null)
                {
                    _subtypeField = subs.SubtypeFieldName;

                    SortedDictionary <string, object> t =
                        GetCodeValues(_subtypeField, (IObjectClass)subs);
                    _subtypes = new Dictionary <int, string>();

                    foreach (KeyValuePair <string, object> pair in t)
                    {
                        Subtypes.Add((int)pair.Value, pair.Key);
                    }

                    continue;
                }

                IField field = fields.Field[fieldIndex];

                if (field.Domain is ICodedValueDomain)
                {
                    fieldNames.Add(field.Name.ToUpper(),
                                   new FieldValues(field, fieldIndex, NullValue));
                }
            }

            return(fieldNames);
        }
        protected void CreateCore([NotNull] TextReader reader,
                                  [NotNull] IEnumerable <Dataset> datasets)
        {
            Assert.ArgumentNotNull(reader, nameof(reader));
            Assert.ArgumentNotNull(datasets, nameof(datasets));

            string attributesLine = reader.ReadLine();

            Assert.NotNull(attributesLine, "attributesLine");

            string[] attributesStrings = attributesLine.Split(';');

            string conditionLine = reader.ReadLine();

            Assert.NotNull(conditionLine, "conditionLine");

            string[] conditionStrings = conditionLine.Split(';');

            string datasetName = attributesStrings[0];

            Dataset = Assert.NotNull(
                ConfiguratorUtils.GetDataset <ObjectDataset>(datasetName, datasets),
                "Dataset {0} not found", datasetName);

            IObjectClass objectClass = ConfiguratorUtils.OpenFromDefaultDatabase(Dataset);

            Assert.True(string.IsNullOrEmpty(attributesStrings[1]), "Invalid Matrix Format");

            Assert.True(string.IsNullOrEmpty(attributesStrings[2]) ||
                        attributesStrings[2].Equals(GeneralConstraintColumnName,
                                                    StringComparison.InvariantCultureIgnoreCase),
                        "Invalid Matrix Format");

            Assert.True(string.IsNullOrEmpty(conditionStrings[0]),
                        "Invalid Matrix Header Format: expected '', got '{0}'",
                        conditionStrings[0]);
            Assert.True(string.IsNullOrEmpty(conditionStrings[1]),
                        "Invalid Matrix Header Format: expected '', got '{0}'",
                        conditionStrings[1]);
            Assert.True(string.IsNullOrEmpty(conditionStrings[2]),
                        "Invalid Matrix Header Format: expected '', got '{0}'",
                        conditionStrings[0]);
            //if (fieldName == null)
            //{
            //    fieldName = ((ISubtypes)table).SubtypeFieldName;
            //}
            //int fieldIdx = table.FindField(fieldName);
            //IField field = table.Fields.get_Field(fieldIdx);

            IList <Code> possibleCodes = GetCodes(attributesStrings, conditionStrings,
                                                  objectClass);

            int n = possibleCodes.Count;

            string attr0 = null;
            SortedDictionary <string, object> codeValues = null;
            var allConstraints = new List <ConstraintNode>();

            for (string codeLine = reader.ReadLine();
                 codeLine != null;
                 codeLine = reader.ReadLine())
            {
                IList <string> codes = codeLine.Split(';');

                string attr = codes[0];
                string code = codes[1];

                var rowConstraints = new List <ConstraintNode>();

                string generelConstraint = codes[2];
                if (string.IsNullOrEmpty(generelConstraint) == false)
                {
                    rowConstraints.Add(new ConstraintNode(generelConstraint));
                }

                var allowedCodes = new List <Code>();
                for (var i = 0; i < n; i++)
                {
                    string value = codes[i + 3].Trim();
                    if (possibleCodes[i] == null)
                    {
                        Assert.True(string.IsNullOrEmpty(value),
                                    "Unhandled value {0} for empty Code",
                                    value);
                    }
                    else if (value == "1")
                    {
                        allowedCodes.Add(possibleCodes[i]);
                    }
                    else if (value == "0")
                    {
                    }
                    else
                    {
                        Assert.True(false, "Unhandled value {0}", value);
                    }
                }

                allowedCodes.Sort(Code.SortField);

                string      field0     = null;
                List <Code> fieldCodes = null;
                foreach (Code allowedCode in allowedCodes)
                {
                    if (allowedCode.Field.Equals(field0,
                                                 StringComparison.InvariantCultureIgnoreCase) ==
                        false)
                    {
                        if (fieldCodes != null)
                        {
                            ConstraintNode node = GetConstraint(fieldCodes);
                            if (node != null)
                            {
                                rowConstraints.Add(node);
                            }
                        }

                        fieldCodes = new List <Code>();
                        field0     = allowedCode.Field;
                    }

                    Assert.NotNull(fieldCodes, "fieldCodes is null");
                    fieldCodes.Add(allowedCode);
                }

                if (fieldCodes != null)
                {
                    rowConstraints.Add(GetConstraint(fieldCodes));
                }

                if (string.IsNullOrEmpty(code))
                {
                    if (string.IsNullOrEmpty(attr))
                    {
                        allConstraints.AddRange(rowConstraints);
                    }
                    else
                    {
                        var constraintConstraint = new ConstraintNode(attr);

                        foreach (ConstraintNode constraint in allConstraints)
                        {
                            constraintConstraint.Nodes.Add(constraint);
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(attr) &&
                        !attr.Equals(attr0, StringComparison.InvariantCultureIgnoreCase))
                    {
                        codeValues = GetCodeValues(attr, objectClass);
                        attr0      = attr;
                    }

                    Assert.NotNull(codeValues, "No coded value field defined");

                    code = AdaptCode(attr0, code, codeValues);

                    Code lineCode = code != _nullValue
                                                                ? new Code(attr0, code, codeValues[code])
                                                                : new Code(attr0, codeValues[_nullValue]);

                    string constraint     = string.Format("{0} = {1}", attr0, lineCode.CodeIdString());
                    var    codeConstraint = new ConstraintNode(constraint);

                    foreach (ConstraintNode node in rowConstraints)
                    {
                        codeConstraint.Nodes.Add(node);
                    }

                    allConstraints.Add(codeConstraint);
                }
            }

            Constraints = allConstraints;
        }