示例#1
0
        private IEnumerable <IndexRange> GetPageRanges()
        {
            pageBlob.FetchAttributesAsync(new AccessCondition(), blobRequestOptions, operationContext: null)
            .ConfigureAwait(false).GetAwaiter().GetResult();
            IEnumerable <PageRange> pageRanges = pageBlob.GetPageRangesAsync(null, null, new AccessCondition(), blobRequestOptions, operationContext: null)
                                                 .ConfigureAwait(false).GetAwaiter().GetResult();

            pageRanges = pageRanges.OrderBy(range => range.StartOffset);
            return(pageRanges.Select(pr => new IndexRange(pr.StartOffset, pr.EndOffset)));
        }
示例#2
0
        //
        // Function for calculating the size of a blob
        //
        private static void CalculateBlobSize(string accountName, object containerName, object blobName, string sasToken, bool isDisk)
        {
            // Now that we hvae the SAS-token, let's calculate the size of the snapshot
            var blobSizeInBytes = 0F;

            System.Console.WriteLine("Trying to retrieve Blob...");
            var blob    = default(ICloudBlob);
            var blobUri = new Uri($"https://{accountName}.blob.core.windows.net/{containerName}/{blobName}?{sasToken}");

            try
            {
                var reqOptions = new BlobRequestOptions
                {
                    ServerTimeout        = TimeSpan.FromMinutes(5),
                    MaximumExecutionTime = TimeSpan.FromMinutes(5)
                };

                if (isDisk)
                {
                    var pageBlob = new CloudPageBlob(blobUri);
                    blob = pageBlob;

                    Task.WaitAll(blob.FetchAttributesAsync());

                    var blobSize = pageBlob.Properties.Length;

                    System.Console.WriteLine($"Blob size per API in bytes: {blobSize}.");
                    System.Console.WriteLine($"Blob size per API in MB: {blobSize / 1024 / 1024}.");
                    System.Console.WriteLine($"Blob size per API in GB: {blobSize / 1024 / 1024 / 1024}.");

                    var pageRanges = pageBlob.GetPageRangesAsync().Result;
                    foreach (var rg in pageRanges)
                    {
                        blobSizeInBytes += (12 + (rg.EndOffset - rg.StartOffset));
                    }
                }
                else
                {
                    var blockBlob = new CloudBlockBlob(blobUri);
                    blob = blockBlob;

                    blobSizeInBytes += 8;

                    var blockList = blockBlob.DownloadBlockListAsync().Result;
                    foreach (var bl in blockList)
                    {
                        blobSizeInBytes += bl.Length + bl.Name.Length;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine($"EXCPETION: {ex.Message}");
                if (ex.InnerException != null)
                {
                    System.Console.WriteLine($"INNER EXCEPTION: {ex.InnerException.Message}");
                }
            }

            // Add the base size to the previously calculated size
            blobSizeInBytes += (124 + (blob.Name.Length * 2));
            foreach (var md in blob.Metadata)
            {
                blobSizeInBytes += (3 + (md.Key.Length + md.Value.Length));
            }

            // Output the final size of the blob
            System.Console.WriteLine("");
            System.Console.WriteLine($"Blob Size per calculation in bytes: {blobSizeInBytes}");
            System.Console.WriteLine($"Blob Size per calculation in MB:    {blobSizeInBytes / 1024 / 1024}");
            System.Console.WriteLine($"Blob Size per calculation in GB:    {blobSizeInBytes / 1024 / 1024 / 1024}");
        }
 public static IEnumerable <PageRange> GetPageRanges(this CloudPageBlob blob, long?offset = default(long?), long?length = default(long?), AccessCondition accessCondition = null, BlobRequestOptions options = null, OperationContext operationContext = null)
 {
     return(blob.GetPageRangesAsync(offset, length, accessCondition, options, operationContext).GetAwaiter().GetResult());
 }