private void MediawikiAccountTestButton_Click(object sender, EventArgs e)
        {
            string text = ucMediaWikiAccounts.btnTest.Text;

            ucMediaWikiAccounts.btnTest.Text    = "Testing...";
            ucMediaWikiAccounts.btnTest.Enabled = false;
            MediaWikiAccount acc = GetSelectedMediaWiki();

            if (acc != null)
            {
                TestMediaWikiAccount(acc,
                                     // callback for success
                                     delegate()
                {
                    // invoke on UI thread
                    Invoke((Action) delegate()
                    {
                        ucMediaWikiAccounts.btnTest.Enabled = true;
                        ucMediaWikiAccounts.btnTest.Text    = text;
                        MessageBox.Show("Login successful!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    });
                },
                                     // callback for failure
                                     delegate(string message)
                {
                    // invoke on UI thread
                    Invoke((Action) delegate()
                    {
                        ucMediaWikiAccounts.btnTest.Enabled = true;
                        ucMediaWikiAccounts.btnTest.Text    = text;
                        MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    });
                });
            }
        }
Example #2
0
        private void TestMediaWikiAccount(MediaWikiAccount account, Action success, Action <string> failure)
        {
            var    timeoutTimer = new System.Windows.Forms.Timer();
            Thread thread       = new Thread(new ThreadStart(delegate
            {
                TestMediaWikiAccountThread(account,
                                           delegate()
                {
                    timeoutTimer.Stop(); success();
                },
                                           delegate(string msg)
                {
                    timeoutTimer.Stop(); failure(msg);
                });
            }));

            thread.Start();
            timeoutTimer.Interval = 10000;
            timeoutTimer.Tick    += new EventHandler(delegate(object sender, EventArgs e)
            {
                thread.Interrupt();
                timeoutTimer.Stop();
                failure("The website at the URL you specified doesn't answer");
            });
            timeoutTimer.Start();
        }
        private void MediawikiAccountAddButton_Click(object sender, EventArgs e)
        {
            MediaWikiAccount acc = new MediaWikiAccount("New Account");

            Config.MediaWikiAccountList.Add(acc);
            ucMediaWikiAccounts.AccountsList.Items.Add(acc);
            ucMediaWikiAccounts.AccountsList.SelectedIndex = ucMediaWikiAccounts.AccountsList.Items.Count - 1;
        }
        private void MediaWikiAccountsList_SelectedIndexChanged(object sender, EventArgs e)
        {
            int sel = ucMediaWikiAccounts.AccountsList.SelectedIndex;

            Config.MediaWikiAccountSelected = sel;
            if (Config.MediaWikiAccountList != null && sel != -1 && sel < Config.MediaWikiAccountList.Count && Config.MediaWikiAccountList[sel] != null)
            {
                MediaWikiAccount acc = Config.MediaWikiAccountList[sel];
                ucMediaWikiAccounts.SettingsGrid.SelectedObject = acc;
            }
        }
Example #5
0
        private MediaWikiAccount GetSelectedMediaWiki()
        {
            MediaWikiAccount account = null;

            if (Config.MediaWikiAccountList.HasValidIndex(Config.MediaWikiAccountSelected))
            {
                account = Config.MediaWikiAccountList[Config.MediaWikiAccountSelected];
            }

            return(account);
        }
Example #6
0
 private void TestMediaWikiAccountThread(MediaWikiAccount acc, Action success, Action <string> failure)
 {
     try
     {
         MediaWiki connector = new MediaWiki(new MediaWikiOptions(acc, null)); // TODO: MediaWiki CheckProxySettings().GetWebProxy
         connector.Login();
         success();
     }
     catch (Exception ex)
     {
         // ignore ThreadInterruptedException : the request timed out and the thread was interrupted
         if (!(ex.InnerException is ThreadInterruptedException))
         {
             failure(ex.Message);
         }
     }
 }