本文整理汇总了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;
}
示例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,
//.........这里部分代码省略.........