Exemplo n.º 1
0
        internal EduHubEntity AddEntity(string Name, string Description)
        {
            var entity = new EduHubEntity(this, Name, Description);

            AddEntity(entity);
            return(entity);
        }
Exemplo n.º 2
0
 internal EduHubIndex(EduHubEntity Entity, string Name, IReadOnlyList<EduHubField> Fields, bool IsPrimary, bool IsUnique, bool IsClustered)
 {
     this.Entity = Entity;
     this.Name = Name;
     this.Fields = Fields;
     this.IsPrimary = IsPrimary;
     this.IsUnique = IsUnique;
     this.IsClustered = IsClustered;
 }
Exemplo n.º 3
0
 internal EduHubIndex(EduHubEntity Entity, string Name, IReadOnlyList <EduHubField> Fields, bool IsPrimary, bool IsUnique, bool IsClustered)
 {
     this.Entity      = Entity;
     this.Name        = Name;
     this.Fields      = Fields;
     this.IsPrimary   = IsPrimary;
     this.IsUnique    = IsUnique;
     this.IsClustered = IsClustered;
 }
Exemplo n.º 4
0
        internal EduHubEntity AddEntity(EduHubEntity Entity)
        {
            if (entities == null)
            {
                entities = new Dictionary <string, EduHubEntity>(StringComparer.Ordinal);
            }

            entities.Add(Entity.Name, Entity);
            return(Entity);
        }
Exemplo n.º 5
0
        internal EduHubEntity AddEntity(EduHubEntity Entity)
        {
            if (entities == null)
            {
                entities = new List<EduHubEntity>();
                Entities = entities.AsReadOnly();
            }

            entities.Add(Entity);
            return Entity;
        }
Exemplo n.º 6
0
 internal EduHubField(EduHubEntity Entity, string Name, string Description, string Type, string TypeDescription, int TypeMaxLength, bool IsNullable, bool IsIdentity, Tuple<string, string> ForeignParentKey)
 {
     this.Entity = Entity;
     this.Name = Name;
     this.Description = Description;
     this.Type = Type;
     this.TypeDescription = TypeDescription;
     this.TypeMaxLength = TypeMaxLength;
     this.IsNullable = IsNullable;
     this.IsIdentity = IsIdentity;
     this.ForeignParentKey = ForeignParentKey;
 }
Exemplo n.º 7
0
        public static EduHubSchema FromC7Schema(IList <IC7Element> Elements)
        {
            var schema = new EduHubSchema();

            foreach (var element in Elements)
            {
                switch (element)
                {
                case IC7Entity c7entity:
                    var entity = new EduHubEntity(schema, c7entity.Name, c7entity.Description.Trim());
                    entity.AddFields(c7entity.ToEduHubFields(entity));
                    schema.AddEntity(entity);
                    break;

                default:
                    break;
                }
            }

            return(schema);
        }
Exemplo n.º 8
0
 public static IEnumerable <EduHubField> ToEduHubFields(this IC7Entity c7Entity, EduHubEntity Entity)
 {
     foreach (var c7Field in c7Entity.Fields)
     {
         foreach (var field in c7Field.ToEduHubFields(c7Entity, Entity))
         {
             yield return(field);
         }
     }
 }
Exemplo n.º 9
0
        public static IEnumerable <EduHubField> ToEduHubFields(this C7Field c7Field, IC7Entity c7Entity, EduHubEntity Entity)
        {
            var type       = ParseType(c7Field.Type);
            var isKey      = c7Entity.Keys?.Contains(c7Field.Name, StringComparer.OrdinalIgnoreCase) ?? false;
            var isIdentity = c7Field.IsSequence || (c7Entity.IsDbSeq && c7Entity.Fields[0] == c7Field);
            var isNullable = !isIdentity;

            if (type.FieldCount == 1)
            {
                yield return(new EduHubField(
                                 Entity: Entity,
                                 Name: c7Field.Name,
                                 Description: c7Field.SchemaComment.Trim(),
                                 Type: type.FrameworkType,
                                 TypeDescription: type.Description,
                                 TypeMaxLength: type.Precision,
                                 IsKey: isKey,
                                 IsNullable: isNullable,
                                 IsIdentity: isIdentity,
                                 ForeignParentKey: (c7Field.Relationship.Entity, c7Field.Relationship.Field)
                                 ));
            }
            else
            {
                for (int i = 0; i < type.FieldCount; i++)
                {
                    yield return(new EduHubField(
                                     Entity: Entity,
                                     Name: $"{c7Field.Name}{i + 1:00}",
                                     Description: c7Field.SchemaComment.Trim(),
                                     Type: type.FrameworkType,
                                     TypeDescription: type.Description,
                                     TypeMaxLength: type.Precision,
                                     IsKey: isKey,
                                     IsNullable: isNullable,
                                     IsIdentity: isIdentity,
                                     ForeignParentKey: (c7Field.Relationship.Entity, c7Field.Relationship.Field)
                                     ));
                }
            }
        }
Exemplo n.º 10
0
        private static void ParseDirectives(EduHubEntity Entity, IEnumerator<string> SchemaIterator)
        {
            do
            {
                if (!string.IsNullOrWhiteSpace(SchemaIterator.Current) && !TestEntityIgnore.IsMatch(SchemaIterator.Current))
                {
                    // Test directive
                    var directiveMatch = TestEntityDirective.Match(SchemaIterator.Current);
                    if (directiveMatch.Success)
                    {
                        switch (directiveMatch.Groups[1].Value.ToUpperInvariant())
                        {
                            case "KEYS":
                                // Process Keys
                                var keys = directiveMatch.Groups[2].Value.Trim().Split(',').Where(k => !string.IsNullOrWhiteSpace(k)).Select(k => k.Trim());

                                foreach (var key in keys)
                                {
                                    Entity.Fields.First(e => e.Name.Equals(key, StringComparison.OrdinalIgnoreCase)).IsKey = true;
                                }
                                break;
                            case "MOREINFO":
                            case "QUICKADD":
                            case "NODUPS":
                                // Ignore directives
                                break;
                            default:
                                // Current entity block finished
                                return;
                        }
                    }
                    else if (TestEntity.IsMatch(SchemaIterator.Current))
                    {
                        // Another entity found, finished current entity block
                        return;
                    }
                    else
                    {
                        throw new InvalidOperationException("Unexpected schema format");
                    }
                }

            } while (SchemaIterator.MoveNext());
        }
Exemplo n.º 11
0
        private static IEnumerable<EduHubField> ParseFields(EduHubEntity Entity, IEnumerator<string> SchemaIterator)
        {
            EduHubField field = null;
            int fieldArraySize = 0;
            while (SchemaIterator.MoveNext())
            {
                if (!string.IsNullOrWhiteSpace(SchemaIterator.Current) && !TestFieldIgnore.IsMatch(SchemaIterator.Current))
                {
                    var commentMatch = TestFieldComment.Match(SchemaIterator.Current);
                    if (commentMatch.Success)
                    {
                        if (field != null)
                        {
                            field.AppendDescription(commentMatch.Groups[1].Value);
                        }
                    }
                    else
                    {
                        var fieldMatch = TestField.Match(SchemaIterator.Current);
                        if (fieldMatch.Success)
                        {
                            if (field != null)
                            {
                                foreach (var expandedField in ExpandField(field, fieldArraySize))
                                {
                                    yield return expandedField;
                                }
                            }

                            string name = fieldMatch.Groups[1].Value.Trim();
                            string description = fieldMatch.Groups[6].Success ? fieldMatch.Groups[6].Value.Trim() : string.Empty;
                            fieldArraySize = fieldMatch.Groups[4].Success ? int.Parse(fieldMatch.Groups[4].Value) : 1;
                            string type, typeDescription;
                            int typeMaxLength;
                            DetermineFieldType(fieldMatch.Groups[5].Value.ToUpperInvariant(), out type, out typeDescription, out typeMaxLength);
                            Tuple<string, string> foreignParentKey = fieldMatch.Groups[2].Success
                                ? Tuple.Create(fieldMatch.Groups[2].Value, fieldMatch.Groups[3].Value)
                                : null;

                            field = new EduHubField(
                                Entity: Entity,
                                Name: name,
                                Description: description,
                                Type: type,
                                TypeDescription: typeDescription,
                                TypeMaxLength: typeMaxLength,
                                IsNullable: true,
                                IsIdentity: false,
                                ForeignParentKey: foreignParentKey);
                        }
                        else
                        {
                            if (TestFieldDirective.IsMatch(SchemaIterator.Current))
                            {
                                // End of Fields Declaration (directives started)
                                break;
                            }
                            else
                            {
                                throw new InvalidOperationException("Unexpected schema format");
                            }
                        }
                    }
                }
            }
            foreach (var expandedField in ExpandField(field, fieldArraySize))
            {
                yield return expandedField;
            }
        }
Exemplo n.º 12
0
 internal EduHubEntity AddEntity(string Name, string Description)
 {
     var entity = new EduHubEntity(this, Name, Description);
     AddEntity(entity);
     return entity;
 }
Exemplo n.º 13
0
 public bool Contains(EduHubEntity Entity)
 {
     return(entities.ContainsValue(Entity));
 }