Ejemplo n.º 1
0
        public void CreateDatabaseInUncPath()
        {
            // This is where cab files will be placed. Also - I'm trying to change the creation so that this is the
            // path that the SQL database will be created in too. For the moment the database will be created in the
            // default location.
            String cabFolder        = @"\\localhost\C$\stackhashunittests\TestCabFolder";
            String connectionString = TestSettings.DefaultConnectionString + "Initial Catalog=MASTER;";
            String databaseName     = "StackHashInstallTestDatabase";


            InstallerInterface sqlInstaller = new InstallerInterface(connectionString, databaseName, cabFolder);


            try
            {
                try
                {
                    // Connect to SQL Server instance.
                    sqlInstaller.Connect();
                }
                catch (System.Exception ex)
                {
                    // Process or log errors here.
                    Console.WriteLine(ex);
                    throw;
                }

                try
                {
                    // Check if the database exists.
                    if (sqlInstaller.DatabaseExists())
                    {
                        return;  // Job done.
                    }
                    sqlInstaller.CreateDatabase(false);

                    Assert.AreEqual(true, sqlInstaller.DatabaseExists());

                    String databaseFileName    = String.Format("{0}\\{1}\\{1}.mdf", cabFolder, databaseName);
                    String databaseLogFileName = String.Format("{0}\\{1}\\{1}.ldf", cabFolder, databaseName);

                    Assert.AreEqual(true, File.Exists(databaseFileName));
                    Assert.AreEqual(true, File.Exists(databaseLogFileName));
                }
                catch (System.Exception ex)
                {
                    // Failed to create the database.
                    // Process or log errors here.
                    Console.WriteLine(ex);
                    throw;
                }
            }
            finally
            {
                sqlInstaller.DeleteDatabase(databaseName);
                sqlInstaller.Disconnect();
            }
        }
Ejemplo n.º 2
0
 public GeneralInstallator(InstallerInterface installer)
 {
     this.installer = installer;
 }
Ejemplo n.º 3
0
        void _worker_DoWork(object sender, DoWorkEventArgs e)
        {
            WorkerResult       result    = new WorkerResult();
            InstallerInterface installer = null;

            try
            {
                WorkerArg arg = e.Argument as WorkerArg;
                result.TestConnectionOnly = arg.TestConnectionOnly;
                result.TestStatus         = StackHashErrorIndexDatabaseStatus.Unknown;

                // configure for local access to the service
                if (!_localServiceConfigComplete)
                {
                    _localServiceGuid = ClientLogic.GetLocalServiceGuid();
                    FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);

                    CheckVersionRequest checkVersionRequest = new CheckVersionRequest();
                    checkVersionRequest.ServiceGuid  = _localServiceGuid == Guid.Empty ? null : _localServiceGuid.ToString();
                    checkVersionRequest.ClientData   = GenerateClientData();
                    checkVersionRequest.MajorVersion = fvi.ProductMajorPart;
                    checkVersionRequest.MinorVersion = fvi.ProductMinorPart;
                    CheckVersionResponse checkVersionResponse = ServiceProxy.Services.Admin.CheckVersion(checkVersionRequest);

                    _localServiceConfigComplete = true;
                }

                // always test that the service can access the database

                StackHashSqlConfiguration sqlConfig = new StackHashSqlConfiguration();
                sqlConfig.ConnectionString  = arg.MasterConnectionString;
                sqlConfig.ConnectionTimeout = DefaultSqlConnectionTimeout;
                sqlConfig.EventsPerBlock    = DefaultSqlEventsPerBlock;
                sqlConfig.InitialCatalog    = arg.ProfileName;
                sqlConfig.MaxPoolSize       = DefaultSqlMaxPoolSize;
                sqlConfig.MinPoolSize       = DefaultSqlMinPoolSize;

                TestDatabaseConnectionRequest request = new TestDatabaseConnectionRequest();
                request.ClientData            = GenerateClientData();
                request.ContextId             = -1;
                request.SqlSettings           = sqlConfig;
                request.TestDatabaseExistence = false;
                request.CabFolder             = arg.CabFolder;

                TestDatabaseConnectionResponse response = ServiceProxy.Services.Admin.TestDatabaseConnection(request);
                result.TestStatus             = response.TestResult;
                result.TestLastExceptionText  = response.LastException;
                result.CanAccessCabFolder     = response.IsCabFolderAccessible;
                result.CabFolderExceptionText = response.CabFolderAccessLastException;

                // contine if the test succeeded and we're not just testing
                if ((result.TestStatus == StackHashErrorIndexDatabaseStatus.Success) &&
                    (result.CanAccessCabFolder) &&
                    (!arg.TestConnectionOnly))
                {
                    // make sure NETWORK SERVICE can access the cab folder
                    FolderPermissionHelper.NSAddAccess(arg.CabFolder);

                    if (arg.CreateDatabase)
                    {
                        installer = new InstallerInterface(arg.MasterConnectionString,
                                                           arg.ProfileName,
                                                           arg.CabFolder);

                        installer.Connect();

                        if (!installer.DatabaseExists())
                        {
                            installer.CreateDatabase(arg.UseDefaultLocation);
                        }
                    }

                    DBConfigSettings.Settings.ProfileName      = arg.ProfileName;
                    DBConfigSettings.Settings.ConnectionString = arg.ConnectionString;
                    DBConfigSettings.Settings.ProfileFolder    = arg.CabFolder;
                    DBConfigSettings.Settings.Save();

                    _configurationSucceeded = true;
                }
            }
            catch (Exception ex)
            {
                result.WorkerException = ex;
            }
            finally
            {
                if (installer != null)
                {
                    installer.Disconnect();
                }
            }

            // if a test exception was reported include it in the  WorkerException
            if (!string.IsNullOrEmpty(result.TestLastExceptionText))
            {
                if (result.WorkerException == null)
                {
                    result.WorkerException = new AdminReportException(result.TestLastExceptionText);
                }
                else
                {
                    result.WorkerException = new AdminReportException(result.TestLastExceptionText, result.WorkerException);
                }
            }
            else if (!string.IsNullOrEmpty(result.CabFolderExceptionText))
            {
                if (result.WorkerException == null)
                {
                    result.WorkerException = new AdminReportException(result.CabFolderExceptionText);
                }
                else
                {
                    result.WorkerException = new AdminReportException(result.CabFolderExceptionText, result.WorkerException);
                }
            }

            e.Result = result;
        }
Ejemplo n.º 4
0
 public Model()
 {
     modelsState           = new ModelsState();
     modelsState.observers = new List <Observer>();
     installer             = new ConcreteInstaller();
 }
Ejemplo n.º 5
0
        public void CheckDatabaseName_ValidButAlmostAKeywordUsed()
        {
            String databaseName = "Index2";

            Assert.AreEqual(true, InstallerInterface.IsValidSqlDatabaseName(databaseName));
        }
Ejemplo n.º 6
0
        public void CheckDatabaseName_KeywordUsed()
        {
            String databaseName = "Index";

            Assert.AreEqual(false, InstallerInterface.IsValidSqlDatabaseName(databaseName));
        }
Ejemplo n.º 7
0
        public void CheckDatabaseName_Invalid_MaxLengthPlusOne()
        {
            String databaseName = "T23456789012345678901234567890123456789012345678901";

            Assert.AreEqual(false, InstallerInterface.IsValidSqlDatabaseName(databaseName));
        }
Ejemplo n.º 8
0
        public void CheckDatabaseName_Valid_MaxLength()
        {
            String databaseName = "T2345678901234567890123456789012345678901234567890";

            Assert.AreEqual(true, InstallerInterface.IsValidSqlDatabaseName(databaseName));
        }
Ejemplo n.º 9
0
        public void CheckDatabaseName_Valid_UnderscoreInName()
        {
            String databaseName = "TE1236__S_T";

            Assert.AreEqual(true, InstallerInterface.IsValidSqlDatabaseName(databaseName));
        }
Ejemplo n.º 10
0
        public void CheckDatabaseName_InvalidCharInsideName()
        {
            String databaseName = "TE1236+ST";

            Assert.AreEqual(false, InstallerInterface.IsValidSqlDatabaseName(databaseName));
        }
Ejemplo n.º 11
0
        public void CheckDatabaseName_InvalidFirstChar_Hat()
        {
            String databaseName = "^TEST";

            Assert.AreEqual(false, InstallerInterface.IsValidSqlDatabaseName(databaseName));
        }
Ejemplo n.º 12
0
        public void ValidDatabaseName()
        {
            String databaseName = "TEST";

            Assert.AreEqual(true, InstallerInterface.IsValidSqlDatabaseName(databaseName));
        }