/// <summary> /// Gets the blob's attributes, including its metadata and properties, from the response. /// </summary> /// <param name="response"> The web response. </param> /// <returns> The blob's attributes. </returns> public static BlobAttributes GetAttributes(HttpWebResponse response) { var attributes = new BlobAttributes(); var properties = attributes.Properties = new BlobProperties(); properties.CacheControl = response.Headers[HttpResponseHeader.CacheControl]; properties.ContentEncoding = response.Headers[HttpResponseHeader.ContentEncoding]; properties.ContentLanguage = response.Headers[HttpResponseHeader.ContentLanguage]; properties.ContentMD5 = response.Headers[HttpResponseHeader.ContentMd5]; properties.ContentType = response.Headers[HttpResponseHeader.ContentType]; properties.ETag = response.Headers[HttpResponseHeader.ETag]; properties.LastModifiedUtc = response.LastModified.ToUniversalTime(); var blobType = response.Headers[Constants.HeaderConstants.BlobType]; var leaseStatus = response.Headers[Constants.HeaderConstants.LeaseStatus]; if (!string.IsNullOrEmpty(blobType)) { properties.BlobType = (BlobType)Enum.Parse(typeof(BlobType), blobType, true); } if (!string.IsNullOrEmpty(leaseStatus)) { properties.LeaseStatus = (LeaseStatus)Enum.Parse(typeof(LeaseStatus), leaseStatus, true); } // Get the content length. Prioritize range and x-ms over content length for the special cases. var rangeHeader = response.Headers[HttpResponseHeader.ContentRange]; var xContentLengthHeader = response.Headers[Constants.HeaderConstants.ContentLengthHeader]; if (!string.IsNullOrEmpty(rangeHeader)) { properties.Length = long.Parse(rangeHeader.Split('/')[1]); } else if (!string.IsNullOrEmpty(xContentLengthHeader)) { properties.Length = long.Parse(xContentLengthHeader); } else { properties.Length = response.ContentLength; } attributes.Uri = new Uri(response.ResponseUri.GetLeftPart(UriPartial.Path)); var queryParameters = HttpUtility.ParseQueryString(response.ResponseUri.Query); DateTime snapshot; var snapshotString = queryParameters.Get(Constants.QueryConstants.Snapshot); if (!string.IsNullOrEmpty(snapshotString) && DateTime.TryParse( snapshotString, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out snapshot)) { attributes.Snapshot = snapshot; } attributes.Metadata = GetMetadata(response); return attributes; }
public static BlobAttributesDataModel ToAttributesDataModel(this BlobAttributes blob) { return(new BlobAttributesDataModel { Id = blob.Id, ContainerId = blob.Container.Id, Name = blob.Name, CacheControl = blob.Properties.CacheControl, ContentDisposition = blob.Properties.ContentDisposition, ContentEncoding = blob.Properties.ContentEncoding, ContentLanguage = blob.Properties.ContentLanguage, ContentMD5 = blob.Properties.ContentMD5, ContentType = blob.Properties.ContentType, ETag = blob.Properties.ETag, Length = blob.Properties.Length, Metadata = blob.Metadata.ToJson(), CreatedUtcDateTime = blob.Properties.CreatedUtcDateTime, LastModifiedUtcDateTime = blob.Properties.LastModifiedUtcDateTime, StorageId = blob.Storage.Id, }); }
public async Task <Storage> GetStorageAsync(BlobAttributes blobAttributes, CancellationToken cancellationToken) { var blobDbCommand = new BlobDbCommand(ConnectionString); var target = await blobDbCommand.GetAttributesAsync(blobAttributes.Id, cancellationToken).ConfigureAwait(false); if (target != null && target.Storage != null && target.Storage != Storage.None) { return(target.Storage); } var account = blobAttributes.Container.Account; if (account.StorageType == StorageType.Common) { return(await GetCommonStorageAsync(blobAttributes, cancellationToken).ConfigureAwait(false)); } if (!account.Storages.Any() || account.Storages.All(x => x.IsSuspended || x.ThresholdLength == 0)) { return(Storage.None); } var storage = account.Storages.OrderBy(x => { var threshold = x.ThresholdLength * 1.0; var used = x.UsedLength; var thisTimeUse = blobAttributes.Properties.Length; return((used + thisTimeUse) / threshold); }).First(); return(storage); }
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; 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; } 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; 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", BlobRequest.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); } return(new ListBlobEntry(name, blob)); }
/// <summary> /// Parses the response XML for a blob listing operation. /// </summary> /// <returns>An enumerable collection of objects that implement <see cref="IListBlobEntry"/>.</returns> protected override IEnumerable <IListBlobEntry> ParseXml() { bool needToRead = true; while (true) { if (needToRead && !reader.Read()) { break; } needToRead = true; // Run through the stream until we find what we are looking for. Retain what we've found. if (reader.NodeType == XmlNodeType.Element && !reader.IsEmptyElement) { switch (reader.Name) { case Constants.DelimiterElement: needToRead = false; this.delimiter = reader.ReadElementContentAsString(); this.delimiterConsumable = true; yield return(null); break; case Constants.MarkerElement: needToRead = false; this.marker = reader.ReadElementContentAsString(); this.markerConsumable = true; yield return(null); break; case Constants.NextMarkerElement: needToRead = false; this.nextMarker = reader.ReadElementContentAsString(); this.nextMarkerConsumable = true; yield return(null); break; case Constants.MaxResultsElement: needToRead = false; this.maxResults = reader.ReadElementContentAsInt(); this.maxResultsConsumable = true; yield return(null); break; case Constants.PrefixElement: needToRead = false; this.prefix = reader.ReadElementContentAsString(); this.prefixConsumable = true; yield return(null); break; case Constants.BlobsElement: // While we're still in the blobs section. while (reader.Read()) { // We found a blob. if (reader.NodeType == XmlNodeType.Element && !reader.IsEmptyElement && reader.Name == Constants.BlobElement) { BlobAttributes blob = null; string url = null; DateTime? lastModifiedTime = null; string etag = null; string name = null; long? contentLength = null; string contentType = null; string contentEncoding = null; string contentLanguage = null; string contentMD5 = null; BlobType? blobType = null; LeaseStatus? leaseStatus = null; DateTime? snapshot = null; NameValueCollection metadata = null; // Go until we are out of the blob. bool blobNeedToRead = true; while (true) { if (blobNeedToRead && !reader.Read()) { break; } blobNeedToRead = true; if (reader.NodeType == XmlNodeType.Element && !reader.IsEmptyElement) { switch (reader.Name) { case Constants.UrlElement: url = reader.ReadElementContentAsString(); blobNeedToRead = false; break; case Constants.LastModifiedElement: lastModifiedTime = reader.ReadElementContentAsString().ToUTCTime(); blobNeedToRead = false; break; case Constants.EtagElement: etag = reader.ReadElementContentAsString(); blobNeedToRead = false; break; case Constants.NameElement: name = reader.ReadElementContentAsString(); blobNeedToRead = false; break; case Constants.ContentLengthElement: contentLength = reader.ReadElementContentAsLong(); blobNeedToRead = false; break; case Constants.ContentTypeElement: contentType = reader.ReadElementContentAsString(); blobNeedToRead = false; break; case Constants.ContentEncodingElement: contentEncoding = reader.ReadElementContentAsString(); blobNeedToRead = false; break; case Constants.ContentLanguageElement: contentLanguage = reader.ReadElementContentAsString(); blobNeedToRead = false; break; case Constants.ContentMD5Element: contentMD5 = reader.ReadElementContentAsString(); blobNeedToRead = false; break; case Constants.BlobTypeElement: string blobTypeString = reader.ReadElementContentAsString(); blobNeedToRead = false; switch (blobTypeString) { case Constants.BlockBlobValue: blobType = BlobType.BlockBlob; break; case Constants.PageBlobValue: blobType = BlobType.PageBlob; break; } break; case Constants.LeaseStatusElement: string leaseStatusString = reader.ReadElementContentAsString(); blobNeedToRead = false; switch (leaseStatusString) { case Constants.LockedValue: leaseStatus = LeaseStatus.Locked; break; case Constants.UnlockedValue: leaseStatus = LeaseStatus.Unlocked; break; } break; case Constants.SnapshotElement: snapshot = reader.ReadElementContentAsString().ToUTCTime(); blobNeedToRead = false; break; case Constants.MetadataElement: metadata = Response.ParseMetadata(reader); blobNeedToRead = false; break; } } else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == Constants.BlobElement) { // Add quotes to the ETag if (!string.IsNullOrEmpty(etag)) { etag = string.Format("\"{0}\"", etag); } blob = new BlobAttributes(); blob.Properties = new BlobProperties(); blob.Properties.ContentEncoding = contentEncoding; blob.Properties.ContentLanguage = contentLanguage; blob.Properties.ContentMD5 = contentMD5; blob.Properties.Length = contentLength ?? 0; blob.Properties.ContentType = contentType; blob.Properties.ETag = etag; if (lastModifiedTime != null) { blob.Properties.LastModifiedUtc = (DateTime)lastModifiedTime; } var blobNameSectionIndex = url.LastIndexOf(NavigationHelper.Slash + name); string baseUri = url.Substring(0, blobNameSectionIndex + 1); var ub = new UriBuilder(baseUri); ub.Path += Uri.EscapeUriString(name); if (baseUri.Length + name.Length < url.Length) { // it's a url for snapshot. // Snapshot blob URI example:http://<yourstorageaccount>.blob.core.windows.net/<yourcontainer>/<yourblobname>?snapshot=2009-12-03T15%3a26%3a19.4466877Z ub.Query = url.Substring(baseUri.Length + name.Length + 1); } blob.Uri = ub.Uri; blob.Properties.LeaseStatus = leaseStatus ?? LeaseStatus.Unspecified; if (snapshot != null) { blob.Snapshot = (DateTime)snapshot; } blob.Properties.BlobType = blobType ?? BlobType.Unspecified; if (metadata != null) { blob.Metadata = metadata; } break; } } yield return(new BlobEntry(name, blob)); } else if (reader.NodeType == XmlNodeType.Element && !reader.IsEmptyElement && reader.Name == Constants.BlobPrefixElement) { BlobPrefixEntry commonPrefix = new BlobPrefixEntry(); // Go until we are out of the blob. bool blobPrefixNeedToRead = true; while (true) { if (blobPrefixNeedToRead && !reader.Read()) { break; } blobPrefixNeedToRead = true; if (reader.NodeType == XmlNodeType.Element && !reader.IsEmptyElement) { switch (reader.Name) { case Constants.NameElement: commonPrefix.Name = reader.ReadElementContentAsString(); blobPrefixNeedToRead = false; break; } } else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == Constants.BlobPrefixElement) { break; } } yield return(commonPrefix); } else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == Constants.BlobsElement) { this.allObjectsParsed = true; break; } } break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="ListBlobEntry"/> class. /// </summary> /// <param name="name">The name of the blob.</param> /// <param name="attributes">The blob's attributes.</param> internal ListBlobEntry(string name, BlobAttributes attributes) { this.Name = name; this.Attributes = attributes; }
private static async Task <IListBlobEntry> ParseBlobEntryAsync(XmlReader reader, Uri baseUri, CancellationToken token) { token.ThrowIfCancellationRequested(); 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; await reader.ReadStartElementAsync().ConfigureAwait(false); while (await reader.IsStartElementAsync().ConfigureAwait(false)) { token.ThrowIfCancellationRequested(); if (reader.IsEmptyElement) { await reader.SkipAsync().ConfigureAwait(false); } else { switch (reader.Name) { case Constants.NameElement: name = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.SnapshotElement: blob.SnapshotTime = (await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)).ToUTCTime(); break; case Constants.DeletedElement: blob.IsDeleted = BlobHttpResponseParsers.GetDeletionStatus(await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)); break; case Constants.PropertiesElement: await reader.ReadStartElementAsync().ConfigureAwait(false); while (await reader.IsStartElementAsync().ConfigureAwait(false)) { token.ThrowIfCancellationRequested(); if (reader.IsEmptyElement) { await reader.SkipAsync().ConfigureAwait(false); } else { switch (reader.Name) { case Constants.CreationTimeElement: blob.Properties.Created = (await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)).ToUTCTime(); break; case Constants.LastModifiedElement: blob.Properties.LastModified = (await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)).ToUTCTime(); break; case Constants.EtagElement: blob.Properties.ETag = string.Format(CultureInfo.InvariantCulture, "\"{0}\"", await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)); break; case Constants.ContentLengthElement: blob.Properties.Length = await reader.ReadElementContentAsInt64Async().ConfigureAwait(false); break; case Constants.CacheControlElement: blob.Properties.CacheControl = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.ContentTypeElement: blob.Properties.ContentType = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.HeaderConstants.ContentDispositionResponseHeader: blob.Properties.ContentDisposition = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.ContentEncodingElement: blob.Properties.ContentEncoding = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.ContentLanguageElement: blob.Properties.ContentLanguage = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.ContentMD5Element: blob.Properties.ContentMD5 = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.BlobTypeElement: string blobTypeString = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); 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(await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)); break; case Constants.LeaseStateElement: blob.Properties.LeaseState = BlobHttpResponseParsers.GetLeaseState(await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)); break; case Constants.LeaseDurationElement: blob.Properties.LeaseDuration = BlobHttpResponseParsers.GetLeaseDuration(await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)); break; case Constants.CopyIdElement: copyId = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.CopyCompletionTimeElement: copyCompletionTime = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.CopyStatusElement: copyStatus = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.CopyProgressElement: copyProgress = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.CopySourceElement: copySource = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.CopyStatusDescriptionElement: copyStatusDescription = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.ServerEncryptionElement: blob.Properties.IsServerEncrypted = BlobHttpResponseParsers.GetServerEncrypted(await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)); break; case Constants.IncrementalCopy: blob.Properties.IsIncrementalCopy = BlobHttpResponseParsers.GetIncrementalCopyStatus(await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)); break; case Constants.CopyDestinationSnapshotElement: copyDestinationSnapshotTime = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.AccessTierElement: blobTierString = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.ArchiveStatusElement: rehydrationStatusString = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.AccessTierInferred: blobTierInferred = await reader.ReadElementContentAsBooleanAsync().ConfigureAwait(false); break; case Constants.AccessTierChangeTimeElement: string t = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); blobTierLastModifiedTime = DateTimeOffset.Parse(t, CultureInfo.InvariantCulture); break; case Constants.DeletedTimeElement: blob.Properties.DeletedTime = (await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)).ToUTCTime(); break; case Constants.RemainingRetentionDaysElement: blob.Properties.RemainingDaysBeforePermanentDelete = int.Parse(await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)); break; default: await reader.SkipAsync().ConfigureAwait(false); break; } } } await reader.ReadEndElementAsync().ConfigureAwait(false); break; case Constants.MetadataElement: blob.Metadata = await Response.ParseMetadataAsync(reader).ConfigureAwait(false); break; default: await reader.SkipAsync().ConfigureAwait(false); break; } } } await reader.ReadEndElementAsync().ConfigureAwait(false); 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)); }
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 attributes, including its metadata and properties, from the response. /// </summary> /// <param name="response">The web response.</param> /// <returns>The blob's attributes.</returns> public static BlobAttributes GetAttributes(HttpWebResponse response) { BlobAttributes attributes = new BlobAttributes(); var properties = attributes.Properties = new BlobProperties(); properties.CacheControl = response.Headers[HttpResponseHeader.CacheControl]; properties.ContentEncoding = response.Headers[HttpResponseHeader.ContentEncoding]; properties.ContentLanguage = response.Headers[HttpResponseHeader.ContentLanguage]; properties.ContentMD5 = response.Headers[HttpResponseHeader.ContentMd5]; properties.ContentType = response.Headers[HttpResponseHeader.ContentType]; properties.ETag = response.Headers[HttpResponseHeader.ETag]; properties.LastModifiedUtc = response.LastModified.ToUniversalTime(); string blobType = response.Headers[Constants.HeaderConstants.BlobType]; string leaseStatus = response.Headers[Constants.HeaderConstants.LeaseStatus]; if (!string.IsNullOrEmpty(blobType)) { properties.BlobType = (BlobType)Enum.Parse(typeof(BlobType), blobType, true); } if (!string.IsNullOrEmpty(leaseStatus)) { properties.LeaseStatus = (LeaseStatus)Enum.Parse(typeof(LeaseStatus), leaseStatus, true); } // Get the content length. Prioritize range and x-ms over content length for the special cases. var rangeHeader = response.Headers[HttpResponseHeader.ContentRange]; var xContentLengthHeader = response.Headers[Constants.HeaderConstants.ContentLengthHeader]; if (!string.IsNullOrEmpty(rangeHeader)) { properties.Length = long.Parse(rangeHeader.Split('/')[1]); } else if (!string.IsNullOrEmpty(xContentLengthHeader)) { properties.Length = long.Parse(xContentLengthHeader); } else { properties.Length = response.ContentLength; } attributes.Uri = new Uri(response.ResponseUri.GetLeftPart(UriPartial.Path)); var queryParameters = Utilities.ParseQueryString(response.ResponseUri.Query); DateTime snapshot; var snapshotString = queryParameters.Get(Constants.QueryConstants.Snapshot); if (!string.IsNullOrEmpty(snapshotString) && DateTime.TryParse( snapshotString, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal, out snapshot)) { attributes.Snapshot = snapshot; } attributes.Metadata = GetMetadata(response); return(attributes); }
/// <summary> /// Initializes a new instance of the <see cref="ListBlobEntry"/> class. /// </summary> /// <param name="name">A string containing the name of the blob.</param> /// <param name="attributes">The blob's attributes.</param> internal ListBlobEntry(string name, BlobAttributes attributes) { this.Name = name; this.Attributes = attributes; }
/// <summary> /// Parses a blob entry in a blob listing response. /// </summary> /// <returns>Blob listing entry</returns> private IListBlobEntry ParseBlobEntry() { BlobAttributes blob = new BlobAttributes(); string url = null; 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; this.reader.ReadStartElement(); while (this.reader.IsStartElement()) { if (this.reader.IsEmptyElement) { this.reader.Skip(); } else { switch (this.reader.Name) { case Constants.UrlElement: url = reader.ReadElementContentAsString(); break; 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("\"{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.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; } 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; 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(); var blobNameSectionIndex = url.LastIndexOf(NavigationHelper.Slash + name); string baseUri = url.Substring(0, blobNameSectionIndex + 1); var ub = new UriBuilder(baseUri); ub.Path += Uri.EscapeUriString(name); if (baseUri.Length + name.Length < url.Length) { // it's a url for snapshot. // Snapshot blob URI example:http://<yourstorageaccount>.blob.core.windows.net/<yourcontainer>/<yourblobname>?snapshot=2009-12-03T15%3a26%3a19.4466877Z ub.Query = url.Substring(baseUri.Length + name.Length + 1); } blob.Uri = ub.Uri; if (!string.IsNullOrEmpty(copyStatus)) { blob.CopyState = BlobHttpResponseParsers.GetCopyAttributes( copyStatus, copyId, copySource, copyProgress, copyCompletionTime, copyStatusDescription); } return(new ListBlobEntry(name, blob)); }
/// <summary></summary> /// <param name="blobAttribute"></param> /// <returns></returns> public Task UpdateAttributesAsync(BlobAttributes blobAttribute) { return(UpdateAttributesAsync(blobAttribute, CancellationToken.None)); }
internal ListBlobEntry(string name, BlobAttributes attributes) { throw new System.NotImplementedException(); }
public BlobImageDataModel(BlobAttributes attributes) { AccountId = Hash(attributes.Container.Account.Id, attributes.Container.Account.CryptKey); ContainerId = Hash(attributes.Container.Id, attributes.Container.Account.CryptKey); BlobId = Hash(attributes.Id, attributes.Container.Account.CryptKey); }