Exemplo n.º 1
0
        private static BitmapImage GetFromUrl(string value)
        {
            String url = FindUrl(value);

            if (url == null)
            {
                return(null);
            }
            String[] url_parts = new Uri(url).DnsSafeHost.Split(new char[] { '.' });
            String   key       = url_parts[url_parts.Length - 2];

            MemoryStream   ms      = new MemoryStream();
            HttpWebRequest request = WebRequest.CreateHttp(url);

            HttpWebResponse response       = request.GetResponse() as HttpWebResponse;
            Stream          responseStream = response.GetResponseStream();

            responseStream.CopyTo(ms);
            responseStream.Close();
            response.Close();

            ms.Position = 0;
            FileStream f = new FileStream(Path.Combine(cachePath, key + url.Substring(url.LastIndexOf('.'))), FileMode.Create, FileAccess.Write);

            ms.CopyTo(f);

            f.Close();
            ms.Position = 0;
            var bmap = CachedBitmap.BitmapImageFromStream(ms);

            _dictCache.Add(key, bmap);
            return(bmap);
        }
Exemplo n.º 2
0
 static FavIcon()
 {
     Directory.CreateDirectory(cachePath);
     string[] files = Directory.GetFiles(cachePath);
     foreach (var file in files)
     {
         FileStream fs     = new FileStream(file, FileMode.Open, FileAccess.Read);
         var        bitmap = CachedBitmap.BitmapImageFromStream(fs);
         _dictCache.Add(Path.GetFileNameWithoutExtension(file), bitmap);
         fs.Close();
     }
 }
Exemplo n.º 3
0
        public ShowTileViewModel(FavShowData show)
        {
            _dispatcher = Dispatcher.CurrentDispatcher;
            _show = show;
               // _showViewModel  = new ShowViewModel(_show);

            Title= _show.Name;
            IsLoadingVisible = (_show.IsLoading) ? Visibility.Visible : Visibility.Collapsed;
            RecalcText();
            if (!String.IsNullOrWhiteSpace(_show.Cover))
                Background = new CachedBitmap(_show.Cover);
            else
                Background = null;
            _show.PropertyChanged += _show_PropertyChanged;
        }
Exemplo n.º 4
0
        private static BitmapImage GetFromLetters(String value)
        {
            Bitmap     bmp   = new Bitmap(48, 48);
            RectangleF rectf = new RectangleF(0, 0, 48, 48);
            Graphics   g     = Graphics.FromImage(bmp);

            //g.Clear(System.Drawing.Color.Gray);

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
            StringFormat format = new StringFormat();

            format.LineAlignment = StringAlignment.Center;
            format.Alignment     = StringAlignment.Center;
            System.Windows.Media.Color c = ((SolidColorBrush)App.Current.FindResource("LabelTextBrush")).Color; // ye i know, it's hacky but it works
            g.DrawString("" + value.ToUpper().First(), new Font("Tahoma", 40, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B)), rectf, format);
            g.Flush();
            MemoryStream ms = new MemoryStream();

            bmp.Save(ms, ImageFormat.Png);
            ms.Position = 0;
            return(CachedBitmap.BitmapImageFromStream(ms));
        }
Exemplo n.º 5
0
        void _show_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Name")
            {
                Title = _show.Name;
            }
            else if (e.PropertyName == "Cover")
            {
                _dispatcher.Invoke(delegate
                {
                    Background = new CachedBitmap(_show.Cover);
                });

            } else if (e.PropertyName == "NumberOfEpisodes" || e.PropertyName == "NumberOfSeasons")
            {
                RecalcText();
            } else if (e.PropertyName == "NewEpisodes")
            {
                NewEpisodesVisible = (_show.NewEpisodes) ? Visibility.Visible : Visibility.Collapsed;
            } else if (e.PropertyName == "IsLoading")
            {
                IsLoadingVisible = (_show.IsLoading) ? Visibility.Visible : Visibility.Collapsed;
            }
        }
Exemplo n.º 6
0
 void _show_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     switch (e.PropertyName)
     {
         case nameof(FavShowData.Name):
             Title = _show.Name;
             break;
         case nameof(FavShowData.Cover):
             _dispatcher.Invoke(delegate
             {
                 Background = new CachedBitmap(_show.Cover);
             });
             break;
         case nameof(FavShowData.NumberOfEpisodes):
         case nameof(FavShowData.NumberOfSeasons):
             RecalcText();
             break;
         case nameof(FavShowData.IsLoading):
             IsLoadingVisible = (_show.IsLoading) ? Visibility.Visible : Visibility.Collapsed;
             break;
         default:
             if (String.IsNullOrEmpty(e.PropertyName) || e.PropertyName == nameof(FavShowData.Status) || e.PropertyName.StartsWith("NextEpisode") ||
                 e.PropertyName.StartsWith("PreviousEpisode") || e.PropertyName == nameof(FavShowData.NewEpisodes) || e.PropertyName == nameof(FavShowData.NewUpdates))
             {
                 RecalcNextPrevEpText();
             }
             break;
     }
 }