本文整理汇总了C#中Chorus.merge.xml.generic.XmlMerger.ConflictOccurred方法的典型用法代码示例。如果您正苦于以下问题:C# XmlMerger.ConflictOccurred方法的具体用法?C# XmlMerger.ConflictOccurred怎么用?C# XmlMerger.ConflictOccurred使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chorus.merge.xml.generic.XmlMerger
的用法示例。
在下文中一共展示了XmlMerger.ConflictOccurred方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MergeAttributes
internal static void MergeAttributes(XmlMerger merger, ref XmlNode ours, XmlNode theirs, XmlNode ancestor)
{
// Review: What happens if 'ours' is null?
// My (RandyR) theory is that deletions are handled in the MergeChildrenMethod code, as are additions.
// That being the case, then that code will only call back to the XmlMerger MergerInner code when all three nodes are present,
// and will thus never get here.
var skipProcessingInOurs = new HashSet<string>();
// Deletions from ancestor, no matter who did it.
foreach (var ancestorAttr in XmlUtilities.GetAttrs(ancestor))
{
var ourAttr = XmlUtilities.GetAttributeOrNull(ours, ancestorAttr.Name);
var theirAttr = XmlUtilities.GetAttributeOrNull(theirs, ancestorAttr.Name);
if (theirAttr == null)
{
if (ourAttr == null)
{
// Both deleted.
// Route tested (x1).
merger.EventListener.ChangeOccurred(new XmlAttributeBothDeletedReport(merger.MergeSituation.PathToFileInRepository, ancestorAttr));
ancestor.Attributes.Remove(ancestorAttr);
continue;
}
if (ourAttr.Value != ancestorAttr.Value)
{
// They deleted, but we changed, so we win under the principle of
// least data loss (an attribute can be a huge text element).
// Route tested (x1).
merger.ConflictOccurred(new EditedVsRemovedAttributeConflict(ourAttr.Name, ourAttr.Value, null, ancestorAttr.Value, merger.MergeSituation, merger.MergeSituation.AlphaUserId));
continue;
}
// They deleted. We did zip.
// Route tested (x1).
if(theirs != null) //if there is no theirs node, then attributes weren't actually removed
{
//Route tested (x1)
merger.EventListener.ChangeOccurred(new XmlAttributeDeletedReport(merger.MergeSituation.PathToFileInRepository, ancestorAttr));
ancestor.Attributes.Remove(ancestorAttr);
ours.Attributes.Remove(ourAttr);
}
continue;
}
if (ourAttr != null)
continue; // Route used.
// ourAttr == null
if (ancestorAttr.Value != theirAttr.Value)
{
// We deleted it, but at the same time, they changed it. So just add theirs in, under the principle of
// least data loss (an attribute can be a huge text element)
// Route tested (x1).
skipProcessingInOurs.Add(theirAttr.Name); // Make sure we don't process it again in 'ours' loop, below.
var importedAttribute = (XmlAttribute)ours.OwnerDocument.ImportNode(theirAttr.CloneNode(true), true);
ours.Attributes.Append(importedAttribute);
merger.ConflictOccurred(new RemovedVsEditedAttributeConflict(theirAttr.Name, null, theirAttr.Value, ancestorAttr.Value, merger.MergeSituation, merger.MergeSituation.BetaUserId));
continue;
}
// We deleted it. They did nothing.
// Route tested (x1).
merger.EventListener.ChangeOccurred(new XmlAttributeDeletedReport(merger.MergeSituation.PathToFileInRepository, ancestorAttr));
ancestor.Attributes.Remove(ancestorAttr);
theirs.Attributes.Remove(theirAttr);
}
var extantNode = ours ?? theirs ?? ancestor;
foreach (var theirAttr in XmlUtilities.GetAttrs(theirs))
{
// Will never return null, since it will use the default one, if it can't find a better one.
var mergeStrategy = merger.MergeStrategies.GetElementStrategy(extantNode);
var ourAttr = XmlUtilities.GetAttributeOrNull(ours, theirAttr.Name);
var ancestorAttr = XmlUtilities.GetAttributeOrNull(ancestor, theirAttr.Name);
if (ourAttr == null)
{
if (ancestorAttr == null)
{
// Route tested (x1).
skipProcessingInOurs.Add(theirAttr.Name); // Make sure we don't process it again in 'ours loop, below.
var importedAttribute = (XmlAttribute)ours.OwnerDocument.ImportNode(theirAttr.CloneNode(true), true);
ours.Attributes.Append(importedAttribute);
merger.EventListener.ChangeOccurred(new XmlAttributeAddedReport(merger.MergeSituation.PathToFileInRepository, theirAttr));
}
// NB: Deletes are all handled above in first loop.
continue;
}
if (ancestorAttr == null) // Both introduced this attribute
{
if (ourAttr.Value == theirAttr.Value)
{
// Route tested (x1).
merger.EventListener.ChangeOccurred(new XmlAttributeBothAddedReport(merger.MergeSituation.PathToFileInRepository, ourAttr));
continue;
}
// Both added, but not the same.
if (!mergeStrategy.AttributesToIgnoreForMerging.Contains(ourAttr.Name))
{
if (merger.MergeSituation.ConflictHandlingMode == MergeOrder.ConflictHandlingModeChoices.WeWin)
//.........这里部分代码省略.........
示例2: Run
/// <summary>
/// "Merge" elemement if it is 'atomic' and return true. Otherwise, do nothing and return false.
/// </summary>
/// <remarks>
/// <param name="ours" /> may be changed to <param name="theirs"/>,
/// if <param name="ours"/> is null and <param name="theirs"/> is not null.
/// </remarks>
/// <returns>'True' if the given elements were 'atomic'. Otherwise 'false'.</returns>
internal static void Run(XmlMerger merger, ref XmlNode ours, XmlNode theirs, XmlNode commonAncestor)
{
if (merger == null)
throw new ArgumentNullException("merger"); // Route tested.
if (ours == null && theirs == null && commonAncestor == null)
throw new ArgumentNullException(); // Route tested.
// One or two of the elements may be null.
// If commonAncestor is null and one of the others is null, then the other one added a new element.
// if ours and theirs are both null, they each deleted the element.
var nodeForStrategy = ours ?? (theirs ?? commonAncestor);
// Here is where we sort out the new 'IsAtomic' business of ElementStrategy.
// 1. Fetch the relevant ElementStrategy
var elementStrategy = merger.MergeStrategies.GetElementStrategy(nodeForStrategy);
if (!elementStrategy.IsAtomic)
throw new InvalidOperationException("This method class only handles elements that are atomic (basically binary type data that can't really be merged.)");
if (commonAncestor == null)
{
if (ours == null)
{
// They can't all be null, or there would have bene an expected thrown, above.
//if (theirs == null)
//{
// // Nobody did anything.
// return true;
//}
// They seem to have added a new one.
// Route tested (x2).
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(merger.MergeSituation.PathToFileInRepository, theirs));
ours = theirs; // They added it.
}
else
{
// Ours is not null.
if (theirs != null)
{
// Neither is theirs.
if (XmlUtilities.AreXmlElementsEqual(ours, theirs))
{
// Both added the same thing.
// Route tested (x2).
merger.EventListener.ChangeOccurred(new BothChangedAtomicElementReport(merger.MergeSituation.PathToFileInRepository, ours));
}
else
{
// Both added, but not the same thing.
if (merger.MergeSituation.ConflictHandlingMode == MergeOrder.ConflictHandlingModeChoices.WeWin)
{
// Route tested.
merger.ConflictOccurred(new BothEditedTheSameAtomicElement(ours.Name,
ours, theirs, null, merger.MergeSituation, elementStrategy, merger.MergeSituation.AlphaUserId));
}
else
{
// Route tested.
merger.ConflictOccurred(new BothEditedTheSameAtomicElement(ours.Name,
ours, theirs, null, merger.MergeSituation, elementStrategy, merger.MergeSituation.BetaUserId));
ours = theirs;
}
}
}
else
{
// We added. They are still null.
// Route tested (x2).
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(merger.MergeSituation.PathToFileInRepository, ours));
}
}
return; // Routed used (x2).
}
// commonAncestor != null from here on out.
if (ours == null && theirs == null)
{
// No problemo, since both deleted it.
// Route tested (x2).
merger.EventListener.ChangeOccurred(new XmlBothDeletionChangeReport(merger.MergeSituation.PathToFileInRepository, commonAncestor));
return;
}
// 2A1. Compare 'ours' with 'theirs'.
// If one is null, keep the other one, but only if it was edited.
var theirsAndCommonAreEqual = theirs != null && XmlUtilities.AreXmlElementsEqual(theirs, commonAncestor);
if (ours == null && !theirsAndCommonAreEqual)
{
// We deleted, they edited, so keep theirs under the least loss principle.
// Route tested (x2 WeWin & !WeWin).
merger.ConflictOccurred(new RemovedVsEditedElementConflict(theirs.Name, null, theirs,
commonAncestor,
merger.MergeSituation, elementStrategy,
merger.MergeSituation.BetaUserId));
//.........这里部分代码省略.........
示例3: DoMerge
internal static void DoMerge(XmlMerger merger, ref XmlNode ours, XmlNode theirs, XmlNode ancestor)
{
if (ours == null && theirs == null && ancestor == null)
return; // I don't think this is possible, but....
if (ancestor == null)
{
// Somebody added it.
if (ours == null && theirs != null)
{
// They added it.
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(merger.MergeSituation.PathToFileInRepository, theirs));
ours = theirs;
return;
}
if (theirs == null && ours != null)
{
// We added it.
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(merger.MergeSituation.PathToFileInRepository, ours));
return;
}
// Both added.
if (XmlUtilities.AreXmlElementsEqual(ours, theirs))
{
// Both added the same thing.
merger.EventListener.ChangeOccurred(new XmlBothAddedSameChangeReport(merger.MergeSituation.PathToFileInRepository, ours));
return;
}
// Both added it, but it isn't the same thing.
if (merger.MergeSituation.ConflictHandlingMode == MergeOrder.ConflictHandlingModeChoices.WeWin)
{
// We win.
merger.ConflictOccurred(new BothAddedMainElementButWithDifferentContentConflict(ours.Name, ours, theirs, merger.MergeSituation, merger.MergeStrategies.GetElementStrategy(ours), merger.MergeSituation.AlphaUserId));
}
else
{
// They win.
merger.ConflictOccurred(new BothAddedMainElementButWithDifferentContentConflict(ours.Name, theirs, ours, merger.MergeSituation, merger.MergeStrategies.GetElementStrategy(theirs), merger.MergeSituation.BetaUserId));
ours = theirs;
return;
}
return;
}
// ancestor is not null here.
if (ours == null)
{
if (theirs == null)
{
// Both deleted it. Add change report.
merger.EventListener.ChangeOccurred(new XmlBothDeletionChangeReport(merger.MergeSituation.PathToFileInRepository, ancestor));
}
else
{
// We deleted. We don't care if they made any changes, since such changes aren't legal.
merger.EventListener.ChangeOccurred(new XmlDeletionChangeReport(merger.MergeSituation.PathToFileInRepository, ancestor.ParentNode, ancestor));
}
return;
}
if (theirs == null)
{
// They deleted. We don't care if we made any changes, since such changes aren't legal.
merger.EventListener.ChangeOccurred(new XmlDeletionChangeReport(merger.MergeSituation.PathToFileInRepository, ancestor.ParentNode, ancestor));
ours = null;
return;
}
// Nothing is null here.
if (!XmlUtilities.AreXmlElementsEqual(ours, ancestor))
ours = ancestor; // Restore ours to ancestor, since ours was changed by some buggy client code or by a hand edit.
// At this point, we don't need to test if ancestor and theirs are the same, or not,
// since we have restored current (ours) to the original, or ours was the same as ancestor.
// There is probably no point to adding some kind of warning.
}
示例4: Run
private static XmlNode Run(XmlMerger merger, XmlNode ours, XmlNode theirs, XmlNode ancestor)
{
if (ours == null && theirs == null && ancestor == null)
return null;
if (ancestor == null)
{
return HandleCaseOfNoAncestor(merger, ours, theirs);
}
// ancestor is not null at this point.
var mergeSituation = merger.MergeSituation;
var pathToFileInRepository = mergeSituation.PathToFileInRepository;
if (ours == null && theirs == null)
{
// We both deleted main node.
// Route tested, but the MergeChildrenMethod adds the change report for us.
merger.EventListener.ChangeOccurred(new XmlBothDeletionChangeReport(pathToFileInRepository, ancestor));
return null;
}
if (ours == null)
{
return HandleOursNotPresent(merger, ancestor, theirs);
}
if (theirs == null)
{
return HandleTheirsNotPresent(merger, ancestor, ours);
}
// End of checking main parent node.
// ancestor, ours, and theirs all exist here.
var ourChild = GetElementChildren(ours).FirstOrDefault();
var theirChild = GetElementChildren(theirs).FirstOrDefault();
var ancestorChild = GetElementChildren(ancestor).FirstOrDefault();
if (ourChild == null && theirChild == null && ancestorChild == null)
{
return ours; // All three are childless.
}
if (ancestorChild == null)
{
return HandleCaseOfNoAncestorChild(merger, ours, ourChild, theirChild);
}
var mergeStrategyForChild = merger.MergeStrategies.GetElementStrategy(ancestorChild);
if (ourChild == null)
{
return HandleOurChildNotPresent(merger, ours, ancestor, theirChild, pathToFileInRepository, ancestorChild, mergeSituation, mergeStrategyForChild);
}
if (theirChild == null)
{
return HandleTheirChildNotPresent(merger, ours, ancestor, ancestorChild, ourChild, mergeSituation, mergeStrategyForChild, pathToFileInRepository);
}
// ancestorChild, ourChild, and theirChild all exist.
// But, it could be that we or they deleted and added something.
// Check for edit vs delete+add, or there can be two items in ours, which is not legal.
var match = mergeStrategyForChild.MergePartnerFinder.GetNodeToMerge(ourChild, ancestor, SetFromChildren.Get(ancestor));
if (match == null)
{
// we deleted it and added a new one.
if (XmlUtilities.AreXmlElementsEqual(theirChild, ancestorChild))
{
// Our delete+add wins, since they did nothing.
merger.EventListener.ChangeOccurred(new XmlDeletionChangeReport(pathToFileInRepository, ancestor, ancestorChild));
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(pathToFileInRepository, ourChild));
return ours;
}
// They edited old one, so they win over our delete+add.
merger.ConflictOccurred(new RemovedVsEditedElementConflict(theirChild.Name, theirChild, null, ancestorChild,
mergeSituation, mergeStrategyForChild,
mergeSituation.BetaUserId));
XmlUtilities.ReplaceOursWithTheirs(ours, ref ourChild, theirChild);
return ours;
}
match = mergeStrategyForChild.MergePartnerFinder.GetNodeToMerge(theirChild, ancestor, SetFromChildren.Get(ancestor));
if (match == null)
{
// they deleted it and added a new one.
if (XmlUtilities.AreXmlElementsEqual(ourChild, ancestorChild))
{
// Their delete+add wins, since we did nothing.
merger.EventListener.ChangeOccurred(new XmlDeletionChangeReport(pathToFileInRepository, ancestor, ancestorChild));
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(pathToFileInRepository, theirChild));
XmlUtilities.ReplaceOursWithTheirs(ours, ref ourChild, theirChild);
return ours;
}
// We edited old one, so we win over their delete+add.
merger.ConflictOccurred(new RemovedVsEditedElementConflict(ourChild.Name, ourChild, null, ancestorChild,
mergeSituation, mergeStrategyForChild,
mergeSituation.AlphaUserId));
return ours;
}
merger.MergeInner(ours, ref ourChild, theirChild, ancestorChild);
// Route tested. (UsingWith_NumberOfChildrenAllowed_ZeroOrOne_DoesNotThrowWhenParentHasOneChildNode)
return ours;
}
示例5: HandleCaseOfNoAncestor
private static XmlNode HandleCaseOfNoAncestor(XmlMerger merger, XmlNode ours, XmlNode theirs)
{
var mainNodeStrategy = merger.MergeStrategies.GetElementStrategy(ours ?? theirs);
var mergeSituation = merger.MergeSituation;
var pathToFileInRepository = mergeSituation.PathToFileInRepository;
if (ours == null)
{
// They added, we did nothing.
// Route tested, but the MergeChildrenMethod adds the change report for us.
// So, theory has it one can't get here from any normal place.
// But, keep it, in case MergeChildrenMethod gets 'fixed'.
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(pathToFileInRepository, theirs));
return theirs;
}
if (theirs == null)
{
// We added, they did nothing.
// Route tested.
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(pathToFileInRepository, ours));
return ours;
}
// Both added the special containing node.
// Remove children nodes to see if main containing nodes are the same.
if (XmlUtilities.AreXmlElementsEqual(ours, theirs))
{
// Route tested.
// Same content.
merger.EventListener.ChangeOccurred(new XmlBothAddedSameChangeReport(pathToFileInRepository, ours));
}
else
{
// Different content.
var ourChild = GetElementChildren(ours).FirstOrDefault();
var theirChild = GetElementChildren(theirs).FirstOrDefault();
var ourClone = MakeClone(ours);
var theirClone = MakeClone(theirs);
if (XmlUtilities.AreXmlElementsEqual(ourClone, theirClone))
{
// new main elements are the same, but not the contained child
merger.EventListener.ChangeOccurred(new XmlBothAddedSameChangeReport(pathToFileInRepository, ourClone));
if (ourChild == null && theirChild == null)
return ours; // Nobody added the child node.
if (ourChild == null)
{
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(pathToFileInRepository, theirChild));
ours.AppendChild(theirChild);
return ours;
}
if (theirChild == null)
{
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(pathToFileInRepository, ourChild));
return ours;
}
// both children exist, but are different.
var mergeStrategyForChild = merger.MergeStrategies.GetElementStrategy(ourChild);
if (merger.MergeSituation.ConflictHandlingMode == MergeOrder.ConflictHandlingModeChoices.WeWin)
{
// Do the clone thing on the two child nodes to see if the diffs are in the child or lower down.
var ourChildClone = MakeClone(ourChild);
var theirChildClone = MakeClone(theirChild);
if (XmlUtilities.AreXmlElementsEqual(ourChildClone, theirChildClone))
{
var ourChildReplacement = ourChild;
merger.MergeInner(ours, ref ourChildReplacement, theirChild, null);
if (!ReferenceEquals(ourChild, ourChildReplacement))
{
XmlUtilities.ReplaceOursWithTheirs(ours, ref ourChild, ourChildReplacement);
}
}
else
{
merger.ConflictOccurred(new BothAddedMainElementButWithDifferentContentConflict(ourChild.Name, ourChild, theirChild,
mergeSituation, mergeStrategyForChild,
mergeSituation.AlphaUserId));
}
}
else
{
// Do the clone thing on the two child nodes to see if the diffs are in the child or lower down.
var ourChildClone = MakeClone(ourChild);
var theirChildClone = MakeClone(theirChild);
if (XmlUtilities.AreXmlElementsEqual(ourChildClone, theirChildClone))
{
var ourChildReplacement = ourChild;
merger.MergeInner(ours, ref ourChildReplacement, theirChild, null);
if (!ReferenceEquals(ourChild, ourChildReplacement))
{
XmlUtilities.ReplaceOursWithTheirs(ours, ref ourChild, ourChildReplacement);
}
}
else
{
merger.ConflictOccurred(new BothAddedMainElementButWithDifferentContentConflict(ourChild.Name, ourChild, theirChild,
mergeSituation, mergeStrategyForChild,
mergeSituation.AlphaUserId));
XmlUtilities.ReplaceOursWithTheirs(ours, ref ourChild, theirChild);
}
}
return ours;
//.........这里部分代码省略.........
示例6: HandleTheirsNotPresent
private static XmlNode HandleTheirsNotPresent(XmlMerger merger, XmlNode ancestor, XmlNode ours)
{
// They deleted it,
var mergeSituation = merger.MergeSituation;
if (XmlUtilities.AreXmlElementsEqual(ancestor, ours))
{
// and we did nothing
// Route tested, but the MergeChildrenMethod adds the change report for us.
merger.EventListener.ChangeOccurred(new XmlDeletionChangeReport(mergeSituation.PathToFileInRepository, ancestor, ours));
return null;
}
// but we edited it.
merger.ConflictOccurred(new RemovedVsEditedElementConflict(ancestor.Name, ours, null, ancestor, mergeSituation, merger.MergeStrategies.GetElementStrategy(ancestor), mergeSituation.AlphaUserId));
return ours;
}
示例7: HandleTheirChildNotPresent
private static XmlNode HandleTheirChildNotPresent(XmlMerger merger, XmlNode ours, XmlNode ancestor,
XmlNode ancestorChild, XmlNode ourChild, MergeSituation mergeSituation,
IElementDescriber mergeStrategyForChild, string pathToFileInRepository)
{
if (XmlUtilities.AreXmlElementsEqual(ancestorChild, ourChild))
{
// They deleted it. We did nothing.
merger.EventListener.ChangeOccurred(new XmlDeletionChangeReport(pathToFileInRepository, ancestor, ancestorChild));
}
else
{
// edit vs delete conflict.
merger.ConflictOccurred(new EditedVsRemovedElementConflict(ourChild.Name, ourChild, null, ancestorChild,
mergeSituation, mergeStrategyForChild,
mergeSituation.AlphaUserId));
}
return ours;
}
示例8: HandleOurChildNotPresent
private static XmlNode HandleOurChildNotPresent(XmlMerger merger, XmlNode ours, XmlNode ancestor, XmlNode theirChild,
string pathToFileInRepository, XmlNode ancestorChild,
MergeSituation mergeSituation, IElementDescriber mergeStrategyForChild)
{
if (theirChild == null)
{
// Both deleted it.
merger.EventListener.ChangeOccurred(new XmlBothDeletionChangeReport(pathToFileInRepository, ancestorChild));
}
else
{
if (XmlUtilities.AreXmlElementsEqual(ancestorChild, theirChild))
{
// We deleted it. They did nothing.
merger.EventListener.ChangeOccurred(new XmlDeletionChangeReport(pathToFileInRepository, ancestor, ancestorChild));
}
else
{
// delete vs edit conflict.
merger.ConflictOccurred(new RemovedVsEditedElementConflict(theirChild.Name, theirChild, null, ancestorChild,
mergeSituation, mergeStrategyForChild,
mergeSituation.BetaUserId));
ours.AppendChild(theirChild);
}
}
return ours;
}
示例9: HandleCaseOfNoAncestorChild
private static XmlNode HandleCaseOfNoAncestorChild(XmlMerger merger, XmlNode ours, XmlNode ourChild, XmlNode theirChild)
{
var mergeSituation = merger.MergeSituation;
var pathToFileInRepository = mergeSituation.PathToFileInRepository;
var mergeStrategyForChild = merger.MergeStrategies.GetElementStrategy(ourChild ?? theirChild);
if (ourChild == null)
{
// they added child.
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(pathToFileInRepository, theirChild));
ours.AppendChild(theirChild);
return ours;
}
if (theirChild == null)
{
// We added child.
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(pathToFileInRepository, ourChild));
return ours;
}
// Both added child.
if (XmlUtilities.AreXmlElementsEqual(ourChild, theirChild))
{
// Both are the same.
merger.EventListener.ChangeOccurred(new XmlBothAddedSameChangeReport(pathToFileInRepository, ourChild));
return ours;
}
// Both are different.
if (XmlUtilities.IsTextLevel(ourChild, theirChild, null))
{
if (merger.MergeSituation.ConflictHandlingMode == MergeOrder.ConflictHandlingModeChoices.WeWin)
{
merger.ConflictOccurred(new XmlTextBothAddedTextConflict(ourChild.Name, ourChild, theirChild, mergeSituation,
mergeStrategyForChild, mergeSituation.AlphaUserId));
}
else
{
merger.ConflictOccurred(new XmlTextBothAddedTextConflict(theirChild.Name, theirChild, ourChild, mergeSituation,
mergeStrategyForChild, mergeSituation.BetaUserId));
XmlUtilities.ReplaceOursWithTheirs(ours, ref ourChild, theirChild);
}
}
else
{
if (merger.MergeSituation.ConflictHandlingMode == MergeOrder.ConflictHandlingModeChoices.WeWin)
{
var ourChildClone = MakeClone(ourChild);
var theirChildClone = MakeClone(theirChild);
if (XmlUtilities.AreXmlElementsEqual(ourChildClone, theirChildClone))
{
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(pathToFileInRepository, ourChild));
var ourChildReplacement = ourChild;
merger.MergeInner(ours, ref ourChildReplacement, theirChild, null);
if (!ReferenceEquals(ourChild, ourChildReplacement))
{
XmlUtilities.ReplaceOursWithTheirs(ours, ref ourChild, ourChildReplacement);
}
}
else
{
merger.ConflictOccurred(new BothAddedMainElementButWithDifferentContentConflict(ourChild.Name, ourChild, theirChild,
mergeSituation, mergeStrategyForChild,
mergeSituation.AlphaUserId));
}
}
else
{
var ourChildClone = MakeClone(ourChild);
var theirChildClone = MakeClone(theirChild);
if (XmlUtilities.AreXmlElementsEqual(ourChildClone, theirChildClone))
{
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(pathToFileInRepository, theirChild));
var ourChildReplacement = ourChild;
merger.MergeInner(ours, ref ourChildReplacement, theirChild, null);
if (!ReferenceEquals(ourChild, ourChildReplacement))
{
XmlUtilities.ReplaceOursWithTheirs(ours, ref ourChild, ourChildReplacement);
}
}
else
{
merger.ConflictOccurred(new BothAddedMainElementButWithDifferentContentConflict(theirChild.Name, theirChild, ourChild,
mergeSituation, mergeStrategyForChild,
mergeSituation.BetaUserId));
XmlUtilities.ReplaceOursWithTheirs(ours, ref ourChild, theirChild);
}
}
}
return ours;
}
示例10: Run
private static XmlNode Run(XmlMerger merger, XmlNode ours, XmlNode theirs, XmlNode ancestor)
{
if (ours == null && theirs == null && ancestor == null)
return null;
var ourChild = GetElementChildren(ours).FirstOrDefault();
var theirChild = GetElementChildren(theirs).FirstOrDefault();
var ancestorChild = GetElementChildren(ancestor).FirstOrDefault();
XmlNode ourReplacementChild;
if (ancestor == null)
{
if (ours == null)
{
// They added, we did nothing.
// Route tested, but the MergeChildrenMethod adds the change report for us.
// So, theory has it one can't get here from any normal place.
// But, keep it, in case MergeChildrenMethod gets 'fixed'.
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(merger.MergeSituation.PathToFileInRepository, theirs));
return theirs;
}
if (theirs == null)
{
// We added, they did nothing.
// Route tested.
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(merger.MergeSituation.PathToFileInRepository, ours));
return ours;
}
// Both added the special containing node.
// Route tested.
merger.EventListener.ChangeOccurred(new XmlBothAddedSameChangeReport(merger.MergeSituation.PathToFileInRepository, ours));
if (ourChild == null && theirChild == null && ancestorChild == null)
return null; // Route tested.
if (ourChild == null && theirChild != null)
{
// Route tested.
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(merger.MergeSituation.PathToFileInRepository, theirChild));
ours.AppendChild(theirChild);
return ours;
}
if (theirChild == null)
{
// Route tested.
merger.EventListener.ChangeOccurred(new XmlAdditionChangeReport(merger.MergeSituation.PathToFileInRepository, ourChild));
return ours;
}
// Both ourChild and theirChild exist, and may or may not be the same.
var mergeStrategy = merger.MergeStrategies.GetElementStrategy(ourChild);
var match = mergeStrategy.MergePartnerFinder.GetNodeToMerge(ourChild, theirs, SetFromChildren.Get(theirs));
if (match == null)
{
XmlNode winner;
string winnerId;
XmlNode loser;
// Work up conflict report (for both we and they win options), since the users didn't add the same thing.
if (merger.MergeSituation.ConflictHandlingMode == MergeOrder.ConflictHandlingModeChoices.WeWin)
{
winner = ourChild;
winnerId = merger.MergeSituation.AlphaUserId;
loser = theirChild;
}
else
{
winner = theirChild;
winnerId = merger.MergeSituation.BetaUserId;
loser = ourChild;
ours = theirs;
}
// Route tested.
merger.ConflictOccurred(new BothAddedMainElementButWithDifferentContentConflict(winner.Name, winner, loser, merger.MergeSituation, mergeStrategy, winnerId));
return ours;
}
// Matched nodes, as far as that goes. But, are they the same or not?
if (XmlUtilities.AreXmlElementsEqual(ourChild, theirChild))
{
// Both added the same thing.
// Route tested.
merger.EventListener.ChangeOccurred(new XmlBothAddedSameChangeReport(merger.MergeSituation.PathToFileInRepository, ourChild));
return ours;
}
// Move on down and merge them.
// Both messed with the inner stuff, but not the same way.
// Route tested.
ourReplacementChild = ourChild;
merger.MergeInner(ref ourReplacementChild, theirChild, ancestorChild);
if (!ReferenceEquals(ourChild, ourReplacementChild))
ours.ReplaceChild(ours.OwnerDocument.ImportNode(ourReplacementChild, true), ourChild);
return ours;
}
// ancestor is not null at this point.
// Check the inner nodes
if (ours == null && theirs == null)
{
//.........这里部分代码省略.........