Exemplo n.º 1
0
        public void UpdateSlideShowItem()
        {
            if (SlidesQueue.Count == 0)
            {
                return;
            }
            var slide = SlidesQueue.Peek();

            while (CachedSlides.Count >= MaxCacheSize)
            {
                var idx         = _random.Next(0, SlideShowElements.Count);
                var randomSlide = SlideShowElements[idx];
                while (!CachedSlides.ContainsKey(randomSlide.ModID) || SlidesQueue.Contains(randomSlide))
                {
                    idx         = _random.Next(0, SlideShowElements.Count);
                    randomSlide = SlideShowElements[idx];
                }

                //if (SlidesQueue.Contains(randomSlide)) continue;
                CachedSlides.Remove(randomSlide.ModID);
                if (AppState.GcCollect)
                {
                    GC.Collect();
                }
            }

            if (!slide.IsNSFW || (slide.IsNSFW && ShowNSFW))
            {
                _appState.SplashScreenImage = _appState._noneImage;
                if (slide.ImageURL != null && slide.Image != null)
                {
                    if (!CachedSlides.ContainsKey(slide.ModID))
                    {
                        return;
                    }
                    _appState.SplashScreenImage = slide.Image;
                }

                _appState.SplashScreenModName    = slide.ModName;
                _appState.SplashScreenAuthorName = slide.ModAuthor;
                _appState.SplashScreenSummary    = slide.ModDescription;
                _appState._nexusSiteURL          = slide.ModURL;
            }

            SlidesQueue.Dequeue();
            QueueRandomSlide(false, true);
        }
Exemplo n.º 2
0
        private bool QueueRandomSlide(bool init, bool checkLast)
        {
            var result  = false;
            var idx     = _random.Next(0, SlideShowElements.Count);
            var element = SlideShowElements[idx];

            if (checkLast)
            {
                while (element == _lastSlide && (!element.IsNSFW || (element.IsNSFW && ShowNSFW)))
                {
                    idx     = _random.Next(0, SlideShowElements.Count);
                    element = SlideShowElements[idx];
                }
            }

            if (element.ImageURL == null)
            {
                if (!init)
                {
                    SlidesQueue.Enqueue(element);
                }
            }
            else
            {
                if (!CachedSlides.ContainsKey(element.ModID))
                {
                    CacheImage(element);
                    CachedSlides.Add(element.ModID, element);
                    SlidesQueue.Enqueue(element);
                    result = true;
                }
                else
                {
                    if (!init)
                    {
                        SlidesQueue.Enqueue(element);
                    }
                }

                _lastSlide = element;
            }

            return(result);
        }