Ejemplo n.º 1
0
    /// <summary>
    /// static constructor to determine the state of the environment and set defaults
    /// </summary>
    static CurrentEnvironment()
    {
        // Not on cloud foundry filling in the blanks.
        if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME)))
        {
            Environment.SetEnvironmentVariable(BOUND_SERVICES_ENV_VARIABLE_NAME, "{}");
            Environment.SetEnvironmentVariable(PORT_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
            Environment.SetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
            Environment.SetEnvironmentVariable(INSTANCE_INDEX_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
        }

        // check to see if DB is bound, if so...what type
        // sql server first
        if (BoundServices.GetValue("mssql-dev") != null) // sql server
        {
            DbEngine          = DatabaseEngine.SqlServer;
            _connectionString = BoundServices["mssql-dev"][0]["credentials"]["connectionString"].ToString();
        }
        else if (BoundServices.GetValue("p-mysql") != null)
        {
            DbEngine = DatabaseEngine.MySql;;
            MySqlConnectionStringBuilder csbuilder = new MySqlConnectionStringBuilder();
            csbuilder.Add("server", BoundServices["p-mysql"][0]["credentials"]["hostname"].ToString());
            csbuilder.Add("port", BoundServices["p-mysql"][0]["credentials"]["port"].ToString());
            csbuilder.Add("uid", BoundServices["p-mysql"][0]["credentials"]["username"].ToString());
            csbuilder.Add("pwd", BoundServices["p-mysql"][0]["credentials"]["password"].ToString());
            csbuilder.Add("database", BoundServices["p-mysql"][0]["credentials"]["name"].ToString());
            _connectionString = csbuilder.ToString();
        }
        else
        {
            DbEngine = DatabaseEngine.None;
        }
    }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            Logger.LogError("########################################################\n" +
                            "########################################################\n" +
                            BoundServices +
                            "########################################################\n" +
                            "########################################################\n");
            if (BoundServices.GetValue("cleardb") != null)
            {
                var connectionString =
                    "server=" + BoundServices["cleardb"][0]["credentials"]["hostname"].ToString() + ";" +
                    "database=" + BoundServices["cleardb"][0]["credentials"]["name"].ToString() + ";" +
                    "user="******"cleardb"][0]["credentials"]["username"].ToString() + ";" +
                    "password="******"cleardb"][0]["credentials"]["password"].ToString();
                Configuration["mysql:client:ConnectionString"] = connectionString;
                Logger.LogError("@@@@#######################################################\n" +
                                "@@@@#######################################################\n" +
                                connectionString +
                                "@@@@########################################################\n" +
                                "@@@@########################################################\n");
            }
            services.AddOptions();
            services.ConfigureCloudFoundryService <MySqlServiceOption>(Configuration, "cleardb");
            services.AddDbContext <AirplaneContext>(options => options.UseMySql(Configuration));
            //services.AddMySqlHealthContributor(Configuration);
            services.GetEnumerator();
            services.AddCloudFoundryActuators(Configuration);

            // Add framework services.
            services.AddMvc();

            services.AddOptions();
            services.ConfigureCloudFoundryService <MySqlServiceOption>(Configuration, "cleardb");
        }
        /// <summary>
        /// static constructor to determine the state of the environment and set defaults
        /// </summary>
        static MySQLConnections()
        {
            // Not on cloud foundry filling in the blanks.
            if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME)))
            {
                Environment.SetEnvironmentVariable(BOUND_SERVICES_ENV_VARIABLE_NAME, "{}");
                Environment.SetEnvironmentVariable(PORT_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
                Environment.SetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
                Environment.SetEnvironmentVariable(INSTANCE_INDEX_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
            }

            if (BoundServices.GetValue("p.mysql") != null)
            {
                DbEngine = DatabaseEngine.MySql;;
                MySqlConnectionStringBuilder csbuilder = new MySqlConnectionStringBuilder();
                csbuilder.Add("server", BoundServices["p.mysql"][0]["credentials"]["hostname"].ToString());
                csbuilder.Add("port", BoundServices["p.mysql"][0]["credentials"]["port"].ToString());
                csbuilder.Add("uid", BoundServices["p.mysql"][0]["credentials"]["username"].ToString());
                csbuilder.Add("pwd", BoundServices["p.mysql"][0]["credentials"]["password"].ToString());
                csbuilder.Add("database", BoundServices["p.mysql"][0]["credentials"]["name"].ToString());
                _connectionString = csbuilder.ToString();
            }
            else
            {
                DbEngine = DatabaseEngine.None;
            }
        }
 static PCFEnvironment()
 {
     if (BoundServices.GetValue("p-mysql") != null)
     {
         MySqlConnectionStringBuilder csbuilder = new MySqlConnectionStringBuilder();
         csbuilder.Add("server", BoundServices["p-mysql"][0]["credentials"]["hostname"].ToString());
         csbuilder.Add("port", BoundServices["p-mysql"][0]["credentials"]["port"].ToString());
         csbuilder.Add("uid", BoundServices["p-mysql"][0]["credentials"]["username"].ToString());
         csbuilder.Add("pwd", BoundServices["p-mysql"][0]["credentials"]["password"].ToString());
         csbuilder.Add("database", BoundServices["p-mysql"][0]["credentials"]["name"].ToString());
         _connectionString = csbuilder.ToString();
     }
 }
Ejemplo n.º 5
0
    /// <summary>
    /// static constructor to determine the state of the environment and set defaults
    /// </summary>
    static CurrentEnvironment()
    {
        // Not on cloud foundry filling in the blanks.
        if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME)))
        {
            Environment.SetEnvironmentVariable(BOUND_SERVICES_ENV_VARIABLE_NAME, "{}");
            Environment.SetEnvironmentVariable(PORT_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
            Environment.SetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
            Environment.SetEnvironmentVariable(INSTANCE_INDEX_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
        }

        // check to see if DB is bound, if so...what type
        // SQL server first
        if (BoundServices.GetValue("azure-sqldb") != null) // Azure SQL Database (Azure Broker)
        {
            DbEngine = DatabaseEngine.SqlServer;
            SqlConnectionStringBuilder csbuilder = new SqlConnectionStringBuilder();
            csbuilder.Add("server", BoundServices["azure-sqldb"][0]["credentials"]["hostname"].ToString());
            csbuilder.Add("uid", BoundServices["azure-sqldb"][0]["credentials"]["username"].ToString());
            csbuilder.Add("pwd", BoundServices["azure-sqldb"][0]["credentials"]["password"].ToString());
            csbuilder.Add("database", BoundServices["azure-sqldb"][0]["credentials"]["name"].ToString());
            _connectionString = csbuilder.ToString();
        }
        else if (BoundServices.GetValue("azure-mysqldb") != null || BoundServices.GetValue("p-mysql") != null || BoundServices.GetValue("cleardb") != null) // MySQL for PCF or Mysql for AZURE
        {
            string label = "p-mysql";                                                                                                                       // MySQL Database.

            if (BoundServices.GetValue("azure-mysqldb") != null)
            {
                label = "azure-mysqldb"; //Mysql Database on Azure (Mysql For Azure)
            }
            if (BoundServices.GetValue("cleardb") != null)
            {
                label = "cleardb"; //Mysql cleardb
            }
            DbEngine = DatabaseEngine.MySql;
            MySqlConnectionStringBuilder csbuilder = new MySqlConnectionStringBuilder();
            csbuilder.Add("server", BoundServices[label][0]["credentials"]["hostname"].ToString());
            csbuilder.Add("port", BoundServices[label][0]["credentials"]["port"].ToString());
            csbuilder.Add("uid", BoundServices[label][0]["credentials"]["username"].ToString());
            csbuilder.Add("pwd", BoundServices[label][0]["credentials"]["password"].ToString());
            csbuilder.Add("database", BoundServices[label][0]["credentials"]["name"].ToString());
            _connectionString = csbuilder.ToString();
        }
        else
        {
            DbEngine = DatabaseEngine.None;
        }
    }