/// <summary> /// Generates content item visual and makes a picture of it /// </summary> /// <param name="_title">String containing title of the content item</param> /// <param name="_url">Uri of the media element of the content item</param> /// <param name="_desc">String contanting the description of the content item</param> /// <param name="initialSize">Initial size of the content item</param> /// <returns>BitmapSource with image of the content item of the specified size</returns> internal static BitmapSource[] MakeThumbs(ContentItem ciData, Size[] sizes, Size initialSize) { if (ciData.thumbnail == null) { ciData.thumbnail = Thumbs.GetMediaThumbnail(ciData); } if (ciData.thumbnail == null) { // cannot create thumbnail return(null); } ContentItemControl element = new ContentItemControl(); element.Height = initialSize.Height; element.Width = initialSize.Width; element.Data = ciData; element.Measure(initialSize); element.Arrange(new Rect(initialSize)); BitmapSource bmpSource = CreateBitmapSourceFromVisual(initialSize, element); return(CreateResizedBitmapSources(bmpSource, sizes)); }
/// <summary> /// Create thumbs for specific item /// </summary> /// <param name="ciGuid">ContentItem to create thumbnail of</param> public void MakeThumbsForItem(ContentItem ci) { MediaTypes mt = MediaType.GetMediaType(ci.MediaTypeID); if (mt == MediaTypes.Video || mt == MediaTypes.Image || mt == MediaTypes.PDF || mt == MediaTypes.Photosynth) { mrLogger.Log("Making thumbs for content item with id " + ci.ID.ToString()); // Create bitmaps of Infodot BitmapSource[] resultBmps = Thumbs.MakeThumbs(ci, Utils.GetSizes(), InitialSize); if (resultBmps == null) { string c = "Cannot create thumbnails for Content Item with ID " + ci.ID.ToString() + ", skipping."; Console.WriteLine(c); mrLogger.Log(c); return; } // Save thumbnails foreach (BitmapSource bmp in resultBmps) { SaveThumbnailAsPng(bmp, ci.ID); } } else { string ms = "Media Type for Content Item " + ci.ID.ToString() + " is not supported"; Console.WriteLine(ms); mrLogger.Log(ms); } }
/// <summary> /// Delete blob if it exists /// </summary> /// <param name="id">Id of the ContentItem for which blob was created</param> public void DeleteThumbsForItemID(Guid id) { foreach (Size s in Utils.GetSizes()) { String p = Thumbs.GenerateThumbnailUrlString(id, s.Width.ToString()); mrLogger.Log("Performing deletion of thumbnails with path " + p); // Get name of the blob CloudBlob blob = blobContainer.GetBlobReference(p); blob.DeleteIfExists(); } }
private void SaveThumbnailAsPng(Stream remoteStream, Guid id) { CloudBlob blob = blobContainer.GetBlobReference(Thumbs.GenerateThumbnailUrlString(id, remoteStream.Length.ToString())); mrLogger.Log("Azure: started uploading png picture to the blob: " + blob.Uri); // Upload a file from the memory stream to the blob. blob.UploadFromStream(remoteStream); blob.Properties.ContentType = "image/png"; blob.SetProperties(); mrLogger.Log("Azure: finishing uploading blob"); }
/// <summary> /// Check whether thumbnail exists for specified contentitem id /// </summary> /// <param name="id">ContentItem Id</param> /// <returns>True if all thumbnails for specified ContentItem id exist, False if any of them doesn't</returns> private bool CheckThumbnailExistenceByItemID(Guid id) { foreach (Size s in Utils.GetSizes()) { // Get name of the blob CloudBlob blob = blobContainer.GetBlobReference(Thumbs.GenerateThumbnailUrlString(id, s.Width.ToString())); // Check it existence if (!BlobExists(blob)) { return(false); } } return(true); }
/// <summary> /// Connects to blob storage and saves bitmap under the specified path with given name /// </summary> /// <param name="bmp">BitmapSource to upload into the blob</param> /// <param name="relativePath"></param> /// <param name="filename"></param> private void SaveThumbnailAsPng(BitmapSource bmp, Guid id) { using (var stream = new MemoryStream()) { PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Interlace = PngInterlaceOption.On; encoder.Frames.Add(BitmapFrame.Create(bmp)); encoder.Save(stream); stream.Seek(0, SeekOrigin.Begin); CloudBlob blob = blobContainer.GetBlobReference(Thumbs.GenerateThumbnailUrlString(id, bmp.Width.ToString())); mrLogger.Log("Azure: started uploading png picture to the blob: " + blob.Uri); // Upload a file from the memory stream to the blob. blob.UploadFromStream(stream); blob.Properties.ContentType = "image/png"; blob.SetProperties(); mrLogger.Log("Azure: finishing uploading blob"); } }