Example #1
0
        /// <summary>
        /// Get Search Param from Batch Job
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public DanbooruSearchParam GetSearchParamsFromJob(DanbooruBatchJob job)
        {
            var option = new DanbooruPostDaoOption()
            {
                BlacklistedTags         = TagBlacklist,
                BlacklistedTagsRegex    = TagBlacklistRegex,
                BlacklistedTagsUseRegex = chkBlacklistTagsUseRegex.Checked,
                IgnoredTags             = TagIgnore,
                IgnoredTagsRegex        = TagIgnoreRegex,
                IgnoredTagsUseRegex     = chkIgnoreTagsUseRegex.Checked,
                Provider   = _currProvider,
                SearchTags = !String.IsNullOrWhiteSpace(job.TagQuery) ? job.TagQuery : "",
                IsBlacklistOnlyForGeneral = chkBlacklistOnlyGeneral.Checked
            };

            DanbooruSearchParam searchParam = new DanbooruSearchParam
            {
                Provider = option.Provider,
                Tag      = option.SearchTags,
                Source   = ""
            };

            // check if given limit is more than the hard limit
            if (job.Limit > job.Provider.HardLimit)
            {
                searchParam.Limit = job.Provider.HardLimit;
            }
            else
            {
                searchParam.Limit = job.Limit;
            }

            // reflect to current page
            searchParam.Page = job.StartPage + job.CalculatedCurrentPage;

            searchParam.IsNotRating = false;
            searchParam.Rating      = job.Rating;

            searchParam.OrderBy = "";

            searchParam.Option = option;

            return(searchParam);
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            bool providerFlag = false;

            this.DialogResult = DialogResult.OK;
            Jobs = new List <DanbooruBatchJob>();

            foreach (CheckBox c in chkList)
            {
                if (c.Checked)
                {
                    var p = providerList.Where(x => x.Name == c.Text).FirstOrDefault();
                    if (p != null)
                    {
                        providerFlag = true;
                        DanbooruBatchJob Job = new DanbooruBatchJob();
                        Job.Provider = p;

                        try
                        {
                            if (!string.IsNullOrWhiteSpace(txtLimit.Text))
                            {
                                Job.Limit = Convert.ToInt32(txtLimit.Text);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error at Limit." + Environment.NewLine + ex.Message);
                            txtLimit.Focus();
                            txtLimit.SelectAll();
                            return;
                        }

                        try
                        {
                            if (!string.IsNullOrWhiteSpace(txtPage.Text))
                            {
                                Job.StartPage = Convert.ToInt32(txtPage.Text);
                            }
                            else
                            {
                                Job.StartPage = -1;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error at StartPage." + Environment.NewLine + ex.Message);
                            txtPage.Focus();
                            txtPage.SelectAll();
                            return;
                        }

                        if (cbxRating.SelectedValue != null && chkNotRating.Checked)
                        {
                            Job.Rating = "-" + cbxRating.SelectedValue;
                        }
                        else
                        {
                            Job.Rating = (string)cbxRating.SelectedValue;
                        }

                        // do encoding later on main form.
                        Job.TagQuery = txtTagQuery.Text;

                        if (string.IsNullOrWhiteSpace(txtFilenameFormat.Text))
                        {
                            MessageBox.Show("Filename Format is empty!");
                            txtFilenameFormat.Focus();
                            return;
                        }
                        Job.SaveFolder = txtFilenameFormat.Text;
                        Jobs.Add(Job);
                    }
                }
            }
            if (!providerFlag)
            {
                MessageBox.Show("Please select at least 1 provider.");
                pnlProvider.Focus();
                this.DialogResult = DialogResult.None;
                this.Jobs         = null;
            }
        }