Exemplo n.º 1
0
        public Database Create(DatabaseSchema databaseSchema)
        {
            if (File.Exists(settings.MappingFile))
            {
                _database = Dbml.CopyWithFilledInDefaults(Dbml.FromFile(settings.MappingFile));
            }
            else
            {
                _database = new Database();
            }

            Database.Name = databaseSchema.Name;
            CreateContext(databaseSchema);

            _enumDatabase = new DbmlEnum.Database {
                Name = databaseSchema.Name
            };
            _existingEnumDatabase = DbmlEnum.Database.DeserializeFromFile(EnumXmlFileName) ?? new DbmlEnum.Database();

            foreach (TableSchema t in databaseSchema.Tables)
            {
                if (Settings.IsIgnored(t.FullName))
                {
                    Debug.WriteLine("Skipping Table: " + t.FullName);
                }
                else if (Settings.IsEnum(t))
                {
                    Debug.WriteLine("Getting Enum Table: " + t.FullName);
                    GetEnum(t);
                }
                else
                {
                    Debug.WriteLine("Getting Table Schema: " + t.FullName);
                    GetTable(t);
                }
                OnSchemaItemProcessed(t.FullName);
            }

            if (Settings.IncludeViews)
            {
                foreach (ViewSchema v in databaseSchema.Views)
                {
                    if (Settings.IsIgnored(v.FullName))
                    {
                        Debug.WriteLine("Skipping View: " + v.FullName);
                    }
                    else
                    {
                        Debug.WriteLine("Getting View Schema: " + v.FullName);
                        CreateView(v);
                    }
                    OnSchemaItemProcessed(v.FullName);
                }
            }

            if (Settings.IncludeFunctions)
            {
                foreach (CommandSchema c in databaseSchema.Commands)
                {
                    if (Settings.IsIgnored(c.FullName))
                    {
                        Debug.WriteLine("Skipping Function: " + c.FullName);
                    }
                    else
                    {
                        Debug.WriteLine("Getting Function Schema: " + c.FullName);
                        CreateFunction(c);
                    }
                    OnSchemaItemProcessed(c.FullName);
                }
            }

            //sync tables
            RemoveExtraMembers(_database);

            _database.Tables.Sort();
            Dbml.ToFile(Dbml.CopyWithNulledOutDefaults(_database),
                        settings.MappingFile);

            if (_enumDatabase.Enums.Count > 0 || File.Exists(EnumXmlFileName))
            {
                _enumDatabase.SerializeToFile(EnumXmlFileName);
            }

            return(_database);
        }
Exemplo n.º 2
0
        public Database Create(DatabaseSchema databaseSchema)
        {
            if (File.Exists(settings.MappingFile))
                _database = Dbml.CopyWithFilledInDefaults(Dbml.FromFile(settings.MappingFile));
            else
                _database = new Database();

            Database.Name = databaseSchema.Name;
            CreateContext(databaseSchema);

            _enumDatabase = new DbmlEnum.Database { Name = databaseSchema.Name };
            _existingEnumDatabase = DbmlEnum.Database.DeserializeFromFile(EnumXmlFileName) ?? new DbmlEnum.Database();

            foreach (TableSchema t in databaseSchema.Tables)
            {
                if (Settings.IsIgnored(t.FullName))
                {
                    Debug.WriteLine("Skipping Table: " + t.FullName);
                }
                else if (Settings.IsEnum(t))
                {
                    Debug.WriteLine("Getting Enum Table: " + t.FullName);
                    GetEnum(t);
                }
                else
                {
                    Debug.WriteLine("Getting Table Schema: " + t.FullName);
                    GetTable(t);
                }
                OnSchemaItemProcessed(t.FullName);
            }

            if (Settings.IncludeViews)
            {
                foreach (ViewSchema v in databaseSchema.Views)
                {
                    if (Settings.IsIgnored(v.FullName))
                    {
                        Debug.WriteLine("Skipping View: " + v.FullName);
                    }
                    else
                    {
                        Debug.WriteLine("Getting View Schema: " + v.FullName);
                        CreateView(v);
                    }
                    OnSchemaItemProcessed(v.FullName);
                }
            }

            if (Settings.IncludeFunctions)
            {
                foreach (CommandSchema c in databaseSchema.Commands)
                {
                    if (Settings.IsIgnored(c.FullName))
                    {
                        Debug.WriteLine("Skipping Function: " + c.FullName);
                    }
                    else
                    {
                        Debug.WriteLine("Getting Function Schema: " + c.FullName);
                        CreateFunction(c);
                    }
                    OnSchemaItemProcessed(c.FullName);
                }
            }

            //sync tables
            RemoveExtraMembers(_database);

            _database.Tables.Sort();
            Dbml.ToFile(Dbml.CopyWithNulledOutDefaults(_database),
                settings.MappingFile);

            if (_enumDatabase.Enums.Count > 0 || File.Exists(EnumXmlFileName))
                _enumDatabase.SerializeToFile(EnumXmlFileName);

            return _database;
        }