Example #1
0
        private static async Task <bool> DownloadDocument(object data)
        {
            bool result = false;
            AzureBlobDocuments document = jsonHelper.FromJson <AzureBlobDocuments>(data.ToString());
            //AzureBlobDocuments document = JsonConvert.DeserializeObject<AzureBlobDocuments>(data.ToString());

            CloudAppendBlob appendBlob = CONTAINER.GetAppendBlobReference(document.Filename); // Get a reference to a blob named.

            List <AzureBlobDocuments> azureCollection = ListDocuments().GetAwaiter().GetResult();

            if (azureCollection != null)
            {
                if (azureCollection.Exists(o => o.Filename == document.Filename))
                {
                    try
                    {
                        new FileInfo(DOWNLOAD_DIRECTORY).Directory.Create(); //Create directory if not found

                        using (var fileStream = System.IO.File.OpenWrite(DOWNLOAD_DIRECTORY + document.Filename))
                        {
                            await appendBlob.DownloadToStreamAsync(fileStream);

                            result = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("Exception Caught - " + ex.Message);
                    }
                }
            }

            return(result);
        }
Example #2
0
        } // End of the LogError method

        #endregion

        #region Get methods

        /// <summary>
        /// Get an append blob as a stream
        /// </summary>
        public async Task GetLogAsStream(string blob_name, Stream stream)
        {
            // Get a blob object
            CloudAppendBlob blob = this.container.GetAppendBlobReference(blob_name);

            // Download the blob to a stream
            await blob.DownloadToStreamAsync(stream);

        } // End of the GetLogAsStream method
Example #3
0
        private static async Task downloadblobs()
        {
            Console.Write("Please enter text to download from blob: ");
            string text = Console.ReadLine();

            // Get a reference to a blob named.
            CloudAppendBlob appendBlob = container.GetAppendBlobReference(text);

            // Save the blob contents to a file. Path should be made beforehand.
            using (var fileStream = System.IO.File.OpenWrite(@"c:\download\" + text))
            {
                await appendBlob.DownloadToStreamAsync(fileStream);
            }
        }
Example #4
0
        } // End of the GetLogAsStream method

        /// <summary>
        /// Get an append blob as a stream
        /// </summary>
        public async Task<string> GetLogAsString(string blob_name)
        {
            // Create a string to return
            string log = "";

            // Get a blob object
            CloudAppendBlob blob = this.container.GetAppendBlobReference(blob_name);

            // Get the append blob
            using (MemoryStream stream = new MemoryStream())
            {
                await blob.DownloadToStreamAsync(stream);
                stream.Seek(0, SeekOrigin.Begin);
                log = Encoding.UTF8.GetString(stream.ToArray());
            }

            // Return the log
            return log;

        } // End of the GetLogAsString method
Example #5
0
 public static void DownloadToStream(this CloudAppendBlob blob, System.IO.Stream stream)
 {
     blob.DownloadToStreamAsync(stream).Wait();
 }