Skip to content

Instantly share code, notes, and snippets.

@zgramana
Created April 12, 2016 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zgramana/d3505a5fc502f4c61bd0f0049257e12b to your computer and use it in GitHub Desktop.
Save zgramana/d3505a5fc502f4c61bd0f0049257e12b to your computer and use it in GitHub Desktop.
Auto-merging conflicting revisions in C# using LINQ
Dictionary<string, object> mergedProps;
try
{
mergedProps = doc.ConflictingRevisions
.SelectMany(rev => rev.UserProperties)
.Distinct()
.ToDictionary(
kvp => kvp.Key,
kvp => kvp.Value
);
} catch (ArgumentException ex) {
// Merge conflict requires manual resolution.
}
var current = doc.CurrentRevision;
foreach(var rev in doc.ConflictingRevisions)
{
var newRev = rev.CreateRevision();
if (rev.Equals(current)) {
newRev.SetProperties(mergedProps);
} else {
newRev.IsDeletion = true;
}
newRev.Save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment