/// <summary> /// Gets the container's properties from the response. /// </summary> /// <param name="response">The web response.</param> /// <returns>The container's attributes.</returns> public static BlobContainerProperties GetProperties(HttpWebResponse response) { CommonUtility.AssertNotNull("response", response); // Set the container properties BlobContainerProperties containerProperties = new BlobContainerProperties(); containerProperties.ETag = HttpResponseParsers.GetETag(response); #if WINDOWS_PHONE containerProperties.LastModified = HttpResponseParsers.GetLastModified(response); #else containerProperties.LastModified = response.LastModified.ToUniversalTime(); #endif // Get lease properties containerProperties.LeaseStatus = BlobHttpResponseParsers.GetLeaseStatus(response); containerProperties.LeaseState = BlobHttpResponseParsers.GetLeaseState(response); containerProperties.LeaseDuration = BlobHttpResponseParsers.GetLeaseDuration(response); return(containerProperties); }
private IListBlobEntry ParseBlobEntry(Uri baseUri) { BlobAttributes blob = new BlobAttributes(); string name = null; // copy blob attribute strings string copyId = null; string copyStatus = null; string copyCompletionTime = null; string copyProgress = null; string copySource = null; string copyStatusDescription = null; string copyDestinationSnapshotTime = null; string blobTierString = null; bool? blobTierInferred = null; string rehydrationStatusString = null; DateTimeOffset?blobTierLastModifiedTime = null; this.reader.ReadStartElement(); while (this.reader.IsStartElement()) { if (this.reader.IsEmptyElement) { this.reader.Skip(); } else { switch (this.reader.Name) { case Constants.NameElement: name = reader.ReadElementContentAsString(); break; case Constants.SnapshotElement: blob.SnapshotTime = reader.ReadElementContentAsString().ToUTCTime(); break; case Constants.PropertiesElement: this.reader.ReadStartElement(); while (this.reader.IsStartElement()) { if (this.reader.IsEmptyElement) { this.reader.Skip(); } else { switch (this.reader.Name) { case Constants.LastModifiedElement: blob.Properties.LastModified = reader.ReadElementContentAsString().ToUTCTime(); break; case Constants.EtagElement: blob.Properties.ETag = string.Format(CultureInfo.InvariantCulture, "\"{0}\"", reader.ReadElementContentAsString()); break; case Constants.ContentLengthElement: blob.Properties.Length = reader.ReadElementContentAsLong(); break; case Constants.CacheControlElement: blob.Properties.CacheControl = reader.ReadElementContentAsString(); break; case Constants.ContentTypeElement: blob.Properties.ContentType = reader.ReadElementContentAsString(); break; case Constants.HeaderConstants.ContentDispositionResponseHeader: blob.Properties.ContentDisposition = reader.ReadElementContentAsString(); break; case Constants.ContentEncodingElement: blob.Properties.ContentEncoding = reader.ReadElementContentAsString(); break; case Constants.ContentLanguageElement: blob.Properties.ContentLanguage = reader.ReadElementContentAsString(); break; case Constants.ContentMD5Element: blob.Properties.ContentMD5 = reader.ReadElementContentAsString(); break; case Constants.BlobTypeElement: string blobTypeString = reader.ReadElementContentAsString(); switch (blobTypeString) { case Constants.BlockBlobValue: blob.Properties.BlobType = BlobType.BlockBlob; break; case Constants.PageBlobValue: blob.Properties.BlobType = BlobType.PageBlob; break; case Constants.AppendBlobValue: blob.Properties.BlobType = BlobType.AppendBlob; break; } break; case Constants.LeaseStatusElement: blob.Properties.LeaseStatus = BlobHttpResponseParsers.GetLeaseStatus(reader.ReadElementContentAsString()); break; case Constants.LeaseStateElement: blob.Properties.LeaseState = BlobHttpResponseParsers.GetLeaseState(reader.ReadElementContentAsString()); break; case Constants.LeaseDurationElement: blob.Properties.LeaseDuration = BlobHttpResponseParsers.GetLeaseDuration(reader.ReadElementContentAsString()); break; case Constants.CopyIdElement: copyId = reader.ReadElementContentAsString(); break; case Constants.CopyCompletionTimeElement: copyCompletionTime = reader.ReadElementContentAsString(); break; case Constants.CopyStatusElement: copyStatus = reader.ReadElementContentAsString(); break; case Constants.CopyProgressElement: copyProgress = reader.ReadElementContentAsString(); break; case Constants.CopySourceElement: copySource = reader.ReadElementContentAsString(); break; case Constants.CopyStatusDescriptionElement: copyStatusDescription = reader.ReadElementContentAsString(); break; case Constants.ServerEncryptionElement: blob.Properties.IsServerEncrypted = BlobHttpResponseParsers.GetServerEncrypted(reader.ReadElementContentAsString()); break; case Constants.IncrementalCopy: blob.Properties.IsIncrementalCopy = BlobHttpResponseParsers.GetIncrementalCopyStatus(reader.ReadElementContentAsString()); break; case Constants.CopyDestinationSnapshotElement: copyDestinationSnapshotTime = reader.ReadElementContentAsString(); break; case Constants.AccessTierElement: blobTierString = reader.ReadElementContentAsString(); break; case Constants.ArchiveStatusElement: rehydrationStatusString = reader.ReadElementContentAsString(); break; case Constants.AccessTierInferred: blobTierInferred = reader.ReadElementContentAsBoolean(); break; case Constants.AccessTierChangeTimeElement: string t = reader.ReadElementContentAsString(); blobTierLastModifiedTime = DateTimeOffset.Parse(t, CultureInfo.InvariantCulture); break; default: reader.Skip(); break; } } } this.reader.ReadEndElement(); break; case Constants.MetadataElement: blob.Metadata = Response.ParseMetadata(this.reader); break; default: this.reader.Skip(); break; } } } this.reader.ReadEndElement(); Uri uri = NavigationHelper.AppendPathToSingleUri(baseUri, name); if (blob.SnapshotTime.HasValue) { UriQueryBuilder builder = new UriQueryBuilder(); builder.Add("snapshot", Request.ConvertDateTimeToSnapshotString(blob.SnapshotTime.Value)); uri = builder.AddToUri(uri); } blob.StorageUri = new StorageUri(uri); if (!string.IsNullOrEmpty(copyStatus)) { blob.CopyState = BlobHttpResponseParsers.GetCopyAttributes( copyStatus, copyId, copySource, copyProgress, copyCompletionTime, copyStatusDescription, copyDestinationSnapshotTime); } if (!string.IsNullOrEmpty(blobTierString)) { StandardBlobTier? standardBlobTier; PremiumPageBlobTier?premiumPageBlobTier; BlobHttpResponseParsers.GetBlobTier(blob.Properties.BlobType, blobTierString, out standardBlobTier, out premiumPageBlobTier); blob.Properties.StandardBlobTier = standardBlobTier; blob.Properties.PremiumPageBlobTier = premiumPageBlobTier; } blob.Properties.RehydrationStatus = BlobHttpResponseParsers.GetRehydrationStatus(rehydrationStatusString); blob.Properties.BlobTierLastModifiedTime = blobTierLastModifiedTime; blob.Properties.BlobTierInferred = blobTierInferred; return(new ListBlobEntry(name, blob)); }
/// <summary> /// Gets the blob's properties from the response. /// </summary> /// <param name="response">The web response.</param> /// <returns>The blob's properties.</returns> public static BlobProperties GetProperties(HttpWebResponse response) { CommonUtility.AssertNotNull("response", response); BlobProperties properties = new BlobProperties(); properties.ETag = HttpResponseParsers.GetETag(response); #if WINDOWS_PHONE properties.LastModified = HttpResponseParsers.GetLastModified(response); properties.ContentLanguage = response.Headers[Constants.HeaderConstants.ContentLanguageHeader]; #else properties.LastModified = response.LastModified.ToUniversalTime(); properties.ContentLanguage = response.Headers[HttpResponseHeader.ContentLanguage]; #endif properties.ContentDisposition = response.Headers[Constants.HeaderConstants.ContentDispositionResponseHeader]; properties.ContentEncoding = response.Headers[HttpResponseHeader.ContentEncoding]; // For range gets, only look at 'x-ms-blob-content-md5' for overall MD5 if (response.Headers[HttpResponseHeader.ContentRange] != null) { properties.ContentMD5 = response.Headers[Constants.HeaderConstants.BlobContentMD5Header]; } else { properties.ContentMD5 = response.Headers[HttpResponseHeader.ContentMd5]; } properties.ContentType = response.Headers[HttpResponseHeader.ContentType]; properties.CacheControl = response.Headers[HttpResponseHeader.CacheControl]; string blobEncryption = response.Headers[Constants.HeaderConstants.ServerEncrypted]; properties.IsServerEncrypted = string.Equals(blobEncryption, Constants.HeaderConstants.TrueHeader, StringComparison.OrdinalIgnoreCase); string incrementalCopy = response.Headers[Constants.HeaderConstants.IncrementalCopyHeader]; properties.IsIncrementalCopy = string.Equals(incrementalCopy, Constants.HeaderConstants.TrueHeader, StringComparison.OrdinalIgnoreCase); // Get blob type string blobType = response.Headers[Constants.HeaderConstants.BlobType]; if (!string.IsNullOrEmpty(blobType)) { properties.BlobType = (BlobType)Enum.Parse(typeof(BlobType), blobType, true); } // Get lease properties properties.LeaseStatus = GetLeaseStatus(response); properties.LeaseState = GetLeaseState(response); properties.LeaseDuration = GetLeaseDuration(response); // Get the content length. Prioritize range and x-ms over content length for the special cases. string rangeHeader = response.Headers[HttpResponseHeader.ContentRange]; string contentLengthHeader = response.Headers[Constants.HeaderConstants.ContentLengthHeader]; string blobContentLengthHeader = response.Headers[Constants.HeaderConstants.BlobContentLengthHeader]; if (!string.IsNullOrEmpty(rangeHeader)) { properties.Length = long.Parse(rangeHeader.Split('/')[1], CultureInfo.InvariantCulture); } else if (!string.IsNullOrEmpty(blobContentLengthHeader)) { properties.Length = long.Parse(blobContentLengthHeader, CultureInfo.InvariantCulture); } else if (!string.IsNullOrEmpty(contentLengthHeader)) { // On Windows Phone, ContentLength property is not always same as Content-Length header, // so we try to parse the header first. properties.Length = long.Parse(contentLengthHeader, CultureInfo.InvariantCulture); } else { properties.Length = response.ContentLength; } // Get sequence number string sequenceNumber = response.Headers[Constants.HeaderConstants.BlobSequenceNumber]; if (!string.IsNullOrEmpty(sequenceNumber)) { properties.PageBlobSequenceNumber = long.Parse(sequenceNumber, CultureInfo.InvariantCulture); } // Get committed block count string comittedBlockCount = response.Headers[Constants.HeaderConstants.BlobCommittedBlockCount]; if (!string.IsNullOrEmpty(comittedBlockCount)) { properties.AppendBlobCommittedBlockCount = int.Parse(comittedBlockCount, CultureInfo.InvariantCulture); } // Get the tier of the blob string premiumPageBlobTierInferredString = response.Headers[Constants.HeaderConstants.AccessTierInferredHeader]; if (!string.IsNullOrEmpty(premiumPageBlobTierInferredString)) { properties.BlobTierInferred = Convert.ToBoolean(premiumPageBlobTierInferredString); } string blobTierString = response.Headers[Constants.HeaderConstants.AccessTierHeader]; StandardBlobTier? standardBlobTier; PremiumPageBlobTier?premiumPageBlobTier; BlobHttpResponseParsers.GetBlobTier(properties.BlobType, blobTierString, out standardBlobTier, out premiumPageBlobTier); properties.StandardBlobTier = standardBlobTier; properties.PremiumPageBlobTier = premiumPageBlobTier; if ((properties.PremiumPageBlobTier.HasValue || properties.StandardBlobTier.HasValue) && !properties.BlobTierInferred.HasValue) { properties.BlobTierInferred = false; } // Get the rehydration status string rehydrationStatusString = response.Headers[Constants.HeaderConstants.ArchiveStatusHeader]; properties.RehydrationStatus = BlobHttpResponseParsers.GetRehydrationStatus(rehydrationStatusString); // Get the time the tier of the blob was last modified string accessTierChangeTimeString = response.Headers[Constants.HeaderConstants.AccessTierChangeTimeHeader]; if (!string.IsNullOrEmpty(accessTierChangeTimeString)) { properties.BlobTierLastModifiedTime = DateTimeOffset.Parse(accessTierChangeTimeString, CultureInfo.InvariantCulture); } return(properties); }
/// <summary> /// Reads a container entry completely including its properties and metadata. /// </summary> /// <returns>Container listing entry</returns> private BlobContainerEntry ParseContainerEntry(Uri baseUri) { string name = null; IDictionary <string, string> metadata = null; BlobContainerProperties containerProperties = new BlobContainerProperties(); containerProperties.PublicAccess = BlobContainerPublicAccessType.Off; this.reader.ReadStartElement(); while (this.reader.IsStartElement()) { if (this.reader.IsEmptyElement) { this.reader.Skip(); } else { switch (this.reader.Name) { case Constants.NameElement: name = this.reader.ReadElementContentAsString(); break; case Constants.PropertiesElement: this.reader.ReadStartElement(); while (this.reader.IsStartElement()) { if (this.reader.IsEmptyElement) { this.reader.Skip(); } else { switch (this.reader.Name) { case Constants.LastModifiedElement: containerProperties.LastModified = reader.ReadElementContentAsString().ToUTCTime(); break; case Constants.EtagElement: containerProperties.ETag = reader.ReadElementContentAsString(); break; case Constants.LeaseStatusElement: containerProperties.LeaseStatus = BlobHttpResponseParsers.GetLeaseStatus(reader.ReadElementContentAsString()); break; case Constants.LeaseStateElement: containerProperties.LeaseState = BlobHttpResponseParsers.GetLeaseState(reader.ReadElementContentAsString()); break; case Constants.LeaseDurationElement: containerProperties.LeaseDuration = BlobHttpResponseParsers.GetLeaseDuration(reader.ReadElementContentAsString()); break; case Constants.PublicAccessElement: containerProperties.PublicAccess = ContainerHttpResponseParsers.GetContainerAcl(reader.ReadElementContentAsString()); break; default: reader.Skip(); break; } } } this.reader.ReadEndElement(); break; case Constants.MetadataElement: metadata = Response.ParseMetadata(this.reader); break; default: reader.Skip(); break; } } } this.reader.ReadEndElement(); if (metadata == null) { metadata = new Dictionary <string, string>(); } return(new BlobContainerEntry { Properties = containerProperties, Name = name, Uri = NavigationHelper.AppendPathToSingleUri(baseUri, name), Metadata = metadata, }); }