Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        private static void MergeTable(List <Variable> variables,
                                       SchemaModifier schema,
                                       TableModifier tblToMerge)
        {
            //Remplacement de la variable
            if (tblToMerge.Name.IsVariable())
            {
                tblToMerge.Name = variables.First(v => v.Name.ParseConfigVariable().Key == tblToMerge.Name.ParseConfigVariable().Key).Value;
            }

            if (!schema.Tables.Exists(d => d.Name == tblToMerge.Name))
            {
                schema.Tables.Add(tblToMerge);
            }

            //TODO :
            //MERGE ALL
        }