Ejemplo n.º 1
0
        /// <summary>
        /// ImageLoader worker todo work.
        /// Currently this fetches images for the specified tag and page
        /// </summary>
        private void BackgroundLoaderWork(object sender, DoWorkEventArgs e)
        {
            foreach (BasePost post in _postFetcher.GetImages(CurrentPage, TagsBox))
            {
                _threadList.Add(new BasePost(post));
            }

            if (_imageLoader.CancellationPending)
            {
                _threadList.Clear();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks that the board user is adding is valid
        /// </summary>
        private string IsValidBooru()
        {
            string retval    = null;
            bool   hadErrors = false;

            try
            {
                if (!string.IsNullOrEmpty(CurrentSelectedBoard.Name) && !string.IsNullOrEmpty(CurrentSelectedBoard.URL))
                {
                    CurrentSelectedBoard.URL = NormalizeURL(CurrentSelectedBoard.URL);

                    //Now we try and fetch a page until we get result... or an exception
                    PostsFetcher posts = new PostsFetcher(true);

                    try
                    {
                        CurrentSelectedBoard.ProviderType = ProviderAccessType.DanbooruV2;
                        if (posts.GetImages(1).Count > 0)
                        {
                            hadErrors = false;
                        }
                    }
                    catch
                    {
                        hadErrors = true;
                    }

                    if (hadErrors)
                    {
                        try
                        {
                            CurrentSelectedBoard.ProviderType = ProviderAccessType.XML;
                            if (posts.GetImages(1).Count > 0)
                            {
                                hadErrors = false;
                            }
                        }
                        catch
                        {
                            hadErrors = true;
                        }
                    }

                    if (hadErrors)
                    {
                        try
                        {
                            CurrentSelectedBoard.ProviderType = ProviderAccessType.JSON;
                            if (posts.GetImages(1).Count > 0)
                            {
                                hadErrors = false;
                            }
                        }
                        catch
                        {
                            hadErrors = true;
                        }
                    }

                    if (hadErrors)
                    {
                        try
                        {
                            CurrentSelectedBoard.ProviderType = ProviderAccessType.Gelbooru;
                            if (posts.GetImages(1).Count > 0)
                            {
                                hadErrors = false;
                            }
                        }
                        catch
                        {
                            hadErrors = true;
                        }
                    }

                    if (hadErrors)
                    {
                        retval = "Invalid or unsupported booru.";
                    }
                }
                else
                {
                    hadErrors = true;
                    retval    = "Enter address and name.";
                }
            }
            catch
            {
                hadErrors = true;
                retval    = "Invalid or unsupported booru.";
            }
            finally
            {
                if (!hadErrors)
                {
                    retval = null;
                }
            }

            return(retval);
        }