예제 #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
예제 #2
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);
     }
 }
예제 #3
0
        public static void ProcessQueueMessage([QueueTrigger("merchantid-179")] string blobName, [Blob("merchantid-179/{queueTrigger}")] Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blobToDownload)
        {
            Console.WriteLine("Msg is {0}", blobName);
            string[]     words = blobName.Split('_');
            MemoryStream ms;

            try
            {
                ms = new MemoryStream();
                blobToDownload.DownloadToStream(ms);
            }

            catch (Exception e)
            {
                Console.WriteLine("Blob Download to memory has Failed for Blob Name " + blobName + e.Message);
                return;
            }


            int key4Index = GettWordAfteKey(words, "KEY4");
            int key5Index = GettWordAfteKey(words, "KEY5");
            int key1Index = GettWordAfteKey(words, "KEY1");

            string storeid;
            string posid;
            string tablename;

            if (key4Index != -1)
            {
                Console.WriteLine(" store id is  = " + words[key4Index]);
                storeid = (words[key4Index]);
            }
            else
            {
                Console.WriteLine(" store id is  -1");
                return;
            }
            if (key5Index != -1)
            {
                Console.WriteLine(" pos id is  = " + words[key5Index]);
                posid = (words[key5Index]);
            }
            else
            {
                Console.WriteLine(" pos id is  -1");
                return;
            }
            if (key1Index != -1)
            {
                Console.WriteLine(" table name is  = " + words[key1Index]);
                tablename = (words[key1Index]);
            }
            else
            {
                Console.WriteLine("table name  is  -1");
                return;
            }
            try
            {
                if (blobName.Contains(".csv"))
                {
                    ProcesssingAllTable(tablename, ms, storeid, posid, blobName);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }