當前位置: 首頁>>代碼示例>>C#>>正文


C# ApiEdit.Open方法代碼示例

本文整理匯總了C#中WikiFunctions.API.ApiEdit.Open方法的典型用法代碼示例。如果您正苦於以下問題:C# ApiEdit.Open方法的具體用法?C# ApiEdit.Open怎麽用?C# ApiEdit.Open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WikiFunctions.API.ApiEdit的用法示例。


在下文中一共展示了ApiEdit.Open方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ProcessArticle

        public string ProcessArticle(IAutoWikiBrowser sender, IProcessArticleEventArgs eventargs)
        {
            if (!Enabled) return eventargs.ArticleText;

            if (username == "" || password == "")
            {
                MessageBox.Show("Source wiki username and/or password not set. Turning off the plugin.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                disablePlugin();
                return eventargs.ArticleText;
            }

            String linkTitle;
            String linkBody;
            String sourceText = eventargs.ArticleText;
            String url = String.Format("http://{0}.wikipedia.org/w/", SourceLanguage);
            ApiEdit sourceWiki = new ApiEdit(url);

            try
            {
                sourceWiki.Login(username, password);
            }
            catch (LoginException e)
            {
                MessageBox.Show("Source wiki username and/or password incorrect. Turning off the plugin.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                disablePlugin();
                return eventargs.ArticleText;
            }

            #if DEBUG_OUTPUT_DIALOG
            DebugOutput dlg = new DebugOutput();
            dlg.Show(sender.Form);
            #endif

            String langCode = Variables.LangCode.ToString();
            Regex r = new Regex(String.Format(@"\[\[{0}:([^\]]+)\]\]", langCode));
            Match m;
            String replaceReg;
            String replaceTo;

            string[] arr = { eventargs.ArticleTitle };
            LinksOnPageListProvider linksProvider = new LinksOnPageListProvider();
            List<Article> links = linksProvider.MakeList(arr);

            // Message
            AWBForm.StartProgressBar();
            AWBForm.StatusLabelText = String.Format("Translating {0} links...", links.Count);

            #if DEBUG_OUTPUT_DIALOG
            dlg.StartSection(string.Format("Article {0}", eventargs.ArticleTitle));
            #endif

            foreach (Article link in links)
            {
            #if DEBUG_OUTPUT_DIALOG
                dlg.StartSection(string.Format("Link: {0}", link.Name));
            #endif
                linkTitle = link.Name;
                linkBody = sourceWiki.Open(linkTitle);
                m = r.Match(linkBody);
                if (m.Success)
                {
            #if DEBUG_OUTPUT_DIALOG
                    dlg.AddSection("From: ", linkTitle);
                    dlg.AddSection("To: ", m.Groups[1].ToString());
            #endif
                    replaceReg = String.Format(@"\[\[{0}\]\]", linkTitle);
                    replaceTo = String.Format("[[{0}|{1}]]", m.Groups[1], linkTitle);
                    sourceText = Regex.Replace(sourceText, replaceReg, replaceTo, RegexOptions.IgnoreCase);

                    replaceReg = String.Format(@"\[\[{0}\|([^\]]+)\]\]", linkTitle);
                    replaceTo = String.Format("[[{0}|$1]]", m.Groups[1], linkTitle);
                    sourceText = Regex.Replace(sourceText, replaceReg, replaceTo, RegexOptions.IgnoreCase);
                }
            #if DEBUG_OUTPUT_DIALOG
                else {
                    dlg.AddSection("No match", "");
                }
            #endif
            #if DEBUG_OUTPUT_DIALOG
                dlg.EndSection();
            #endif
                Application.DoEvents();
            }
            #if DEBUG_OUTPUT_DIALOG
            dlg.EndSection();
            #endif
            AWBForm.StopProgressBar();
            AWBForm.StatusLabelText = "";
            eventargs.EditSummary = "Automatic translation";
            return sourceText;
        }
開發者ID:leafnode,項目名稱:AWB-Translate-Plugin,代碼行數:91,代碼來源:TranslatorCore.cs


注:本文中的WikiFunctions.API.ApiEdit.Open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。