Exemplo n.º 1
0
        /// <summary>
        /// Main view model for the BooruReader window
        /// </summary>
        public MainScreenVM()
            : base()
        {
            _imageList = new ObservableCollection<BasePost>();
            _previewList = new List<PrviewScreenView>();
            _postFetcher = new PostsFetcher();
            _threadList = new List<BasePost>();
            _imageLoader = new BackgroundWorker();
            _cache = new ImageCache();
            DownloadList = new ObservableCollection<BasePost>();
            DownloadList.CollectionChanged += DowloadList_CollectionChanged;
            _imageLoader.DoWork += BackgroundLoaderWork;
            _imageLoader.RunWorkerCompleted += ServerListLoadWorkerCompleted;
            _imageLoader.WorkerSupportsCancellation = true;
            _showedLastPageWarning = false;
            //Ugly hack for settings vm
            GlobalSettings.Instance.MainScreenVM = this;
            SettingsOpen = false;
            IsFavoritesMode = false;
            _favorites = new FavoriteHandler();

            InitialiseDelegates();

            ProgressBarVisibility = Visibility.Hidden;
        }
Exemplo 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;
        }