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


C# Page.GetSectionByName方法代码示例

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


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

示例1: ProcessPage

        protected override void ProcessPage(Page p, EditStatus edit)
        {
            if (p.GetNamespace() != 0) return;
            p.Load();

            //ignore pages which already have {{standort}}
            if (p.GetAllTemplates().Any(t => t.Title == "Standort")) return;

            var section = p.GetSectionByName("Standort", false);
            if (section == null) return;

            var standorte = new List<string>();

            Match lastMatch = null;
            var prependText = "";
            var remainingText = "";
            var foundNonSchauplatz = false;
            var compactTemplate = true;

            var lines = section.Content.GetLines().Skip(1).ToList();
            var addAdditionalStar = !lines.First().Contains('*') && lines.First().Length > 2 && PageIsSchauplatz(lines.First().Trim('[', ']', '\'', ';'));

            foreach (var line in lines)
            {
                //just add the line to the remaining text as soon as we found a non schauplatz
                if (foundNonSchauplatz) remainingText += "\r\n" + line;

                if (string.IsNullOrWhiteSpace(line))
                    continue;

                var match = StandortItemRegex.Match((addAdditionalStar ? "*" : "") + line);

                //if the line is no listitem and no schauplatz, we are done with the standort list
                //all remaining text will be added to remainingText
                if (!match.Success || !PageIsSchauplatz(match.Groups[2].Value))
                {
                    if (standorte.Count == 0 && lastMatch == null)
                    {
                        prependText += line + "\r\n";
                    }
                    else
                    {
                        foundNonSchauplatz = true;
                        remainingText = line;
                    }
                    continue;
                }

                var added = false;

                //has a descripting text
                if (match.Groups[3].Length > 0)
                {
                    standorte.Add(match.Groups[2].Value + " = " + match.Groups[4].Value);
                    compactTemplate = false;
                    added = true;
                }
                if (lastMatch != null && match.Groups[1].Length <= lastMatch.Groups[1].Length)
                {
                    //add last
                    standorte.Add(lastMatch.Groups[2].Value + (lastMatch.Groups[4].Length > 0 ? " = " + lastMatch.Groups[4].Value : ""));
                    lastMatch = null;
                }

                lastMatch = !added ? match : null;
            }

            if (lastMatch != null)
            {
                standorte.Add(lastMatch.Groups[2].Value + (lastMatch.Groups[4].Length > 0 ? " = " + lastMatch.Groups[4].Value : ""));
            }

            if (standorte.Count == 0) return;

            if (!foundNonSchauplatz) remainingText += "\r\n";

            if (standorte.Count > 3) compactTemplate = false;

            //build the new section content
            section.Content = section.Content.GetLines().First() + "\r\n" + prependText +
                              (compactTemplate
                                   ? "{{Standort|" + string.Join("|", standorte) + "}}"
                                   : "{{Standort\r\n | " + string.Join("\r\n | ", standorte) + "\r\n}}")
                              + "\r\n" + remainingText;

            section.Save();

            edit.Save = true;
            edit.EditComment = "/* "+section.Title+" */ [[Benutzer: Darthmaim Bot/Projekte#Standort|Standortvorlage eingebaut]] ("+standorte.Count+")";
        }
开发者ID:knabbi,项目名称:GW2WBot,代码行数:90,代码来源:StandortTemplateJob.cs


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