Esempio n. 1
0
        /// <summary>
        /// Delete a file from blob
        /// exits if file not found
        /// </summary>
        /// <param name="containerName"></param>
        /// <param name="fileName"></param>
        internal static void DeleteBlob(string fileName)
        {
            CloudBlockBlob blockBlob = AzureBlob.BlobContainer.GetBlockBlobReference(fileName);

            if (blockBlob.Exists())
            {
                AzureBlob.DeleteBlob(blockBlob);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Download Block Blob within specificed Container
        /// </summary>
        /// <param name="tmpFilePath"></param>
        /// <param name="containerName"></param>
        /// <param name="fileName"></param>
        internal static string DownloadBlob(string fileName, int cacheDurationSeconds)
        {
            CloudBlockBlob blockBlob = AzureBlob.BlobContainer.GetBlockBlobReference(fileName);

            if (blockBlob.Exists())
            {
                //check if blob is stale
                if (AzureBlob.IsStale(blockBlob, cacheDurationSeconds))
                {
                    AzureBlob.DeleteBlob(blockBlob);
                }
                else
                {
                    using (MemoryStream stream = new MemoryStream())
                    {
                        int attempt     = 0;
                        int MaxAttempts = 3;

                        while (++attempt <= MaxAttempts)
                        {
                            try
                            {
                                blockBlob.DownloadToStream(stream);
                                break;
                            }
                            catch (Exception ex)
                            {
                                if (attempt == MaxAttempts)
                                {
                                    throw ex;
                                }

                                Thread.Sleep(100);
                            }
                        }

                        string res = System.Text.Encoding.UTF8.GetString(stream.ToArray());
                    }
                }
            }

            return(null);
        }