public void CanSetEnvAndConfigInheritance2()
        {
            // 1. Setup current env using supplied environment names/types.
            //    and all the available environments.
            // 2. Also supply the refpaths( config paths in this case ).
            Envs.Set("ny.prod,qa,dev", "ny.prod:prod,london.prod:prod,uat,qa,dev", "ny.prod.config,qa.config,dev.config");

            Assert.AreEqual(Env.Name, "ny.prod");
            Assert.AreEqual(Env.EnvType, EnvType.Prod);
            Assert.AreEqual(Env.IsDev, false);
            Assert.AreEqual(Env.IsProd, true);
            Assert.AreEqual(Env.IsQa, false);
            Assert.AreEqual(Env.IsUat, false);
            Assert.AreEqual(Env.Available[0], "ny.prod");
            Assert.AreEqual(Env.Available[1], "london.prod");
            Assert.AreEqual(Env.Available[2], "uat");
            Assert.AreEqual(Env.Available[3], "qa");
            Assert.AreEqual(Env.Available[4], "dev");
            Assert.AreEqual(Env.Selected, Env.Get("ny.prod"));

            // Check that the refpaths ( config files) have been set on the respective envs)
            Assert.AreEqual(Env.Get("ny.prod").RefPath, "ny.prod.config");
            Assert.AreEqual(Env.Get("qa").RefPath, "qa.config");
            Assert.AreEqual(Env.Get("dev").RefPath, "dev.config");

            Assert.AreEqual(Env.Count, 5);
        }
        /// <summary>
        /// Run the application.
        /// </summary>
        public override BoolMessageItem Execute()
        {
            //// Setup notification on Environment changed.
            Env.OnChange += (sender, args) => Console.Write("New Env: " + Env.Name);

            // Use 1: Set to "prod"(PRODUCTION) with default available envs as "prod,uat,qa,dev".
            Envs.Set("prod");
            PrintEnvironment();

            // Use 2: Set to "qa"(QA) with default available envs as "prod,qa,dev".
            Envs.Set("qa", "prod,qa,dev");
            PrintEnvironment();

            // Use 3: Set to "dev"(DEVELOPMENT) with default available envs as "prod,uat,qa,dev".
            //        Also set the "dev" env RefPath to "dev.config".
            Envs.Set("dev", "prod,uat,qa,dev", "dev.config");
            PrintEnvironment();

            // Use 4: Env Set up & Configuration File Setup with Inheritance
            //        - Set env to "newyork.prod"(PRODUCTION) with default available envs as "newyork.prod,london.prod,qa,dev".
            //        - Also set the "newyork.prod" env RefPath to use 3 config files "ny.prod.config,prod.config,dev.config.
            //        - Config file sequence is an inheritance of files ny.prod.config (inherits) prod.config (inherits) dev.config
            Envs.Set("newyork.prod", "newyork.prod,london.prod,qa,dev", "newyork.prod.config,prod.config,dev.config");
            PrintEnvironment();

            // Use 5: Set up the environment using Built objects.
            Envs.Set("Dev2", GetSampleEvironments(), "");
            PrintEnvironment();


            // Use 6: Change the environment from the last one ("Dev2").
            Env.Change("Qa");
            PrintEnvironment();
            return(BoolMessageItem.True);
        }
        public void CanSetProdConfig()
        {
            // 2. Non-Strict setup indicating current environment and config references.
            Envs.Set("prod", "prod,uat,qa,dev", "prod.config");

            // 3. Non-Strict setup indicating current environment and config inheritance 2 files.
            Envs.Set("dev", "prod,uat,qa,dev", "dev1.config,dev2.config");

            // 4. Non-Strict setup indicating current environment inheritance and config inheritance.
            Envs.Set("prod,qa,dev", "prod,uat,qa,dev", "prod.config,qa.config,dev.config");
            //EnvironmentCurrent.Change("qa");

            // 5. Strict setup indicating current environments selected from the possible environments.
            //Envs.Set(GetSampleEvironments(), "Prod");
        }
        public void CanChangeEnv()
        {
            // 1. Setup current env using supplied environment names/types.
            //    and all the available environments.
            // 2. Also supply the refpaths( config paths in this case ).
            Envs.Set("prod,qa,dev", "prod,uat,qa,dev", "prod.config,qa.config,dev.config");

            Assert.AreEqual(Env.Name, "prod");
            Assert.AreEqual(Env.EnvType, EnvType.Prod);
            Assert.AreEqual(Env.IsDev, false);
            Assert.AreEqual(Env.IsProd, true);
            Assert.AreEqual(Env.IsQa, false);
            Assert.AreEqual(Env.IsUat, false);
            Assert.AreEqual(Env.Available[0], "prod");
            Assert.AreEqual(Env.Available[1], "uat");
            Assert.AreEqual(Env.Available[2], "qa");
            Assert.AreEqual(Env.Available[3], "dev");
            Assert.AreEqual(Env.Selected, Env.Get("prod"));

            // Check that the refpaths ( config files) have been set on the respective envs)
            Assert.AreEqual(Env.Get("prod").RefPath, "prod.config");
            Assert.AreEqual(Env.Get("qa").RefPath, "qa.config");
            Assert.AreEqual(Env.Get("dev").RefPath, "dev.config");

            // Now change environment.
            Env.OnChange += ((sender, eventArgs) =>
            {
                Assert.AreEqual(Env.Name, "qa");
                Assert.AreEqual(Env.EnvType, EnvType.Qa);
                Assert.AreEqual(Env.IsDev, false);
                Assert.AreEqual(Env.IsProd, false);
                Assert.AreEqual(Env.IsQa, true);
                Assert.AreEqual(Env.IsUat, false);
                Assert.AreEqual(Env.Available[0], "prod");
                Assert.AreEqual(Env.Available[1], "uat");
                Assert.AreEqual(Env.Available[2], "qa");
                Assert.AreEqual(Env.Available[3], "dev");
                Assert.AreEqual(Env.Selected, Env.Get("qa"));

                // Check that the refpaths ( config files) have been set on the respective envs)
                Assert.AreEqual(Env.Get("prod").RefPath, "prod.config");
                Assert.AreEqual(Env.Get("qa").RefPath, "qa.config");
                Assert.AreEqual(Env.Get("dev").RefPath, "dev.config");
            });

            Env.Change("qa");
            Assert.AreEqual(Env.Count, 4);
        }
        /// <summary>
        /// Run the application.
        /// </summary>
        public override BoolMessageItem Execute()
        {
            //// Setup notification on Environment changed.
            Env.OnChange += (sender, args) => Console.Write("New Env: " + Env.Name);

            // Use 1: Set to "prod"(PRODUCTION) with default available envs as "prod,uat,qa,dev".
            Envs.Set("prod");
            PrintEnvironment();

            // Use 2: Set to "qa"(QA) with default available envs as "prod,qa,dev".
            Envs.Set("qa", "prod,qa,dev");
            PrintEnvironment();

            // Use 3: Set to "dev"(DEVELOPMENT) with default available envs as "prod,uat,qa,dev".
            //        Also set the "dev" env RefPath to "dev.config".
            Envs.Set("dev", "prod,uat,qa,dev", "dev.config");
            PrintEnvironment();

            // Use 4: Env Set up & Configuration File Setup WITH-OUT Inheritance
            //        - Set env to "ny.prod"(PRODUCTION) with default available envs as "ny.prod,london.prod,qa,dev".
            //        - The "ny.prod" environment name is set to environment type of "prod" via format "<envName>:<envType>" e.g. "myprod:prod"
            //        - Also set the "ny.prod" env RefPath to use 3 config files "ny.prod.config,london.prod.config,dev.config. ( For config file inheritance ).
            Envs.Set("ny.prod", "ny.prod:prod,london.prod:prod,qa,dev", "ny.prod.config,london.prod.config,qa.config,dev.config");
            PrintEnvironment();

            // Use 5: Env Set up & Configuration File Setup WITH-OUT Inheritance but WITH config file distribution.
            //        - Also set the "ny.prod" env RefPath to use 1 config files "ny.prod.config,london.prod.config,dev.config.
            Envs.Set("ny.prod", "ny.prod:prod,london.prod:prod,qa,dev", "ny.prod.config,london.prod.config,qa.config,dev.config", true, false);
            PrintEnvironment();

            // Use 5: Env Set up & Configuration File Setup WITH Inheritance
            //        - Also set the "ny.prod" env RefPath to use 1 config files "ny.prod.config,london.prod.config,dev.config.
            Envs.Set("ny.prod", "ny.prod:prod,london.prod:prod,qa,dev", "ny.prod.config,london.prod.config,qa.config,dev.config", true, true);
            PrintEnvironment();

            // Use 5: Set up the environment using Built objects.
            Envs.Set("Dev2", GetSampleEvironments());
            PrintEnvironment();


            // Use 6: Change the environment from the last one ("Dev2").
            Env.Change("Qa");
            PrintEnvironment();
            return(BoolMessageItem.True);
        }
        public void CanSetEnvViaNameOnly()
        {
            // 1. Setup current env using default environment names/types.
            Envs.Set("prod");

            Assert.AreEqual(Env.Name, "prod");
            Assert.AreEqual(Env.EnvType, EnvType.Prod);
            Assert.AreEqual(Env.IsDev, false);
            Assert.AreEqual(Env.IsProd, true);
            Assert.AreEqual(Env.IsQa, false);
            Assert.AreEqual(Env.IsUat, false);
            Assert.AreEqual(Env.Available[0], "prod");
            Assert.AreEqual(Env.Available[1], "uat");
            Assert.AreEqual(Env.Available[2], "qa");
            Assert.AreEqual(Env.Available[3], "dev");
            Assert.AreEqual(Env.Selected, Env.Get("prod"));
            Assert.AreEqual(Env.Count, 4);
        }
예제 #7
0
        /// <summary>
        /// Show how to set the environment and load the config files
        /// based on the environment.
        /// </summary>
        public void SetEnvironment()
        {
            // 1. Get environment passed from command line. -env:Prod
            // 2. Get all the environments supported.
            // 3. Create environment.
            // 4. Set current environment.
            IEnv env = new EnvDef(AppConfig.GetSampleEvironments(), _argsReciever.Environment);

            Envs.Set(env);

            // Show the environment selection API.
            Logger.Info("====================================================");
            Logger.Info("ENVIRONMENTS ");
            Logger.Info("Environment name: " + Env.Name);
            Logger.Info("Environment type: " + Env.EnvType);
            Logger.Info("Environment inherits: " + Env.Inherits);
            Logger.Info("Environment file: " + Env.RefPath);
            Logger.Info("Environment prod: " + Env.IsProd);
            Logger.Info(Environment.NewLine);
        }
예제 #8
0
        /// <summary>
        /// Initialize with contextual data.
        /// </summary>
        /// <param name="context"></param>
        public virtual void Init(object context)
        {
            string env    = _argsParsed.Get("env", "dev");
            string log    = _argsParsed.Get("log", "%name%-%yyyy%-%MM%-%dd%-%env%-%user%.log");
            string config = _argsParsed.Get("config", string.Format(@"config\{0}.config", env));

            // 1. Initialize the environment. prod, prod.config
            Envs.Set(env, "prod,uat,qa,dev", config);

            // 2. Append the file based logger.
            Logger.Default.Append(new LogFile(this.GetType().Name, log, DateTime.Now, env));

            // 3. Initialize config inheritance from environment inheritance.
            Config.Init(Configs.LoadFiles(Env.RefPath));

            // 4. Set the config and logger, and emailer instances on the application.
            _config  = Config.Current;
            _log     = Logger.Default;
            _emailer = new EmailService(_config, "EmailServiceSettings");
        }
        public void CanSetEnvViaNameAndType()
        {
            // 1. Setup current env using supplied environment names/types.
            // Not that <envName>:<envType> is the format
            // where <envType> = prod | uat | qa | dev
            Envs.Set("ny.prod", "ny.prod:prod,london.prod:prod,uat,qa,dev");

            Assert.AreEqual(Env.Name, "ny.prod");
            Assert.AreEqual(Env.EnvType, EnvType.Prod);
            Assert.AreEqual(Env.IsDev, false);
            Assert.AreEqual(Env.IsProd, true);
            Assert.AreEqual(Env.IsQa, false);
            Assert.AreEqual(Env.IsUat, false);
            Assert.AreEqual(Env.Available[0], "ny.prod");
            Assert.AreEqual(Env.Available[1], "london.prod");
            Assert.AreEqual(Env.Available[2], "uat");
            Assert.AreEqual(Env.Available[3], "qa");
            Assert.AreEqual(Env.Available[4], "dev");
            Assert.AreEqual(Env.Selected, Env.Get("ny.prod"));
            Assert.AreEqual(Env.Count, 5);
        }
        public void CanSetEnvViaBuildEnvs()
        {
            // 1. Setup current env using supplied environment names/types.
            // Not that <envName>:<envType> is the format
            // where <envType> = prod | uat | qa | dev
            List <EnvItem> available = GetSampleEvironments();

            Envs.Set("Dev2", available, "");

            Assert.AreEqual(Env.Name, "Dev2");
            Assert.AreEqual(Env.EnvType, EnvType.Dev);
            Assert.AreEqual(Env.IsDev, true);
            Assert.AreEqual(Env.IsProd, false);
            Assert.AreEqual(Env.IsQa, false);
            Assert.AreEqual(Env.IsUat, false);
            Assert.AreEqual(Env.Available[0], "Dev");
            Assert.AreEqual(Env.Available[1], "Dev2");
            Assert.AreEqual(Env.Available[2], "Qa");
            Assert.AreEqual(Env.Available[3], "Prod");
            Assert.AreEqual(Env.Available[4], "MyProd");
            Assert.AreEqual(Env.Selected, Env.Get("Dev2"));
            Assert.AreEqual(Env.Count, 5);
        }
예제 #11
0
        /// <summary>
        /// INHERITANCE
        /// 1. -env:Prod -date:${today}   -config:prod.config,dev.config -log:{env}.log -source:Bloomberg 10
        /// 2. -env:Prod -date:${today-1} -config:prod.config,dev.config -log:{env}.log -source:Reuters 10
        /// </summary>
        public override void Init()
        {
            // base.Init(). Does everything, this is just to show how to setup everything.
            //base.Init();

            string env    = _argsParsed.Get("env", "dev");
            string log    = _argsParsed.Get("log", "%name%-%yyyy%-%MM%-%dd%-%env%-%user%.log");
            string config = _argsParsed.Get("config", string.Format(@"config\{0}.config", env));

            // 1. Initialize the environment
            Envs.Set(env, "prod,uat,qa,dev", config);

            // 2. Append the file logger.
            Logger.Default.Append(new LogFile(this.GetType().Name, log, DateTime.Now, env));

            // 3. Initialize config inheritance.
            Config.Init(Configs.LoadFiles(Env.RefPath));

            // 4. Set the config, logger, emailer instances on the application.
            _config  = Config.Current;
            _log     = Logger.Default;
            _emailer = new EmailService(_config, "EmailServiceSettings");
        }