Exemplo n.º 1
0
        /// <summary>
        /// Gets from blob storage
        /// NOTE: If you plan on getting the same blob over and over and quickly saving you will need to throttle and retry
        /// </summary>
        /// <param name="blobContainer"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public BlobResultModel GetBlob(string blobContainer, string fileName)
        {
            InitializeStorage(blobContainer);

            string containerName = blobContainer.ToString().ToLower(); // must be lower case!

            Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient    blobStorage = blobStorageDictionary[containerName];
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container   = blobStorage.GetContainerReference(containerName);
            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob     blob        = container.GetBlockBlobReference(fileName);

            if (blob.Exists())
            {
                BlobResultModel blobResultModel = new BlobResultModel();

                blobResultModel.Stream = new MemoryStream();
                blob.DownloadToStream(blobResultModel.Stream);
                blobResultModel.eTag = blob.Properties.ETag;

                return(blobResultModel);
            }
            else
            {
                return(null);
            }
        } // GetBlob
Exemplo n.º 2
0
        } // GetBlobHandle

        /// <summary>
        /// Tests to see if a blob exists
        /// </summary>
        /// <param name="blobContainer"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public bool Exists(string blobContainer, string fileName)
        {
            InitializeStorage(blobContainer);

            string containerName = blobContainer.ToString().ToLower(); // must be lower case!

            Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient    blobStorage = blobStorageDictionary[containerName];
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container   = blobStorage.GetContainerReference(containerName);
            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob     blob        = container.GetBlockBlobReference(fileName);

            return(blob.Exists());
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the text from a blob reference
 /// </summary>
 /// <param name="blob"></param>
 /// <returns></returns>
 public BlobResultModel GetText(Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blob)
 {
     if (blob.Exists())
     {
         string          text            = string.Empty;
         BlobResultModel blobResultModel = new BlobResultModel();
         using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
         {
             blob.DownloadToStream(memoryStream);
             blobResultModel.Text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
             blobResultModel.eTag = blob.Properties.ETag;
         }
         return(blobResultModel);
     }
     else
     {
         return(null);
     }
 }