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); } }
private static void MergeServer(Behaviour behaviour, Modifiers templates, List <Variable> variables, Dictionary <string, ServerModifier> compiledConfig, ServerModifier srvToMerge) { //Remplacement de la variable if (srvToMerge.Id.IsVariable()) { srvToMerge.Id = variables.First(v => v.Name.ParseConfigVariable().Key == srvToMerge.Id.ParseConfigVariable().Key).Value; } if (!compiledConfig.ContainsKey(srvToMerge.Id)) { compiledConfig.Add(srvToMerge.Id, srvToMerge); } //Template if (srvToMerge.BasedOn > 0) { var srvTemplate = behaviour.Modifiers.ServerModifiers.FirstOrDefault(s => s.TemplateId == srvToMerge.BasedOn); if (srvTemplate == null) { srvTemplate = templates.ServerModifiers.First(s => s.TemplateId == srvToMerge.BasedOn); } MergeServer(behaviour, templates, variables, compiledConfig, srvTemplate); srvToMerge.TemplateId = 0; srvToMerge.BasedOn = 0; } //Merge foreach (var database in srvToMerge.Databases) { var dstServer = compiledConfig[srvToMerge.Id]; MergeDatabase(behaviour, templates, variables, dstServer, database); } }