private static ISessionFactory CreateForSqlServer(DatabaseCredentials credentials)
 {
     return Fluently.Configure()
         .Database(MsSqlConfiguration.MsSql2008
                       .ConnectionString(credentials.BuildConnectionString()))
         .Mappings(MappingForSchemaInfo)
         .BuildSessionFactory();
 }
 private static ISessionFactory CreateForMysql(DatabaseCredentials credentials)
 {
     return Fluently.Configure()
         .Database(MySQLConfiguration.Standard
             .ConnectionString(credentials.BuildConnectionString()))
         .Mappings(MappingForSchemaInfo)
         .BuildSessionFactory();
 }
 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);
     }
 }
 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);
 }
 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;
     }
 }
 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";
     }
 }
        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;
        }
 public IVersionRepo GetVersionRepo(DatabaseCredentials credentials)
 {
     return new VersionRepo(_sessionFactoryProvider.Create(credentials));
 }