private static async void MediaIdPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { var _this = (CachedImage)dependencyObject; var _value = (string)dependencyPropertyChangedEventArgs.NewValue; if (PictureCache.HasPicture(_value)) { var entry = PictureCache.GetPicture(_value); if (_this.RenderSize.Width > ThumbnailSize || _this.RenderSize.Height > ThumbnailSize) { await entry.GetFullSizeAsync(); _this.Source = entry.XamlFullSizeBitmap; } else { await entry.GetThumbnailAsync(); _this.Source = entry.XamlThumbnailBitmap; } } else { // TODO: write to log when I figure this shit out } }
private async void GetCachedBitmapAsync() { isWaiting = true; WaitCompleted?.Invoke(this, EventArgs.Empty); var s = mediaId.ToString(); if (PictureCache.HasPicture(s)) { var entry = PictureCache.GetPicture(s); if (Thumbnail && entry.OriginalPicture.IsThumbnailAvailable) { await entry.GetThumbnailAsync(); Image = entry.XamlThumbnailBitmap; } else { await entry.GetFullSizeAsync(); Image = entry.XamlFullSizeBitmap; } } else { Image = new BitmapImage(ResourceUriHelper.BuildUri("DefaultArtwork.png")); Log.Warning(nameof(CacheImageSource), $"No picture cache entry for {s}"); } isWaiting = false; WaitCompleted?.Invoke(this, EventArgs.Empty); }
internal IActionResult PrintHtml(BaseController controller) { PictureCache.Clear(); using (var htmlExport = new HTMLExport()) { htmlExport.OpenAfterExport = false; htmlExport.Navigator = false; htmlExport.Layers = Layers; htmlExport.SinglePage = true; htmlExport.Pictures = Pictures; htmlExport.Print = true; htmlExport.Preview = true; htmlExport.SubFolder = false; htmlExport.EmbedPictures = EmbedPictures; //htmlExport.WebImagePrefix = WebUtils.ToUrl(FastReportGlobal.FastReportOptions.RouteBasePath, controller.RouteBasePath, ID, "picture") + "/"; htmlExport.WebImagePrefix = WebUtils.ToUrl(FastReportGlobal.FastReportOptions.RouteBasePath, $"preview.getPicture?reportId={ID}&pictureId="); htmlExport.ExportMode = HTMLExport.ExportType.WebPrint; byte[] file = null; using (MemoryStream ms = new MemoryStream()) { htmlExport.Export(Report, ms); file = ms.ToArray(); } if (htmlExport.PrintPageData != null) { //WebReportCache cache = new WebReportCache(this.Context); // add all pictures in cache for (int i = 0; i < htmlExport.PrintPageData.Pictures.Count; i++) { Stream stream = htmlExport.PrintPageData.Pictures[i]; byte[] image = new byte[stream.Length]; stream.Position = 0; int n = stream.Read(image, 0, (int)stream.Length); string picGuid = htmlExport.PrintPageData.Guids[i]; //cache.PutObject(picGuid, image); PictureCache[picGuid] = image; } // cleanup for (int i = 0; i < htmlExport.PrintPageData.Pictures.Count; i++) { Stream stream = htmlExport.PrintPageData.Pictures[i]; stream.Dispose(); stream = null; } htmlExport.PrintPageData.Pictures.Clear(); htmlExport.PrintPageData.Guids.Clear(); } return(new FileContentResult(file, "text/html")); } }
public PictureInfo GetPicture() { SetMarket(); string pictureUrl = string.Empty; string pictureName = string.Empty; string metadataJson = String.Empty; // Download metadata using (var client = new WebClient()) { metadataJson = client.DownloadString(BingBaseUrl + BingWallpaperDataUrl); byte[] bytes = Encoding.Default.GetBytes(metadataJson); metadataJson = Encoding.UTF8.GetString(bytes); } JObject metadataObject = JObject.Parse(metadataJson); List <JToken> imagesMetadata = metadataObject["images"].Children().ToList(); if (imagesMetadata.Count > 0) { pictureUrl = string.Format("{0}{1}_{2}.jpg", BingBaseUrl, imagesMetadata[0].ToObject <ImageResult>().UrlBase, PictureSize); // Get Picture name pictureName = ParsePictureName(imagesMetadata[0].ToObject <ImageResult>()); } // Download Image PictureCache pictureCache = new PictureCache("bing"); Uri pictureUri = null; try { pictureUri = pictureCache.DownloadImage(new Uri(pictureUrl), pictureName); } catch { pictureUrl = string.Format("{0}{1}", BingBaseUrl, imagesMetadata[0].ToObject <ImageResult>().Url); pictureUri = pictureCache.DownloadImage(new Uri(pictureUrl)); } PictureInfo info = new PictureInfo { PictureUrl = pictureUri, Description = imagesMetadata[0].ToObject <ImageResult>().Copyright }; return(info); }
public static void Write(EnqueuedTrack completedTrack, AlbumArtworkSaveFormat saveFormat, string path) { // Get album artwork from cache PictureCacheEntry albumArtwork = null; if (PictureCache.HasPicture(completedTrack.Smid.ToString())) { albumArtwork = PictureCache.GetPicture(completedTrack.Smid.ToString()); } // Write track tags var track = completedTrack.OriginalTrack; using (var file = File.Create(new File.LocalFileAbstraction(path), completedTrack.TrackFile.FileType.MimeType, ReadStyle.Average)) { file.Tag.Title = track.Title; file.Tag.Performers = new[] { track.Artist.Name }; if (track.Album.Artist != null) { file.Tag.AlbumArtists = new[] { track.Album.Artist.Name }; } file.Tag.Genres = new[] { track.Genre }; file.Tag.Album = track.Album.Title; file.Tag.Track = (uint)track.TrackNumber; file.Tag.TrackCount = (uint)(track.Album.GetNumberOfTracksOnDisc(track.DiscNumber) ?? 0); file.Tag.Disc = (uint)track.DiscNumber; file.Tag.DiscCount = (uint)(track.Album.GetTotalDiscs() ?? 0); file.Tag.Year = (uint)track.Year; file.Tag.Copyright = CopyrightText; file.Tag.Comment = CopyrightText; if (albumArtwork != null) { file.Tag.Pictures = new IPicture[] { new TagLib.Picture(new ByteVector(albumArtwork.FullSize)) }; } file.Save(); } // Write album artwork to file if requested string parentDirectory; if (saveFormat != AlbumArtworkSaveFormat.DontSave && (parentDirectory = Path.GetDirectoryName(path)) != null) { WriteArtworkFile(parentDirectory, saveFormat, track, albumArtwork); } }
public override bool Add(ModelBase model) { var pictureModel = model as PictureCacheModel; if (pictureModel == null || string.IsNullOrEmpty(pictureModel.Name)) { return(false); } var picture = new PictureCache() { Name = pictureModel.Name }; Context.PicturesInCache.Add(picture); Context.SaveChanges(); pictureModel.PictureCacheId = picture.Id; return(true); }
private static async void MediaIdPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { var _this = (CachedImage)dependencyObject; var _value = (string)dependencyPropertyChangedEventArgs.NewValue; if (PictureCache.HasPicture(_value)) { var entry = PictureCache.GetPicture(_value); if (_this.RenderSize.Width > ThumbnailSize || _this.RenderSize.Height > ThumbnailSize) { await entry.GetFullSizeAsync(); _this.MainImage.Source = entry.XamlFullSizeBitmap; } else { if (entry.OriginalPicture.IsThumbnailAvailable) { await entry.GetThumbnailAsync(); _this.MainImage.Source = entry.XamlThumbnailBitmap; } else { await entry.GetFullSizeAsync(); _this.MainImage.Source = entry.XamlFullSizeBitmap; } } } else { _this.MainImage.Source = new BitmapImage(ResourceUriHelper.BuildUri("DefaultArtwork.png")); Log.Warning(nameof(CachedImage), $"No picture cache entry for {_value}"); } }
internal StringBuilder ReportInHtml() { PictureCache.Clear(); var sb = new StringBuilder(); using (HTMLExport html = new HTMLExport()) { html.ExportMode = HTMLExport.ExportType.WebPreview; //html.CustomDraw += this.CustomDraw; html.StylePrefix = $"fr{ID}"; //html.StylePrefix = Prop.ControlID.Substring(0, 6); html.Init_WebMode(); html.Pictures = Pictures; //html.Pictures = Prop.Pictures; html.EmbedPictures = EmbedPictures; //html.EmbedPictures = EmbedPictures; html.OnClickTemplate = "fr{0}.click(this,'{1}','{2}')"; html.ReportID = ID; //html.ReportID = Prop.ControlID; html.EnableMargins = EnableMargins; //html.EnableMargins = Prop.EnableMargins; // calc zoom //CalcHtmlZoom(html); html.Zoom = Zoom; html.Layers = Layers; //html.Layers = Layers; html.PageNumbers = SinglePage ? "" : (CurrentPageIndex + 1).ToString(); //html.PageNumbers = SinglePage ? "" : (Prop.CurrentPage + 1).ToString(); //if (Prop.AutoWidth) // html.WidthUnits = HtmlSizeUnits.Percent; //if (Prop.AutoHeight) // html.HeightUnits = HtmlSizeUnits.Percent; //html.WebImagePrefix = WebUtils.ToUrl(FastReportGlobal.FastReportOptions.RouteBasePath, controller.RouteBasePath, ID, "picture") + "/"; //html.WebImagePrefix = String.Concat(context.Response.ApplyAppPathModifier(WebUtils.HandlerFileName), "?", WebUtils.PicsPrefix); html.WebImagePrefix = WebUtils.ToUrl(FastReportGlobal.FastReportOptions.RouteBasePath, $"preview.getPicture?reportId={ID}&pictureId="); html.SinglePage = SinglePage; //html.SinglePage = SinglePage; html.CurPage = CurrentPageIndex; //html.CurPage = CurrentPage; html.Export(Report, (Stream)null); //sb.Append("<div class=\"frbody\" style =\""); //if (HtmlLayers) // sb.Append("position:relative;z-index:0;"); //sb.Append("\">"); // container for html report body //int pageWidth = (int)Math.Ceiling(GetReportPageWidthInPixels() * html.Zoom); //int pageHeight = (int)Math.Ceiling(GetReportPageHeightInPixels() * html.Zoom); //int paddingLeft = (int)Math.Ceiling(Padding.Left * html.Zoom); //int paddingRight = (int)Math.Ceiling(Padding.Right * html.Zoom); //int paddingTop = (int)Math.Ceiling(Padding.Top * html.Zoom); //int paddingBottom = (int)Math.Ceiling(Padding.Bottom * html.Zoom); //sb.Append("<div class=\"frcontainer\" style=\"width:" + pageWidth + // "px;height:" + (SinglePage ? pageHeight * html.Count : pageHeight) + // "px;padding-left:" + paddingLeft + // "px;padding-right:" + paddingRight + // "px;padding-top:" + paddingTop + // "px;padding-bottom:" + paddingBottom + "px\">"); if (html.Count > 0) { if (SinglePage) { DoAllHtmlPages(sb, html); CurrentPageIndex = 0; //Prop.CurrentPage = 0; } else { DoHtmlPage(sb, html, 0); } } //sb.Append("</div>"); //sb.Append("</div>"); // important container, it cuts off elements that are outside of the report page bounds int pageWidth = (int)Math.Ceiling(GetReportPageWidthInPixels() * html.Zoom); int pageHeight = (int)Math.Ceiling(GetReportPageHeightInPixels() * html.Zoom); sb.Insert(0, $@"<div style=""width:{pageWidth}px;height:{(SinglePage ? pageHeight * html.Count : pageHeight)}px;overflow:hidden;display:inline-block;"">"); sb.Append("</div>"); } return(sb); }