public ConflictPresenter(IXmlChangeReport report, IRetrieveFileVersionsFromRepository fileRetriever) { _fileRetriever = fileRetriever; _report = report; // as XmlAdditionChangeReport; if (_report == null) { _conflict = new UnreadableConflict(null); } else { if (_report.ChildNode.Name == "conflict") // old style situation, only on Tok Pisin before Oct 2009 { _conflict = Conflict.CreateFromConflictElement(_report.ChildNode); } else { var conflictNode = _report.ChildNode.SelectSingleNode("data/conflict"); if (conflictNode != null) { _conflict = Conflict.CreateFromConflictElement(conflictNode); } else { _conflict = new UnreadableConflict(_report.ChildNode); } } } }
public void CreateFromConflictElement_ProducesDifferentConflictReports() { //Setup const string conflictNode1 = @"<conflict typeGuid='3d9ba4ae-4a25-11df-9879-0800200c9a66' class='Chorus.merge.xml.generic.BothEditedTheSameAtomicElement' relativeFilePath='Linguistics\TextCorpus\Text_74506f5d-3c43-4a4b-92ec-385aa1b1bf36.textincorpus' type='Both Edited the Same Atomic Element' guid='f63a2116-5917-4c67-845f-7b9ea456e96b' date='2012-07-06T20:13:49Z' whoWon='Gordon' htmlDetails='<head></head><body><div>Text "My text"</div></body>' contextPath='silfw://localhost/link?app=flex&database=current&server=&tool=default&guid=d36e3143-ec72-4187-8059-a1647d04a39c&tag=&label=Text "My text" Contents Paragraphs' contextDataLabel='Text "My text" Contents Paragraphs'> <MergeSituation alphaUserId='Gordon' betaUserId='Fred' alphaUserRevision='9fa7329596ff' betaUserRevision='7754ffdecf94' path='Linguistics\TextCorpus\Text_74506f5d-3c43-4a4b-92ec-385aa1b1bf36.textincorpus' conflictHandlingMode='WeWin' /> </conflict>" ; const string conflictNode2 = @"<conflict typeGuid='3d9ba4ae-4a25-11df-9879-0800200c9a66' class='Chorus.merge.xml.generic.BothEditedTheSameAtomicElement' relativeFilePath='Linguistics\Lexicon\Lexicon.lexdb' type='Both Edited the Same Atomic Element' guid='5186426d-f200-4d32-af17-9df145cdd80a' date='2012-07-03T19:17:04Z' whoWon='Gordon' htmlDetails='<head></head><body><div>Entry "text" Participle:</div></body>' contextPath='silfw://localhost/link?app=flex&database=current&server=&tool=default&guid=774efee3-0f2e-4dec-a548-c3b90fe0961a&tag=&label=Entry "text" Participle' contextDataLabel='Entry "text" Participle'> <MergeSituation alphaUserId='Gordon' betaUserId='Fred' alphaUserRevision='27de9e012ffc' betaUserRevision='ba8826e5fbf9' path='Linguistics\Lexicon\Lexicon.lexdb' conflictHandlingMode='WeWin' /> </conflict>" ; var doc = new XmlDocument(); doc.LoadXml(conflictNode1); var node1 = doc.DocumentElement as XmlNode; var doc2 = new XmlDocument(); doc2.LoadXml(conflictNode2); var node2 = doc2.DocumentElement as XmlNode; //SUT var conflict1 = Conflict.CreateFromConflictElement(node1); var conflict2 = Conflict.CreateFromConflictElement(node2); //verify Assert.IsFalse(ReferenceEquals(conflict1, conflict2), "Two different conflicts of the same type but different istances."); Assert.AreNotEqual(conflict1.Guid, conflict2.Guid); }
public void HandleUrl(Uri uri, string annotationFilePath) { var key = uri.Query.Substring(uri.Query.IndexOf('=') + 1); var data = (from item in _recentLinks where item.Key == key select item).FirstOrDefault(); if (data == null) { Debug.Fail("page has more links than we can currently handle"); return; // give up. } var content = data.Data; try { var doc = new XmlDocument(); var conflict = Conflict.CreateFromConflictElement(XmlUtilities.GetDocumentNodeFromRawXml(content, doc)); var html = @"<html>" + conflict.HtmlDetails + @"</html>"; if (HtmlAdjuster != null) { html = HtmlAdjuster(html); } if (string.IsNullOrEmpty(html)) { MessageBox.Show(LocalizationManager.GetString("Messages.NoDetailsRecorded", "Sorry, no conflict details are recorded for this conflict (it might be an old one). Here's the content:") + "\r\n" + content); return; } using (var conflictForm = new ConflictDetailsForm()) { doc.LoadXml(content); var detailAttr = doc.DocumentElement.Attributes["htmlDetails"]; if (detailAttr != null) { doc.DocumentElement.SetAttribute("htmlDetails", "...(see above)..."); } MemoryStream mStream = new MemoryStream(); var settings = new XmlWriterSettings() { NewLineOnAttributes = true, Encoding = Encoding.UTF8, Indent = true }; var writer = XmlWriter.Create(mStream, settings); doc.WriteContentTo(writer); writer.Flush(); mStream.Flush(); mStream.Position = 0; var prettyContent = new StreamReader(mStream).ReadToEnd(); // Insert the technical details into the original HTML right at the end. int endOfBody = html.LastIndexOf("</body>"); var techHtml = html.Substring(0, endOfBody) + "<div style='margin-top:10pt'>Source file: " + annotationFilePath.Replace("<", "<").Replace(">", ">") + "</div><PRE>" + prettyContent.Replace("<", "<").Replace(">", ">") + "</PRE>" + html.Substring(endOfBody); conflictForm.TechnicalDetails = techHtml; conflictForm.SetDocumentText(html); conflictForm.ShowDialog(Form.ActiveForm); return; } } catch (Exception) { } MessageBox.Show(LocalizationManager.GetString("Messages.DetailsNotWorking", "Sorry, conflict details aren't working for this conflict (it might be an old one). Here's the content:") + "\r\n" + content); //uri.ToString()); }