Exemplo n.º 1
0
        /// <summary>
        /// Creates a new platform database and patches it
        /// </summary>
        /// <param name="patcher">Determines the SQL schema created</param>
        /// <param name="notifier">audit object, can be a new ThrowImmediatelyCheckNotifier if you aren't in a position to pass one</param>
        public void CreateAndPatchDatabase(IPatcher patcher, ICheckNotifier notifier)
        {
            var initialPatch = patcher.GetInitialCreateScriptContents(Database);

            CreateDatabase(initialPatch, notifier);

            //get everything in the /up/ folder that are .sql
            var patches = patcher.GetAllPatchesInAssembly(Database);

            PatchDatabase(patches, notifier, (p) => true);//apply all patches without question
        }
Exemplo n.º 2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            var db = serverDatabaseTableSelector1.GetDiscoveredDatabase();

            if (db == null)
            {
                MessageBox.Show(
                    "You must pick an empty database or enter the name of a new one (that doesn't exist yet)");
                return;
            }

            if (_completed)
            {
                MessageBox.Show("Setup completed already, review progress messages then close Form");
                return;
            }

            if (_tCreateDatabase != null && !_tCreateDatabase.IsCompleted)
            {
                MessageBox.Show("Setup already underaway");
                return;
            }

            var createSql = _patcher.GetInitialCreateScriptContents(db);
            var patches   = _patcher.GetAllPatchesInAssembly(db);

            var preview = new SQLPreviewWindow("Confirm happiness with SQL",
                                               "The following SQL is about to be executed:", createSql.EntireScript);

            var executor = new MasterDatabaseScriptExecutor(db);

            if (preview.ShowDialog() == DialogResult.OK)
            {
                _tCreateDatabase = Task.Run(() =>

                {
                    var memory = new ToMemoryCheckNotifier(checksUI1);

                    if (executor.CreateDatabase(createSql, memory))
                    {
                        _completed = executor.PatchDatabase(patches, memory, silentlyApplyPatchCallback);

                        DatabaseCreatedIfAny = db;

                        var worst = memory.GetWorst();
                        if (worst == CheckResult.Success || worst == CheckResult.Warning)
                        {
                            if (MessageBox.Show("Succesfully created database, close form?", "Success", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                _programaticClose = true;
                                Invoke(new MethodInvoker(Close));
                            }
                        }
                    }
                    else
                    {
                        _completed = false;    //failed to create database
                    }
                }
                                            );
            }
        }