private void PrepareIndexUsingPathNameSource(out Dictionary <string, byte[]> childIndex) { const int estimatedObjectCount = 400; var fileInfo = new FileInfo(_childPathname); childIndex = new Dictionary <string, byte[]>((int)(fileInfo.Length / estimatedObjectCount), StringComparer.OrdinalIgnoreCase); using (var prepper = new MakeRecordDictionary(childIndex, _childPathname, _firstElementTag, _startTag, _identfierAttribute)) { prepper.ShouldContinueAfterDuplicateKey = s => { _eventListener.WarningOccurred(new MergeWarning(_childPathname + ": " + s)); return(true); }; prepper.Run(); } }
/// <summary> /// Add warning. /// </summary> public static void AddWarningToListener(IMergeEventListener listener, IConflict warning, XmlNode oursContext, XmlNode theirsContext, XmlNode ancestorContext, IGenerateHtmlContext htmlContextGenerator) { // NB: All three of these are crucially ordered. listener.RecordContextInConflict(warning); warning.MakeHtmlDetails(oursContext, theirsContext, ancestorContext, htmlContextGenerator); listener.WarningOccurred(warning); }
private static Dictionary<string, string> MakeRecordDictionary(IMergeEventListener mainMergeEventListener, IMergeStrategy mergeStrategy, string pathname, string firstElementMarker, string recordStartingTag, string identifierAttribute) { var records = new Dictionary<string, string>(EstimatedObjectCount(pathname), StringComparer.InvariantCultureIgnoreCase); using (var fastSplitter = new FastXmlElementSplitter(pathname)) { bool foundOptionalFirstElement; foreach (var record in fastSplitter.GetSecondLevelElementStrings(firstElementMarker, recordStartingTag, out foundOptionalFirstElement)) { if (foundOptionalFirstElement) { var key = firstElementMarker.ToLowerInvariant(); if (records.ContainsKey(key)) { mainMergeEventListener.WarningOccurred( new MergeWarning(string.Format("{0}: There is more than one optional first element '{1}'", pathname, key))); } else { if (RemoveAmbiguousChildNodes) { var possiblyRevisedRecord = RemoveAmbiguousChildren(mainMergeEventListener, mergeStrategy.GetStrategies(), record, pathname); records.Add(key, possiblyRevisedRecord); } else { records.Add(key, record); } } foundOptionalFirstElement = false; } else { var attrValues = XmlUtils.GetAttributes(record, new HashSet<string> {"dateDeleted", identifierAttribute}); // Eat tombstones. if (attrValues["dateDeleted"] != null) continue; var identifier = attrValues[identifierAttribute]; if (string.IsNullOrEmpty(identifierAttribute)) { mainMergeEventListener.WarningOccurred( new MergeWarning(string.Format("{0}: There was no identifier for the record", pathname))); continue; } if (records.ContainsKey(identifier)) { mainMergeEventListener.WarningOccurred( new MergeWarning(string.Format("{0}: There is more than one element with the identifier '{1}'", pathname, identifier))); } else { if (RemoveAmbiguousChildNodes) { var possiblyRevisedRecord = RemoveAmbiguousChildren(mainMergeEventListener, mergeStrategy.GetStrategies(), record, pathname); records.Add(identifier, possiblyRevisedRecord); } else { records.Add(identifier, record); } } } } } return records; }