Exemple #1
0
        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 ExecuteTransaction()
        {
            var transaction = CreateTransaction(100);

            var addr1 = transaction.Sender;
            var addr2 = transaction.Receiver;

            var           store    = new AccountsState();
            AccountsState newstore = null;

            store = store.Put(addr1, new AccountState(new BigInteger(200), 0));

            var processor = new BlockExecutor();

            Assert.IsTrue(processor.ExecuteTransaction(transaction, store, ref newstore));

            Assert.IsNotNull(newstore);
            Assert.AreNotSame(store, newstore);

            Assert.AreEqual(new BigInteger(200), store.Get(addr1).Balance);
            Assert.AreEqual(BigInteger.Zero, store.Get(addr2).Balance);

            Assert.AreEqual(new BigInteger(100), newstore.Get(addr1).Balance);
            Assert.AreEqual(new BigInteger(100), newstore.Get(addr2).Balance);
        }
Exemple #3
0
        internal IBlockExecutor GetBlockExecutor(ClientManager clientManager = null)
        {
            var blockExecutor = new BlockExecutor(_chainService, _concurrencyExecutingService,
                                                  _transactionResultManager, clientManager, _binaryMerkleTreeManager,
                                                  new TxHub(_transactionManager, _transactionReceiptManager, _chainService, _signatureVerifier, _refBlockValidator), _chainManagerBasic, StateStore);

            return(blockExecutor);
        }
        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);
        }
        public void ExecuteTransactionWithoutFunds()
        {
            var transaction = CreateTransaction(100);

            var addr1 = transaction.Sender;
            var addr2 = transaction.Receiver;

            var           store    = new AccountsState();
            AccountsState newstore = null;

            var processor = new BlockExecutor();

            Assert.IsFalse(processor.ExecuteTransaction(transaction, store, ref newstore));

            Assert.IsNull(newstore);

            Assert.AreEqual(BigInteger.Zero, store.Get(addr1).Balance);
            Assert.AreEqual(BigInteger.Zero, store.Get(addr2).Balance);
        }
 private void SyncDifferences(ExecutionBlock block)
 {
     var executor = new BlockExecutor();
     executor.ExecuteBlock(block, destinationParms.Connection);
 }
Exemple #8
0
        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");
                    }
                }
            }
        }