Example #1
0
        /// <summary>
        /// Set the current environment.
        /// </summary>
        /// <param name="envGroupName">Can have multiple environment definitions.
        /// If you just want to use the default one, supply emtpy string.</param>
        /// <param name="selected">"prod"</param>
        /// <param name="availableEnvs">All the available environments.</param>
        public static void Set(string envGroupName, string selected, List <EnvItem> availableEnvs, string refPaths)
        {
            // Check if refpaths(configs) were supplied.
            bool hasConfigs      = !string.IsNullOrEmpty(refPaths);
            bool hasMultiConfigs = hasConfigs && refPaths.Contains(",");

            string[] configs = hasConfigs ? refPaths.Split(',') : new string[] { };

            // Multiple env selection indicating inheritance.
            // e.g. prod,qa indicates prod inherits from qa.
            bool isEnvInherited = selected.Contains(",");

            string[] envsSelected = isEnvInherited ? selected.Split(',') : new string[] { selected };
            selected = envsSelected[0];

            IEnv envDef = new EnvDef(availableEnvs, selected);

            // Case 1: Single config file = "prod",  "prod,qa,dev", "prod.config"
            if (configs.Length == 1 && envsSelected.Length == 1)
            {
                envDef.Get(selected).RefPath = refPaths;
            }

            // Case 2: Config Inheritance = "prod",  "prod,qa,dev", "prod.config,dev.config"
            else if (configs.Length > envsSelected.Length || configs.Length < envsSelected.Length)
            {
                envDef.Get(selected).RefPath = refPaths;
            }

            // Case 3: Env & Config Inherit = "prod,qa,dev", "prod,qa,dev", "prod.config,qa.config,dev.config".
            // Apply prod.config to "prod" refpath, qa.config to "qa" refPath.
            else if (configs.Length > 1 && envsSelected.Length > 1 && configs.Length == envsSelected.Length)
            {
                for (int ndx = 0; ndx < envsSelected.Length; ndx++)
                {
                    envDef.Get(envsSelected[ndx]).RefPath = configs[ndx];
                }
            }

            Set(envGroupName, envDef);
        }
Example #2
0
        /// <summary>
        /// Set the current environment.
        /// </summary>
        /// <param name="envGroupName">Can have multiple environment definitions.
        /// If you just want to use the default one, supply emtpy string.</param>
        /// <param name="selected">"prod"</param>
        /// <param name="availableEnvs">All the available environments.</param>
        public static void Set(string envGroupName, string selected, List <EnvItem> availableEnvs)
        {
            IEnv envDef = new EnvDef(selected, availableEnvs);

            Set(envGroupName, envDef);
        }