Multithreaded API editor class
Inheritance: IApiEdit
Ejemplo n.º 1
0
        public LogUploader(AsyncApiEdit e)
        {
            BotTag = "|}<!--/bottag-->"; // doing it this way OUGHT to allow inherited classes to override
            TableHeaderUserName = "******";
            TableHeaderNoUserName = "******";

            editor = e.Clone();
        }
Ejemplo n.º 2
0
		internal void Init(AsyncApiEdit e, Label ETALabel, PluginSettingsControl.Stats Stats)
		{
			if (!TimerEnabled) {
				ResetVars();
				mETALabel = ETALabel;

				TimerEnabled = true;

				mStats = Stats;
			    mStats.SkipMisc += mStats_SkipMisc;

				Timer1_Tick(null, null);
			}
		}
Ejemplo n.º 3
0
        internal void Init(AsyncApiEdit e, Label etaLabel, PluginSettingsControl.Stats stats)
        {
            if (!TimerEnabled)
            {
                ResetVars();
                _etaLabel = etaLabel;

                TimerEnabled = true;

                _stats = stats;
                _stats.SkipMisc += StatsSkipMisc;

                Timer1_Tick(null, null);
            }
        }
Ejemplo n.º 4
0
        private AsyncApiEdit CreateEditor(string url, bool php5)
        {
            AsyncApiEdit edit = new AsyncApiEdit(url, parentControl, php5)
                                    {
                                        NewMessageThrows = false
                                    };

            edit.OpenComplete += OnOpenComplete;
            edit.SaveComplete += OnSaveComplete;
            edit.PreviewComplete += OnPreviewComplete;
            edit.ExceptionCaught += OnExceptionCaught;
            edit.MaxlagExceeded += OnMaxlagExceeded;
            edit.LoggedOff += OnLoggedOff;
            edit.StateChanged += OnStateChanged;
            edit.Aborted += OnAborted;

            return edit;
        }
Ejemplo n.º 5
0
 void OnStateChanged(AsyncApiEdit sender)
 {
     if (StateChanged != null) StateChanged(sender);
 }
Ejemplo n.º 6
0
 void OnMaxlagExceeded(AsyncApiEdit sender, int maxlag, int retryAfter)
 {
     if (MaxlagExceeded != null) MaxlagExceeded(sender, maxlag, retryAfter);
 }
Ejemplo n.º 7
0
 void OnLoggedOff(AsyncApiEdit sender)
 {
     if (LoggedOff != null) LoggedOff(sender);
 }
Ejemplo n.º 8
0
 void OnPreviewComplete(AsyncApiEdit sender, string result)
 {
     if (PreviewComplete != null) PreviewComplete(sender, result);
 }
Ejemplo n.º 9
0
 void OnExceptionCaught(AsyncApiEdit sender, Exception ex)
 {
     if (ExceptionCaught != null) ExceptionCaught(sender, ex);
 }
Ejemplo n.º 10
0
		// Webcontrol event handlers:
		private void EditorStatusChanged(AsyncApiEdit sender)
		{
			if (PluginManager.AWBForm.TheSession.Editor.IsActive) {
				LoadArticle();
			}
		}
Ejemplo n.º 11
0
 internal void IncrementSavedEdits(AsyncApiEdit sender, SaveInfo save)
 {
     IncrementSavedEdits();
 }
Ejemplo n.º 12
0
        private void PageSaved(AsyncApiEdit sender, SaveInfo saveInfo)
        {
            ClearBrowser();
            txtEdit.Text = "";

            //TODO:Reinstate as needed
            //try
            //{
            //    if (IsReadOnlyDB())
            //    {
            //        StartDelayedRestartTimer(null, null);
            //        return;
            //    }
            //}
            //catch (Exception)
            //{
            //    Start();
            //}

            //lower restart delay
            if (_restartDelay > 5)
                _restartDelay -= 1;

            NumberOfEdits++;

            LastArticle = "";
            listMaker.Remove(TheArticle);
            NudgeTimer.Stop();
            SameArticleNudges = 0;
            if (EditBoxTab.SelectedTab == tpHistory)
                EditBoxTab.SelectedTab = tpEdit;
            if (loggingEnabled)
                logControl.AddLog(false, TheArticle.LogListener);
            UpdateOverallTypoStats();

            if (listMaker.Count == 0 && _autoSaveEditBoxEnabled)
                EditBoxSaveTimer.Enabled = false;
            Retries = 0;

            // if user has loaded a settings file, save it every 10 edits if autosavesettings is set
            if (autoSaveSettingsToolStripMenuItem.Checked && (NumberOfEdits % 10 == 0) && !string.IsNullOrEmpty(SettingsFile) && (NumberOfEdits > 5))
                SavePrefs(SettingsFile);

            Start();
        }
Ejemplo n.º 13
0
 private void LoggedOff(AsyncApiEdit sender)
 {
     DisableButtons();
 }
Ejemplo n.º 14
0
        private void CreateEditor()
        {
            APIEdit = new AsyncApiEdit(Variables.URLLong, this, Variables.PHP5);
            APIEdit.PreviewComplete += PreviewComplete;

            APIEdit.ExceptionCaught += APIEditExceptionCaught;
        }
Ejemplo n.º 15
0
 private void APIEditExceptionCaught(AsyncApiEdit sender, Exception ex)
 {
     StartDelayedRestartTimer(null, null);
 }
Ejemplo n.º 16
0
        // AWB processing stopped/started:
        internal void AWBProcessingStart(AsyncApiEdit editor)
        {
            foreach (Label lbl in _statLabels)
            {
                if (string.IsNullOrEmpty(lbl.Text))
                    lbl.Text = "0";
            }

            TimerStats1.Visible = true;
            TimerStats1.Init(editor, ETALabel, PluginStats);

            PluginManager.StatusText.Text = "Started";
        }
Ejemplo n.º 17
0
		private static void EditorAborted(AsyncApiEdit sender)
		{
			PluginSettings.AWBProcessingAborted();
		}
Ejemplo n.º 18
0
		private static void EditorStatusChanged(AsyncApiEdit sender)
		{
			if (AWBForm.TheSession.Editor.IsActive) {
				if (ActivePlugins.Count > 0)
					PluginSettings.AWBProcessingStart(sender);
			} else {
				DefaultStatusText();
				// If AWB has stopped and the list is empty we assume the job is finished, so close the log and upload:
				if (AWBForm.ListMaker.Count == 0) {
					AWBForm.TraceManager.Close();
				}
			}
		}
Ejemplo n.º 19
0
 void OnAborted(AsyncApiEdit sender)
 {
     if (Aborted != null) Aborted(sender);
 }
Ejemplo n.º 20
0
        private void MaxlagExceeded(AsyncApiEdit sender, int maxlag, int retryAfter)
        {
            Retries++;

            if (Retries < MaxRetries)
            {
                StartDelayedRestartTimer(retryAfter);
            }
            else
            {
                Stop();
                MessageBox.Show(this, "Maxlag exceeded " + MaxRetries + " times in a row. Processing stopped, please try later when the server is under a less load.", "Stopped", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 21
0
        private void ApiEditExceptionCaught(AsyncApiEdit sender, Exception ex)
        {
            if (ex is InterwikiException)
            {
                SkipPage(ex.Message);
            }
            else if (ex is SpamlistException)
            {
                string message = "Text '" + (ex as SpamlistException).URL + "' is blocked by spam blacklist";

                if (!BotMode)
                {
                    if (!chkSkipSpamFilter.Checked
                        && MessageBox.Show(message + ".\r\nTry and edit again?",
                                           "Spam blacklist", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        Start();
                        return;
                    }
                }
                SkipPage(message);
            }
            else if (ex is ApiErrorException)
            {
                switch ((ex as ApiErrorException).ErrorCode)
                {
                    case "editconflict":
                        //TODO: must be a less crude way
                        MessageBox.Show(this, "There has been an edit conflict. AWB will now re-apply its changes on the updated page.\r\nPlease re-review the changes before saving. Any Custom edits will be lost, and have to be re-added manually.", "Edit conflict");
                        NudgeTimer.Stop();
                        Start();
                        break;

                    case "writeapidenied":
                        NoWriteApiRight();
                        break;

                    case "customcssprotected":
                        SkipPage("You're not allowed to edit custom CSS pages");
                        break;

                    case "customjsprotected":
                        SkipPage("You're not allowed to edit custom JavaScript pages");
                        break;

                    case "badmd5":
                        SkipPage("API MD5 hash error: The page you are editing may contain an unsupported or invalid Unicode character");
                        break;

                    default:
                        StartDelayedRestartTimer();
                        break;
                }
            }
            else if (ex is ApiBlankException)
            {
                StartDelayedRestartTimer();
            }
            else if (ex is NewMessagesException)
            {
                WeHaveNewMessages();
            }
            else if (ex is LoggedOffException)
            {
                HandleLogoff();
            }
            else if (ex is CaptchaException)
            {
                MessageBox.Show("Captcha required, is the user account autoconfirmed etc?", "Captcha Required");
                Stop();
            }
            else if (ex is InvalidTitleException)
            {
                SkipPage("Invalid title");
            }
            else if (ex is RedirectToSpecialPageException)
            {
                SkipPage("Page is a redirect to a special page");
            }
            else if (ex is WebException || (ex is IOException && ex.Message.Contains("0x2746")))
            {
                // some 404 error or similar, or "Unable to write data to the transport connection: Unknown error (0x2746)"
                StatusLabelText = ex.Message;
                if (Tools.WriteDebugEnabled)
                    Tools.WriteTextFile(ex.Message, "Log.txt", true);
                StartDelayedRestartTimer();
            }
            else if (ex is SharedRepoException)
            {
                MessageBox.Show("Cannot move this file to the specified target, as it exists in a shared repo (such as commons).", "Target file exists in shared repo");
            }
            else if (ex is MediaWikiSaysNoException)
            {
                MessageBox.Show("MediaWiki prevented you from making that edit. Chances are it's spam filter related", "MediaWiki says no");
                SkipPage("");
            }
            else
            {
                Stop();
                ErrorHandler.Handle(ex);
            }
        }
Ejemplo n.º 22
0
 public Session(string url)
 {
     Editor = new AsyncApiEdit(url);
     LoadProjectOptions();
     Update();
 }
Ejemplo n.º 23
0
        private void PreviewComplete(AsyncApiEdit sender, string result)
        {
            LastArticle = txtEdit.Text;

            Skippable = false;

            if (webBrowser.Document != null)
            {
                webBrowser.Document.OpenNew(false);
                webBrowser.Document.Write("<html><head>"
                                          + sender.HtmlHeaders
                                          + "</head><body style=\"background:white; margin:10px; text-align:left;\">"
                                          + result
                                          + "</html>"
                                         );
                //webBrowser.BringToFront();
            }

            StatusLabelText = "";

            GuiUpdateAfterProcessing();
        }
Ejemplo n.º 24
0
 void OnOpenComplete(AsyncApiEdit sender, PageInfo pageInfo)
 {
     if (OpenComplete != null) OpenComplete(sender, pageInfo);
 }
Ejemplo n.º 25
0
 private void OpenComplete(AsyncApiEdit editor, PageInfo page)
 {
     PageLoaded(page);
 }
Ejemplo n.º 26
0
 void OnSaveComplete(AsyncApiEdit sender, SaveInfo saveInfo)
 {
     if (SaveComplete != null) SaveComplete(sender, saveInfo);
 }
Ejemplo n.º 27
0
        private void ApiEditExceptionCaught(AsyncApiEdit sender, Exception ex)
        {
            if (ex is InterwikiException)
                SkipPage(ex.Message);
            else if (ex is SpamlistException)
            {
                string message = "Text '" + (ex as SpamlistException).URL + "' is blocked by spam blacklist";

                if (!BotMode)
                {
                    if (!chkSkipSpamFilter.Checked
                        && MessageBox.Show(message + ".\r\nTry and edit again?",
                                           "Spam blacklist", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        Start();
                        return;
                    }
                }
                SkipPage(message);
            }
            else if (ex is ApiErrorException)
            {
                switch ((ex as ApiErrorException).ErrorCode)
                {
                    case "editconflict":
                        //TODO: must be a less crude way
                        MessageBox.Show(this, "There has been an edit conflict. AWB will now re-apply its changes on the updated page.\r\nPlease re-review the changes before saving. Any Custom edits will be lost, and have to be re-added manually.", "Edit conflict");
                        NudgeTimer.Stop();
                        Start();
                        break;

                    case "writeapidenied":
                        NoWriteApiRight();
                        break;

                    default:
                        StartDelayedRestartTimer();
                        break;
                }
            }
            else if (ex is ApiBlankException)
            {
                StartDelayedRestartTimer();
            }
            else if (ex is NewMessagesException)
            {
                WeHaveNewMessages();
            }
            else if (ex is LoggedOffException)
            {
                HandleLogoff();
            }
            else if (ex is CaptchaException)
            {
                MessageBox.Show("Captcha required, is the user account autoconfirmed etc?", "Captcha Required");
                Stop();
            }
            else if (ex is InvalidTitleException)
            {
                SkipPage("Invalid title");
            }
            else if (ex is RedirectToSpecialPageException)
            {
                SkipPage("Page is a redirect to a special page");
            }
            else if (ex is WebException)
            {
                // some 404 error or similar
                StatusLabelText = ex.Message;
                StartDelayedRestartTimer();
            }
            else
            {
                Stop();
                ErrorHandler.Handle(ex);
            }
        }
Ejemplo n.º 28
0
 private void CreateEditor()
 {
     apiEdit = new AsyncApiEdit(Variables.URLLong, this, Variables.PHP5);
     apiEdit.PreviewComplete += PreviewComplete;
 }