예제 #1
0
        public static string GetPKType(Table table)
        {
            var pk = GetPK(table);
            if (pk != null)
            {
                return pk.Datatype.AsDotNetType();
            }

            return DotNetType.Object;
        }
예제 #2
0
        public static string GetPKName(Table table)
        {
            var pk = GetPK(table);
            if (pk != null)
            {
                return pk.Name.Pascalize();
            }

            return "";
        }
예제 #3
0
        private static void InsertProperty(Table match, Table fk)
        {
            var properties = (match.Parameters ?? Enumerable.Empty<Parameter>()).ToList();

            properties.Insert(0, new Parameter
            {
                Name = "Is A " + fk.Name,
                Datatype = fk.Name,
                Parent = match,
                Summary = fk.Summary
            });

            match.Parameters = properties;
        }
예제 #4
0
        public static string ToKey(bool pk, bool fk, Table referencedTable)
        {
            var result = "";
            if (pk)
            {
                result = "PK ";
            }

            if (fk)
            {
                result += string.Format(@"<a href=""#{0}"" title=""{1}"">FK ({1})</a>", MakeName(referencedTable.Type, referencedTable.Name), referencedTable.Name);
            }

            return result;
        }
예제 #5
0
        private static Table ToTable(ProductDefinition productDefinition)
        {
            var t = new Table
            {
                Name = productDefinition.Name,
                Summary = productDefinition.Description,
                Type = productDefinition.DefinitionType
            };

            t.Parameters = productDefinition.ProductProperties.Select(p => new Parameter
            {
                Parent = t,
                Name = p.Name + (p.IsVariant ? " (Variant)" : "")
            });

            return t;
        }
예제 #6
0
        private static Parameter GetPK(Table table)
        {
            foreach (var col in table.Parameters)
            {
                if (col.IsPrimaryKey)
                {
                    return col;
                }
            }

            return null;
        }
예제 #7
0
        private IEnumerable<Table> GetTables()
        {
            // TODO:

            // table is a class, columns is a proprty

            // foreign key is a

            var assembly = Assembly.LoadFrom(DatabaseName);
            var results = new List<Table>();

            foreach (var exportedType in assembly.GetExportedTypes())
            {
                var table = new Table
                {
                    Name = exportedType.Name,
                    Summary = exportedType.FullName
                };

                table.Parameters = exportedType.GetProperties().Select(info => new Parameter
                {
                    Name = info.Name,
                    Datatype = info.GetType().Name,
                    Parent = table,
                    Summary = info.GetType().FullName
                });

                results.Add(table);
            }

            foreach (var exportedType in assembly.GetExportedTypes())
            {
                // ahh.... inheritance is not something we model...
                var matches = new List<Tuple<Table, Table>>();
                var matchTable = results.First(table => table.Summary.Equals(exportedType.FullName));

                foreach (var i in exportedType.GetInterfaces())
                {
                    var m = results.FirstOrDefault(table => table.Summary.Equals(i.FullName));

                    if (m == null) continue;
                    if (m.Summary == matchTable.Summary) continue;

                    matches.Add(new Tuple<Table, Table>(matchTable, m));
                }

                var matchBaseType = results.FirstOrDefault(table => table.Summary.Equals(exportedType.BaseType?.FullName));
                if (matchBaseType != null) matches.Add(new Tuple<Table, Table>(matchTable, matchBaseType));

                foreach (var match in matches)
                {
                    InsertProperty(match.Item1, match.Item2);
                }
            }

            // foreach property
            // if p.GetType in tables then FK

            foreach (var p in results.SelectMany(table => table.Parameters))
            {
                var match = results.FirstOrDefault(table => table.Summary.Equals(p.Summary));

                p.IsForeignKey = match != null;
                p.ForeignKeyTable = match;
                p.ForeignKeyTableName = match?.Name;
            }

            return results;
        }