Exemple #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (comm.TextLength > 100)
            {
                MessageBox.Show("Summary is longer than it should be!".T()); return;
            }
            if (text.Text.Equals(""))
            {
                MessageBox.Show("You are not supposed to clear the text!".T()); return;
            }
            String c        = comm.Text;
            String t        = text.Text;
            bool   m        = minor.Checked;
            Thread myThread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
            {
                try
                {
                    saved       = true;
                    long lrv    = Convert.ToInt64(pg.lastRevisionID);
                    long newrev = pg.Save2(t, c, m);
                    //Page p=aw.GetPage(pg.title);
                    if (newrev <= 0)
                    {
                        SweepNetPage p = new SweepNetPage(aw.mysite, pg.title);
                        p.LoadRevision(lrv);
                        newrev = p.maxid;
                        //  MessageBox.Show("rr");
                    }
                    if (newrev > 0)
                    {
                        // aw.UpdateMaxRevid(curr.stable_id, curr.curr_id, p.maxid);
                        curr.curr_id = newrev;
                        //обновить дифф

                        aw.UpdateDiff(curr);

                        if (review.Checked)
                        {
                            aw.Review(newrev);
                            // this.reviewed = true;
                        }
                    }
                }
                catch (Exception et) { MessageBox.Show("Error occured while applying the changes: ".T() + et.Message); }
            }));

            myThread.Start();
            this.reviewed = review.Checked;
            //   myThread.Join();
            this.Close();
        }
        /* Applying changes */
        private void ThreadFunction()
        {
            try
            {
                if (aw != null && wb != null)
                {
                    Page p = aw.PageCreate(element.page.title);
                    p.Load();

                    if (p.text != "")
                    {
                        string[] lines = p.text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                        foreach (DiffPiece d in pieces)
                        {
                            int from = d.starting;
                            for (int k = (from - 1) >= 0 ? (from - 1) : 0; k < lines.Length; k++)
                            {
                                if (lines[k] == d.text)
                                {
                                    d.real_line = k;
                                    d.ready     = true;
                                    break;
                                }
                            }
                        }


                        //  EditAndReview(this, new EditAndReviewActionArguments(element, p.text));
                        bool error = false, done = false;
                        lock (wb)
                        {
                            for (int i = 0; i < pieces.Count; i++)
                            {
                                if (pieces[i].being_edited)
                                {
                                    if (!pieces[i].ready)
                                    {
                                        error = true;
                                    }
                                    else
                                    {
                                        HtmlElement el = null;
                                        wb.Invoke((MethodInvoker) delegate
                                        {
                                            el = wb.Document.GetElementById("textarea_" + (i + 1).ToString());
                                        });
                                        if (el == null)
                                        {
                                            error = true;
                                        }
                                        else
                                        {
                                            lines[pieces[i].real_line] = el.InnerText;
                                            done = true;
                                        }
                                    }
                                }
                            }
                        }

                        if (error)
                        {
                            string errstr = "Due to internal errors the application did not manage to apply the changes you've made.".T();
                            wb.Invoke((MethodInvoker) delegate
                            {
                                MessageBox.Show(errstr, "Error", MessageBoxButtons.OK);
                            });
                            return;
                        }

                        string summary = ""; bool success = false, minor = false;
                        wb.Invoke((MethodInvoker) delegate
                        {
                            TextInputForm form = new TextInputForm("Enter a summary".T(), "([[Project:Sweep-Net|Sweep-Net]]): ");
                            form.ShowDialog((IWin32Window)wb.Parent);
                            if (form.successfully)
                            {
                                success = true;
                                summary = form.text;
                            }

                            HtmlElement el = wb.Document.GetElementById("is_minor");
                            if (el != null)
                            {
                                minor = el.GetAttribute("checked").ToLower() == "true";
                            }
                        });

                        if (success)
                        {
                            wb.Invoke((MethodInvoker) delegate
                            {
                                SetUpdatingStatus();
                            });
                            //    MessageBox.Show(String.Join("\r\n", lines));
                            p.Save2(String.Join("\r\n", lines), summary, minor);
                            SweepNetPage tp = new SweepNetPage(aw.mysite, p.title);

                            element.page.ReloadRevision();
                            //tp.LoadRevision(Convert.ToInt64(p.lastRevisionID));

                            if (element.page.maxid > 0)
                            {
                                element.curr_id = element.page.curr.revid;

                                //обновить дифф

                                aw.UpdateDiff(element);
                                wb.Invoke((MethodInvoker) delegate
                                {
                                    SetUpdatedStatus();
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //    MessageBox.Show(e.Message+e.StackTrace);
            }
        }