public ActionResult Login(string username, string functionName) { ConnectionManagement connectionManagement = new ConnectionManagement(); DbBusiness dbBusiness = new DbBusiness(); string result = "NG"; string description = ""; try { //if (!dbBusiness.ExistUser(username, connectionManagement.GetDefaultConnection())) //{ // result = "NG"; // description = "Tài khoản này không tồn tại"; //} //else { //if (!dbBusiness.CheckAuthorization(username, functionName, connectionManagement.GetDefaultConnection())) //{ // result = "NG"; // description = "Tài khoản này không có quyền"; //} //else { result = "OK"; description = ""; } } } catch { result = "NG"; description = "Không thể kết nối với máy chủ"; } return(Content(result + "#" + description)); }
public void When_VerifyDatabaseServer_With_valid_database_Should_return_Ok() { // Arrange var di = DependencyInjectionFactory.ConfigureDependencyInjection(); var clientConfig = di.GetService <IClientConfig>(); if (!clientConfig.IsAssigned()) { throw new Exception("clientconfig not returned by dependency injection"); } clientConfig.DefaultDatabase = "TestClassGenerator"; var connection = clientConfig.GetConfigConnection(); if (!connection.IsAssigned()) { throw new Exception("connection not returned by configuration"); } var config = ConnectionManagement.SetDatabaseSecurityInMemory(connection.UserName, connection.Password, connection.ConnectionName); var databaseProviderFactory = new DatabaseProviderFactory(config.GetSection); var database = databaseProviderFactory.Create("TestClassGenerator"); // Act var result = SqlServerCheck.VerifyDatabaseServer(database, 1000); // Assert result.Should().BeTrue(); }
public void When_VerifyDatabaseServer_With_invalid_database_Should_return_DoesNotExist() { // Arrange var di = DependencyInjectionFactory.ConfigureDependencyInjection(); var clientConfig = di.GetService <IClientConfig>(); if (!clientConfig.IsAssigned()) { throw new Exception("clientconfig not returned by dependency injection"); } clientConfig.DefaultDatabase = "TestDatabase"; var connection = clientConfig.GetConfigConnection(); if (!connection.IsAssigned()) { throw new Exception("connection not returned by configuration"); } var config = ConnectionManagement.SetDatabaseSecurityInMemory(connection.UserName, connection.Password, connection.ConnectionName); var databaseProviderFactory = new DatabaseProviderFactory(config.GetSection); var database = databaseProviderFactory.Create("TestDatabase"); // Act Action action = () => SqlServerCheck.VerifyDatabaseServer(database, 1000); // Assert action.Should().Throw <SqlClientException>().WithMessage("Database TestDatabase does not exist"); }
private Database GetDatabase() { Debug.WriteLine($"SqlClientRepository GetDatabase, default database: '{_clientConfig.DefaultDatabase}'"); var connection = _clientConfig.GetConfigConnection(); if (!connection.IsAssigned()) { return(new DatabaseProviderFactory().CreateDefault()); } var config = ConnectionManagement.SetDatabaseSecurityInMemory(connection.UserName, connection.Password, connection.ConnectionName); return(new DatabaseProviderFactory(config.GetSection).Create(connection.ConnectionName)); }
public static void SetSqlApplicationSettings([NotNull] this ClientConfig clientConfig) { if (!clientConfig.DefaultDatabase.IsAssigned()) { return; } var connection = clientConfig.Connections.FirstOrDefault(x => x.ConnectionName == clientConfig.DefaultDatabase); if (connection.IsAssigned()) { ConnectionManagement.SetApplicationDatabase(connection.Database, connection.Server, connection.ConnectionName); } ConnectionManagement.SetActiveConnection(clientConfig.DefaultDatabase); if (clientConfig.UseEnvironmentSetting && (!connection.IsAssigned() || !connection.UserName.IsAssigned())) { ConnectionManagement.CopySqlSecurityToClientConfig(clientConfig); } }
public ServerForm() { InitializeComponent(); chatServer = new ConnectionManagement(); chatServer.run(); }
public void GlobalSetup() { Util.Initialize(); _connectionManagement = Util.ConnectionManagement; _amountOfKeys = Util.BenchmarkSettings.AmountOfKeys; }