private void buttonFinish_Click(object sender, EventArgs e)
        {
            if (ucDatabaseInformation1.ConnectionStringHelper.CurrentDbType == DatabaseTypes.Unknown)
            {
                MessageBox.Show(this, "Please select a database.", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            Cursor = Cursors.WaitCursor;

            try
            {
                bool informationFilled = TestConnection(false, ucDatabaseInformation1);

                if (informationFilled == false)
                {
                    return;
                }

                NewProjectForm.SetScreenData(ScreenDataKey, new ScreenData(DatabasePresenter.CreateDatabaseLoader(ucDatabaseInformation1)));

                NewProjectForm.UserChosenAction      = NewProjectFormActions.NewProject;
                NewProjectForm.NewProjectInformation = new LoadExistingDatabaseInfo
                {
                    DatabaseLoader   = DatabasePresenter.CreateDatabaseLoader(ucDatabaseInformation1),
                    ConnStringHelper = ucDatabaseInformation1.GetHelper()
                };

                NewProjectForm.LoadScreen(typeof(SelectDatabaseObjects));
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Пример #2
0
        private void Save()
        {
            if (_Database.ConnectionInformation == null)
            {
                IDatabaseLoader dbLoader = DatabasePresenter.CreateDatabaseLoader(ucDatabaseInformation1);

                try
                {
                    _Database = dbLoader.LoadDatabase(dbLoader.DatabaseObjectsToFetch, null);
                }
                catch (DatabaseLoaderException e)
                {
                    #region Save what we can
                    _Database.DatabaseType = ucDatabaseInformation1.SelectedDatabaseType;

                    _Database.ConnectionInformation          = new Helper.ConnectionStringHelper();
                    _Database.ConnectionInformation.FileName = ucDatabaseInformation1.ConnectionStringHelper.FileName;
                    _Database.ConnectionInformation.UseIntegratedSecurity = ucDatabaseInformation1.ConnectionStringHelper.UseIntegratedSecurity;
                    _Database.ConnectionInformation.UserName    = ucDatabaseInformation1.ConnectionStringHelper.UserName;
                    _Database.ConnectionInformation.Password    = ucDatabaseInformation1.ConnectionStringHelper.Password;
                    _Database.ConnectionInformation.Port        = ucDatabaseInformation1.ConnectionStringHelper.Port;
                    _Database.ConnectionInformation.ServerName  = ucDatabaseInformation1.ConnectionStringHelper.ServerName;
                    _Database.ConnectionInformation.ServiceName = ucDatabaseInformation1.ConnectionStringHelper.ServiceName;
                    #endregion

                    //if (e.InnerException != null && e.InnerException.Message.StartsWith("Database cannot be null, the empty string, or string of only whitespace."))
                    //    return;
                    //else
                    //    throw;
                }
            }
            else
            {
                //_Database.Name = ucDatabaseInformation1.ConnectionStringHelper.DatabaseName;
                _Database.DatabaseType = ucDatabaseInformation1.SelectedDatabaseType;
                var connStringHelper = ucDatabaseInformation1.ConnectionStringHelper;

                _Database.ConnectionInformation.FileName = connStringHelper.FileName;
                _Database.ConnectionInformation.UseIntegratedSecurity = connStringHelper.UseIntegratedSecurity;
                _Database.ConnectionInformation.UserName    = connStringHelper.UserName;
                _Database.ConnectionInformation.Password    = connStringHelper.Password;
                _Database.ConnectionInformation.Port        = connStringHelper.Port;
                _Database.ConnectionInformation.ServerName  = connStringHelper.ServerName;
                _Database.ConnectionInformation.ServiceName = connStringHelper.ServiceName;
            }
        }
        internal static bool TestConnection(bool showSuccess, ArchAngel.Providers.EntityModel.UI.PropertyGrids.ucDatabaseInformation dbInfo)
        {
            Monitor.Enter(databaseLock);

            try
            {
                if (!dbInfo.ReadyToProceed())
                {
                    return(false);
                }

                dbInfo.SetDatabaseOperationResults(new DatabaseOperationResults("Testing connection...", true));

                IDatabaseLoader loader = DatabasePresenter.CreateDatabaseLoader(dbInfo);

                try
                {
                    loader.TestConnection();
                    if (showSuccess)
                    {
                        dbInfo.SetDatabaseOperationResults(new DatabaseOperationResults("Connection Test", true));
                    }

                    return(true);
                }
                catch (DatabaseLoaderException e)
                {
                    DatabaseOperationResults results = new DatabaseOperationResults("Connection Test", false, e.ActualMessage);

                    dbInfo.SetDatabaseOperationResults(results);

                    return(false);
                }
            }
            finally
            {
                Monitor.Exit(databaseLock);
            }
        }
        public void A_SQLCEDatabaseLoader_Is_Returned()
        {
            IDatabaseForm form  = MockRepository.GenerateMock <IDatabaseForm>();
            IMainPanel    panel = MockRepository.GenerateMock <IMainPanel>();

            DatabasePresenter presenter = new DatabasePresenter(panel, form);

            form.Stub(t => t.SelectedDatabaseType).Return(DatabaseTypes.SQLCE);
            form.Stub(t => t.SelectedDatabase).Return("1Table3Columns.sdf");

            IDatabaseLoader loader = presenter.CreateDatabaseLoader();

            Assert.That(loader, Is.Not.Null);
            Assert.That(loader, Is.TypeOf(typeof(SQLCEDatabaseLoader)));

            // Will throw an error if the database connection could not be established.
            loader.TestConnection();

            IDatabase db = loader.LoadDatabase();

            Assert.That(db.Name, Is.EqualTo("1Table3Columns"));
            Assert.That(db.Tables, Has.Count(1));             // Basic check to see if we got the correct database back.
        }
        public void A_SQLServer2005DatabaseLoader_Is_Returned()
        {
            IDatabaseForm form  = MockRepository.GenerateMock <IDatabaseForm>();
            IMainPanel    panel = MockRepository.GenerateMock <IMainPanel>();

            DatabasePresenter presenter = new DatabasePresenter(panel, form);

            form.Stub(t => t.SelectedDatabaseType).Return(DatabaseTypes.SQLServer2005);
            form.Stub(t => t.ConnectionStringHelper).Return(new ConnectionStringHelper
            {
                CurrentDbType         = DatabaseTypes.SQLServer2005,
                DatabaseName          = "TestDatabase",
                Password              = "******",
                ServerName            = ".",
                UseFileName           = false,
                UseIntegratedSecurity = false,
                UserName              = "******"
            });

            IDatabaseLoader loader = presenter.CreateDatabaseLoader();

            Assert.That(loader, Is.Not.Null);
            Assert.That(loader, Is.TypeOf(typeof(SQLServer2005DatabaseLoader)));
        }
 private void buttonBack_Click(object sender, EventArgs e)
 {
     NewProjectForm.SetScreenData(ScreenDataKey, new ScreenData(DatabasePresenter.CreateDatabaseLoader(ucDatabaseInformation1)));
     NewProjectForm.LoadScreen(typeof(LoadExistingProject));
 }