internal void RedGateReleaseDifferences(string sourceServer, string sourceDatabase, string targetServer, string targetDatabase) { var differences = RedGateCompare(sourceServer, sourceDatabase, targetServer, targetDatabase); // Select the differences to include in the synchronization. In this case, we're using all differences. foreach (var difference in differences) { difference.Selected = true; } var work = new Work(); // Calculate the work to do using sensible default options // The script is to be run on WidgetProduction so the runOnTwo parameter is true work.BuildFromDifferences(differences, Options.Default, true); // Disposing the execution block when it's not needed any more is important to ensure // that all the temporary files are cleaned up using (var block = work.ExecutionBlock) { // Finally, use a BlockExecutor to run the SQL against the target database var executor = new BlockExecutor(); executor.ExecuteBlock(block, targetServer, targetDatabase); } }
public void ExecuteBlockWithoutTransactions() { Block block = new Block(0, null); var state = new AccountsState(); var processor = new BlockExecutor(); var result = processor.ExecuteBlock(block, state); Assert.IsNotNull(result); Assert.AreSame(state, result); }
public void ExecuteBlockWithTransactionWithoutFunds() { Transaction tx = CreateTransaction(100); Block block = new Block(0, null, new Transaction[] { tx }); var state = new AccountsState(); var processor = new BlockExecutor(); var result = processor.ExecuteBlock(block, state); Assert.IsNotNull(result); Assert.AreSame(state, result); Assert.AreEqual(BigInteger.Zero, state.Get(tx.Sender).Balance); Assert.AreEqual(BigInteger.Zero, state.Get(tx.Receiver).Balance); }
private void SyncDifferences(ExecutionBlock block) { var executor = new BlockExecutor(); executor.ExecuteBlock(block, destinationParms.Connection); }
private static void SchemaSync(string scriptFolder, ConnectionProperties targetConnectionProperties, bool deployOnBuild, string deployPath) { using (Database sourceDatabaseScripts = new Database(), targetDatabase = new Database()) { Console.WriteLine("Beginning schema sync\r\n"); // Cleanup output dir so that script folder registration does not find duplicate Object definitions //CleanUpDBSyncScriptFolder(scriptFolder); // Establish the schema from the scripts stored in the sourceDatabaseScripts scripts folder // Passing in null for the database information parameter causes SQL Compare to read the // XML file supplied in the folder. Console.WriteLine("Registering Source Controlled-Path: {0}", scriptFolder); sourceDatabaseScripts.Register(scriptFolder, null, Options.Default); // Read the schema for the targetDatabase database Console.WriteLine("Registering Target DB: {0}", targetConnectionProperties.ServerName + " " + targetConnectionProperties.DatabaseName); targetDatabase.Register(targetConnectionProperties, Options.Default); // Compare the database against the scripts. // Comparing in this order makes the targetDatabase the second database Console.WriteLine("Performing comparison...\r\n"); Differences sourceDatabaseScriptsVStargetDatabaseDiffs = sourceDatabaseScripts.CompareWith(targetDatabase, Options.Default); // Select all of the differences for synchronization var outputStream = new StringBuilder(); outputStream.AppendLine("/*"); outputStream.AppendLine("Differences summary:"); outputStream.AppendLine("Object Type Diff Object Name"); outputStream.AppendLine("============================================="); int diffCount = 0; foreach (Difference difference in sourceDatabaseScriptsVStargetDatabaseDiffs) { difference.Selected = IsIncludeObject(difference); if (difference.Selected) { if (difference.Type != DifferenceType.Equal) { difference.Selected = true; diffCount++; outputStream.Append(difference.DatabaseObjectType.ToString().PadRight(18)); outputStream.Append(replaceDiffType(difference.Type.ToString())); outputStream.Append(difference.Name + "\r\n"); } else difference.Selected = false; } } outputStream.AppendLine("*/"); if (diffCount == 0) { Console.WriteLine("Schemas match!\r\n"); return; } // Calculate the work to do using sensible default options // The targetDatabase is to be updated, so the runOnTwo parameter is true Console.WriteLine("\r\nCalculating changes to make...\r\n"); var work = new Work(); work.BuildFromDifferences(sourceDatabaseScriptsVStargetDatabaseDiffs, Options.Default, true); // We can now access the messages and warnings Console.WriteLine("Messages:"); foreach (Message message in work.Messages) { Console.WriteLine(message.Text); } Console.WriteLine("Warnings:"); foreach (Message message in work.Warnings) { Console.WriteLine(message.Text); } // Disposing the execution block when it's not needed any more is important to ensure // that all the temporary files are cleaned up using (ExecutionBlock block = work.ExecutionBlock) { // Display the SQL used to synchronize Console.WriteLine("Synchronization SQL:"); //Console.WriteLine(block.GetString()); outputStream.AppendLine(block.GetString()); Console.WriteLine(outputStream.ToString()); WriteDBSyncScriptFile(outputStream.ToString(), scriptFolder, targetConnectionProperties, deployPath); if (deployOnBuild) { // Finally, use a BlockExecutor to run the SQL against the WidgetProduction database Console.WriteLine("Executing SQL..."); var executor = new BlockExecutor(); try { executor.ExecuteBlock(block, targetConnectionProperties.ServerName, targetConnectionProperties.DatabaseName, false, targetConnectionProperties.UserName, targetConnectionProperties.Password); block.Dispose(); } catch (Exception ex) { Console.WriteLine("Error synchronizing schema:\r\n" + ex.Message); throw (ex); } Console.WriteLine("Schema sync complete"); } } } }