Created
April 12, 2016 20:18
-
-
Save zgramana/d3505a5fc502f4c61bd0f0049257e12b to your computer and use it in GitHub Desktop.
Auto-merging conflicting revisions in C# using LINQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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