Пример #1
0
        private void DoUpdateTagsState()
        {
            int current_limit = AvailableImageBoards[this.Source.SelectedIndex].MaxTagGroup;

            IList <ImageTag> tags = ImageTag.ParseTags(this.Tags.Text);

            bool weight_error = (tags.TagCost() > current_limit);

            if (tags.Any(tag => tag.Filter == ImageTag.TagFilter.Rating))
            {
                throw new ImageTagParseException("Rating tag not needed");
            }

            this.TagsBorder.BorderBrush = weight_error
                ? Brushes.Orange : this.textbox_border;

            this.CurrentTagCount.Content = $"Current:  {tags.TagCost()}";

            this.CurrentTagCount.Foreground = weight_error
                ? Brushes.Orange : Brushes.Black;
        }
        public async void StartDownloadSequence()
        {
            _is_downloading = true;

            LockView();

            List <ImageTag> tags = ImageTag.ParseTags(Tags.Text) as List <ImageTag>;

            ImageTag rating_tag = Post.RatingTag(CurrentRating());

            if (!(await CurrentBoard.GetBestTags(tags, rating_tag) is List <ImageTag> best_tags))
            {
                DownloadFailed("Failed to get optimal tags");
                return;
            }

            if (CancelQueued)
            {
                ResetView("Download canceled");
                return;
            }

            List <Post> posts;

            try {
                posts = await CurrentBoard.GetPages(best_tags, tags,
                                                    CurrentRating(), -1, this) as List <Post>;

                if (posts == null)
                {
                    ResetView("Download canceled");
                    return;
                }
            } catch (WebException e) {
                DownloadFailed(e.Message);
                return;
            }

            if (posts.Count == 0)
            {
                DownloadFailed($"No posts were found for {best_tags.AsTagString(' ')}");
                ResetView();
                return;
            }

            if (CancelQueued)
            {
                ResetView("Download canceled");
                return;
            }

            string output_base;

            try {
                output_base = GetOutputPath(tags);
            } catch (InvalidPathException e) {
                DownloadFailed(e.Message);
                return;
            }

            await DownloadPosts(posts, output_base);

            ResetView($"Downloading {(CancelQueued ? "canceled" : "finished")}");
        }