コード例 #1
0
        /// <summary>
        /// Creates and uploades to storage thumbnails for the given content item.
        /// </summary>
        /// <param name="contentItem"></param>
        internal void CreateThumbnails(ContentItem contentItem)
        {
            if (contentItem == null || _thumbnailsStorage == null || contentItem.Uri == null || string.Compare(contentItem.MediaType, "Image", StringComparison.OrdinalIgnoreCase) != 0)
                return;

            // Retrieve storage account information
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_thumbnailsStorage);

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to images container.
            CloudBlobContainer imagesContainer = blobClient.GetContainerReference("images");
            if (!imagesContainer.Exists())
            {
                imagesContainer.CreateIfNotExists();
                imagesContainer.SetPermissions(
                    new BlobContainerPermissions
                    {
                        PublicAccess = BlobContainerPublicAccessType.Blob
                    });
            }

            // Generate thumbnails
            WebRequest request = WebRequest.Create(contentItem.Uri);
            using (WebResponse response = request.GetResponse())
            {
                Stream responseStream = response.GetResponseStream();
                using (Bitmap bitmap = new Bitmap(responseStream))
                {
                    if (response.ContentLength > _maxSourceContentLength)
                    {
                        throw new InvalidDataException("Source image is too big.");
                    }

                    SaveUploadThumbnail(imagesContainer, contentItem.Id.ToString(), bitmap, 8);
                    SaveUploadThumbnail(imagesContainer, contentItem.Id.ToString(), bitmap, 16);
                    SaveUploadThumbnail(imagesContainer, contentItem.Id.ToString(), bitmap, 32);
                    SaveUploadThumbnail(imagesContainer, contentItem.Id.ToString(), bitmap, 64);
                    SaveUploadThumbnail(imagesContainer, contentItem.Id.ToString(), bitmap, 128);
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: sowmyavenkat1986/LocaltoDB
 //used if creating timeline objects instead of flat json objects
 private static Exhibit createExhibit(Timeline j, String URL, Collection col)
 {
     Exhibit e = new Exhibit();
     e.Id = Guid.NewGuid();
     e.Title = j.Title + " - Exhibit"; //todo
     e.Threshold = "8. Origins of modern world"; //todo
     e.Regime = "Humanity";  //todo
     e.TimeUnit = "ce";
     e.Day = j.FromDay;
     e.Month = j.FromMonth;
     e.Year = j.FromYear;
     e.Sequence = 100;
     e.UniqueId = my_exhibit_count++;
     e.Collection = col;
     e.ContentItems = new System.Collections.ObjectModel.Collection<ContentItem>();
     for (int i = 0; i < 4; i++)
     {
         ContentItem c = new ContentItem();
         c.Id = Guid.NewGuid();
         c.UniqueId = my_contentitem_count++;
         c.Title = j.Title + "- ContentItem";
         c.Threshold = "8. Origins of modern world";
         c.Regime = "Humanity";
         c.TimeUnit = "ce";
         c.Year = j.ToYear;
         c.Order = 1; //todo
         c.HasBibliography = false; //todo
         c.MediaSource = "Library of Congress"; //todo
         c.Attribution = "Library of Congress";  //todo
         c.Collection = col;
         switch (i)
         {
             case 0:
                 {
                     c.Caption = j.Title + "- JP2";
                     c.MediaType = "JP2";
                     c.Uri = URL + ".jp2";
                     break;
                 }
             case 1:
                 {
                     c.Caption = j.Title + "- TXT";
                     c.MediaType = "TXT";
                     c.Uri = URL + "/ocr.txt";
                     break;
                 }
             case 2:
                 {
                     c.Caption = j.Title + "- PDF";
                     c.MediaType = "PDF";
                     c.Uri = URL + ".pdf";
                     break;
                 }
             case 3:
                 {
                     c.Caption = j.Title + "- OCR";
                     c.MediaType = "OCR";
                     c.Uri = URL + "/ocr.xml";
                     break;
                 }
         }
         // Insert into db here
         dbInst.ContentItems.Add(c);
         e.ContentItems.Add(c);
     }
     dbInst.Exhibits.Add(e);
     return e;
 }