Пример #1
0
        protected virtual EditPageRetvals DoLogEntry(LogEntry logEntry, string logTitle, string logDetails, int pageNumber,
            DateTime startDate, string uploadTo, string editSummary, string username,
            bool addLogArticlesToAnAWBList, IAutoWikiBrowser awb, string sender)
        {
            AWBLogListener awbLogListener = null;

            try
            {
                editor.Open(logEntry.Location, true);
                editor.Wait();

                string strExistingText = editor.Page.Text;

                if (DoAWBLogListener(addLogArticlesToAnAWBList, awb))
                {
                    if (string.IsNullOrEmpty(sender))
                        sender = "WikiFunctions DLL";
                    awbLogListener = new AWBLogListener(logEntry.Location);
                }

                Application.DoEvents();

                string tableAddition = "|-" + NewCell + "[[" + uploadTo + "|" + logTitle + "]]" + NewCell +
                    logDetails + NewCell + "[[" + uploadTo + "|" + pageNumber + "]]" +
                    (logEntry.LogUserName ? NewCell + "[[User:"******"|" + username + "]]" : "") +
                    NewCell + string.Format("[[{0:d MMMM}]] [[{0:yyyy}]]", startDate) +
                    Environment.NewLine + BotTag;

                SaveInfo save;

                if (strExistingText.Contains(BotTag))
                {
                    save = editor.SynchronousEditor.Save(strExistingText.Replace(BotTag, tableAddition), editSummary, false, WatchOptions.NoChange);
                }
                else
                {
                    save = editor.SynchronousEditor.Save(strExistingText + Environment.NewLine + "<!--bottag-->" +
                                Environment.NewLine + "{| class=\"wikitable\" width=\"100%\"" +
                                Environment.NewLine +
                                (logEntry.LogUserName ? TableHeaderUserName : TableHeaderNoUserName) +
                                Environment.NewLine + tableAddition, editSummary, false, WatchOptions.NoChange);
                }

                EditPageRetvals retval = new EditPageRetvals
                {
                    Article = logEntry.Location,
                    DiffLink = editor.URL + "index.php?oldid=" + save.NewId + "&diff=prev",
                    ResponseText = save.ResponseXml.OuterXml
                };

                try
                {
                    if (awbLogListener != null)
                    {
                        awbLogListener.WriteLine("Log entry uploaded", sender);
                        //AWB.AddLogItem(true, AWBLogListener);
                    }
                }
                catch { } // errors shouldn't happen here, but even if they do we want to avoid entering the outer catch block

                logEntry.Success=true;
                return retval;
            }
            catch (Exception ex)
            {
                if (awbLogListener != null)
                    AWBLogListenerUploadFailed(ex, sender, awbLogListener, awb);
                throw;
            }
        }
Пример #2
0
        protected virtual EditPageRetvals DoLogEntry(LogEntry logEntry, string logTitle, string logDetails, int pageNumber,
                                                     DateTime startDate, string uploadTo, string editSummary, string username,
                                                     bool addLogArticlesToAnAWBList, IAutoWikiBrowser awb, string sender)
        {
            AWBLogListener awbLogListener = null;

            try
            {
                editor.Open(logEntry.Location);
                editor.Wait();

                string strExistingText = editor.Page.Text;

                if (DoAWBLogListener(addLogArticlesToAnAWBList, awb))
                {
                    if (string.IsNullOrEmpty(sender))
                    {
                        sender = "WikiFunctions DLL";
                    }
                    awbLogListener = new AWBLogListener(logEntry.Location);
                }

                Application.DoEvents();

                string tableAddition = "|-" + NewCell + "[[" + uploadTo + "|" + logTitle + "]]" + NewCell +
                                       logDetails + NewCell + "[[" + uploadTo + "|" + pageNumber + "]]" +
                                       (logEntry.LogUserName ? NewCell + "[[User:"******"|" + username + "]]" : "") +
                                       NewCell + string.Format("[[{0:d MMMM}]] [[{0:yyyy}]]", startDate) +
                                       Environment.NewLine + BotTag;

                SaveInfo save;

                if (strExistingText.Contains(BotTag))
                {
                    save = editor.SynchronousEditor.Save(strExistingText.Replace(BotTag, tableAddition), editSummary, false, WatchOptions.NoChange);
                }
                else
                {
                    save = editor.SynchronousEditor.Save(strExistingText + Environment.NewLine + "<!--bottag-->" +
                                                         Environment.NewLine + "{| class=\"wikitable\" width=\"100%\"" +
                                                         Environment.NewLine +
                                                         (logEntry.LogUserName ? TableHeaderUserName : TableHeaderNoUserName) +
                                                         Environment.NewLine + tableAddition, editSummary, false, WatchOptions.NoChange);
                }

                EditPageRetvals retval = new EditPageRetvals
                {
                    Article      = logEntry.Location,
                    DiffLink     = editor.URL + "index.php?oldid=" + save.NewId + "&diff=prev",
                    ResponseText = save.ResponseXml.OuterXml
                };

                try
                {
                    if (awbLogListener != null)
                    {
                        awbLogListener.WriteLine("Log entry uploaded", sender);
                        //AWB.AddLogItem(true, AWBLogListener);
                    }
                }
                catch { } // errors shouldn't happen here, but even if they do we want to avoid entering the outer catch block

                logEntry.Success = true;
                return(retval);
            }
            catch (Exception ex)
            {
                if (awbLogListener != null)
                {
                    AWBLogListenerUploadFailed(ex, sender, awbLogListener, awb);
                }
                throw;
            }
        }