Exemple #1
0
        private static List <XmlProjectSetting> GetProjectSettings(XmlAppSetting setting, XElement xElement, IEnumerable <EnvironmentMapping> environmentMappings)
        {
            List <XmlProjectSetting> projectSettings = new List <XmlProjectSetting>();
            var xProjectSettings = xElement.Descendants("project");

            foreach (var xProjectSetting in xProjectSettings)
            {
                XmlProjectSetting projectSetting = new XmlProjectSetting
                {
                    Name              = GetAttribute(xProjectSetting, "name", true),
                    DevValue          = GetAttribute(xProjectSetting, "dev", false),
                    QaValue           = GetAttribute(xProjectSetting, "qa", false),
                    StagingValue      = GetAttribute(xProjectSetting, "staging", false),
                    LiveValue         = GetAttribute(xProjectSetting, "live", false),
                    DefaultValue      = GetAttribute(xProjectSetting, "default", false),
                    OtherEnvironments = GetOtherEnvironmentSettings(xProjectSetting, environmentMappings, false)
                };
                if (projectSetting.DefaultValue == null)
                {
                    projectSetting.DefaultValue = setting.DefaultValue;
                }
                if (projectSetting.DefaultValue != null)
                {
                    projectSetting = ApplyDefaultValueWhereNeeded <XmlProjectSetting>(projectSetting);
                }
                projectSettings.Add(projectSetting);
            }
            return(projectSettings);
        }
Exemple #2
0
        private static IEnumerable <XmlAppSetting> GetAppSettingsFromXml(XDocument document)
        {
            List <XmlAppSetting>             xmlAppSettings      = new List <XmlAppSetting>();
            IEnumerable <EnvironmentMapping> environmentMappings = GetEnvironmentMappings(document);

            foreach (var xElement in document.Descendants("appSettings").Descendants("key"))
            {
                XmlAppSetting setting = new XmlAppSetting
                {
                    Name              = GetAttribute(xElement, "name", true),
                    DevValue          = GetAttribute(xElement, "dev", false),
                    QaValue           = GetAttribute(xElement, "qa", false),
                    StagingValue      = GetAttribute(xElement, "staging", false),
                    LiveValue         = GetAttribute(xElement, "live", false),
                    DefaultValue      = GetAttribute(xElement, "default", false),
                    Delimiter         = GetAttribute(xElement, "delimiter", false),
                    OtherEnvironments = GetOtherEnvironmentSettings(xElement, environmentMappings, false)
                };
                setting.Autogenerate          = GetAutoGenValue(xElement);
                setting.AzureExclude          = GetAzureExcludeValue(xElement);
                setting.AzureDefinitonExclude = GetAzureDefinitionExcludeValue(xElement);
                setting.Type = GetTypeString(xElement);
                //only check for not null as that means the attribute existed and was set
                if (setting.DefaultValue != null)
                {
                    setting = ApplyDefaultValueWhereNeeded <XmlAppSetting>(setting);
                }
                setting.ProjectSettings = GetProjectSettings(setting, xElement, environmentMappings);
                xmlAppSettings.Add(setting);
            }
            return(xmlAppSettings);
        }
Exemple #3
0
        private static void GetAppSettingProperty(StringBuilder stringBuilder, XmlAppSetting xmlAppSetting, SettingsClass settingsClassSettings)
        {
            const string indentation          = "    ";
            string       doubleIndentation    = string.Concat(indentation, indentation);
            string       trippleIndentation   = string.Concat(doubleIndentation, indentation);
            string       quadrupleIndentation = string.Concat(doubleIndentation, doubleIndentation);
            string       escapedSettingName   = xmlAppSetting.Name.Replace(":", "").Replace(".", "").CapitaliseFirstLetter();

            stringBuilder.AppendLineFormat("{0}public static {1} {2} {{ get {{ return GetSetting({3}.{2}); }} }}", doubleIndentation, xmlAppSetting.Type, escapedSettingName, settingsClassSettings.Name.Replace(".cs", ""));
            stringBuilder.AppendLine();
        }
Exemple #4
0
        private static string GetProjectEnvironmentSettingValue(XmlAppSetting appSetting, string projectName, string environment)
        {
            string value;
            var    projectSettings = appSetting.ProjectSettings.FirstOrDefault(p => p.Name.Equals(projectName));

            if (projectSettings != null)
            {
                value = GetEnvironmentValueFromSetting(environment, projectSettings);
                if (value == null)
                {
                    value = GetEnvironmentValueFromSetting(environment, appSetting);
                }
            }
            else
            {
                value = GetEnvironmentValueFromSetting(environment, appSetting);
            }
            return(value);
        }