public SolutionReader(ObjectElement solutionElement, string solutionConfigDir, bool loadIncludes) { Log.Heading("Reading solution element: {0}", solutionElement); using (new Log.ScopedIndent()) { if (ExpandableVars.Instance == null) { throw new InvalidOperationException("ExpandableVars are null"); } ExpandableVars.Instance.SetExpandableVariable(ExpandableVars.VAR_SOLUTION_NAME, solutionElement.Heading.Name); ExpandableVars.Instance.SetExpandableVariable(ExpandableVars.VAR_CONFIG_DIR, solutionConfigDir); settingsReader = new SolutionSettingsReader(ExpandableVars.Instance.Variables); Settings settings = settingsReader.Read(solutionElement); Solution = new Solution(solutionElement.Heading.Name, settings, solutionConfigDir, GetConfigurationGroups(settings), new FileUtil.ResultCache()); ExpandableVars.Instance.SetExpandableVariable(ExpandableVars.VAR_SOLUTION_PATH, Path.Combine(Solution.OutputDir, solutionElement.Heading.Name + ".sln")); ObjectElement settingsElement = solutionElement.Children .OfType <ObjectElement>() .FirstOrDefault(obj => obj.Heading.Type == SectionType.SETTINGS && obj.Heading.Name == DEFAULT_TEMPLATE_SETTINGS); if (settingsElement == null) { Log.Info( "No settings named '{0}' found in solution element. " + "Templates will use hard coded defaults instead.", DEFAULT_TEMPLATE_SETTINGS); TemplateDefaultSettings = settingsReader.GetDefaultSettings(); } else { Log.Info( "Settings named '{0}' found in solution element. " + "Templates will default to the settings read below.", DEFAULT_TEMPLATE_SETTINGS); using (new Log.ScopedIndent()) { TemplateDefaultSettings = new ProjectSettingsReader(ExpandableVars.Instance.Variables) .Read(settingsElement); } } if (loadIncludes) { LoadIncludes(); } } }
// private Task<(Configuration cfg, TemplateConfiguration templateConfig)> CreateTemplateConfigAsync( // ObjectElement templateElement, Configuration configuration) // { // var baseVars = new Dictionary<string, string>(ExpandableVars.Instance.Variables); // return Task.Run(() => // { // using (new Log.BufferedTaskOutput($"CTC-{templateElement.ElementHeading.Name}-{configuration.Name}")) // { // ExpandableVars.Init(baseVars); // return (configuration, CreateTemplateConfig(templateElement, configuration)); // } // }); // } private TemplateConfiguration CreateTemplateConfig(ObjectElement templateElement, Configuration configuration) { Log.Heading("Creating template config '{0} - {1}' for template '{2}'", configuration.GroupName, configuration.Name, templateElement.Heading.Name); using (new Log.ScopedIndent()) { string baseTemplateName = templateElement.Heading.InheritedObjectName; Template baseTemplate = null; Settings baseTemplateSettings = null; lock (cachedTemplates) { if (!string.IsNullOrEmpty(baseTemplateName) && cachedTemplates.TryGetValue(baseTemplateName, out baseTemplate)) { baseTemplateSettings = baseTemplate.Configurations[configuration].TemplateSettings; } } var rootReader = new ProjectSettingsReader(configuration, baseTemplateSettings, null); Settings templateSettings = rootReader.Read(templateElement); Dictionary <string, Settings> settingsLookup = baseTemplate != null ? new Dictionary <string, Settings>(baseTemplate.Configurations[configuration].ProjectSettingsLookup) : new Dictionary <string, Settings>(); foreach (ConfigElement element in templateElement.Children) { if (element is ObjectElement objElement && objElement.Heading.Type == SectionType.SETTINGS) { string settingsName = objElement.Heading.Name; string inheritedSettingsName = objElement.Heading.InheritedObjectName; Settings inheritedSettings = null; if (!string.IsNullOrEmpty(inheritedSettingsName) && !settingsLookup.TryGetValue(inheritedSettingsName, out inheritedSettings)) { throw new UndefinedInheritedSettingsException(settingsName, inheritedSettingsName); } Settings baseSettings; // 1. reading a root template settings object so use the inherited settings as the base if (baseTemplate == null) { Log.Info("Using inherited settings '{0}' for base settings (1)", inheritedSettingsName); // Can be null if the settings element does not inherit anything baseSettings = inheritedSettings; } // 2. reading a non-root template settings object without inheritance so use the template // settings of the same name as the base settings if they exist else if (inheritedSettings == null) { Log.Info("Using template settings of same name '{0}' for base settings (2)", settingsName); settingsLookup.TryGetValue(settingsName, out baseSettings); } // 3. reading a non-root template settings object with inheritance else { // a. When a non root template settings object inherits other settings, the base template's // settings must be re-read (reinterpreted) ontop of the inherited settings if (baseTemplate.SettingsSourceElements.TryGetValue(settingsName, out ObjectElement sourceElement)) { Log.Info("Re-reading template settings of same name '{0}' for base settings (3.a)", settingsName); baseSettings = new ProjectSettingsReader(configuration, inheritedSettings, defaultSettings).Read( sourceElement); } // b. Base template does not contain settings of same name so use the inheritedSettings // without re-reading them. else { Log.Info( "Template does not contain settings of same name '{0}' so using inherited settings " + "'{0}' for base settings (3.b)", settingsName, inheritedSettingsName); baseSettings = inheritedSettings; } } settingsLookup[settingsName] = new ProjectSettingsReader(configuration, baseSettings, defaultSettings).Read(objElement); } } return(new TemplateConfiguration(settingsLookup, templateSettings)); } }