コード例 #1
0
 private static ISessionFactory CreateForSqlServer(DatabaseCredentials credentials)
 {
     return Fluently.Configure()
         .Database(MsSqlConfiguration.MsSql2008
                       .ConnectionString(credentials.BuildConnectionString()))
         .Mappings(MappingForSchemaInfo)
         .BuildSessionFactory();
 }
コード例 #2
0
 private static ISessionFactory CreateForMysql(DatabaseCredentials credentials)
 {
     return Fluently.Configure()
         .Database(MySQLConfiguration.Standard
             .ConnectionString(credentials.BuildConnectionString()))
         .Mappings(MappingForSchemaInfo)
         .BuildSessionFactory();
 }
コード例 #3
0
 public ISessionFactory Create(DatabaseCredentials credentials)
 {
     switch(credentials.DatabaseType)
     {
         case "mysql":
             return CreateForMysql(credentials);
         case "sqlserver":
             return CreateForSqlServer(credentials);
         default:
             throw new UserException(ExceptionType.InvalidDatabaseType, credentials.DatabaseType);
     }
 }
コード例 #4
0
 public void Setup()
 {
     _kernel = new StandardKernel(new RepoModule());
     _provider = _kernel.Get<IVersionRepoProvider>();
     var credentials = new DatabaseCredentials
                           {
                               Database = "ETF",
                               DatabaseType = "sqlserver",
                               Host = "(local)",
                               IntegratedSecurity = true
                           };
     _repo = _provider.GetVersionRepo(credentials);
 }
コード例 #5
0
 private static string TestSqlServerConnection(DatabaseCredentials credentials)
 {
     try
     {
         using (var connection = new SqlConnection(credentials.BuildConnectionString()))
         {
             connection.Open();
             connection.Close();
             return "OK";
         }
     }
     catch (Exception e)
     {
         return e.Message;
     }
 }
コード例 #6
0
 public string TestConnection(DatabaseCredentials credentials)
 {
     if (!credentials.IsValid)
     {
         return "Invalid credentials";
     }
     switch(credentials.DatabaseType)
     {
         case "sqlserver":
             return TestSqlServerConnection(credentials);
         case "mysql":
             return TestMySql(credentials);
         default:
             return "Invalid databasetype";
     }
 }
コード例 #7
0
        public DatabaseState GetDatabaseState(EnvironmentData environmentData)
        {
            var state = new DatabaseState();
            if (environmentData.DatabaseType == null || environmentData.DatabaseType.Equals("none"))
            {
                state.Status = "N/A";
                state.Version = "N/A";
                return state;
            }

            var credentials = new DatabaseCredentials
            {
                DatabaseType = environmentData.DatabaseType,
                Host = environmentData.DatabaseHost,
                Database = environmentData.DatabaseName,
                Username = environmentData.DatabaseUsername,
                Password = environmentData.DatabasePassword,
                IntegratedSecurity = environmentData.IntegratedSecurity
            };

            state.Status = _provider.TestConnection(credentials);

            if (credentials.IsValid)
            {
                try
                {
                    using (var repo = _provider.GetVersionRepo(credentials))
                    {
                        state.Version = repo.GetVersion().ToString();
                    }
                }
                catch (Exception e)
                {
                    state.Version = "No SchemaInfo";
                }
            }
            else
            {
                state.Status = "Invalid credentials";
            }

            return state;
        }
コード例 #8
0
 public IVersionRepo GetVersionRepo(DatabaseCredentials credentials)
 {
     return new VersionRepo(_sessionFactoryProvider.Create(credentials));
 }