コード例 #1
0
        /// <summary>
        /// Reads the application settings from appsettings.json
        /// </summary>
        private void ReadAppConfig()
        {
            DatabaseConfig = new DatabaseConfig
            {
                DatabasePassword   = Configuration["DatabasePassword"],
                DatabaseUser       = Configuration["DatabaseUser"],
                DatabaseServerPort = Convert.ToInt32(Configuration["DatabaseServerPort"]),
                SqlProtocol        = SqlProtocol.Tcp,
                ConnectionTimeOut  = Convert.ToInt32(Configuration["ConnectionTimeOut"]),
                LearnHowFooterUrl  = Configuration["LearnHowFooterUrl"]
            };

            CatalogConfig = new CatalogConfig
            {
                ServicePlan     = Configuration["ServicePlan"],
                CatalogDatabase = Configuration["CatalogDatabase"],
                CatalogServer   = Configuration["CatalogServer"] + ".database.windows.net"
            };

            TenantServerConfig = new TenantServerConfig
            {
                TenantServer    = Configuration["TenantServer"] + ".database.windows.net",
                ResetEventDates = Convert.ToBoolean(Configuration["ResetEventDates"])
            };
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: candyalladi/BookMyHotel
        /// <summary>
        /// Reads the application settings from appsettings.json
        /// </summary>
        private void ReadAppConfig()
        {
            DatabaseConfig = new DatabaseConfig
            {
                DatabasePassword   = Configuration["DatabasePassword"],
                DatabaseUser       = Configuration["DatabaseUser"],
                DatabaseServerPort = Convert.ToInt32(Configuration["DatabaseServerPort"]),
                SqlProtocol        = SqlProtocol.Tcp,
                ConnectionTimeOut  = Convert.ToInt32(Configuration["ConnectionTimeOut"]),
                LearnHowFooterUrl  = Configuration["LearnHowFooterUrl"]
            };

            CatalogConfig = new CatalogConfig
            {
                ServicePlan     = Configuration["ServicePlan"],
                CatalogDatabase = Configuration["CatalogDatabase"],
                CatalogServer   = Configuration["CatalogServer"] + ".database.windows.net",
                CatalogLocation = Configuration["APP_REGION"]
            };

            TenantServerConfig = new TenantServerConfig
            {
                TenantServer = Configuration["TenantServer"] + ".database.windows.net"
            };

            bool isResetBookingDatesEnabled = false;

            if (bool.TryParse(Configuration["ResetBookingDates"], out isResetBookingDatesEnabled))
            {
                TenantServerConfig.ResetBookingDates = isResetBookingDatesEnabled;
            }
        }
コード例 #3
0
ファイル: Helper.cs プロジェクト: joaomajesus/WingtipSaaS
        /// <summary>
        /// Register tenant shard
        /// </summary>
        /// <param name="tenantServerConfig">The tenant server configuration.</param>
        /// <param name="databaseConfig">The database configuration.</param>
        /// <param name="catalogConfig">The catalog configuration.</param>
        /// <param name="resetEventDate">If set to true, the events dates for all tenants will be reset </param>
        public void RegisterTenantShard(TenantServerConfig tenantServerConfig, DatabaseConfig databaseConfig, CatalogConfig catalogConfig, bool resetEventDate)
        {
            //get all database in devtenantserver
            var tenants          = GetAllTenantNames(tenantServerConfig, databaseConfig);
            var connectionString = GetBasicSqlConnectionString(databaseConfig);

            foreach (var tenant in tenants)
            {
                var tenantId = GetTenantKey(tenant);
                if (Sharding.RegisterNewShard(tenant, tenantId, tenantServerConfig, databaseConfig, catalogConfig))
                {
                    // resets all tenants' event dates
                    if (resetEventDate)
                    {
                        #region EF6
                        //use EF6 since execution of Stored Procedure in EF Core for anonymous return type is not supported yet
                        using (var context = new TenantContext(Sharding.ShardMap, tenantId, connectionString))
                        {
                            context.Database.ExecuteSqlCommand("sp_ResetEventDates");
                        }
                        #endregion

                        #region EF core
                        //https://github.com/aspnet/EntityFramework/issues/7032
                        //using (var context = new TenantDbContext(Sharding.ShardMap, tenantId, connectionString))
                        //{
                        //     context.Database.ExecuteSqlCommand("sp_ResetEventDates");
                        //}
                        #endregion
                    }
                }
            }
        }
コード例 #4
0
        public void RegisterShardTest()
        {
            TenantServerConfig tenantServerConfig = new TenantServerConfig
            {
                TenantServer = "localhost"
            };

            _databaseConfig = new DatabaseConfig
            {
                SqlProtocol = SqlProtocol.Default
            };
            _mockHelper.Setup(helper => helper.GetSqlConnectionString(_databaseConfig, _catalogConfig)).Returns(ShardMapManagerConnString);

            var sharding = new Sharding(_catalogConfig, _databaseConfig, _mockTenantsRepo.Object, _mockHelper.Object);
            var result   = Sharding.RegisterNewShard("TestTenant", 397858529, tenantServerConfig, _databaseConfig, _catalogConfig);

            Assert.IsTrue(result);
        }
コード例 #5
0
ファイル: Utilities.cs プロジェクト: Erbaver/godataa
        public async void RegisterTenantShard(TenantServerConfig tenantServerConfig, DatabaseConfig databaseConfig, CatalogConfig catalogConfig)
        {
            //get all database in devtenantserver
            var tenants = GetAllTenantNames(tenantServerConfig, databaseConfig);

            var connectionString = new SqlConnectionStringBuilder
            {
                UserID          = databaseConfig.DatabaseUser,
                Password        = databaseConfig.DatabasePassword,
                ApplicationName = "EntityFramework",
                ConnectTimeout  = databaseConfig.ConnectionTimeOut
            };

            Shard shard = Sharding.CreateNewShard(tenantServerConfig.TenantDatabase, tenantServerConfig.TenantServer, databaseConfig.DatabaseServerPort, catalogConfig.ServicePlan);

            foreach (var tenant in tenants)
            {
                var tenantId = GetTenantKey(tenant);
                _ = await Sharding.RegisterNewShard(tenantId, catalogConfig.ServicePlan, shard);
            }
        }
コード例 #6
0
ファイル: Utilities.cs プロジェクト: Erbaver/godataa
        private List <string> GetAllTenantNames(TenantServerConfig tenantServerConfig, DatabaseConfig databaseConfig)
        {
            List <string> list = new List <string>();

            string conString = $"Server={databaseConfig.SqlProtocol}:{tenantServerConfig.TenantServer},{databaseConfig.DatabaseServerPort};Database={tenantServerConfig.TenantDatabase};User ID={databaseConfig.DatabaseUser};Password={databaseConfig.DatabasePassword};Trusted_Connection=False;Encrypt=False;Connection Timeout={databaseConfig.ConnectionTimeOut};";

            using (SqlConnection con = new SqlConnection(conString))
            {
                con.Open();

                using (SqlCommand cmd = new SqlCommand("SELECT Name from Teams", con))
                {
                    using (IDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            list.Add(dr[0].ToString().ToLower().Replace(" ", ""));
                        }
                    }
                }
            }
            return(list);
        }
コード例 #7
0
        /// <summary>
        /// Reads the application settings from appsettings.json
        /// </summary>
        private void ReadAppConfig()
        {
            DatabaseConfig = new DatabaseConfig
            {
                DatabasePassword   = Configuration["DatabasePassword"],
                DatabaseUser       = Configuration["DatabaseUser"],
                DatabaseServerPort = Convert.ToInt32(Configuration["DatabaseServerPort"]),
                ConnectionTimeOut  = Convert.ToInt32(Configuration["ConnectionTimeOut"]),
                LearnHowFooterUrl  = Configuration["LearnHowFooterUrl"]
            };

            TenantServerConfig = new TenantServerConfig
            {
                TenantServer   = Configuration["TenantServer"] + ".database.windows.net",
                TenantDatabase = Configuration["TenantDatabase"],
            };
            bool isResetEventDatesEnabled = false;

            if (bool.TryParse(Configuration["ResetEventDates"], out isResetEventDatesEnabled))
            {
                TenantServerConfig.ResetEventDates = isResetEventDatesEnabled;
            }
        }
コード例 #8
0
ファイル: Startup.cs プロジェクト: Erbaver/godataa
        private void ReadAppConfig(IConfiguration configuration)
        {
            DatabaseConfig = new DatabaseConfig
            {
                DatabasePassword   = Configuration["DatabaseOptions:DatabasePassword"],
                DatabaseUser       = Configuration["DatabaseOptions:DatabaseUser"],
                DatabaseServerPort = Int32.Parse(Configuration["DatabaseOptions:DatabaseServerPort"]),
                SqlProtocol        = SqlProtocol.Tcp,
                ConnectionTimeOut  = Int32.Parse(Configuration["DatabaseOptions:ConnectionTimeOut"]),
            };

            CatalogConfig = new CatalogConfig
            {
                ServicePlan     = Configuration["DatabaseOptions:ServicePlan"],
                CatalogDatabase = Configuration["DatabaseOptions:CatalogDatabase"],
                CatalogServer   = Configuration["DatabaseOptions:CatalogServer"], // + ".database.windows.net"
            };

            TenantServerConfig = new TenantServerConfig
            {
                TenantServer   = Configuration["DatabaseOptions:CatalogServer"],// + ".database.windows.net",
                TenantDatabase = Configuration["DatabaseOptions:TenantDatabase"],
            };
        }
コード例 #9
0
        public async Task <IActionResult> Post([FromBody] CreateTeamModel model)
        {
            //TODO: Implement Detailed Error Checking
            if (ModelState.IsValid)
            {
                try
                {
                    //TenantServerConfig tenantServerConfig, DatabaseConfig databaseConfig, CatalogConfig catalogConfig
                    var databaseConfig = new DatabaseConfig
                    {
                        DatabasePassword   = _configuration["DatabaseOptions:DatabasePassword"],
                        DatabaseUser       = _configuration["DatabaseOptions:DatabaseUser"],
                        DatabaseServerPort = Int32.Parse(_configuration["DatabaseOptions:DatabaseServerPort"]),
                        SqlProtocol        = SqlProtocol.Tcp,
                        ConnectionTimeOut  = Int32.Parse(_configuration["DatabaseOptions:ConnectionTimeOut"]),
                    };

                    var catalogConfig = new CatalogConfig
                    {
                        ServicePlan     = _configuration["DatabaseOptions:ServicePlan"],
                        CatalogDatabase = _configuration["DatabaseOptions:CatalogDatabase"],
                        CatalogServer   = _configuration["DatabaseOptions:CatalogServer"], // + ".database.windows.net"
                    };

                    var tenantServerConfig = new TenantServerConfig
                    {
                        TenantServer   = _configuration["DatabaseOptions:CatalogServer"],// + ".database.windows.net",
                        TenantDatabase = _configuration["DatabaseOptions:TenantDatabase"],
                    };

                    var team = new Team
                    {
                        Id       = _utilities.GetTenantKey(model.TenantName),
                        Name     = model.TenantName,
                        LogoLink = model.TenantLogoLink,
                    };



                    //Create Shard, Add Team and Register Tenant against shard
                    var shard = Sharding.CreateNewShard(tenantServerConfig.TenantDatabase, tenantServerConfig.TenantServer, databaseConfig.DatabaseServerPort, null);
                    await _tenantRepository.AddTeam(team);

                    var x = await Sharding.RegisterNewShard(team.Id, "", shard);

                    //Add first user to team. Team Owner!
                    var applicationUser = await _userService.GetApplicationUserAsync();

                    var user = new User {
                        ApplicationUserId = applicationUser.Id, Email = applicationUser.Email, UserRole = Role.SuperAdministrator
                    };
                    await _tenantRepository.AddUserToTeam(user, team.Id);


                    return(Ok(new { team_id = team.Id, team_name = team.Name }));
                }
                catch (Exception ex)
                {
                    //TODO: Log Error
                    return(BadRequest(new { Error = ex.Message }));
                }
            }

            return(BadRequest(ModelState));
        }
コード例 #10
0
ファイル: Startup.cs プロジェクト: Erbaver/godataa
 private string GetTenantConnectionString(TenantServerConfig tenantServerConfig, DatabaseConfig databaseConfig)
 {
     return($"Server=tcp:{tenantServerConfig.TenantServer},1433;Database={tenantServerConfig.TenantDatabase};User ID={databaseConfig.DatabaseUser};Password={databaseConfig.DatabasePassword};Trusted_Connection=False;Encrypt=False;");
 }