示例#1
0
        private static void MergeSchema(Behaviour behaviour,
                                        Modifiers templates,
                                        List <Variable> variables,
                                        DatabaseModifier compiledDatabase,
                                        SchemaModifier schemaToMerge)
        {
            //Remplacement de la variable
            if (schemaToMerge.Name.IsVariable())
            {
                schemaToMerge.Name = variables.First(v => v.Name.ParseConfigVariable().Key == schemaToMerge.Name.ParseConfigVariable().Key).Value;
            }

            if (!compiledDatabase.Schemas.Exists(d => d.Name == schemaToMerge.Name))
            {
                compiledDatabase.Schemas.Add(schemaToMerge);
            }

            //Template
            if (schemaToMerge.BasedOn > 0)
            {
                var allSchema = new List <SchemaModifier>();

                //Pass 1 : Search inside the behaviour
                allSchema.AddRange(behaviour.Modifiers.SchemaModifiers);
                foreach (var s in  behaviour.Modifiers.ServerModifiers)
                {
                    foreach (var d in s.Databases)
                    {
                        allSchema.AddRange(d.Schemas);
                    }
                }

                var sch = allSchema.First(d => d.TemplateId == schemaToMerge.BasedOn);
                if (sch == null)
                {
                    //Pass 2 : Search inside the templates
                    allSchema.Clear();
                    allSchema.AddRange(templates.SchemaModifiers);
                    foreach (var s in templates.ServerModifiers)
                    {
                        foreach (var d in s.Databases)
                        {
                            allSchema.AddRange(d.Schemas);
                        }
                    }
                }
                sch = allSchema.First(d => d.TemplateId == schemaToMerge.BasedOn);

                MergeSchema(behaviour, templates, variables, compiledDatabase, sch);
                schemaToMerge.TemplateId = 0;
                schemaToMerge.BasedOn    = 0;
            }

            //Merge
            foreach (var table in schemaToMerge.Tables)
            {
                var dstSchema = compiledDatabase.Schemas.First(d => d.Name == schemaToMerge.Name);
                MergeTable(variables, dstSchema, table);
            }
        }
示例#2
0
        private static void MergeDatabase(Behaviour behaviour,
                                          Modifiers templates,
                                          List <Variable> variables,
                                          ServerModifier compiledServer,
                                          DatabaseModifier dbToMerge)
        {
            //Remplacement de la variable
            if (dbToMerge.Name.IsVariable())
            {
                dbToMerge.Name = variables.First(v => v.Name.ParseConfigVariable().Key == dbToMerge.Name.ParseConfigVariable().Key).Value;
            }

            if (!compiledServer.Databases.Exists(d => d.Name == dbToMerge.Name))
            {
                compiledServer.Databases.Add(dbToMerge);
            }

            //Template
            if (dbToMerge.BasedOn > 0)
            {
                var allDb = new List <DatabaseModifier>();

                //Pass 1 : Search inside the behaviour
                allDb.AddRange(behaviour.Modifiers.DatabaseModifiers);
                foreach (var s in behaviour.Modifiers.ServerModifiers)
                {
                    allDb.AddRange(s.Databases);
                }

                var db = allDb.FirstOrDefault(d => d.TemplateId == dbToMerge.BasedOn);
                if (db == null)
                {
                    //Pass 2 : Search inside the templates
                    allDb.Clear();
                    allDb.AddRange(templates.DatabaseModifiers);
                    foreach (var s in templates.ServerModifiers)
                    {
                        allDb.AddRange(s.Databases);
                    }
                }
                db = allDb.First(d => d.TemplateId == dbToMerge.BasedOn);

                MergeDatabase(behaviour, templates, variables, compiledServer, db);
                dbToMerge.TemplateId = 0;
                dbToMerge.BasedOn    = 0;
            }

            //Merge
            foreach (var schema in dbToMerge.Schemas)
            {
                var dstDb = compiledServer.Databases.First(d => d.Name == dbToMerge.Name);
                MergeSchema(behaviour, templates, variables, dstDb, schema);
            }
        }