Exemplo n.º 1
0
 public void AddRev_first(Element el, bool restart = true, bool sworq = false)
 {
     try
     {
         support_thread = false;
         Stop();
         DiffData dd = new DiffData();
         dd.el = el; dd.send_wo_req = sworq; dd.rand = el.rand;
         CheckDup(el);
         Stop();
         list.Insert(0, dd);
         Logging.AddLog(el.title + " inserted");
     }
     catch (Exception e) { MessageBox.Show(e.Message); }
     if (restart)
     {
         support_thread = true; thread_running = false; RunThread();
     }
 }
Exemplo n.º 2
0
        private void _thread_function()
        {
            // MessageBox.Show("start_thread");
st:
            rt             = false;
            thread_restart = false;
            try
            {
                thread_running = true;
                stop_thread    = false;

                int  current_max = Options.GetOptionInt("buff3");
                bool skipifnull  = Options.GetOptionInt("skip_null") == 1 ? true : false;
                // MessageBox.Show(current_max + "");

                //  DiffData dd;
                CheckAllEvents();
                DiffData tmp = new DiffData();

                for (int a = 0; a < list.Count; a++)
                {
                    double rand = list[a].rand;
                    CheckAllEvents();
                    if (a == current_max)
                    {
                        thread_running = false; return;
                    }
                    if (stop_thread)
                    {
                        thread_running = false; return;
                    }
                    if (thread_restart)
                    {
                        goto st;
                    }
                    if (list[a].data.Equals(""))
                    {
                        //
                        for (int b = 0; b < (a < 2 ? 2 : 1); b++)
                        {
                            tmp = list[a];
                            if (tmp.skip == true)
                            {
                                break;
                            }

                            CheckAllEvents();

                            if (thread_restart)
                            {
                                goto st;
                            }


                            if (stop_thread)
                            {
                                thread_running = false; return;
                            }

                            Logging.AddLog("Trying to load diff for \"" + tmp.el.title + "\" #" + (b + 1));

                            //  try
                            if (tmp.el.page.list.Count == 0)
                            {
                                if (tmp.el.check == true)
                                {
                                    tmp.el.page.LoadRevision(-1);
                                    lock (aw.list.list) { tmp.el.Check(); }
                                    if (tmp.el.skip_me)
                                    {
                                        tmp.skip = true; tmp.el.skipped = true;
                                        tmp.data = "В настройках отключено";
                                        break;
                                    }
                                }
                                else
                                {
                                    tmp.el.skipped = false;
                                    tmp.el.page.LoadRevision(tmp.el.stable_id);
                                }
                            }
                            else
                            {
                                if (tmp.el.check == true)
                                {
                                    lock (aw.list.list) { tmp.el.Check(); }
                                    if (tmp.el.skip_me)
                                    {
                                        tmp.skip = true; tmp.el.skipped = true;
                                        tmp.data = "В настройках отключено";
                                        break;
                                    }
                                }
                            }
                            //catch (Exception e) { Logging.AddLog("Exception while loading diff for \"" + tmp.el.title + "\": " + e.Message); continue; }

                            //  try
                            if (tmp.el.page.list.Count == 0 || tmp.el.error)
                            {
                                tmp.data = "API error.";
                            }
                            else
                            {
                                if (data_type == 0)
                                {
                                    DiffTemporaryResult dtr = DiffBase._GetDiff(aw, tmp.el);
                                    tmp.data   = dtr.data;
                                    tmp.pieces = dtr.pieces;
                                }
                                else
                                {
                                    tmp.data = DiffBase._GetView(aw, tmp.el);
                                }
                            }

                            tmp.data = tmp.data.Trim();
                            if (tmp.Equals(""))
                            {
                                Logging.AddLog("creating diff for \"" + tmp.el.title + "\" failed #" + (b + 1)); continue;
                            }

                            Logging.AddLog("diff for \"" + tmp.el.title + "\" successfully loaded #" + (b + 1) + "  [" + tmp.data.Length + "]");

                            int newid = -1;
                            int fnw   = 0;

                            for (newid = 0; newid < list.Count; newid++)
                            {
                                if (list[newid].rand == rand)
                                {
                                    fnw = 1;
                                    list[newid].data      = tmp.data;
                                    list[newid].el.loaded = true;
                                    list[newid].el.MakeRevisions();

                                    if (list[newid].send_wo_req)
                                    {
                                        CheckForEvent(list[newid]); list[newid].send_event = true;
                                    }

                                    if (tmp.data.Contains("<!--diff_is_empty-->") && skipifnull == true && list[newid].send_wo_req == false)
                                    {
                                        list[newid].skip = true;
                                    }
                                    break;
                                }
                            }

                            if (fnw == 0)
                            {
                                thread_running = false; Logging.AddLog(list[a] + " ......... 0"); return;
                            }
                            else
                            {
                            }

                            CheckAllEvents();

                            if (thread_restart)
                            {
                                goto st;
                            }
                            break;
                        }
                    }
                }
                CheckAllEvents();
            }
            catch (Exception) {
                /*   MessageBox.Show(e.Message+"\r\n\r\n"+e.StackTrace); */ CheckAllEvents(); thread_running = false; if (thread_restart)
                {
                    goto st;
                }
                return;
            }
            thread_running = false; return;
        }