当前位置: 首页>>代码示例>>C#>>正文


C# XmlMerger.MergeFiles方法代码示例

本文整理汇总了C#中Chorus.merge.xml.generic.XmlMerger.MergeFiles方法的典型用法代码示例。如果您正苦于以下问题:C# XmlMerger.MergeFiles方法的具体用法?C# XmlMerger.MergeFiles怎么用?C# XmlMerger.MergeFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chorus.merge.xml.generic.XmlMerger的用法示例。


在下文中一共展示了XmlMerger.MergeFiles方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AllFilesMissingThrows

 public void AllFilesMissingThrows()
 {
     var merger = new XmlMerger(new NullMergeSituation());
     Assert.Throws<InvalidOperationException>(() => merger.MergeFiles(null, null, null));
 }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:5,代码来源:XmlMergerTests.cs

示例2: Do3WayMerge

        /// <summary>
        /// Do a 3-file merge, placing the result over the "ours" file and returning an error status
        /// </summary>
        /// <remarks>Implementations can exit with an exception, which the caller will catch and deal with.
        /// The must not have any UI, no interaction with the user.</remarks>
        public void Do3WayMerge(MergeOrder mergeOrder)
        {
            if (mergeOrder == null)
                throw new ArgumentNullException("mergeOrder");

            bool addedCollationAttr;
            PreMergeFile(mergeOrder, out addedCollationAttr);

            var merger = new XmlMerger(mergeOrder.MergeSituation);
            SetupElementStrategies(merger);

            merger.EventListener = mergeOrder.EventListener;
            XmlMergeService.RemoveAmbiguousChildNodes = true;
            var result = merger.MergeFiles(mergeOrder.pathToOurs, mergeOrder.pathToTheirs, mergeOrder.pathToCommonAncestor);
            using (var writer = XmlWriter.Create(mergeOrder.pathToOurs, CanonicalXmlSettings.CreateXmlWriterSettings()))
            {
                var nameSpaceManager = new XmlNamespaceManager(new NameTable());
                nameSpaceManager.AddNamespace("palaso", "urn://palaso.org/ldmlExtensions/v1");
                nameSpaceManager.AddNamespace("palaso2", "urn://palaso.org/ldmlExtensions/v2");
                nameSpaceManager.AddNamespace("fw", "urn://fieldworks.sil.org/ldmlExtensions/v1");
                nameSpaceManager.AddNamespace("sil", "urn://www.sil.org/ldml/0.1");

                var readerSettings = CanonicalXmlSettings.CreateXmlReaderSettings(ConformanceLevel.Auto);
                readerSettings.NameTable = nameSpaceManager.NameTable;
                readerSettings.XmlResolver = null;
                readerSettings.ProhibitDtd = false;
                if (addedCollationAttr)
                {
                    // Remove the optional 'key' attr we added.
                    var adjustedCollation = result.MergedNode.SelectSingleNode("collations")
                        .SelectNodes("collation")
                        .Cast<XmlNode>().FirstOrDefault(collation => collation.Attributes["type"].Value == "standard");
                    if (adjustedCollation != null)
                    {
                        adjustedCollation.Attributes.Remove(adjustedCollation.Attributes["type"]);
                    }
                }
                using (var nodeReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(result.MergedNode.OuterXml)), readerSettings))
                {
                    writer.WriteNode(nodeReader, false);
                }
            }
        }
开发者ID:regnrand,项目名称:chorus,代码行数:48,代码来源:LdmlFileHandler.cs

示例3: AncestorIsEmptyFileAndWeBothAddedDifferentContentWithTheyWinHasOneConflictReport

 public void AncestorIsEmptyFileAndWeBothAddedDifferentContentWithTheyWinHasOneConflictReport()
 {
     const string data =
     @"<?xml version='1.0' encoding='utf-8'?>
     <data />";
     using (var ancestor = new TempFile())
     using (var ours = new TempFile())
     using (var theirs = new TempFile())
     {
         File.WriteAllText(ancestor.Path, "");
         File.WriteAllText(ours.Path, data.Replace("<data />", "<data>our addition</data>"));
         File.WriteAllText(theirs.Path, data.Replace("<data />", "<data>their addition</data>"));
         var listener = new ListenerForUnitTests();
         var merger = new XmlMerger(new NullMergeSituationTheyWin())
         {
             EventListener = listener
         };
         var result = merger.MergeFiles(ours.Path, theirs.Path, ancestor.Path);
         Assert.IsNotNull(result);
         listener.AssertExpectedChangesCount(0);
         listener.AssertExpectedConflictCount(1);
         listener.AssertFirstConflictType<BothAddedMainElementButWithDifferentContentConflict>();
         Assert.IsTrue(result.MergedNode.OuterXml.Contains("their addition"));
     }
 }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:25,代码来源:XmlMergerTests.cs

示例4: AncestorIsNotXmlThrows

 public void AncestorIsNotXmlThrows()
 {
     const string data =
     @"<?xml version='1.0' encoding='utf-8'?>
     <data />";
     using (var ancestor = new TempFile())
     using (var ours = new TempFile())
     using (var theirs = new TempFile())
     {
         File.WriteAllText(ancestor.Path, "Not xml stuff.");
         File.WriteAllText(ours.Path, data);
         File.WriteAllText(theirs.Path, data);
         var merger = new XmlMerger(new NullMergeSituation());
         Assert.Throws<XmlException>(() => merger.MergeFiles(ours.Path, theirs.Path, ancestor.Path));
     }
 }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:16,代码来源:XmlMergerTests.cs

示例5: AncestorIsEmptyFileAndBothAddedSameThingHasOneChangeReport

 public void AncestorIsEmptyFileAndBothAddedSameThingHasOneChangeReport()
 {
     const string data =
     @"<?xml version='1.0' encoding='utf-8'?>
     <data />";
     using (var ancestor = new TempFile())
     using (var ours = new TempFile())
     using (var theirs = new TempFile())
     {
         File.WriteAllText(ancestor.Path, "");
         File.WriteAllText(ours.Path, data);
         File.WriteAllText(theirs.Path, data);
         var listener = new ListenerForUnitTests();
         var merger = new XmlMerger(new NullMergeSituation())
             {
                 EventListener = listener
             };
         var result = merger.MergeFiles(ours.Path, theirs.Path, ancestor.Path);
         Assert.IsNotNull(result);
         listener.AssertExpectedChangesCount(1);
         listener.AssertFirstChangeType<XmlBothAddedSameChangeReport>();
         listener.AssertExpectedConflictCount(0);
     }
 }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:24,代码来源:XmlMergerTests.cs

示例6: WeChangedTheyDeletedFileHasOneConflictReport

 public void WeChangedTheyDeletedFileHasOneConflictReport()
 {
     const string data =
     @"<?xml version='1.0' encoding='utf-8'?>
     <data />";
     using (var ancestor = new TempFile())
     using (var ours = new TempFile())
     using (var theirs = new TempFile())
     {
         File.WriteAllText(ancestor.Path, data);
         File.WriteAllText(ours.Path, data.Replace("<data />", "<data>our change</data>"));
         File.WriteAllText(theirs.Path, "");
         var listener = new ListenerForUnitTests();
         var merger = new XmlMerger(new NullMergeSituation())
         {
             EventListener = listener
         };
         var result = merger.MergeFiles(ours.Path, theirs.Path, ancestor.Path);
         Assert.IsNotNull(result);
         listener.AssertExpectedChangesCount(0);
         listener.AssertExpectedConflictCount(1);
         listener.AssertFirstConflictType<EditedVsRemovedElementConflict>();
         Assert.IsTrue(result.MergedNode.OuterXml.Contains("our change"));
     }
 }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:25,代码来源:XmlMergerTests.cs

示例7: Do3WayMerge

        /// <summary>
        /// Do a 3-file merge, placing the result over the "ours" file and returning an error status
        /// </summary>
        /// <remarks>Implementations can exit with an exception, which the caller will catch and deal with.
        /// The must not have any UI, no interaction with the user.</remarks>
        public void Do3WayMerge(MergeOrder mergeOrder)
        {
            Guard.AgainstNull(mergeOrder, "mergeOrder");

            if (mergeOrder == null)
                throw new ArgumentNullException("mergeOrder");

            var merger = new XmlMerger(mergeOrder.MergeSituation);
            SetupElementStrategies(merger);

            merger.EventListener = mergeOrder.EventListener;

            using(var oursXml = new HtmlFileForMerging(mergeOrder.pathToOurs))
            using(var theirsXml = new HtmlFileForMerging(mergeOrder.pathToTheirs))
            using (var ancestorXml = new HtmlFileForMerging(mergeOrder.pathToCommonAncestor))
            {
                var result = merger.MergeFiles(oursXml.GetPathToXHtml(), theirsXml.GetPathToXHtml(), ancestorXml.GetPathToXHtml());

                CarefullyWriteOutResultingXml(oursXml, result);

                //now convert back to html
                oursXml.SaveHtml();
            }
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:29,代码来源:BloomHtmlFileTypeHandler.cs

示例8: Do3WayMerge

        /// <summary>
        /// Do a 3-file merge, placing the result over the "ours" file and returning an error status
        /// </summary>
        /// <remarks>Implementations can exit with an exception, which the caller will catch and deal with.
        /// The must not have any UI, no interaction with the user.</remarks>
        public void Do3WayMerge(MergeOrder mergeOrder)
        {
            if (mergeOrder == null)
                throw new ArgumentNullException("mergeOrder");
            PreMergeFile(mergeOrder);

            var merger = new XmlMerger(mergeOrder.MergeSituation);
            SetupElementStrategies(merger);

            merger.EventListener = mergeOrder.EventListener;
            var result = merger.MergeFiles(mergeOrder.pathToOurs, mergeOrder.pathToTheirs, mergeOrder.pathToCommonAncestor);
            using (var writer = XmlWriter.Create(mergeOrder.pathToOurs, CanonicalXmlSettings.CreateXmlWriterSettings()))
            {
                var nameSpaceManager = new XmlNamespaceManager(new NameTable());
                nameSpaceManager.AddNamespace("palaso", "urn://palaso.org/ldmlExtensions/v1");
                nameSpaceManager.AddNamespace("fw", "urn://fieldworks.sil.org/ldmlExtensions/v1");

                var readerSettings = CanonicalXmlSettings.CreateXmlReaderSettings(ConformanceLevel.Auto);
                readerSettings.NameTable = nameSpaceManager.NameTable;
                readerSettings.XmlResolver = null;
                readerSettings.ProhibitDtd = false;
                using (var nodeReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(result.MergedNode.OuterXml)), readerSettings))
                {
                    writer.WriteNode(nodeReader, false);
                }
            }
        }
开发者ID:sillsdev,项目名称:chack,代码行数:32,代码来源:LdmlFileHandler.cs

示例9: Do3WayMerge

        /// <summary>
        /// Do a 3-file merge, placing the result over the "ours" file and returning an error status
        /// </summary>
        /// <remarks>Implementations can exit with an exception, which the caller will catch and deal with.
        /// The must not have any UI, no interaction with the user.</remarks>
        public void Do3WayMerge(MergeOrder mergeOrder)
        {
            if (mergeOrder == null)
                throw new ArgumentNullException("mergeOrder");

            bool addedCollationAttr;
            PreMergeFile(mergeOrder, out addedCollationAttr);

            var merger = new XmlMerger(mergeOrder.MergeSituation);
            SetupElementStrategies(merger);

            merger.EventListener = mergeOrder.EventListener;
            XmlMergeService.RemoveAmbiguousChildNodes = true;
            var result = merger.MergeFiles(mergeOrder.pathToOurs, mergeOrder.pathToTheirs, mergeOrder.pathToCommonAncestor);
            using (var writer = XmlWriter.Create(mergeOrder.pathToOurs, CanonicalXmlSettings.CreateXmlWriterSettings()))
            {
                var readerSettings = CanonicalXmlSettings.CreateXmlReaderSettings(ConformanceLevel.Auto);
                readerSettings.XmlResolver = null;
                readerSettings.ProhibitDtd = false;
                using (var nodeReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(result.MergedNode.OuterXml)), readerSettings))
                {
                    writer.WriteNode(nodeReader, false);
                }
            }
        }
开发者ID:regnrand,项目名称:chorus,代码行数:30,代码来源:UserLexiconSettingsFileHandler.cs


注:本文中的Chorus.merge.xml.generic.XmlMerger.MergeFiles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。