private bool NewDatabase(string dbName, int serverAccountId) { var apiClient = GetApiClient(serverAccountId); var request = new CreateDatabase(); CreateDatabase.ResponseParams response; try { response = request.GetResponse(apiClient); } catch (RequestException e) { MessageBox.Show(e.ErrorCode); return false; } /*var linkSuccessful = false; var startTime = DateTime.Now; while (!linkSuccessful) { Thread.Sleep(2000); if (startTime.AddSeconds(30) < DateTime.Now) break; var checkRequest = new CheckClientLink {LinkIdentifier = response.DatabaseIdentifier}; CheckClientLink.ResponseParams checkLinkResponse; try { checkLinkResponse = checkRequest.GetResponse(apiClient); } catch (BadRequestException e) { MessageBox.Show(e.ErrorCode); return false; } if (checkLinkResponse.LinkEstablished) linkSuccessful = true; } if (!linkSuccessful) return false;*/ var newDatabaseMetaId = Model.DatabasesMeta.Create(new DatabaseMeta {Name = dbName}); var newDatabaseId = Model.Databases.Create(new Database { Identifier = response.DatabaseIdentifier, ServerAccountId = serverAccountId, DatabaseMetaId = newDatabaseMetaId }); SetDatabaseAsModified(newDatabaseId); var newGroupIdentifier = Guid.NewGuid().ToString(); var groupMetaId = Model.DatabasesGroupsMeta.Create(new DatabaseGroupMeta {Name = "Websites"}); var groupId = Model.DatabasesGroups.Create(new DatabaseGroup { Identifier = newGroupIdentifier, DatabaseId = newDatabaseId, DatabaseGroupMetaId = groupMetaId }); SetGroupAsModified(groupId); UpdateHomePage(); return true; }
private void crearNuevaToolStripMenuItem_Click(object sender, EventArgs e) { var nuevaDb = new CreateDatabase(); nuevaDb.Show(); }
public DatabaseService(IDbProvider dbProvider, CreateDatabase createDatabase) { _adoTemplate = new AdoTemplate(dbProvider); this.createDatabase = createDatabase; }
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(); }
protected override void Generate(CreateDatabase op) { //不需要传入 DataBase 的值,因为 CreateDbMigrationRun 会直接使用连接中指定的数据库名称。 this.AddRun(new CreateDbMigrationRun()); }
private void MenuItem_Click(object sender, RoutedEventArgs e) { CreateDatabase create = new CreateDatabase(this); create.Show(); }
private void BuildAll(Config config, Solution solution) { String solutionFolder = solution.SolutionFolder; CreateSolutionFolders(solutionFolder); if (deleteTempFiles) { solutionFolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(solutionFolder); Directory.CreateDirectory(System.IO.Path.Combine(solutionFolder, @"Database")); Directory.CreateDirectory(System.IO.Path.Combine(solutionFolder, @"configuration")); Directory.CreateDirectory(System.IO.Path.Combine(solutionFolder, @"sqlite")); } solution.Log("Start building solution"); Dictionary <String, String> tempFiles = GetTempFiles(solutionFolder); DatabaseFactory.DatabaseFactory dbf = null; //init database dbf = new DatabaseFactory.DatabaseFactory(solution.DatabaseServer); String dropDatabaseScript; if (solution.IsAsured) { dropDatabaseScript = new DropDatabaseAzure(config).TransformText(); } else { dropDatabaseScript = new DropDatabase(config).TransformText(); } System.IO.File.WriteAllText(tempFiles["dropdatabase"], dropDatabaseScript); try { dbf.RunScript(dropDatabaseScript); } catch (Exception) { } String createDatabaseScript; if (solution.IsAsured) { createDatabaseScript = new CreateDatabaseAzure(config).TransformText(); } else { createDatabaseScript = new CreateDatabase(config).TransformText(); } System.IO.File.WriteAllText(tempFiles["createdatabase"], createDatabaseScript); dbf.RunScript(createDatabaseScript); solution.Log("DB scripts ok"); //create database dbf = new DatabaseFactory.DatabaseFactory(solution.ConnectionString); String dbScript = new Database(config).TransformText(); System.IO.File.WriteAllText(tempFiles["database"], dbScript); dbf.RunScript(dbScript); solution.Log("Database ok"); System.Data.SqlClient.SqlConnection.ClearAllPools(); //sort tables SyncOrder.Initialize(solution.ConnectionString); SyncOrder.Sort(config.Entities); //provisioning String syncConfig = tempFiles["syncconfig"]; System.IO.File.WriteAllText(syncConfig, new SyncConfig(config, solution.ConnectionString).TransformText()); dbf.Provision(new String[] { "/mode:provision", String.Format("/scopeconfig:{0}", syncConfig) }); solution.Log("Provision ok"); //filters String filtersScript; if (solution.IsAsured) { filtersScript = new FiltersAzure(config).TransformText(); } else { filtersScript = new Filters(config).TransformText(); } System.IO.File.WriteAllText(tempFiles["filters"], filtersScript); dbf.RunScript(filtersScript); solution.Log("Filters ok"); //sync patch String syncPatchScript = new SyncPatch2(config).TransformText(); System.IO.File.WriteAllText(tempFiles["syncpatch"], syncPatchScript); dbf.RunScript(syncPatchScript); solution.Log("Sync patch ok"); //admin dbScript = new DatabaseAdmin(config).TransformText(); System.IO.File.WriteAllText(tempFiles["admin"], dbScript); dbf.RunScript(dbScript); solution.Log("Admin ok"); //clustered primary keys patch config.BuildClusteredPrimaryKeys(solution.ConnectionString); String keysPatchScript = new KeysPatch(config).TransformText(); System.IO.File.WriteAllText(tempFiles["keyspatch"], keysPatchScript); dbf.RunScript(keysPatchScript); solution.Log("Clustered keys patch ok"); if (solution.IsAsured) { //clustered primary keys patch config.BuildNonClusteredPrimaryKeys(solution.ConnectionString); String azureKeysPatchScript = new AzureKeysPatch(config).TransformText(); System.IO.File.WriteAllText(tempFiles["azurekeyspatch"], azureKeysPatchScript); dbf.RunScript(azureKeysPatchScript); solution.Log("Non clustered keys patch ok"); solution.Log("Default NEWID values on tabular sections ok"); } else { String nonAzureKeysPatchScript = new NonAzureKeysPatch(config).TransformText(); System.IO.File.WriteAllText(tempFiles["azurekeyspatch"], nonAzureKeysPatchScript); dbf.RunScript(nonAzureKeysPatchScript); solution.Log("Default NEWSEQUENTIALID values on tabular sections ok"); } //initial load String dataLoadScript = new DataLoad(config).TransformText(); System.IO.File.WriteAllText(tempFiles["dataload"], dataLoadScript); dbf.RunScript(dataLoadScript); solution.Log("initial data load ok"); //sqlite String sqlieScript = new SQLiteDatabase(config).TransformText(); System.IO.File.WriteAllText(tempFiles["sqlite"], sqlieScript); if (!System.IO.Directory.Exists(System.IO.Path.Combine(solution.SolutionFolder, "sqlite"))) { System.IO.Directory.CreateDirectory(System.IO.Path.Combine(solution.SolutionFolder, "sqlite")); } String sqlitedb = System.IO.Path.Combine(solution.SolutionFolder, @"sqlite\sqlite.db"); if (System.IO.File.Exists(sqlitedb)) { System.IO.File.Delete(sqlitedb); } //SQLiteDatabaseFactory dbflite = new SQLiteDatabaseFactory(sqlitedb); //dbflite.CreateDatabase(); //dbflite.RunScript(sqlieScript); //dbflite.InsertMetadata(solution.ConfigurationFile); solution.Log("sqlite ok"); System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\Server.cs"), new Server(config).TransformText()); System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\Client.cs"), new Client(config).TransformText()); System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\ClientMetadata.cs"), new ClientMetadata(config).TransformText()); System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\ClientConstants.cs"), new ClientConstants(config).TransformText()); System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\Fake.cs"), new Fake().TransformText()); System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\DbFake.cs"), new DbFake().TransformText()); solution.Log("Code generation ok"); BuildClientDll(solution.SolutionFolder); solution.Log("Client dll ok"); BuildServerDll(solution.SolutionFolder); solution.Log("Server dll ok"); BuildResources(config, solution); solution.Log("Resources ok"); if (deleteTempFiles) { foreach (var entry in tempFiles) { System.IO.File.Delete(entry.Value); } } solution.Log("Solution has been successfully built"); }
/// <summary> /// 生成创建数据库的语句 /// </summary> /// <param name="op">创建数据库的实例对象</param> protected override void Generate(CreateDatabase op) { this.AddRun(new SQLiteCreateDbMigrationRun { Database = op.Database }); }
private void CreateDatabase_Executed(object sender, ExecutedRoutedEventArgs e) { CreateDatabase createDabaseDialog = new CreateDatabase(); createDabaseDialog.ShowDialog(); }
public void CreateDatabaseWithoutCollation() { var expression = new CreateDatabase(Database); Assert.Equal("CREATE DATABASE " + Database, expression.ToString()); }
public void CreateDatabaseWithCollation() { var expression = new CreateDatabase(Database, Collation); Assert.Equal("CREATE DATABASE " + Database + " COLLATE " + Collation, expression.ToString()); }
public void Can_ExecuteThePackageAction() { var packageAction = new CreateDatabase(_database); packageAction.Execute("merchello", null); }