コード例 #1
0
        private void ReadSQLMetadata(MetaObject metaObject)
        {
            if (string.IsNullOrWhiteSpace(metaObject.TableName))
            {
                return;
            }

            List <FieldSqlInfo> sql_fields = GetSqlFields(metaObject.TableName);

            ClusteredIndexInfo indexInfo = GetClusteredIndexInfo(metaObject.TableName);

            foreach (FieldSqlInfo info in sql_fields)
            {
                bool found = false; MetaField field = null;
                foreach (MetaProperty p in metaObject.Properties)
                {
                    if (string.IsNullOrEmpty(p.Field))
                    {
                        continue;
                    }

                    if (info.COLUMN_NAME.TrimStart('_') == MetadataTokens.Periodicity)
                    {
                        continue;
                    }

                    if (info.COLUMN_NAME.TrimStart('_').StartsWith(p.Field))
                    {
                        field = new MetaField()
                        {
                            Name    = info.COLUMN_NAME,
                            Purpose = SqlUtility.ParseFieldPurpose(info.COLUMN_NAME)
                        };
                        p.Fields.Add(field);
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    string propertyName = string.Empty;
                    int    propertyType = (int)DataTypes.NULL;

                    if (metaObject.Owner != null && // таблица итогов регистра накопления
                        metaObject.TypeName == MetaObjectTypes.AccumulationRegister &&
                        metaObject.Owner.TypeName == MetaObjectTypes.AccumulationRegister)
                    {
                        // find property name in main table object by field name
                        foreach (MetaProperty ownerProperty in metaObject.Owner.Properties)
                        {
                            if (ownerProperty.Fields.Where(f => f.Name == info.COLUMN_NAME).FirstOrDefault() != null)
                            {
                                propertyName = ownerProperty.Name;
                                if (ownerProperty.PropertyType == (int)DataTypes.Multiple)
                                {
                                    propertyType = (int)DataTypes.Multiple;
                                }
                                break;
                            }
                        }
                    }

                    MetaProperty property = metaObject.Properties.Where(p => p.Name == propertyName).FirstOrDefault();
                    if (property == null)
                    {
                        property = new MetaProperty()
                        {
                            Name    = string.IsNullOrEmpty(propertyName) ? info.COLUMN_NAME : propertyName,
                            Purpose = PropertyPurpose.System
                        };
                        metaObject.Properties.Add(property);

                        MatchFieldToProperty(info, property);

                        if (property.PropertyType == (int)DataTypes.NULL)
                        {
                            property.PropertyType = propertyType;
                        }
                    }

                    field = new MetaField()
                    {
                        Name    = info.COLUMN_NAME,
                        Purpose = SqlUtility.ParseFieldPurpose(info.COLUMN_NAME)
                    };
                    property.Fields.Add(field);
                }
                field.TypeName   = info.DATA_TYPE;
                field.Length     = info.CHARACTER_MAXIMUM_LENGTH;
                field.Precision  = info.NUMERIC_PRECISION;
                field.Scale      = info.NUMERIC_SCALE;
                field.IsNullable = info.IS_NULLABLE;

                if (indexInfo != null)
                {
                    ClusteredIndexColumnInfo columnInfo = indexInfo.GetColumnByName(info.COLUMN_NAME);
                    if (columnInfo != null)
                    {
                        field.IsPrimaryKey = true;
                        field.KeyOrdinal   = columnInfo.KEY_ORDINAL;
                    }
                }
            }
        }
コード例 #2
0
        private void MatchFieldToProperty(FieldSqlInfo field, MetaProperty property)
        {
            string columnName = field.COLUMN_NAME.TrimStart('_');

            if (columnName.StartsWith(MetadataTokens.IDRRef))
            {
                property.Name         = "Ссылка";
                property.Field        = MetadataTokens.IDRRef;
                property.PropertyType = (int)DataTypes.Object;
            }
            else if (columnName.StartsWith(MetadataTokens.Version))
            {
                property.Name         = "ВерсияДанных";
                property.Field        = MetadataTokens.Version;
                property.PropertyType = (int)DataTypes.Binary;
            }
            else if (columnName.StartsWith(MetadataTokens.Marked))
            {
                property.Name         = "ПометкаУдаления";
                property.Field        = MetadataTokens.Marked;
                property.PropertyType = (int)DataTypes.Boolean;
            }
            else if (columnName.StartsWith(MetadataTokens.PredefinedID))
            {
                property.Name         = "ИмяПредопределённыхДанных";
                property.Field        = MetadataTokens.PredefinedID;
                property.PropertyType = (int)DataTypes.UUID;
            }
            else if (columnName.StartsWith(MetadataTokens.Code))
            {
                property.Name  = "Код";
                property.Field = MetadataTokens.Code;
                // TODO: find out field data type: string or numeric
                //property.PropertyTypes.Add((int)DataTypes.String);
            }
            else if (columnName.StartsWith(MetadataTokens.Description))
            {
                property.Name         = "Наименование";
                property.Field        = MetadataTokens.Description;
                property.PropertyType = (int)DataTypes.String;
            }
            else if (columnName.StartsWith(MetadataTokens.Folder))
            {
                property.Name         = "ЭтоГруппа";
                property.Field        = MetadataTokens.Folder;
                property.PropertyType = (int)DataTypes.Boolean;
            }
            else if (columnName.StartsWith(MetadataTokens.ParentIDRRef))
            {
                property.Name         = "Родитель";
                property.Field        = MetadataTokens.ParentIDRRef;
                property.PropertyType = (int)DataTypes.Object;
            }
            else if (columnName.StartsWith(MetadataTokens.OwnerID))
            {
                property.Name  = "Владелец";
                property.Field = MetadataTokens.OwnerID;
                // TODO: apply object or multiple data type
                property.PropertyType = (int)DataTypes.Object;
            }
            else if (columnName.StartsWith(MetadataTokens.DateTime))
            {
                property.Name         = "Дата";
                property.Field        = MetadataTokens.DateTime;
                property.PropertyType = (int)DataTypes.DateTime;
            }
            else if (columnName == MetadataTokens.Number)
            {
                property.Name  = "Номер";
                property.Field = MetadataTokens.Number;
                // TODO: find out field data type: string or numeric
                //property.PropertyTypes.Add((int)DataTypes.String);
            }
            else if (columnName.StartsWith(MetadataTokens.Posted))
            {
                property.Name         = "Проведён";
                property.Field        = MetadataTokens.Posted;
                property.PropertyType = (int)DataTypes.Boolean;
            }
            else if (columnName == MetadataTokens.NumberPrefix)
            {
                property.Name  = "МоментВремени";
                property.Field = MetadataTokens.NumberPrefix;
            }
            else if (columnName.StartsWith(MetadataTokens.Periodicity))
            {
                property.Name  = "Периодичность";
                property.Field = MetadataTokens.Periodicity;
            }
            else if (columnName.StartsWith(MetadataTokens.Period))
            {
                property.Name  = "Период";
                property.Field = MetadataTokens.Period;
            }
            else if (columnName.StartsWith(MetadataTokens.ActualPeriod))
            {
                property.Name  = "ПериодАктуальности";
                property.Field = MetadataTokens.ActualPeriod;
            }
            else if (columnName.StartsWith(MetadataTokens.Recorder))
            {
                property.Name  = "Регистратор";
                property.Field = MetadataTokens.Recorder;
                // TODO: apply object or multiple data type
                property.PropertyType = (int)DataTypes.Object;
            }
            else if (columnName.StartsWith(MetadataTokens.Active))
            {
                property.Name         = "Активность";
                property.Field        = MetadataTokens.Active;
                property.PropertyType = (int)DataTypes.Boolean;
            }
            else if (columnName.StartsWith(MetadataTokens.LineNo))
            {
                property.Name  = "НомерСтроки";
                property.Field = MetadataTokens.LineNo;
            }
            else if (columnName.StartsWith(MetadataTokens.RecordKind))
            {
                property.Name  = "ВидДвижения";
                property.Field = MetadataTokens.RecordKind;
            }
            else if (columnName.StartsWith(MetadataTokens.KeyField))
            {
                property.Name  = "КлючСтроки";
                property.Field = MetadataTokens.KeyField;
            }
            else if (columnName.EndsWith(MetadataTokens.IDRRef)) // табличные части
            {
                property.Name         = "Ссылка";
                property.Field        = MetadataTokens.IDRRef;
                property.PropertyType = (int)DataTypes.Object;
            }
            else if (columnName == MetadataTokens.EnumOrder)
            {
                property.Name  = "Порядок";
                property.Field = MetadataTokens.EnumOrder;
            }
            else if (columnName == MetadataTokens.Type) // ПланВидовХарактеристик
            {
                property.Name  = "ТипЗначения";         // ОписаниеТипов - TypeConstraint
                property.Field = MetadataTokens.Type;
            }
            else if (columnName == MetadataTokens.Splitter)
            {
                property.Name  = "РазделительИтогов";
                property.Field = MetadataTokens.Splitter;
            }
            else if (columnName == MetadataTokens.NodeTRef)
            {
                property.Name         = "Узел";
                property.Field        = MetadataTokens.Node;
                property.PropertyType = (int)DataTypes.Numeric;
            }
            else if (columnName == MetadataTokens.NodeRRef)
            {
                property.Name         = "Узел";
                property.Field        = MetadataTokens.Node;
                property.PropertyType = (int)DataTypes.Object;
            }
            else if (columnName == MetadataTokens.MessageNo)
            {
                property.Name  = "НомерСообщения";
                property.Field = MetadataTokens.MessageNo;
            }
            else if (columnName == MetadataTokens.RepetitionFactor)
            {
                property.Name  = "КоэффициентПериодичности";
                property.Field = MetadataTokens.RepetitionFactor;
            }
            else if (columnName == MetadataTokens.UseTotals)
            {
                property.Name  = "ИспользоватьИтоги";
                property.Field = MetadataTokens.UseTotals;
            }
            else if (columnName == MetadataTokens.UseSplitter)
            {
                property.Name  = "ИспользоватьРазделительИтогов";
                property.Field = MetadataTokens.UseSplitter;
            }
            else if (columnName == MetadataTokens.MinPeriod)
            {
                property.Name  = "МинимальныйПериод";
                property.Field = MetadataTokens.MinPeriod;
            }
            else if (columnName == MetadataTokens.MinCalculatedPeriod)
            {
                property.Name  = "МинимальныйПериодРассчитанныхИтогов";
                property.Field = MetadataTokens.MinCalculatedPeriod;
            }
            else if (columnName == MetadataTokens.Kind)
            {
                property.Name         = "ТипСчёта";
                property.Field        = MetadataTokens.Kind;
                property.PropertyType = (int)DataTypes.Numeric;
            }
            else if (columnName == MetadataTokens.OrderField)
            {
                property.Name         = "Порядок";
                property.Field        = MetadataTokens.OrderField;
                property.PropertyType = (int)DataTypes.String;
            }
            else if (columnName == MetadataTokens.OffBalance)
            {
                property.Name         = "Забалансовый";
                property.Field        = MetadataTokens.OffBalance;
                property.PropertyType = (int)DataTypes.Boolean;
            }
            else if (columnName == MetadataTokens.AccountDtRRef)
            {
                property.Name         = "СчётДебет";
                property.Field        = MetadataTokens.AccountDtRRef;
                property.PropertyType = (int)DataTypes.Object;
            }
            else if (columnName == MetadataTokens.AccountCtRRef)
            {
                property.Name         = "СчётКредит";
                property.Field        = MetadataTokens.AccountCtRRef;
                property.PropertyType = (int)DataTypes.Object;
            }
            else if (columnName == MetadataTokens.EDHashDt)
            {
                property.Name         = "ХешДебет";
                property.Field        = MetadataTokens.EDHashDt;
                property.PropertyType = (int)DataTypes.Numeric;
            }
            else if (columnName == MetadataTokens.EDHashCt)
            {
                property.Name         = "ХэшКредит";
                property.Field        = MetadataTokens.EDHashCt;
                property.PropertyType = (int)DataTypes.Numeric;
            }
            else if (columnName == MetadataTokens.SentNo)
            {
                property.Name         = "НомерОтправленного";
                property.Field        = MetadataTokens.SentNo;
                property.PropertyType = (int)DataTypes.Numeric;
            }
            else if (columnName == MetadataTokens.ReceivedNo)
            {
                property.Name         = "НомерПринятого";
                property.Field        = MetadataTokens.ReceivedNo;
                property.PropertyType = (int)DataTypes.Numeric;
            }
        }
コード例 #3
0
        private void ParseMetaPropertyTypes(StreamReader reader, MetaProperty property)
        {
            string line = reader.ReadLine();

            if (line == null)
            {
                return;
            }

            while (line != "{\"Pattern\",")
            {
                line = reader.ReadLine();
                if (line == null)
                {
                    return;
                }
            }

            Match match;

            while ((line = reader.ReadLine()) != null)
            {
                match = rxDbType.Match(line);
                if (!match.Success)
                {
                    break;
                }

                int    typeCode = 0;
                string typeName = string.Empty;
                string token    = match.Value.Replace("{", string.Empty).Replace("\"", string.Empty);
                switch (token)
                {
                case DBToken.B: { typeCode = -1; typeName = "Boolean"; break; }

                case DBToken.S: { typeCode = -2; typeName = "String"; break; }

                case DBToken.D: { typeCode = -3; typeName = "DateTime"; break; }

                case DBToken.N: { typeCode = -4; typeName = "Numeric"; break; }
                }
                if (typeCode != 0)
                {
                    property.Types.Add(new TypeInfo()
                    {
                        Name     = typeName,
                        TypeCode = typeCode
                    });
                }
                else
                {
                    string[] lines = line.Split(',');
                    string   UUID  = lines[1].Replace("}", string.Empty);

                    if (UUID == "e199ca70-93cf-46ce-a54b-6edc88c3a296")
                    {
                        // ХранилищеЗначения - varbinary(max)
                        property.Types.Add(new TypeInfo()
                        {
                            Name     = "BLOB",
                            TypeCode = -5
                        });
                    }
                    else if (UUID == "fc01b5df-97fe-449b-83d4-218a090e681e")
                    {
                        // УникальныйИдентификатор - binary(16)
                        property.Types.Add(new TypeInfo()
                        {
                            Name     = "UUID",
                            TypeCode = -6
                        });
                    }
                    else if (UUIDs.TryGetValue(UUID, out MetaObject dbo))
                    {
                        property.Types.Add(new TypeInfo()
                        {
                            Name       = dbo.TableName,
                            TypeCode   = dbo.TypeCode,
                            UUID       = UUID,
                            MetaObject = dbo
                        });
                        property.PropertyTypes.Add(dbo.TypeCode);
                    }
                    else // UUID is not loaded yet - see MakeSecondPass procedure
                    {
                        // TODO: get type code some how ...
                        property.Types.Add(new TypeInfo()
                        {
                            UUID = UUID
                        });
                        property.PropertyTypes.Add(int.MaxValue); // костыль !?
                    }
                }
            }
        }