Наследование: System.Windows.Forms.Form
Пример #1
0
        private bool LoadSuccess()
        {
            try
            {
                string HTML = null;
                if (webBrowserEdit.Document != null && webBrowserEdit.Document.Body != null)
                    HTML = webBrowserEdit.Document.Body.InnerHtml;

                if (string.IsNullOrEmpty(HTML) || IsReadOnlyDB(HTML))
                {
                    if (retries < 10)
                    {
                        StartDelayedRestartTimer(null, null);
                        retries++;
                        Start();
                        return false;
                    }
                    else
                    {
                        retries = 0;
                        if (!string.IsNullOrEmpty(HTML)) SkipPage("Database is locked, tried 10 times");
                        else
                        {
                            MessageBox.Show("Loading edit page failed after 10 retries. Processing stopped.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Stop();
                        }
                        return false;
                    }
                }
                else if (HTML.Contains("Sorry! We could not process your edit due to a loss of session data. Please try again. If it still doesn't work, try logging out and logging back in."))
                {
                    Save();
                    return false;
                }

                //check we are still logged in
                try
                {
                    if (!webBrowserEdit.GetLogInStatus())
                    {
                        Variables.User.LoggedIn = false;
                        NudgeTimer.Stop();
                        Start();
                        return false;
                    }
                }
                catch
                {
                    // No point writing to log listener I think, as it gets destroyed when we Stop?
                    if (mErrorGettingLogInStatus)
                    {
                        MessageBox.Show("Error getting login status", "Error", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        // Stop AWB and reset the state variable:
                        Stop(); mErrorGettingLogInStatus = false;
                    }
                    else
                    {
                        mErrorGettingLogInStatus = true; // prevent start / error / start / error loop
                        Stop();
                        Start();
                    }
                    return false;
                }

                mErrorGettingLogInStatus = false;

                if (!webBrowserEdit.Url.ToString().StartsWith(Variables.URLLong))
                {
                    SkipPage("Interwiki in page title");
                    return false;
                }

                if (webBrowserEdit.NewMessage)
                {//check if we have any messages
                    NudgeTimer.Stop();
                    Variables.User.WikiStatus = false;
                    UpdateButtons(null, null);
                    webBrowserEdit.Document.Write("");
                    this.Focus();

                    using (TalkMessage DlgTalk = new TalkMessage())
                    {
                        if (DlgTalk.ShowDialog() == DialogResult.Yes)
                            Tools.OpenUserTalkInBrowser();
                        else
                            Process.Start("iexplore", Variables.GetUserTalkURL());
                    }
                    return false;
                }
                if (!webBrowserEdit.HasArticleTextBox)
                {
                    if (!BotMode)
                    {
                        SkipPage("There was a problem loading the page");
                        return false;
                    }

                    StatusLabelText = "There was a problem loading the page. Re-starting.";
                    StartDelayedRestartTimer(null, null);
                    return false;
                }

                bool wpTextbox1IsNull = (webBrowserEdit.Document.GetElementById("wpTextbox1").InnerText == null);

                if (wpTextbox1IsNull && radSkipNonExistent.Checked)
                {//check if it is a non-existent page, if so then skip it automatically.
                    SkipPage("Non-existent page");
                    return false;
                }
                if (!wpTextbox1IsNull && radSkipExistent.Checked)
                {
                    SkipPage("Existing page");
                    return false;
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.Handle(ex);
            }
            NudgeTimer.Reset();
            return true;
        }