/// <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"]) }; }
/// <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; } }
public void Save(CatalogConfig data) { var path = Path.Combine(_appSettings.Value.ConfigPath, "configs", "CatalogSetting.json"); var json = JsonConvert.SerializeObject(data, Formatting.Indented); File.WriteAllText(path, json); }
public void Setup() { _catalogConfig = new CatalogConfig { ServicePlan = "Standard", CatalogDatabase = "ShardMapManager", CatalogServer = TestServer }; _databaseConfig = new DatabaseConfig { DatabasePassword = "", DatabaseUser = "", ConnectionTimeOut = 30, DatabaseServerPort = 1433, LearnHowFooterUrl = "", SqlProtocol = SqlProtocol.Tcp }; var tenant = new Tenants { ServicePlan = "Standard", TenantName = "Test Tenant 1", TenantId = new byte[0] }; _connectionString = string.Format("{0}Initial Catalog={1};", ShardMapManagerTestConnectionString, _catalogConfig.CatalogDatabase); _mockCatalogRepo = new MockCatalogRepository(); _mockCatalogRepo.Add(tenant); _mockTenantRepo = new MockTenantRepository(); _mockUtilities = new Mock <IUtilities>(); #region Create databases on localhost // Clear all connection pools. SqlConnection.ClearAllPools(); using (SqlConnection conn = new SqlConnection(ShardMapManagerTestConnectionString)) { conn.Open(); // Create ShardMapManager database using (SqlCommand cmd = new SqlCommand(string.Format(CreateDatabaseQueryFormat, _catalogConfig.CatalogDatabase), conn)) { cmd.ExecuteNonQuery(); } // Create Tenant database using (SqlCommand cmd = new SqlCommand(string.Format(CreateDatabaseQueryFormat, tenant.TenantName), conn)) { cmd.ExecuteNonQuery(); } } #endregion }
public ShardingManager( DatabaseConfig databaseConfig, CatalogConfig catalogConfig, IKeyVaultClient keyVaultClient) { DatabaseConfig = databaseConfig; CatalogConfig = catalogConfig; KeyVaultClient = keyVaultClient; }
public SettingsDialog(CatalogConfig config) { InitializeComponent(); App.SetWindowFont(this); this.Config = config.Clone <CatalogConfig>(); this.DataContext = this.Config; UpdatePlatformConfigs(); UpdateDevices(); }
private static void RegisterConfiguration(IServiceCollection services, IConfiguration configuration) { var catalogConfig = new CatalogConfig(); configuration.Bind("CatalogConfig", catalogConfig); services.AddSingleton(catalogConfig); var databaseConfig = new DatabaseConfig(); configuration.Bind("DatabaseConfig", databaseConfig); services.AddSingleton(databaseConfig); }
public void Setup() { _catalogConfig = new CatalogConfig { ServicePlan = "Standard", CatalogDatabase = "ShardMapManager", CatalogServer = "localhost" }; _databaseConfig = new DatabaseConfig { DatabasePassword = "", DatabaseUser = "", ConnectionTimeOut = 30, DatabaseServerPort = 1433, LearnHowFooterUrl = "", SqlProtocol = SqlProtocol.Tcp }; var tenant = new Tenants { ServicePlan = "Standard", TenantName = "TestTenant", TenantId = new byte[0] }; _connectionString = "Data Source=localhost;Initial Catalog=ShardMapManager;Integrated Security=SSPI;"; _mockCatalogRepo = new Mock <ICatalogRepository>(); _mockCatalogRepo.Setup(repo => repo.Add(tenant)); _mockTenantRepo = new Mock <ITenantRepository>(); _mockUtilities = new Mock <IUtilities>(); #region Create tenant database on localhost // Clear all connection pools. SqlConnection.ClearAllPools(); using (SqlConnection conn = new SqlConnection(ShardMapManagerTestConnectionString)) { conn.Open(); // Create ShardMapManager database using (SqlCommand cmd = new SqlCommand(CreateDatabaseQuery, conn)) { cmd.ExecuteNonQuery(); } } #endregion }
public void Setup() { _catalogConfig = new CatalogConfig { ServicePlan = "Standard", CatalogDatabase = "ShardMapManager", CatalogServer = "localhost" }; _databaseConfig = new DatabaseConfig { DatabasePassword = "", DatabaseUser = "", ConnectionTimeOut = 30, DatabaseServerPort = 1433, LearnHowFooterUrl = "", SqlProtocol = SqlProtocol.Tcp }; var tenant = new Tenants { ServicePlan = "Standard", TenantName = "TestTenant", TenantId = new byte[0] }; _mockTenantsRepo = new Mock <ITenantsRepository>(); _mockTenantsRepo.Setup(repo => repo.Add(tenant)); _mockHelper = new Mock <IHelper>(); _mockHelper.Setup(helper => helper.GetSqlConnectionString(_databaseConfig, _catalogConfig)).Returns(ShardMapManagerConnString); #region Create tenant database on localhost // Clear all connection pools. SqlConnection.ClearAllPools(); using (SqlConnection conn = new SqlConnection(ShardMapManagerTestConnectionString)) { conn.Open(); // Create ShardMapManager database using (SqlCommand cmd = new SqlCommand(CreateDatabaseQuery, conn)) { cmd.ExecuteNonQuery(); } } #endregion }
/// <summary> /// Gets the SQL connection string. /// </summary> /// <param name="databaseConfig">The database configuration.</param> /// <param name="catalogConfig">The catalog configuration.</param> /// <returns></returns> public string GetSqlConnectionString(DatabaseConfig databaseConfig, CatalogConfig catalogConfig) { var smmconnstr = GetBasicSqlConnectionString(databaseConfig); // Connection string with administrative credentials for the root database SqlConnectionStringBuilder connStrBldr = new SqlConnectionStringBuilder(smmconnstr) { DataSource = databaseConfig.SqlProtocol + ":" + catalogConfig.CatalogServer + "," + databaseConfig.DatabaseServerPort, InitialCatalog = catalogConfig.CatalogDatabase, ConnectTimeout = databaseConfig.ConnectionTimeOut }; return(connStrBldr.ConnectionString); }
public void GetSqlConnectionStringTest() { DatabaseConfig dbConfig = new DatabaseConfig { ConnectionTimeOut = 30, DatabasePassword = "******", DatabaseUser = "******" }; CatalogConfig catalogConfig = new CatalogConfig { CatalogDatabase = "testDatabase", CatalogServer = "testServer" }; var connectionStr = _helper.GetSqlConnectionString(dbConfig, catalogConfig); Assert.IsNotNull(connectionStr); Assert.AreEqual("Data Source=Default:testServer,0;Initial Catalog=testDatabase;User ID=dbUser;Password=password;Connect Timeout=30;Application Name=EntityFramework", connectionStr); }
private async Task <CatalogConfig> LoadConfigAsync() { string configFolderPath = ReflectionHelper.GetExecutingAssemblyFolderPath(); var accessProcessor = new LocalAccessProvider(); var config = await Config.LoadAsync <CatalogConfig>(accessProcessor, configFolderPath); if (config == null) { string romsFolderPath = CommonDialogsHelper.ShowFolderBrowseDialog( "Select the location of your ROMs folder:"); if (!String.IsNullOrEmpty(romsFolderPath)) { config = new CatalogConfig(accessProcessor, configFolderPath, romsFolderPath); await config.SaveAsync(); } } return(config); }
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"], }; }
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); } }
/// <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 } } } }
/// <summary> /// Gets the catalog connection string using the app settings /// </summary> /// <param name="catalogConfig">The catalog configuration.</param> /// <param name="databaseConfig">The database configuration.</param> /// <returns></returns> private string GetCatalogConnectionString(CatalogConfig catalogConfig, DatabaseConfig databaseConfig) { return ($"Server=tcp:{catalogConfig.CatalogServer},1433;Database={catalogConfig.CatalogDatabase};User ID={databaseConfig.DatabaseUser};Password={databaseConfig.DatabasePassword};Trusted_Connection=False;Encrypt=True;"); }
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)); }