Esempio n. 1
0
 public static byte[] GetBlobMd5Hash(this CloudPageBlob blob)
 {
     blob.FetchAttributesAsync().ConfigureAwait(false).GetAwaiter().GetResult();
     return(String.IsNullOrEmpty(blob.Properties.ContentMD5)
         ? null
         : Convert.FromBase64String(blob.Properties.ContentMD5));
 }
Esempio n. 2
0
        private async Task ReadBlobMetadata(CloudPageBlob pageBlob)
        {
            await pageBlob.FetchAttributesAsync();

            var metadata = AddMetadata(pageBlob);

            var nullValue       = float.NaN;
            var nullValueParsed = metadata.ContainsKey("nullvalue") && float.TryParse(metadata["nullvalue"],
                                                                                      NumberStyles.Any, CultureInfo.InvariantCulture, out nullValue);

            var dataset = new Dataset
            {
                BlobName     = pageBlob.Name,
                MinX         = ParseHeaderDouble(metadata["minx"]),
                MaxX         = ParseHeaderDouble(metadata["maxx"]),
                MinY         = ParseHeaderDouble(metadata["miny"]),
                MaxY         = ParseHeaderDouble(metadata["maxy"]),
                Resolution   = ParseHeaderDouble(metadata["resolution"]),
                RowLength    = int.Parse(metadata["rowlength"]),
                ColumnLength = int.Parse(metadata["columnlength"]),
                HeaderOffset = int.Parse(metadata["headeroffset"]),
                ValueLength  = int.Parse(metadata["valuelength"]),
                Crs          = metadata.ContainsKey("crs") && metadata["crs"] != "WGS-84" ? int.Parse(metadata["crs"]) : 0,
                NullValue    = nullValueParsed ? nullValue : float.NaN
            };

            Files.Add(dataset);
            PageBlobs[dataset.BlobName] = pageBlob;
        }
Esempio n. 3
0
        public override void SetParameters(object parameters)
        {
            var jParameters = parameters as JObject;

            if (jParameters == null)
            {
                throw new ArgumentException("Expecting JObject parameters");
            }

            var settings = jParameters.ToObject <PageBlobSettings>();
            var client   = new CloudBlobClient(
                new Uri(string.Format("https://{0}.blob.core.windows.net/", settings.AccountName)),
                new StorageCredentials(settings.AccountName, settings.AccountKey));

            var container = client.GetContainerReference(settings.ContainerName.ToLower());

            container.CreateIfNotExistsAsync().Wait();
            cloudBlob = container.GetPageBlobReference(settings.BlobName);
            if (!cloudBlob.ExistsAsync().Result)
            {
                cloudBlob.CreateAsync(settings.BlobSizeGB * 1024L * 1024L * 1024L).Wait();
            }

            cloudBlob.FetchAttributesAsync().Wait();
        }
Esempio n. 4
0
 public static byte[] GetBlobMd5Hash(this CloudPageBlob blob, BlobRequestOptions requestOptions)
 {
     blob.FetchAttributesAsync(new AccessCondition(), requestOptions, operationContext: null)
     .ConfigureAwait(false).GetAwaiter().GetResult();
     return(String.IsNullOrEmpty(blob.Properties.ContentMD5)
         ? null
         : Convert.FromBase64String(blob.Properties.ContentMD5));
 }
Esempio n. 5
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)));
        }
Esempio n. 6
0
        protected async Task <BlobProperties> GetPropertiesAsync(CloudPageBlob pageBlob,
                                                                 CancellationToken cancellationToken)
        {
            if (pageBlob.Properties == null || pageBlob.Properties.Length < 0)
            {
                await pageBlob.FetchAttributesAsync(CreateAccessCondition(pageBlob), this.RequestOptions, this.OperationContext,
                                                    cancellationToken);
            }

            return(pageBlob.Properties);
        }
        /// <summary>
        /// Start copy using transfer mangager by source uri
        /// </summary>
        /// <param name="uri">source uri</param>
        /// <param name="destContainer">Destination CloudBlobContainer object</param>
        /// <param name="destBlobName">Destination blob name</param>
        /// <returns>Destination CloudBlob object</returns>
        private async Task StartCopyAsync(long taskId, IStorageBlobManagement destChannel, Uri uri, CloudBlobContainer destContainer, string destBlobName)
        {
            NameUtil.ValidateContainerName(destContainer.Name);
            NameUtil.ValidateBlobName(destBlobName);

            CloudPageBlob sourceBlob = new CloudPageBlob(uri);
            //try
            //{
            await sourceBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);

            VerifyIncrementalCopySourceBlob(sourceBlob);

            //}
            //catch (StorageException)
            //{
            //    //The source blob don't have read permission
            //    //We should no block the copy in this case,
            //}
            CloudPageBlob destBlob = GetDestBlob(destChannel, destContainer.Name, destBlobName);

            await this.StartCopyFromUri(taskId, destChannel, uri, destBlob);
        }
Esempio n. 8
0
 /// <inheritdoc />
 public Task FetchAttributesAsync(CancellationToken cancellationToken)
 {
     return(_sdk.FetchAttributesAsync(accessCondition: null, options: null, operationContext: null, cancellationToken: cancellationToken));
 }
Esempio n. 9
0
 /// <inheritdoc />
 public Task FetchAttributesAsync(CancellationToken cancellationToken)
 {
     return(_sdk.FetchAttributesAsync(cancellationToken));
 }