Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
        public void ImageThumbnailGeneration()
        {
            ContentItem ci = new ContentItem("Tamias striatus",
                @"http://upload.wikimedia.org/wikipedia/commons/f/f4/Tamias_striatus_CT.jpg",
                "The eastern chipmunk (Tamias striatus) is a chipmunk species native to eastern North America. Like other chipmunks, they transport food in pouches in their cheeks, as seen here. They eat bulbs, seeds, fruits, nuts, green plants, mushrooms, insects, worms, and bird eggs.",
                MediaType.GetMediaGuid(MediaTypes.Image));

            ci.ID = new Guid();

            ctrl.MakeThumbsForItem(ci);

            foreach (Size s in Utils.GetSizes())
            {
                string p = @"http://czbeta.blob.core.windows.net/images/" +
                    Thumbs.GenerateThumbnailUrlString(ci.ID, s.Width.ToString());
                if (Utils.GetImage(new Uri(p)).PixelWidth != s.Width)
                    Assert.Fail("Test image was not created properly");
            }

            ctrl.DeleteThumbsForItemID(ci.ID);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Determines kind of the media in the content item and returns image
        /// </summary>
        /// <param name="ciData"></param>
        /// <returns></returns>
        private static BitmapSource GetMediaThumbnail(ContentItem ciData)
        {
            BitmapSource bmp;
            string mediasrc = ciData.MediaTypeID.ToString().ToLower();

            MediaTypes mtype = MediaType.GetMediaType(ciData.MediaTypeID);

            try
            {
                if (mtype == MediaTypes.Image)
                {
                        bmp = (BitmapImage)Utils.GetImage(new Uri(ciData.MediaBlobURL));
                }
                else
                {
                        bmp = Utils.GenerateScreenshot(ciData.MediaBlobURL);
                }
            }
            catch (UriFormatException e)
            {
                Console.WriteLine(e.Message);
                bmp = null;
            }
            return bmp;
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        public void VimeoVideoThumbnailGeneration()
        {
            ContentItem ci = new ContentItem("Windsurfing JAWS", @"http://player.vimeo.com/video/2696386",
                "Windsurf is life",
                MediaType.GetMediaGuid(MediaTypes.Video));

            ci.ID = new Guid();

            ctrl.MakeThumbsForItem(ci);

            foreach (Size s in Utils.GetSizes())
            {
                string p = @"http://czbeta.blob.core.windows.net/images/" +
                    Thumbs.GenerateThumbnailUrlString(ci.ID, s.Width.ToString());
                if (Utils.GetImage(new Uri(p)).PixelWidth != s.Width)
                    Assert.Fail("Test image was not created properly");
            }

            ctrl.DeleteThumbsForItemID(ci.ID);
        }
Exemplo n.º 6
0
        public void YouTubeVideoThumbnailGeneration()
        {
            ContentItem ci = new ContentItem("Cute Owls", @"http://www.youtube.com/watch?v=a-LIfVJus8w",
                "No more kittens on youtube, there's a desire for change. Now people prefer to upload videos of little funny owls.",
                MediaType.GetMediaGuid(MediaTypes.Video));

            ci.ID = new Guid();

            ctrl.MakeThumbsForItem(ci);

            foreach (Size s in Utils.GetSizes())
            {
                string p = @"http://czbeta.blob.core.windows.net/images/" +
                    Thumbs.GenerateThumbnailUrlString(ci.ID, s.Width.ToString());
                if (Utils.GetImage(new Uri(p)).PixelWidth != s.Width)
                    Assert.Fail("Test image was not created properly");
            }

            ctrl.DeleteThumbsForItemID(ci.ID);
        }