コード例 #1
0
        public async Task Setup()
        {
            var create = new CreateDatabase(new DatabaseConnection());

            if (!await create.IsCreated())
            {
                await create.Create();
            }

            var populate = new PopulateTables(new DatabaseConnection());

            // as we've modified the SubmissionsEvents table, we need to enable the
            // seamless upgrade of the table on the first run after fetching the new code.
            // previously, the tests didn't populate the table, so we check for that.
            // this way we handle (a) first run with empty database,
            // (b) first run after table modification & (c) subsequent runs
            if (!await create.IsSubmissionEventsCreated() ||
                !await populate.IsSubmissionEventsTablePopulated())
            {
                await create.CreateSubmissionEvents();
            }

            var setup = new DatabaseSetup(populate);
            await setup.PopulateTestData().ConfigureAwait(false);
        }
コード例 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (txtServer.Text.Equals(string.Empty))
            {
                txtServer.Focus();
                MessageBox.Show(@"Please enter the valid server name",
                                @"Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }
            if (cmbAuth.SelectedIndex == -1)
            {
                cmbAuth.Focus();
                MessageBox.Show(@"Please choose authentication type!",
                                @"Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }
            if (cmbDatabase.SelectedIndex == -1)
            {
                cmbDatabase.Focus();
                MessageBox.Show(@"Please choose database",
                                @"Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }
            if (chkNewDatabase.IsChecked == false && cmbDatabase.Text.Equals(cmbDestination.Text))
            {
                MessageBox.Show(@"Source and destination are the same. Not allowed!",
                                @"Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            //Create inputs
            _i = new Inputs
            {
                ServerName           = txtServer.Text,
                DatabaseName         = cmbDatabase.Text,
                InMemoryDataBaseName = cmbDestination.Text,
                UserName             = txtUserName.Text,
                Password             = txtPassword.Password,
                IsWindows            = cmbAuth.SelectedIndex == 0,
                CreateNew            = chkNewDatabase.IsChecked == true
            };
            if (_i.CreateNew)
            {
                _i.InMemoryDataBaseName = $"{_i.DatabaseName}_InMem";
            }
            //create options
            _o = new Options
            {
                CopyData = chkCopyData.IsChecked == true
            };


            switch (cmbIndexOptions.SelectedIndex)
            {
            case 0:
                _o.UseHashIndexes = Options.IndexDecision.Hash;
                break;

            case 1:
                _o.UseHashIndexes = Options.IndexDecision.Range;
                break;

            default:
                _o.UseHashIndexes = Options.IndexDecision.ExtendedPropery;
                break;
            }

            //_o.DropOnDestination = chkDropOnDestination.Checked;

            var arr = txtSchemas.Text.Trim().Split(',');

            foreach (var s in arr)
            {
                if (s != "")
                {
                    _o.Schemas.Add(s.ToLower());
                }
            }

            arr = txtTables.Text.Trim().Split(',');
            foreach (var s in arr)
            {
                if (s != "")
                {
                    _o.Tables.Add(s.ToLower());
                }
            }


            Server server;

            try
            {
                var cnn = new ServerConnection(_i.ServerName);
                cnn.Connect();
                server = new Server(cnn);
            }
            catch (Exception ex)
            {
                MessageBox.Show($@"I'm unable to connect to the server {_i.ServerName}
                                {ex.Message}",
                                @"Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            if ((((int)DataAccess.ExecuteScalar(DataAccess.GetConnectionString(
                                                    txtServer.Text,
                                                    "master",
                                                    cmbAuth.SelectedIndex == 0,
                                                    txtUserName.Text, txtPassword.Password), " SELECT IS_SRVROLEMEMBER ('sysadmin') ") == 1)) == false)
            {
                MessageBox.Show(@"You should connect as a member of sysadmin fixed server role",
                                @"Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }



            if (new Version(server.VersionString) < new Version(CServerVersion))
            {
                MessageBox.Show(@"The server has to be SQL2016 SP2 or higher",
                                @"Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }
            if (server.Databases[_i.DatabaseName] == null)
            {
                MessageBox.Show(@"Choose the database!",
                                @"Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                cmbDatabase.SelectedItem = null;
                return;
            }

            if (server.Databases[_i.DatabaseName].HasMemoryOptimizedObjects)
            {
                MessageBox.Show(@"The source database contains Memory Optimized FileGroup. It is not allowed!",
                                @"Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }
            var error = "";


            if (_i.CreateNew)
            {
                if (MessageBox.Show($"You choose to create a new database {_i.DatabaseName}_InMem {Environment.NewLine} Are you sure?",
                                    @"Question",
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Question) == MessageBoxResult.No)
                {
                    return;
                }
                if (CreateDatabase.Create(server, _i.DatabaseName + "_InMem", ref error, _cnf.FileGroupName, _cnf.FileName, _cnf.MoPath) == false)
                {
                    MessageBox.Show($@"An error occurs while creating the database! {Environment.NewLine} {error}",
                                    @"Error",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    return;
                }
            }
            else
            {
                if (MessageBox.Show(
                        $@"You choose to convert the database {_i.DatabaseName.ToUpper()} to In-Mem {_i.InMemoryDataBaseName.ToUpper()} {Environment.NewLine} Are you sure?",
                        @"Question",
                        MessageBoxButton.YesNo,
                        MessageBoxImage.Question) == MessageBoxResult.No)
                {
                    return;
                }
                if (CreateDatabase.Create(server, _i.InMemoryDataBaseName, ref error, _cnf.FileGroupName, _cnf.FileName,
                                          _cnf.MoPath) == false)
                {
                    MessageBox.Show(@"An error occurs while creating the database!",
                                    @"Error",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    return;
                }
            }


            ProgressBar1.Visibility = Visibility.Visible;
            ProgressBar1.Minimum    = 1;
            ProgressBar1.Maximum    = server.Databases[_i.DatabaseName].Tables.Count;

            SetupRows(false);
            btnConvertToMO.IsEnabled = false;
            btnCancel.IsEnabled      = true;



            _t1 = DateTime.Now;

            _mainObr = new Thread(StartConversion);
            _mainObr.Start();


            _dispatcherTimer          = new DispatcherTimer();
            _dispatcherTimer.Tick    += DispatcherTimer_Tick;
            _dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
            _dispatcherTimer.Start();
        }