Ejemplo n.º 1
0
        /// <summary>
        /// Create database under a provider and environment
        /// </summary>
        /// <param name=""></param>
        /// <param name=""></param>
        /// <param name=""></param>
        public void CreateDatabase(
            string provider, InfraGlobal.EnvironmentTypes env, string envID, InfraGlobal.DatabaseTypes db)
        {
            CloudServiceModel pro = _CloudServices.Find(i => i.Name == provider);

            pro.Environments.Find(j => ((j.Type == env) && (j.ID == envID)))
            .AddDatabase(provider, env, db);
        }
Ejemplo n.º 2
0
        // Helper functions
        private static InfraGlobal.DatabaseTypes SelectDatabase()
        {
            var environment = WhichDatabase();

            InfraGlobal.DatabaseTypes result = InfraGlobal.DatabaseTypes._;
            switch (environment)
            {
            case "m":
                result = InfraGlobal.DatabaseTypes.MySQL;
                break;

            case "s":
                result = InfraGlobal.DatabaseTypes.SQL;
                break;
            }
            return(result);
        }
Ejemplo n.º 3
0
        // Action functions
        private static void DatabaseAction(InfraControl IC, string action)
        {
            var input    = string.Empty;
            var provider = string.Empty;

            InfraGlobal.EnvironmentTypes environment = InfraGlobal.EnvironmentTypes._;
            switch (action)
            {
            case "1":     // Add database
            {
                provider = GetProviderName();
                if (IC.ProviderExist(provider))
                {        // Provider exist then find envronment
                    // Ask for environment type
                    environment = SelectEnvironment();
                    if (environment == 0)
                    {
                        return;                           // Cancelled
                    }
                    if (environment > 0)
                    {
                        if (IC.EnvironmentExist(provider, environment))
                        //if (IC.CloudServices.Find(x => x.Name == provider)
                        //    .Environments.Exists(y => y.Type == environment))
                        {
                            var ID = GetEnvironmentID();
                            if (IC.EnvironmentExistByID(provider, environment, ID))
                            {
                                InfraGlobal.DatabaseTypes database = SelectDatabase();
                                if (database == 0)
                                {
                                    return;                        // Cancelled
                                }
                                if (database > 0)
                                {
                                    // Add database
                                    IC.CreateDatabase(provider, environment, ID, database);
                                }
                            }
                            return;
                        }
                        Console.WriteLine("Environment {0:G} does not exist.", environment);
                    }
                    return;
                }
                Console.WriteLine("Provider {0:G} does not exist.", provider);
            };
                break;

            case "2":     // List all database
            {
                provider = GetProviderName();
                if (IC.ProviderExist(provider))
                {
                    InfraGlobal.EnvironmentTypes environ = SelectEnvironment();
                    if (IC.EnvironmentExist(provider, environ))
                    {
                        var ID = GetEnvironmentID();
                        if (IC.EnvironmentExistByID(provider, environ, ID))
                        {
                            IC.ShowDatabases(provider, environ, ID);
                            return;
                        }
                    }
                    Console.WriteLine("Environment does not exist!");
                    return;
                }
                Console.WriteLine("Provider {0:G} does not exist!", provider);
            };
                break;

            case "3":     // Remove database
            {
                provider = GetProviderName();
                if (IC.ProviderExist(provider))
                {        // Provider exist then find envronment
                    // Ask for environment type
                    environment = SelectEnvironment();
                    if (environment == 0)
                    {
                        return;                           // Cancelled
                    }
                    if (environment > 0)
                    {
                        if (IC.EnvironmentExist(provider, environment))
                        //if (IC.CloudServices.Find(x => x.Name == provider)
                        //    .Environments.Exists(y => y.Type == environment))
                        {
                            var ID = GetEnvironmentID();
                            if (IC.EnvironmentExistByID(provider, environment, ID))
                            {
                                InfraGlobal.DatabaseTypes database = SelectDatabase();
                                if (database == 0)
                                {
                                    return;                        // Cancelled
                                }
                                if (database > 0)
                                {
                                    // Delete database
                                    IC.DeleteDatabase(provider, environment, ID, database);
                                }
                            }
                            return;
                        }
                        Console.WriteLine("Environment {0:G} does not exist.", environment);
                    }
                    return;
                }
                Console.WriteLine("Provider {0:G} does not exist.", provider);
            };
                break;

            case "4":
            {
                Console.WriteLine("Action cancelled.");
            };
                break;

            default: return;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// AddDatabase creates a new database and add it to the list _Databases
        /// </summary>
        /// <param name="provider">Name of provider</param>
        /// <param name="env">Type of environment: UAT, Staging, Production</param>
        /// <param name="db">Type of database MySQL or SQL</param>
        public void AddDatabase(string provider, InfraGlobal.EnvironmentTypes env, InfraGlobal.DatabaseTypes db)
        {
            DatabaseServerModel rdb = new DatabaseServerModel(_EnvPath, provider, env, _ID, db);

            _Databases.Add(rdb);
        }