当前位置: 首页>>代码示例>>C#>>正文


C# Work.BuildFromDifferences方法代码示例

本文整理汇总了C#中Work.BuildFromDifferences方法的典型用法代码示例。如果您正苦于以下问题:C# Work.BuildFromDifferences方法的具体用法?C# Work.BuildFromDifferences怎么用?C# Work.BuildFromDifferences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Work的用法示例。


在下文中一共展示了Work.BuildFromDifferences方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ScriptDifferences

 private ExecutionBlock ScriptDifferences(Differences differences)
 {
     var work = new Work();
     work.BuildFromDifferences(differences, Options.Default, true);
     ExecutionBlock block = work.ExecutionBlock;
     return block;
 }
开发者ID:tcabanski,项目名称:SouthSideDevToys,代码行数:7,代码来源:SchemaSyncEngine.cs

示例2: SchemaSync

        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,
//.........这里部分代码省略.........
开发者ID:KennyBu,项目名称:RedGateSync,代码行数:101,代码来源:DBSync.cs


注:本文中的Work.BuildFromDifferences方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。