Пример #1
0
        void saveButton_Click(object sender, EventArgs e)
        {
            BrowserScriptPocketQueriesPQSetting pq = BrowserScriptPocketQueriesPQSetting.FromPQPage(Core, this.OwnerPlugin, Browser);

            if (pq != null)
            {
                try
                {
                    List <BrowserScriptPocketQueriesPQSetting> l   = BrowserScriptPocketQueriesPQSetting.Load(_settingsFileName);
                    BrowserScriptPocketQueriesPQSetting        pqs = (from p in l where p.Name == pq.Name select p).FirstOrDefault();
                    if (pqs != null)
                    {
                        pq.ID = pqs.ID;
                        l.Remove(pqs);
                    }
                    l.Add(pq);
                    BrowserScriptPocketQueriesPQSetting.Save(_settingsFileName, l);
                    MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_SETTINGSSAVED));
                }
                catch
                {
                    MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                }
            }
            else
            {
                MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
            }
        }
Пример #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (listBox1.SelectedIndex >= 0)
     {
         listBox1.Items.RemoveAt(listBox1.SelectedIndex);
         BrowserScriptPocketQueriesPQSetting.Save(_filename, (from BrowserScriptPocketQueriesPQSetting a in listBox1.Items select a).ToList());
     }
 }
        public BrowserScriptPocketQueriesPQSeriesForm(Framework.Interfaces.ICore core, Framework.Interfaces.IPlugin plugin, string settingsFilename, string seriesFilename, WebBrowser wb)
            : this()
        {
            _settingsFilename = settingsFilename;
            _seriesFilename   = seriesFilename;
            _core             = core;
            _wb     = wb;
            _plugin = plugin;

            List <BrowserScriptPocketQueriesPQSetting> s = BrowserScriptPocketQueriesPQSetting.Load(settingsFilename);

            if (s != null)
            {
                comboBox2.Items.AddRange(s.ToArray());
            }

            List <BrowserScriptPocketQueriesPQSeries> l = BrowserScriptPocketQueriesPQSeries.Load(_seriesFilename);

            if (l != null)
            {
                comboBox1.Items.AddRange(l.ToArray());
            }

            this.Text         = Utils.LanguageSupport.Instance.GetTranslation(STR_TITLE);
            this.button5.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CREATEPQ);
            this.label1.Text  = Utils.LanguageSupport.Instance.GetTranslation(STR_SERIE);
            this.label4.Text  = Utils.LanguageSupport.Instance.GetTranslation(STR_NAME);
            this.label6.Text  = Utils.LanguageSupport.Instance.GetTranslation(STR_SETTINGS);
            this.label12.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_TEMPLATE);
            this.label8.Text  = Utils.LanguageSupport.Instance.GetTranslation(STR_START);
            this.label10.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_END);
            this.listView1.Columns[0].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_DATE);
            this.button1.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_REMOVE);
            this.button12.Text  = Utils.LanguageSupport.Instance.GetTranslation(STR_RENAME);
            this.button2.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_SAVE);
            this.button4.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_NEW);
            this.groupBox1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_AUTODATERANGES);
            this.label14.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_MAXINPQ);
            this.label16.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_MAXINLASTPQ);
            this.button7.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_FROMSELECTION);
            this.button8.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_NETHERLANDS);
            this.button9.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_BELGIUM);
            this.label21.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_DELAY);
            this.label19.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_MARGIN);
            this.button11.Text  = Utils.LanguageSupport.Instance.GetTranslation(STR_AUTOMATIC);
            this.checkBox1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_AUTOMATICACTIVATE);
            this.button13.Text  = Utils.LanguageSupport.Instance.GetTranslation(STR_FROMGCPROJECT);
        }
Пример #4
0
        public BrowserScriptPocketQueriesPQSettingForm(string filename)
            : this()
        {
            _filename = filename;
            List <BrowserScriptPocketQueriesPQSetting> l = BrowserScriptPocketQueriesPQSetting.Load(_filename);

            if (l != null)
            {
                listBox1.Items.AddRange(l.ToArray());
            }

            this.Text         = Utils.LanguageSupport.Instance.GetTranslation(STR_TITLE);
            this.button1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_REMOVE);
            this.button2.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_SAVE);
            this.button3.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_OK);
        }
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            BrowserScriptPocketQueriesPQSeries pqs = comboBox1.SelectedItem as BrowserScriptPocketQueriesPQSeries;

            if (pqs != null)
            {
                BrowserScriptPocketQueriesPQSetting s = comboBox2.SelectedItem as BrowserScriptPocketQueriesPQSetting;
                if (s != null)
                {
                    pqs.SettingsID = s.ID;
                }
                else
                {
                    pqs.SettingsID = "";
                }
            }
            checkReadyToCreate();
            checkReadyToGetDates();
        }
        private void button11_Click(object sender, EventArgs e)
        {
            if (panel1.Enabled)
            {
                string message = "";
                _cancel = false;
                BrowserScriptPocketQueriesPQSeries  pqs     = comboBox1.SelectedItem as BrowserScriptPocketQueriesPQSeries;
                BrowserScriptPocketQueriesPQSetting setting = comboBox2.SelectedItem as BrowserScriptPocketQueriesPQSetting;
                if (pqs != null && setting != null)
                {
                    _init = true;
                    listView1.Items.Clear();
                    pqs.Dates.Clear();
                    pqs.Dates.Add(dateTimePicker1.Value < dateTimePicker2.Value ? dateTimePicker1.Value : dateTimePicker2.Value);
                    pqs.Dates.Add(dateTimePicker2.Value > dateTimePicker1.Value ? dateTimePicker2.Value : dateTimePicker1.Value);

                    this.button5.Text      = Utils.LanguageSupport.Instance.GetTranslation(STR_CANCEL);
                    panel1.Enabled         = false;
                    this.ControlBox        = false;
                    _browserReady          = new ManualResetEvent(false);
                    _wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(_wb_DocumentCompleted);

                    try
                    {
                        string baseUrl = string.Format("http://{0}", _wb.Url.Host);

                        if (setToEnglish())
                        {
                            if (gotoPage(string.Format("{0}/pocket/default.aspx", baseUrl)))
                            {
                                _wb.Document.GetElementById("uxCreateNewPQ").SetAttribute("Target", "_self");
                                _browserReady.Reset();
                                _wb.Document.GetElementById("uxCreateNewPQ").InvokeMember("Click");
                                if (waitForPageReady(string.Format("{0}/pocket/gcquery.aspx", baseUrl)))
                                {
                                    //now, use this page to get the ranges
                                    int      maxInPq            = (int)numericUpDown1.Value;
                                    int      maxInLastPq        = (int)numericUpDown2.Value;
                                    int      margin             = (int)numericUpDown3.Value;
                                    DateTime lastPqEnd          = pqs.Dates[1];
                                    DateTime minOfInterval      = pqs.Dates[0];
                                    DateTime maxOfInterval      = pqs.Dates[1];
                                    DateTime lastAcceptableDate = DateTime.MinValue;

                                    //with every pq, start with begin date (is begin or end date of prev pq
                                    //and have end date
                                    //devide number of days by 2 and add to begin date if too many
                                    //until days=0 or number in pq < desired
                                    setting.PlacedDuring         = "ctl00_ContentBody_rbPlacedBetween";
                                    setting.Name                 = "_gcpqgen_ranges_";
                                    setting.PlacedDuringFromDate = pqs.Dates[0];
                                    setting.PlacedDuringToDate   = pqs.Dates[1];

                                    while (!_cancel && string.IsNullOrEmpty(message))
                                    {
                                        setting.SetPQPage(_wb);
                                        _browserReady.Reset();
                                        _wb.Document.GetElementById("ctl00_ContentBody_btnSubmit").InvokeMember("Click");
                                        if (waitForPageReady(string.Format("{0}/pocket/gcquery.aspx", baseUrl)))
                                        {
                                            Thread.Sleep((int)numericUpDown4.Value);

                                            //check result
                                            int count = getNumberOfCachesInPQ();
                                            if (count >= 0)
                                            {
                                                _core.DebugLog(Framework.Data.DebugLogLevel.Info, _plugin, null, string.Format("PQ => {0} - {1} ({2})", setting.PlacedDuringFromDate.ToString("d"), setting.PlacedDuringToDate.ToString("d"), count));
                                                if (count > maxInPq)
                                                {
                                                    //go between min and current end
                                                    maxOfInterval = setting.PlacedDuringToDate;
                                                    int days = (int)(maxOfInterval - minOfInterval).TotalDays / 2;
                                                    if (days < 2)
                                                    {
                                                        if (lastAcceptableDate >= setting.PlacedDuringFromDate)
                                                        {
                                                            //take this
                                                            //ready for this one!
                                                            pqs.Dates.Add(lastAcceptableDate);

                                                            //update ui
                                                            ListViewItem lvi = new ListViewItem(lastAcceptableDate.ToString("d"));
                                                            lvi.Tag = lastAcceptableDate;
                                                            listView1.Items.Add(lvi);

                                                            setting.PlacedDuringFromDate = lastAcceptableDate.AddDays(1);
                                                            setting.PlacedDuringToDate   = lastPqEnd;

                                                            lastAcceptableDate = DateTime.MinValue;
                                                        }
                                                        else
                                                        {
                                                            message = STR_ERROR;
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        setting.PlacedDuringToDate = minOfInterval.AddDays(days);
                                                    }
                                                }
                                                else if (setting.PlacedDuringToDate >= lastPqEnd)
                                                {
                                                    //ready!
                                                    break;
                                                }
                                                else if (count <= maxInPq && count >= (maxInPq - margin))
                                                {
                                                    //ready for this one!
                                                    pqs.Dates.Add(setting.PlacedDuringToDate);

                                                    //update ui
                                                    ListViewItem lvi = new ListViewItem(setting.PlacedDuringToDate.ToString("d"));
                                                    lvi.Tag = setting.PlacedDuringToDate;
                                                    listView1.Items.Add(lvi);

                                                    setting.PlacedDuringFromDate = setting.PlacedDuringToDate.AddDays(1);
                                                    setting.PlacedDuringToDate   = lastPqEnd;

                                                    lastAcceptableDate = DateTime.MinValue;
                                                }
                                                else //count too small
                                                {
                                                    if (setting.PlacedDuringToDate > lastAcceptableDate)
                                                    {
                                                        lastAcceptableDate = setting.PlacedDuringToDate;
                                                    }
                                                    minOfInterval = setting.PlacedDuringToDate;
                                                    int days = (int)(maxOfInterval - minOfInterval).TotalDays / 2;
                                                    if (days < 2)
                                                    {
                                                        //take this
                                                        //ready for this one!
                                                        pqs.Dates.Add(setting.PlacedDuringToDate);

                                                        //update ui
                                                        ListViewItem lvi = new ListViewItem(setting.PlacedDuringToDate.ToString("d"));
                                                        lvi.Tag = setting.PlacedDuringToDate;
                                                        listView1.Items.Add(lvi);

                                                        setting.PlacedDuringFromDate = setting.PlacedDuringToDate.AddDays(1);
                                                        setting.PlacedDuringToDate   = lastPqEnd;

                                                        lastAcceptableDate = DateTime.MinValue;
                                                    }
                                                    else
                                                    {
                                                        setting.PlacedDuringToDate = minOfInterval.AddDays(days);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                message = STR_ERROR;
                                                break;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    message = STR_ERROR;
                                }
                            }
                            else
                            {
                                message = STR_ERROR;
                            }
                        }
                        else
                        {
                            message = STR_ERROR;
                        }
                    }
                    catch
                    {
                        message = STR_ERROR;
                    }

                    _wb.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(_wb_DocumentCompleted);
                    _browserReady.Dispose();
                    _browserReady = null;

                    this.ControlBox = true;
                    panel1.Enabled  = true;
                    _init           = false;
                    comboBox1_SelectedIndexChanged(this, EventArgs.Empty);
                    this.button5.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CREATEPQ);
                    if (!string.IsNullOrEmpty(message))
                    {
                        MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(message), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                    }
                }
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            if (panel1.Enabled)
            {
                string message = "";
                string inArea  = "";
                string msgid   = "";
                _cancel = false;
                BrowserScriptPocketQueriesPQSeries  pqs     = comboBox1.SelectedItem as BrowserScriptPocketQueriesPQSeries;
                BrowserScriptPocketQueriesPQSetting setting = comboBox2.SelectedItem as BrowserScriptPocketQueriesPQSetting;
                if (pqs != null && pqs.Dates.Count > 1 && setting != null)
                {
                    this.button5.Text      = Utils.LanguageSupport.Instance.GetTranslation(STR_CANCEL);
                    panel1.Enabled         = false;
                    this.ControlBox        = false;
                    _browserReady          = new ManualResetEvent(false);
                    _wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(_wb_DocumentCompleted);

                    try
                    {
                        string baseUrl = string.Format("http://{0}", _wb.Url.Host);
                        pqs.Dates.Sort();
                        if (setToEnglish())
                        {
                            int pqIndex       = 0;
                            int retryCount    = 0;
                            int activationDay = 0;
                            while (pqIndex < pqs.Dates.Count - 1)
                            {
                                message = "";
                                msgid   = "";
                                try
                                {
                                    inArea = "1";
                                    if (gotoPage(string.Format("{0}/pocket/default.aspx", baseUrl)))
                                    {
                                        inArea = "2";
                                        _wb.Document.GetElementById("uxCreateNewPQ").SetAttribute("Target", "_self");
                                        _browserReady.Reset();
                                        _wb.Document.GetElementById("uxCreateNewPQ").InvokeMember("Click");
                                        if (waitForPageReady(string.Format("{0}/pocket/gcquery.aspx", baseUrl)))
                                        {
                                            inArea = "3";
                                            if (pqIndex == 0)
                                            {
                                                setting.PlacedDuringFromDate = pqs.Dates[pqIndex];
                                            }
                                            else
                                            {
                                                setting.PlacedDuringFromDate = pqs.Dates[pqIndex].AddDays(1);
                                            }
                                            setting.PlacedDuringToDate = pqs.Dates[pqIndex + 1];
                                            setting.PlacedDuring       = "ctl00_ContentBody_rbPlacedBetween";
                                            setting.Name = pqs.NameTemplate.Replace("<index>", pqIndex.ToString("00")).Replace("<begindate>", setting.PlacedDuringFromDate.ToString("yyyyMMdd")).Replace("<enddate>", setting.PlacedDuringToDate.ToString("yyyyMMdd"));
                                            inArea       = "4";
                                            if (checkBox1.Checked)
                                            {
                                                setting.SetPQPage(_wb, activationDay);
                                            }
                                            else
                                            {
                                                setting.SetPQPage(_wb);
                                            }
                                            inArea = "5";
                                            _browserReady.Reset();
                                            _wb.Document.GetElementById("ctl00_ContentBody_btnSubmit").InvokeMember("Click");
                                            inArea = "6";
                                            if (waitForPageReady(string.Format("{0}/pocket/gcquery.aspx", baseUrl)))
                                            {
                                                inArea = "7";
                                                if (!_wb.Document.Body.InnerHtml.Contains("Thanks! Your pocket query has been saved and currently results in"))
                                                {
                                                    message = STR_ERROR;
                                                    msgid   = "1";
                                                }
                                            }
                                            else
                                            {
                                                message = STR_ERROR;
                                                msgid   = "2";
                                            }
                                        }
                                        else
                                        {
                                            message = STR_ERROR;
                                            msgid   = "3";
                                        }
                                        if (_cancel)
                                        {
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        msgid   = "4";
                                        message = STR_ERROR;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    msgid   = string.Format("6i - {0}", inArea);
                                    message = STR_ERROR;
                                }
                                if (!string.IsNullOrEmpty(message))
                                {
                                    if (retryCount < 6)
                                    {
                                        _core.DebugLog(Framework.Data.DebugLogLevel.Error, _plugin, null, string.Format("ERROR: Setting PQ settings - retry ({0})", retryCount));
                                        //check if PQ has been created:
                                        if (gotoPage(string.Format("{0}/pocket/default.aspx", baseUrl)))
                                        {
                                            if (_wb.Document.Body.InnerHtml.IndexOf(setting.Name) > 0)
                                            {
                                                _core.DebugLog(Framework.Data.DebugLogLevel.Error, _plugin, null, "But was created");
                                                //created, goto next
                                                retryCount = 0;
                                                pqIndex++;

                                                activationDay++;
                                                if (activationDay > 6)
                                                {
                                                    activationDay = 0;
                                                }
                                            }
                                            else
                                            {
                                                _core.DebugLog(Framework.Data.DebugLogLevel.Error, _plugin, null, "Was not created");
                                                retryCount++;
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    activationDay++;
                                    if (activationDay > 6)
                                    {
                                        activationDay = 0;
                                    }

                                    retryCount = 0;
                                    pqIndex++;
                                }
                            }
                        }
                        else
                        {
                            msgid   = "5";
                            message = STR_ERROR;
                        }
                    }
                    catch (Exception ex)
                    {
                        msgid   = string.Format("6 - {0}", inArea);
                        message = STR_ERROR;
                    }

                    _wb.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(_wb_DocumentCompleted);
                    _browserReady.Dispose();
                    _browserReady = null;

                    this.ControlBox   = true;
                    panel1.Enabled    = true;
                    this.button5.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CREATEPQ);
                    if (!string.IsNullOrEmpty(message))
                    {
                        MessageBox.Show(string.Format("{0} ({1} - {2})", Utils.LanguageSupport.Instance.GetTranslation(message), msgid, inArea), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                    }
                }
            }
            else
            {
                _cancel = true;
            }
        }
Пример #8
0
 private void button3_Click(object sender, EventArgs e)
 {
     SelectedSetting = listBox1.SelectedItem as BrowserScriptPocketQueriesPQSetting;
     DialogResult    = System.Windows.Forms.DialogResult.OK;
 }
Пример #9
0
 private void button2_Click(object sender, EventArgs e)
 {
     BrowserScriptPocketQueriesPQSetting.Save(_filename, (from BrowserScriptPocketQueriesPQSetting a in listBox1.Items select a).ToList());
 }