BlobExtensions
BlockListTypes extensions
using Azure.Core;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Sas;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
namespace Azure.Storage.Blobs
{
internal static class BlobExtensions
{
internal static IDictionary<string, string> ToTagDictionary(this BlobTags blobTags)
{
if (blobTags?.BlobTagSet == null)
return null;
Dictionary<string, string> dictionary = new Dictionary<string, string>();
foreach (BlobTag item in blobTags.BlobTagSet) {
dictionary[item.Key] = item.Value;
}
return dictionary;
}
internal static BlobTags ToBlobTags(this IDictionary<string, string> tags)
{
if (tags == null)
return null;
return new BlobTags(from tag in tags
select new BlobTag(tag.Key, tag.Value));
}
internal static string ToTagsString(this IDictionary<string, string> tags)
{
if (tags == null)
return null;
List<string> list = new List<string>();
foreach (KeyValuePair<string, string> tag in tags) {
list.Add(WebUtility.UrlEncode(tag.Key) + "=" + WebUtility.UrlEncode(tag.Value));
}
return string.Join("&", list);
}
internal static TaggedBlobItem ToBlobTagItem(this FilterBlobItem filterBlobItem)
{
if (filterBlobItem == null)
return null;
return new TaggedBlobItem {
BlobName = filterBlobItem.Name,
BlobContainerName = filterBlobItem.ContainerName,
Tags = filterBlobItem.Tags.ToTagDictionary()
};
}
internal static List<TaggedBlobItem> ToBlobTagItems(this IEnumerable<FilterBlobItem> filterBlobItems)
{
if (filterBlobItems == null)
return null;
List<TaggedBlobItem> list = new List<TaggedBlobItem>();
foreach (FilterBlobItem filterBlobItem in filterBlobItems) {
list.Add(filterBlobItem.ToBlobTagItem());
}
return list;
}
internal static IList<ObjectReplicationPolicy> ParseObjectReplicationIds(this IDictionary<string, string> OrIds)
{
try {
OrIds.Single((KeyValuePair<string, string> id) => id.Key == "policy-id");
return null;
} catch (Exception) {
}
List<ObjectReplicationPolicy> list = new List<ObjectReplicationPolicy>();
foreach (KeyValuePair<string, string> OrId in OrIds) {
string[] parsedIds = OrId.Key.Split('_', StringSplitOptions.None);
int num = list.FindIndex((ObjectReplicationPolicy policy) => policy.PolicyId == parsedIds[0]);
if (num > -1)
list[num].Rules.Add(new ObjectReplicationRule {
RuleId = parsedIds[1],
ReplicationStatus = (ObjectReplicationStatus)Enum.Parse(typeof(ObjectReplicationStatus), OrId.Value, true)
});
else {
IList<ObjectReplicationRule> list2 = new List<ObjectReplicationRule>();
list2.Add(new ObjectReplicationRule {
RuleId = parsedIds[1],
ReplicationStatus = (ObjectReplicationStatus)Enum.Parse(typeof(ObjectReplicationStatus), OrId.Value, true)
});
list.Add(new ObjectReplicationPolicy {
PolicyId = parsedIds[0],
Rules = list2
});
}
}
return list;
}
internal static IList<ObjectReplicationPolicy> ParseObjectReplicationMetadata(this IReadOnlyDictionary<string, string> OrMetadata)
{
List<ObjectReplicationPolicy> list = new List<ObjectReplicationPolicy>();
foreach (KeyValuePair<string, string> OrMetadatum in OrMetadata) {
string[] parsedIds = OrMetadatum.Key.Split('_', StringSplitOptions.None);
if (parsedIds[0].StartsWith("or-", StringComparison.InvariantCulture))
parsedIds[0] = parsedIds[0].Substring("or-".Length);
int num = list.FindIndex((ObjectReplicationPolicy policy) => policy.PolicyId == parsedIds[0]);
if (num > -1)
list[num].Rules.Add(new ObjectReplicationRule {
RuleId = parsedIds[1],
ReplicationStatus = (ObjectReplicationStatus)Enum.Parse(typeof(ObjectReplicationStatus), OrMetadatum.Value, true)
});
else {
IList<ObjectReplicationRule> list2 = new List<ObjectReplicationRule>();
list2.Add(new ObjectReplicationRule {
RuleId = parsedIds[1],
ReplicationStatus = (ObjectReplicationStatus)Enum.Parse(typeof(ObjectReplicationStatus), OrMetadatum.Value, true)
});
list.Add(new ObjectReplicationPolicy {
PolicyId = parsedIds[0],
Rules = list2
});
}
}
return list;
}
internal static RehydratePriority? ToRehydratePriority(this string rehydratePriority)
{
if (rehydratePriority == null)
return null;
RehydratePriority rehydratePriority2 = RehydratePriority.High;
if (rehydratePriority == rehydratePriority2.ToString())
return RehydratePriority.High;
rehydratePriority2 = RehydratePriority.Standard;
if (rehydratePriority == rehydratePriority2.ToString())
return RehydratePriority.Standard;
throw new ArgumentException("Unknown Rehydrate Priority value: " + rehydratePriority);
}
internal static AccountInfo ToAccountInfo(this ResponseWithHeaders<ServiceGetAccountInfoHeaders> response)
{
if (response == null)
return null;
return new AccountInfo {
SkuName = response.Headers.SkuName.GetValueOrDefault(),
AccountKind = response.Headers.AccountKind.GetValueOrDefault(),
IsHierarchicalNamespaceEnabled = response.Headers.IsHierarchicalNamespaceEnabled.GetValueOrDefault()
};
}
internal static AccountInfo ToAccountInfo(this ResponseWithHeaders<BlobGetAccountInfoHeaders> response)
{
if (response == null)
return null;
return new AccountInfo {
SkuName = response.Headers.SkuName.GetValueOrDefault(),
AccountKind = response.Headers.AccountKind.GetValueOrDefault(),
IsHierarchicalNamespaceEnabled = response.Headers.IsHierarchicalNamespaceEnabled.GetValueOrDefault()
};
}
internal static AccountInfo ToAccountInfo(this ResponseWithHeaders<ContainerGetAccountInfoHeaders> response)
{
if (response == null)
return null;
return new AccountInfo {
SkuName = response.Headers.SkuName.GetValueOrDefault(),
AccountKind = response.Headers.AccountKind.GetValueOrDefault(),
IsHierarchicalNamespaceEnabled = response.Headers.IsHierarchicalNamespaceEnabled.GetValueOrDefault()
};
}
internal static BlobContainerInfo ToBlobContainerInfo(this ResponseWithHeaders<ContainerCreateHeaders> response)
{
if (response == null)
return null;
BlobContainerInfo blobContainerInfo = new BlobContainerInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobContainerInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobContainerInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
return blobContainerInfo;
}
internal static BlobContainerAccessPolicy ToBlobContainerAccessPolicy(this ResponseWithHeaders<IReadOnlyList<BlobSignedIdentifier>, ContainerGetAccessPolicyHeaders> response)
{
if (response == null)
return null;
BlobContainerAccessPolicy obj = new BlobContainerAccessPolicy {
BlobPublicAccess = response.Headers.BlobPublicAccess.GetValueOrDefault()
};
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
obj.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
obj.LastModified = response.Headers.LastModified.GetValueOrDefault();
obj.SignedIdentifiers = response.get_Value().ToList();
return obj;
}
internal static BlobContainerInfo ToBlobContainerInfo(this ResponseWithHeaders<ContainerSetAccessPolicyHeaders> response)
{
if (response == null)
return null;
BlobContainerInfo blobContainerInfo = new BlobContainerInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobContainerInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobContainerInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
return blobContainerInfo;
}
internal static BlobContainerInfo ToBlobContainerInfo(this ResponseWithHeaders<ContainerSetMetadataHeaders> response)
{
if (response == null)
return null;
BlobContainerInfo blobContainerInfo = new BlobContainerInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobContainerInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobContainerInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
return blobContainerInfo;
}
internal static BlobContentInfo ToBlobContentInfo(this ResponseWithHeaders<AppendBlobCreateHeaders> response)
{
if (response == null)
return null;
BlobContentInfo blobContentInfo = new BlobContentInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobContentInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobContentInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobContentInfo.ContentHash = response.Headers.ContentMD5;
blobContentInfo.VersionId = response.Headers.VersionId;
blobContentInfo.EncryptionKeySha256 = response.Headers.EncryptionKeySha256;
blobContentInfo.EncryptionScope = response.Headers.EncryptionScope;
return blobContentInfo;
}
internal static BlobContentInfo ToBlobContentInfo(this ResponseWithHeaders<PageBlobCreateHeaders> response)
{
if (response == null)
return null;
BlobContentInfo blobContentInfo = new BlobContentInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobContentInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobContentInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobContentInfo.ContentHash = response.Headers.ContentMD5;
blobContentInfo.VersionId = response.Headers.VersionId;
blobContentInfo.EncryptionKeySha256 = response.Headers.EncryptionKeySha256;
blobContentInfo.EncryptionScope = response.Headers.EncryptionScope;
return blobContentInfo;
}
internal static BlobAppendInfo ToBlobAppendInfo(this ResponseWithHeaders<AppendBlobAppendBlockHeaders> response)
{
if (response == null)
return null;
BlobAppendInfo blobAppendInfo = new BlobAppendInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobAppendInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobAppendInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobAppendInfo.ContentHash = response.Headers.ContentMD5;
blobAppendInfo.ContentCrc64 = response.Headers.XMsContentCrc64;
blobAppendInfo.BlobAppendOffset = response.Headers.BlobAppendOffset;
blobAppendInfo.BlobCommittedBlockCount = response.Headers.BlobCommittedBlockCount.GetValueOrDefault();
blobAppendInfo.IsServerEncrypted = response.Headers.IsServerEncrypted.GetValueOrDefault();
blobAppendInfo.EncryptionKeySha256 = response.Headers.EncryptionKeySha256;
blobAppendInfo.EncryptionScope = response.Headers.EncryptionScope;
return blobAppendInfo;
}
internal static BlobAppendInfo ToBlobAppendInfo(this ResponseWithHeaders<AppendBlobAppendBlockFromUrlHeaders> response)
{
if (response == null)
return null;
BlobAppendInfo blobAppendInfo = new BlobAppendInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobAppendInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobAppendInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobAppendInfo.ContentHash = response.Headers.ContentMD5;
blobAppendInfo.ContentCrc64 = response.Headers.XMsContentCrc64;
blobAppendInfo.BlobAppendOffset = response.Headers.BlobAppendOffset;
blobAppendInfo.BlobCommittedBlockCount = response.Headers.BlobCommittedBlockCount.GetValueOrDefault();
blobAppendInfo.IsServerEncrypted = response.Headers.IsServerEncrypted.GetValueOrDefault();
blobAppendInfo.EncryptionKeySha256 = response.Headers.EncryptionKeySha256;
blobAppendInfo.EncryptionScope = response.Headers.EncryptionScope;
return blobAppendInfo;
}
internal static BlobInfo ToBlobInfo(this ResponseWithHeaders<AppendBlobSealHeaders> response)
{
if (response == null)
return null;
BlobInfo blobInfo = new BlobInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
return blobInfo;
}
internal static PageInfo ToPageInfo(this ResponseWithHeaders<PageBlobUploadPagesHeaders> response)
{
if (response == null)
return null;
PageInfo pageInfo = new PageInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
pageInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
pageInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
pageInfo.ContentHash = response.Headers.ContentMD5;
pageInfo.ContentCrc64 = response.Headers.XMsContentCrc64;
pageInfo.BlobSequenceNumber = response.Headers.BlobSequenceNumber.GetValueOrDefault();
pageInfo.EncryptionKeySha256 = response.Headers.EncryptionKeySha256;
pageInfo.EncryptionScope = response.Headers.EncryptionScope;
return pageInfo;
}
internal static PageInfo ToPageInfo(this ResponseWithHeaders<PageBlobClearPagesHeaders> response)
{
if (response == null)
return null;
PageInfo pageInfo = new PageInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
pageInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
pageInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
pageInfo.ContentHash = response.Headers.ContentMD5;
pageInfo.ContentCrc64 = response.Headers.XMsContentCrc64;
pageInfo.BlobSequenceNumber = response.Headers.BlobSequenceNumber.GetValueOrDefault();
return pageInfo;
}
internal static PageInfo ToPageInfo(this ResponseWithHeaders<PageBlobUploadPagesFromURLHeaders> response)
{
if (response == null)
return null;
PageInfo pageInfo = new PageInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
pageInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
pageInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
pageInfo.ContentHash = response.Headers.ContentMD5;
pageInfo.ContentCrc64 = response.Headers.XMsContentCrc64;
pageInfo.BlobSequenceNumber = response.Headers.BlobSequenceNumber.GetValueOrDefault();
pageInfo.EncryptionKeySha256 = response.Headers.EncryptionKeySha256;
pageInfo.EncryptionScope = response.Headers.EncryptionScope;
return pageInfo;
}
internal static PageRangesInfo ToPageRangesInfo(this ResponseWithHeaders<PageList, PageBlobGetPageRangesHeaders> response)
{
if (response == null)
return null;
PageRangesInfo obj = new PageRangesInfo {
LastModified = response.Headers.LastModified.GetValueOrDefault()
};
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
obj.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
obj.BlobContentLength = response.Headers.BlobContentLength.GetValueOrDefault();
obj.PageRanges = (from r in response.get_Value().PageRange
select r.ToHttpRange()).ToList();
obj.ClearRanges = (from r in response.get_Value().ClearRange
select r.ToHttpRange()).ToList();
return obj;
}
internal static PageRangesInfo ToPageRangesInfo(this ResponseWithHeaders<PageList, PageBlobGetPageRangesDiffHeaders> response)
{
if (response == null)
return null;
PageRangesInfo obj = new PageRangesInfo {
LastModified = response.Headers.LastModified.GetValueOrDefault()
};
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
obj.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
obj.BlobContentLength = response.Headers.BlobContentLength.GetValueOrDefault();
obj.PageRanges = (from r in response.get_Value().PageRange
select r.ToHttpRange()).ToList();
obj.ClearRanges = (from r in response.get_Value().ClearRange
select r.ToHttpRange()).ToList();
return obj;
}
internal static HttpRange ToHttpRange(this PageRange pageRange)
{
return new HttpRange(pageRange.Start, (long?)(pageRange.End - pageRange.Start + 1));
}
internal static HttpRange ToHttpRange(this ClearRange clearRange)
{
return new HttpRange(clearRange.Start, (long?)(clearRange.End - clearRange.Start + 1));
}
internal static PageBlobInfo ToPageBlobInfo(this ResponseWithHeaders<PageBlobResizeHeaders> response)
{
if (response == null)
return null;
PageBlobInfo pageBlobInfo = new PageBlobInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
pageBlobInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
pageBlobInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
pageBlobInfo.BlobSequenceNumber = response.Headers.BlobSequenceNumber.GetValueOrDefault();
return pageBlobInfo;
}
internal static PageBlobInfo ToPageBlobInfo(this ResponseWithHeaders<PageBlobUpdateSequenceNumberHeaders> response)
{
if (response == null)
return null;
PageBlobInfo pageBlobInfo = new PageBlobInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
pageBlobInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
pageBlobInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
pageBlobInfo.BlobSequenceNumber = response.Headers.BlobSequenceNumber.GetValueOrDefault();
return pageBlobInfo;
}
internal static BlockInfo ToBlockInfo(this ResponseWithHeaders<BlockBlobStageBlockHeaders> response)
{
if (response == null)
return null;
return new BlockInfo {
ContentHash = response.Headers.ContentMD5,
ContentCrc64 = response.Headers.XMsContentCrc64,
EncryptionKeySha256 = response.Headers.EncryptionKeySha256,
EncryptionScope = response.Headers.EncryptionScope
};
}
internal static BlockInfo ToBlockInfo(this ResponseWithHeaders<BlockBlobStageBlockFromURLHeaders> response)
{
if (response == null)
return null;
return new BlockInfo {
ContentHash = response.Headers.ContentMD5,
ContentCrc64 = response.Headers.XMsContentCrc64,
EncryptionKeySha256 = response.Headers.EncryptionKeySha256,
EncryptionScope = response.Headers.EncryptionScope
};
}
internal static BlobContentInfo ToBlobContentInfo(this ResponseWithHeaders<BlockBlobCommitBlockListHeaders> response)
{
if (response == null)
return null;
BlobContentInfo blobContentInfo = new BlobContentInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobContentInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobContentInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobContentInfo.ContentHash = response.Headers.ContentMD5;
blobContentInfo.VersionId = response.Headers.VersionId;
blobContentInfo.EncryptionKeySha256 = response.Headers.EncryptionKeySha256;
blobContentInfo.EncryptionScope = response.Headers.EncryptionScope;
return blobContentInfo;
}
internal static BlobContentInfo ToBlobContentInfo(this ResponseWithHeaders<BlockBlobPutBlobFromUrlHeaders> response)
{
if (response == null)
return null;
BlobContentInfo blobContentInfo = new BlobContentInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobContentInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobContentInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobContentInfo.ContentHash = response.Headers.ContentMD5;
blobContentInfo.VersionId = response.Headers.VersionId;
blobContentInfo.EncryptionKeySha256 = response.Headers.EncryptionKeySha256;
blobContentInfo.EncryptionScope = response.Headers.EncryptionScope;
return blobContentInfo;
}
internal static BlobContentInfo ToBlobContentInfo(this ResponseWithHeaders<BlockBlobUploadHeaders> response)
{
if (response == null)
return null;
BlobContentInfo blobContentInfo = new BlobContentInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobContentInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobContentInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobContentInfo.ContentHash = response.Headers.ContentMD5;
blobContentInfo.VersionId = response.Headers.VersionId;
blobContentInfo.EncryptionKeySha256 = response.Headers.EncryptionKeySha256;
blobContentInfo.EncryptionScope = response.Headers.EncryptionScope;
return blobContentInfo;
}
internal static BlockList ToBlockList(this ResponseWithHeaders<BlockList, BlockBlobGetBlockListHeaders> response)
{
if (response == null)
return null;
BlockList obj = new BlockList {
LastModified = response.Headers.LastModified.GetValueOrDefault()
};
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
obj.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
obj.ContentType = response.Headers.ContentType;
obj.BlobContentLength = response.Headers.BlobContentLength.GetValueOrDefault();
obj.CommittedBlocks = response.get_Value().CommittedBlocks;
obj.UncommittedBlocks = response.get_Value().UncommittedBlocks;
return obj;
}
internal static BlobSnapshotInfo ToBlobSnapshotInfo(this ResponseWithHeaders<BlobCreateSnapshotHeaders> response)
{
if (response == null)
return null;
BlobSnapshotInfo obj = new BlobSnapshotInfo {
Snapshot = response.Headers.Snapshot
};
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
obj.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
obj.LastModified = response.Headers.LastModified.GetValueOrDefault();
obj.VersionId = response.Headers.VersionId;
obj.IsServerEncrypted = response.Headers.IsServerEncrypted.GetValueOrDefault();
return obj;
}
internal static BlobInfo ToBlobInfo(this ResponseWithHeaders<BlobSetMetadataHeaders> response)
{
if (response == null)
return null;
BlobInfo blobInfo = new BlobInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobInfo.VersionId = response.Headers.VersionId;
return blobInfo;
}
internal static BlobInfo ToBlobInfo(this ResponseWithHeaders<BlobSetHttpHeadersHeaders> response)
{
if (response == null)
return null;
BlobInfo blobInfo = new BlobInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
return blobInfo;
}
internal static BlobProperties ToBlobProperties(this ResponseWithHeaders<BlobGetPropertiesHeaders> response)
{
if (response == null)
return null;
BlobImmutabilityPolicy blobImmutabilityPolicy = new BlobImmutabilityPolicy();
blobImmutabilityPolicy.ExpiresOn = response.Headers.ImmutabilityPolicyExpiresOn;
blobImmutabilityPolicy.PolicyMode = response.Headers.ImmutabilityPolicyMode;
DateTimeOffset valueOrDefault = response.Headers.LastModified.GetValueOrDefault();
DateTimeOffset valueOrDefault2 = response.Headers.CreationTime.GetValueOrDefault();
IDictionary<string, string> metadata = response.Headers.Metadata;
string objectReplicationPolicyId = response.Headers.ObjectReplicationPolicyId;
IDictionary<string, string> objectReplicationRules = response.Headers.ObjectReplicationRules;
IList<ObjectReplicationPolicy> objectReplicationSourceProperties = (objectReplicationRules != null && objectReplicationRules.Count > 0) ? response.Headers.ObjectReplicationRules.ParseObjectReplicationIds() : null;
BlobType valueOrDefault3 = response.Headers.BlobType.GetValueOrDefault();
DateTimeOffset valueOrDefault4 = response.Headers.CopyCompletionTime.GetValueOrDefault();
string copyStatusDescription = response.Headers.CopyStatusDescription;
string copyId = response.Headers.CopyId;
string copyProgress = response.Headers.CopyProgress;
Uri copySource = (response.Headers.CopySource == null) ? null : new Uri(response.Headers.CopySource);
CopyStatus? copyStatus = response.Headers.CopyStatus;
bool valueOrDefault5 = response.Headers.IsIncrementalCopy.GetValueOrDefault();
string destinationSnapshot = response.Headers.DestinationSnapshot;
LeaseDurationType valueOrDefault6 = response.Headers.LeaseDuration.GetValueOrDefault();
LeaseState valueOrDefault7 = response.Headers.LeaseState.GetValueOrDefault();
LeaseStatus valueOrDefault8 = response.Headers.LeaseStatus.GetValueOrDefault();
long valueOrDefault9 = response.Headers.ContentLength.GetValueOrDefault();
string contentType = response.Headers.ContentType;
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
return new BlobProperties(valueOrDefault, valueOrDefault2, metadata, objectReplicationPolicyId, objectReplicationSourceProperties, valueOrDefault3, valueOrDefault4, copyStatusDescription, copyId, copyProgress, copySource, copyStatus, valueOrDefault5, destinationSnapshot, valueOrDefault6, valueOrDefault7, valueOrDefault8, valueOrDefault9, contentType, headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag), response.Headers.ContentMD5, response.Headers.ContentEncoding, response.Headers.ContentDisposition, response.Headers.ContentLanguage, response.Headers.CacheControl, response.Headers.BlobSequenceNumber.GetValueOrDefault(), response.Headers.AcceptRanges, response.Headers.BlobCommittedBlockCount.GetValueOrDefault(), response.Headers.IsServerEncrypted.GetValueOrDefault(), response.Headers.EncryptionKeySha256, response.Headers.EncryptionScope, response.Headers.AccessTier, response.Headers.AccessTierInferred.GetValueOrDefault(), response.Headers.ArchiveStatus, response.Headers.AccessTierChangeTime.GetValueOrDefault(), response.Headers.VersionId, response.Headers.IsCurrentVersion.GetValueOrDefault(), response.Headers.TagCount.GetValueOrDefault(), response.Headers.ExpiresOn.GetValueOrDefault(), response.Headers.IsSealed.GetValueOrDefault(), response.Headers.RehydratePriority, response.Headers.LastAccessed.GetValueOrDefault(), blobImmutabilityPolicy, response.Headers.LegalHold.GetValueOrDefault());
}
internal static BlobCopyInfo ToBlobCopyInfo(this ResponseWithHeaders<BlobCopyFromURLHeaders> response)
{
if (response == null)
return null;
BlobCopyInfo blobCopyInfo = new BlobCopyInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobCopyInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobCopyInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobCopyInfo.VersionId = response.Headers.VersionId;
blobCopyInfo.CopyId = response.Headers.CopyId;
blobCopyInfo.CopyStatus = response.Headers.CopyStatus.ToCopyStatus();
blobCopyInfo.EncryptionScope = response.Headers.EncryptionScope;
return blobCopyInfo;
}
internal static BlobCopyInfo ToBlobCopyInfo(this ResponseWithHeaders<BlobStartCopyFromURLHeaders> response)
{
if (response == null)
return null;
BlobCopyInfo blobCopyInfo = new BlobCopyInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobCopyInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobCopyInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobCopyInfo.VersionId = response.Headers.VersionId;
blobCopyInfo.CopyId = response.Headers.CopyId;
blobCopyInfo.CopyStatus = response.Headers.CopyStatus.GetValueOrDefault();
return blobCopyInfo;
}
internal static BlobCopyInfo ToBlobCopyInfo(this ResponseWithHeaders<PageBlobCopyIncrementalHeaders> response)
{
if (response == null)
return null;
BlobCopyInfo blobCopyInfo = new BlobCopyInfo();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobCopyInfo.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobCopyInfo.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobCopyInfo.CopyId = response.Headers.CopyId;
blobCopyInfo.CopyStatus = response.Headers.CopyStatus.GetValueOrDefault();
return blobCopyInfo;
}
internal static BlobDownloadStreamingResult ToBlobDownloadStreamingResult(this ResponseWithHeaders<Stream, BlobDownloadHeaders> response)
{
if (response == null)
return null;
response.GetRawResponse().get_Headers().ExtractMultiHeaderDownloadProperties(out IDictionary<string, string> metadata, out IDictionary<string, string> objectReplicationRules);
BlobImmutabilityPolicy blobImmutabilityPolicy = new BlobImmutabilityPolicy();
blobImmutabilityPolicy.ExpiresOn = response.Headers.ImmutabilityPolicyExpiresOn;
blobImmutabilityPolicy.PolicyMode = response.Headers.ImmutabilityPolicyMode;
BlobDownloadStreamingResult obj = new BlobDownloadStreamingResult {
Content = response.get_Value()
};
BlobDownloadDetails obj2 = new BlobDownloadDetails {
BlobType = response.Headers.BlobType.GetValueOrDefault(),
ContentLength = response.Headers.ContentLength.GetValueOrDefault(),
ContentType = response.Headers.ContentType,
ContentHash = response.Headers.ContentMD5,
LastModified = response.Headers.LastModified.GetValueOrDefault(),
Metadata = metadata,
ContentRange = response.Headers.ContentRange
};
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
obj2.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
obj2.ContentEncoding = response.Headers.ContentEncoding;
obj2.CacheControl = response.Headers.CacheControl;
obj2.ContentDisposition = response.Headers.ContentDisposition;
obj2.ContentLanguage = response.Headers.ContentLanguage;
obj2.BlobSequenceNumber = response.Headers.BlobSequenceNumber.GetValueOrDefault();
obj2.CopyCompletedOn = response.Headers.CopyCompletionTime.GetValueOrDefault();
obj2.CopyStatusDescription = response.Headers.CopyStatusDescription;
obj2.CopyId = response.Headers.CopyId;
obj2.CopyProgress = response.Headers.CopyProgress;
obj2.CopySource = ((response.Headers.CopySource == null) ? null : new Uri(response.Headers.CopySource));
obj2.CopyStatus = response.Headers.CopyStatus.GetValueOrDefault();
obj2.LeaseDuration = response.Headers.LeaseDuration.GetValueOrDefault();
obj2.LeaseStatus = response.Headers.LeaseStatus.GetValueOrDefault(LeaseStatus.Unlocked);
obj2.LeaseState = response.Headers.LeaseState.GetValueOrDefault();
obj2.AcceptRanges = response.Headers.AcceptRanges;
obj2.BlobCommittedBlockCount = response.Headers.BlobCommittedBlockCount.GetValueOrDefault();
obj2.IsServerEncrypted = response.Headers.IsServerEncrypted.GetValueOrDefault();
obj2.EncryptionKeySha256 = response.Headers.EncryptionKeySha256;
obj2.EncryptionScope = response.Headers.EncryptionScope;
obj2.BlobContentHash = response.Headers.BlobContentMD5;
obj2.TagCount = response.Headers.TagCount.GetValueOrDefault();
obj2.VersionId = response.Headers.VersionId;
obj2.IsSealed = response.Headers.IsSealed.GetValueOrDefault();
obj2.ObjectReplicationSourceProperties = ((objectReplicationRules != null && objectReplicationRules.Count > 0) ? objectReplicationRules.ParseObjectReplicationIds() : null);
obj2.ObjectReplicationDestinationPolicyId = response.Headers.ObjectReplicationPolicyId;
obj2.LastAccessed = response.Headers.LastAccessed.GetValueOrDefault();
obj2.ImmutabilityPolicy = blobImmutabilityPolicy;
obj2.HasLegalHold = response.Headers.LegalHold.GetValueOrDefault();
obj2.CreatedOn = response.Headers.CreationTime.GetValueOrDefault();
obj.Details = obj2;
return obj;
}
internal static BlobDownloadInfo ToBlobDownloadInfo(ResponseWithHeaders<Stream, BlobQueryHeaders> response, Stream stream)
{
if (response == null)
return null;
BlobType valueOrDefault = response.Headers.BlobType.GetValueOrDefault();
long valueOrDefault2 = response.Headers.ContentLength.GetValueOrDefault();
string contentType = response.Headers.ContentType;
byte[] contentMD = response.Headers.ContentMD5;
BlobDownloadInfo obj = new BlobDownloadInfo {
BlobType = valueOrDefault,
ContentLength = valueOrDefault2,
Content = stream,
ContentType = contentType,
ContentHash = contentMD
};
BlobDownloadDetails obj2 = new BlobDownloadDetails {
BlobType = valueOrDefault,
ContentLength = valueOrDefault2,
ContentType = contentType,
ContentHash = contentMD,
LastModified = response.Headers.LastModified.GetValueOrDefault(),
Metadata = response.Headers.Metadata.ToMetadata(),
ContentRange = response.Headers.ContentRange
};
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
obj2.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
obj2.ContentEncoding = response.Headers.ContentEncoding;
obj2.CacheControl = response.Headers.CacheControl;
obj2.ContentDisposition = response.Headers.ContentDisposition;
obj2.ContentLanguage = response.Headers.ContentLanguage;
obj2.BlobSequenceNumber = response.Headers.BlobSequenceNumber.GetValueOrDefault();
obj2.CopyCompletedOn = response.Headers.CopyCompletionTime.GetValueOrDefault();
obj2.CopyStatusDescription = response.Headers.CopyStatusDescription;
obj2.CopyId = response.Headers.CopyId;
obj2.CopyProgress = response.Headers.CopyProgress;
obj2.CopySource = ((response.Headers.CopySource == null) ? null : new Uri(response.Headers.CopySource));
obj2.CopyStatus = response.Headers.CopyStatus.GetValueOrDefault();
obj2.LeaseDuration = response.Headers.LeaseDuration.GetValueOrDefault();
obj2.LeaseState = response.Headers.LeaseState.GetValueOrDefault();
obj2.AcceptRanges = response.Headers.AcceptRanges;
obj2.BlobCommittedBlockCount = response.Headers.BlobCommittedBlockCount.GetValueOrDefault();
obj2.IsServerEncrypted = response.Headers.IsServerEncrypted.GetValueOrDefault();
obj2.EncryptionKeySha256 = response.Headers.EncryptionKeySha256;
obj2.EncryptionScope = response.Headers.EncryptionScope;
obj2.BlobContentHash = response.Headers.BlobContentMD5;
obj.Details = obj2;
return obj;
}
private static void ExtractMultiHeaderDownloadProperties(this ResponseHeaders headers, out IDictionary<string, string> metadata, out IDictionary<string, string> objectReplicationRules)
{
metadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
objectReplicationRules = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (HttpHeader item in headers) {
HttpHeader current = item;
if (current.get_Name().StartsWith("x-ms-meta-", StringComparison.OrdinalIgnoreCase))
metadata.Add(current.get_Name().Substring("x-ms-meta-".Length), current.get_Value());
else if (current.get_Name().StartsWith("x-ms-or-", StringComparison.OrdinalIgnoreCase)) {
objectReplicationRules.Add(current.get_Name().Substring("x-ms-or-".Length), current.get_Value());
}
}
}
internal static BlobLease ToBlobLease(this ResponseWithHeaders<BlobAcquireLeaseHeaders> response)
{
if (response == null)
return null;
BlobLease blobLease = new BlobLease();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobLease.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobLease.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobLease.LeaseId = response.Headers.LeaseId;
blobLease.LeaseTime = response.GetRawResponse().get_Headers().ExtractLeaseTime();
return blobLease;
}
internal static BlobLease ToBlobLease(this ResponseWithHeaders<ContainerAcquireLeaseHeaders> response)
{
if (response == null)
return null;
BlobLease blobLease = new BlobLease();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobLease.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobLease.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobLease.LeaseId = response.Headers.LeaseId;
blobLease.LeaseTime = response.GetRawResponse().get_Headers().ExtractLeaseTime();
return blobLease;
}
internal static BlobLease ToBlobLease(this ResponseWithHeaders<BlobRenewLeaseHeaders> response)
{
if (response == null)
return null;
BlobLease blobLease = new BlobLease();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobLease.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobLease.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobLease.LeaseId = response.Headers.LeaseId;
blobLease.LeaseTime = response.GetRawResponse().get_Headers().ExtractLeaseTime();
return blobLease;
}
internal static BlobLease ToBlobLease(this ResponseWithHeaders<ContainerRenewLeaseHeaders> response)
{
if (response == null)
return null;
BlobLease blobLease = new BlobLease();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobLease.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobLease.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobLease.LeaseId = response.Headers.LeaseId;
blobLease.LeaseTime = response.GetRawResponse().get_Headers().ExtractLeaseTime();
return blobLease;
}
internal static BlobLease ToBlobLease(this ResponseWithHeaders<BlobChangeLeaseHeaders> response)
{
if (response == null)
return null;
BlobLease blobLease = new BlobLease();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobLease.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobLease.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobLease.LeaseId = response.Headers.LeaseId;
blobLease.LeaseTime = response.GetRawResponse().get_Headers().ExtractLeaseTime();
return blobLease;
}
internal static BlobLease ToBlobLease(this ResponseWithHeaders<ContainerChangeLeaseHeaders> response)
{
if (response == null)
return null;
BlobLease blobLease = new BlobLease();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobLease.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobLease.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobLease.LeaseId = response.Headers.LeaseId;
blobLease.LeaseTime = response.GetRawResponse().get_Headers().ExtractLeaseTime();
return blobLease;
}
internal static BlobLease ToBlobLease(this ResponseWithHeaders<BlobBreakLeaseHeaders> response)
{
if (response == null)
return null;
BlobLease blobLease = new BlobLease();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobLease.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobLease.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobLease.LeaseTime = response.GetRawResponse().get_Headers().ExtractLeaseTime();
return blobLease;
}
internal static BlobLease ToBlobLease(this ResponseWithHeaders<ContainerBreakLeaseHeaders> response)
{
if (response == null)
return null;
BlobLease blobLease = new BlobLease();
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
blobLease.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
blobLease.LastModified = response.Headers.LastModified.GetValueOrDefault();
blobLease.LeaseTime = response.GetRawResponse().get_Headers().ExtractLeaseTime();
return blobLease;
}
internal static int? ExtractLeaseTime(this ResponseHeaders responseHeaders)
{
int? result = null;
string s = default(string);
if (responseHeaders.TryGetValue("x-ms-lease-time", ref s))
result = int.Parse(s, CultureInfo.InvariantCulture);
return result;
}
internal static ReleasedObjectInfo ToReleasedObjectInfo(this ResponseWithHeaders<BlobReleaseLeaseHeaders> response)
{
if (response == null)
return null;
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
return new ReleasedObjectInfo(headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag), response.Headers.LastModified.GetValueOrDefault());
}
internal static ReleasedObjectInfo ToReleasedObjectInfo(this ResponseWithHeaders<ContainerReleaseLeaseHeaders> response)
{
if (response == null)
return null;
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
return new ReleasedObjectInfo(headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag), response.Headers.LastModified.GetValueOrDefault());
}
internal static BlobItem[] ToBlobItems(this IReadOnlyList<BlobItemInternal> blobItemInternals)
{
if (blobItemInternals == null)
return null;
return (from r in blobItemInternals
select r.ToBlobItem()).ToArray();
}
internal static BlobItem ToBlobItem(this BlobItemInternal blobItemInternal)
{
if (blobItemInternal == null)
return null;
BlobItem obj = new BlobItem {
Name = blobItemInternal.Name.ToBlobNameString(),
Deleted = blobItemInternal.Deleted,
Snapshot = blobItemInternal.Snapshot,
VersionId = blobItemInternal.VersionId,
IsLatestVersion = blobItemInternal.IsCurrentVersion,
Properties = blobItemInternal.Properties.ToBlobItemProperties()
};
IReadOnlyDictionary<string, string> metadata = blobItemInternal.Metadata;
object metadata2;
if (metadata == null || metadata.Count <= 0) {
IDictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
metadata2 = dictionary;
} else
metadata2 = blobItemInternal.Metadata.ToMetadata();
obj.Metadata = (IDictionary<string, string>)metadata2;
obj.Tags = blobItemInternal.BlobTags.ToTagDictionary();
IReadOnlyDictionary<string, string> orMetadata = blobItemInternal.OrMetadata;
obj.ObjectReplicationSourceProperties = ((orMetadata != null && orMetadata.Count > 0) ? blobItemInternal.OrMetadata.ParseObjectReplicationMetadata() : null);
obj.HasVersionsOnly = blobItemInternal.HasVersionsOnly;
return obj;
}
internal static string ToBlobNameString(this BlobName blobName)
{
if (!blobName.Encoded.GetValueOrDefault())
return blobName.Content;
return Uri.UnescapeDataString(blobName.Content);
}
internal static BlobItemProperties ToBlobItemProperties(this BlobPropertiesInternal blobPropertiesInternal)
{
if (blobPropertiesInternal == null)
return null;
BlobImmutabilityPolicy blobImmutabilityPolicy = new BlobImmutabilityPolicy();
blobImmutabilityPolicy.ExpiresOn = blobPropertiesInternal.ImmutabilityPolicyExpiresOn;
blobImmutabilityPolicy.PolicyMode = blobPropertiesInternal.ImmutabilityPolicyMode;
return new BlobItemProperties {
LastModified = new DateTimeOffset?(blobPropertiesInternal.LastModified),
ContentLength = blobPropertiesInternal.ContentLength,
ContentType = blobPropertiesInternal.ContentType,
ContentEncoding = blobPropertiesInternal.ContentEncoding,
ContentLanguage = blobPropertiesInternal.ContentLanguage,
ContentHash = blobPropertiesInternal.ContentMD5,
ContentDisposition = blobPropertiesInternal.ContentDisposition,
CacheControl = blobPropertiesInternal.CacheControl,
BlobSequenceNumber = blobPropertiesInternal.BlobSequenceNumber,
BlobType = blobPropertiesInternal.BlobType,
LeaseStatus = blobPropertiesInternal.LeaseStatus,
LeaseState = blobPropertiesInternal.LeaseState,
LeaseDuration = blobPropertiesInternal.LeaseDuration,
CopyId = blobPropertiesInternal.CopyId,
CopyStatus = blobPropertiesInternal.CopyStatus,
CopySource = ((blobPropertiesInternal.CopySource == null) ? null : new Uri(blobPropertiesInternal.CopySource)),
CopyProgress = blobPropertiesInternal.CopyProgress,
CopyStatusDescription = blobPropertiesInternal.CopyStatusDescription,
ServerEncrypted = blobPropertiesInternal.ServerEncrypted,
DestinationSnapshot = blobPropertiesInternal.DestinationSnapshot,
RemainingRetentionDays = blobPropertiesInternal.RemainingRetentionDays,
AccessTier = blobPropertiesInternal.AccessTier,
AccessTierInferred = blobPropertiesInternal.AccessTierInferred.GetValueOrDefault(),
ArchiveStatus = blobPropertiesInternal.ArchiveStatus,
CustomerProvidedKeySha256 = blobPropertiesInternal.CustomerProvidedKeySha256,
EncryptionScope = blobPropertiesInternal.EncryptionScope,
TagCount = blobPropertiesInternal.TagCount,
ExpiresOn = blobPropertiesInternal.ExpiresOn,
IsSealed = blobPropertiesInternal.IsSealed,
RehydratePriority = blobPropertiesInternal.RehydratePriority,
LastAccessedOn = blobPropertiesInternal.LastAccessedOn,
ETag = new ETag?(new ETag(blobPropertiesInternal.Etag)),
CreatedOn = blobPropertiesInternal.CreationTime,
CopyCompletedOn = blobPropertiesInternal.CopyCompletionTime,
DeletedOn = blobPropertiesInternal.DeletedTime,
AccessTierChangedOn = blobPropertiesInternal.AccessTierChangeTime,
ImmutabilityPolicy = blobImmutabilityPolicy,
HasLegalHold = blobPropertiesInternal.LegalHold.GetValueOrDefault()
};
}
internal static BlobContainerItem[] ToBlobContainerItems(this IReadOnlyList<ContainerItemInternal> containerItemInternals)
{
if (containerItemInternals == null)
return null;
return (from r in containerItemInternals
select r.ToBlobContainerItem()).ToArray();
}
internal static BlobContainerItem ToBlobContainerItem(this ContainerItemInternal containerItemInternal)
{
if (containerItemInternal == null)
return null;
return new BlobContainerItem {
Name = containerItemInternal.Name,
IsDeleted = containerItemInternal.Deleted,
VersionId = containerItemInternal.Version,
Properties = ToBlobContainerProperties(containerItemInternal.Properties, containerItemInternal.Metadata)
};
}
internal static BlobContainerProperties ToBlobContainerProperties(ContainerPropertiesInternal containerPropertiesInternal, IReadOnlyDictionary<string, string> metadata)
{
if (containerPropertiesInternal == null)
return null;
return new BlobContainerProperties {
LastModified = containerPropertiesInternal.LastModified,
LeaseStatus = containerPropertiesInternal.LeaseStatus,
LeaseState = containerPropertiesInternal.LeaseState,
LeaseDuration = containerPropertiesInternal.LeaseDuration,
PublicAccess = containerPropertiesInternal.PublicAccess,
HasImmutabilityPolicy = containerPropertiesInternal.HasImmutabilityPolicy,
HasLegalHold = containerPropertiesInternal.HasLegalHold,
DefaultEncryptionScope = containerPropertiesInternal.DefaultEncryptionScope,
PreventEncryptionScopeOverride = containerPropertiesInternal.PreventEncryptionScopeOverride,
DeletedOn = containerPropertiesInternal.DeletedTime,
RemainingRetentionDays = containerPropertiesInternal.RemainingRetentionDays,
ETag = new ETag(containerPropertiesInternal.Etag),
Metadata = metadata.ToMetadata(),
HasImmutableStorageWithVersioning = containerPropertiesInternal.IsImmutableStorageWithVersioningEnabled.GetValueOrDefault()
};
}
internal static BlobContainerProperties ToBlobContainerProperties(this ResponseWithHeaders<ContainerGetPropertiesHeaders> response)
{
if (response == null)
return null;
BlobContainerProperties obj = new BlobContainerProperties {
LastModified = response.Headers.LastModified.GetValueOrDefault(),
LeaseStatus = response.Headers.LeaseStatus,
LeaseState = response.Headers.LeaseState,
LeaseDuration = new LeaseDurationType?(response.Headers.LeaseDuration.GetValueOrDefault()),
PublicAccess = new PublicAccessType?(response.Headers.BlobPublicAccess.GetValueOrDefault()),
HasImmutabilityPolicy = response.Headers.HasImmutabilityPolicy,
HasLegalHold = response.Headers.HasLegalHold,
DefaultEncryptionScope = response.Headers.DefaultEncryptionScope,
PreventEncryptionScopeOverride = response.Headers.DenyEncryptionScopeOverride
};
ResponseHeaders headers = response.GetRawResponse().get_Headers();
string text = default(string);
obj.ETag = (headers.TryGetValue("ETag", ref text) ? new ETag(text) : default(ETag));
obj.Metadata = response.Headers.Metadata.ToMetadata();
obj.HasImmutableStorageWithVersioning = response.Headers.IsImmutableStorageWithVersioningEnabled.GetValueOrDefault();
return obj;
}
internal static IDictionary<string, string> ToMetadata(this IDictionary<string, string> originalMetadata)
{
if (originalMetadata == null)
return null;
IDictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (KeyValuePair<string, string> originalMetadatum in originalMetadata) {
dictionary.Add(originalMetadatum.Key, originalMetadatum.Value);
}
return dictionary;
}
internal static IDictionary<string, string> ToMetadata(this IReadOnlyDictionary<string, string> originalMetadata)
{
if (originalMetadata == null)
return null;
IDictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (KeyValuePair<string, string> originalMetadatum in originalMetadata) {
dictionary.Add(originalMetadatum.Key, originalMetadatum.Value);
}
return dictionary;
}
internal static BlobImmutabilityPolicy ToBlobImmutabilityPolicy(this ResponseWithHeaders<BlobSetImmutabilityPolicyHeaders> response)
{
if (response == null)
return null;
return new BlobImmutabilityPolicy {
ExpiresOn = response.Headers.ImmutabilityPolicyExpiry,
PolicyMode = response.Headers.ImmutabilityPolicyMode
};
}
internal static BlobLegalHoldResult ToBlobLegalHoldInfo(this ResponseWithHeaders<BlobSetLegalHoldHeaders> response)
{
if (response == null)
return null;
return new BlobLegalHoldResult {
HasLegalHold = response.Headers.LegalHold.GetValueOrDefault()
};
}
internal static string ToEncryptionAlgorithmString(this EncryptionAlgorithmType type)
{
if (type != 0)
throw new InvalidEnumArgumentException();
return EncryptionAlgorithmTypeInternal.AES256.ToSerialString();
}
internal static PageRangeItem[] ToPageBlobRanges(this ResponseWithHeaders<PageList, PageBlobGetPageRangesHeaders> response)
{
if (response == null)
return null;
return ToPageBlobRanges(response.get_Value().PageRange, response.get_Value().ClearRange);
}
internal static PageRangeItem[] ToPageBlobRanges(this ResponseWithHeaders<PageList, PageBlobGetPageRangesDiffHeaders> response)
{
if (response == null)
return null;
return ToPageBlobRanges(response.get_Value().PageRange, response.get_Value().ClearRange);
}
internal static PageRangeItem[] ToPageBlobRanges(IReadOnlyList<PageRange> pageRanges, IReadOnlyList<ClearRange> clearRanges)
{
List<PageRangeItem> list = new List<PageRangeItem>();
int num = 0;
int num2 = 0;
while (num < pageRanges.Count || num2 < clearRanges.Count) {
if (num < pageRanges.Count && num2 < clearRanges.Count) {
if (pageRanges[num].Start <= clearRanges[num2].Start) {
list.Add(new PageRangeItem {
IsClear = false,
Range = pageRanges[num].ToHttpRange()
});
num++;
} else {
list.Add(new PageRangeItem {
IsClear = true,
Range = clearRanges[num2].ToHttpRange()
});
num2++;
}
} else if (num < pageRanges.Count) {
list.Add(new PageRangeItem {
IsClear = false,
Range = pageRanges[num].ToHttpRange()
});
num++;
} else {
list.Add(new PageRangeItem {
IsClear = true,
Range = clearRanges[num2].ToHttpRange()
});
num2++;
}
}
return list.ToArray();
}
internal static void ValidateConditionsNotPresent(this RequestConditions requestConditions, BlobRequestConditionProperty invalidConditions, string operationName, string parameterName)
{
if (!CompatSwitches.DisableRequestConditionsValidation && requestConditions != null) {
List<string> invalidList = null;
requestConditions.ValidateConditionsNotPresent(invalidConditions, ref invalidList);
if (invalidList != null && invalidList.Count > 0) {
string str = string.Join(", ", invalidList);
throw new ArgumentException(operationName + " does not support the " + str + " condition(s).", parameterName);
}
}
}
internal static void ValidateConditionsNotPresent(this BlobRequestConditions requestConditions, BlobRequestConditionProperty invalidConditions, string operationName, string parameterName)
{
if (!CompatSwitches.DisableRequestConditionsValidation && requestConditions != null) {
List<string> invalidList = null;
requestConditions.ValidateConditionsNotPresent(invalidConditions, ref invalidList);
if (invalidList != null && invalidList.Count > 0) {
string str = string.Join(", ", invalidList);
throw new ArgumentException(operationName + " does not support the " + str + " condition(s).", parameterName);
}
}
}
internal static void ValidateConditionsNotPresent(this BlobLeaseRequestConditions requestConditions, BlobRequestConditionProperty invalidConditions, string operationName, string parameterName)
{
if (!CompatSwitches.DisableRequestConditionsValidation && requestConditions != null) {
List<string> invalidList = null;
requestConditions.ValidateConditionsNotPresent(invalidConditions, ref invalidList);
if (invalidList != null && invalidList.Count > 0) {
string str = string.Join(", ", invalidList);
throw new ArgumentException(operationName + " does not support the " + str + " condition(s).", parameterName);
}
}
}
internal static void ValidateConditionsNotPresent(this AppendBlobRequestConditions requestConditions, BlobRequestConditionProperty invalidConditions, string operationName, string parameterName)
{
if (!CompatSwitches.DisableRequestConditionsValidation && requestConditions != null) {
List<string> invalidList = null;
((BlobRequestConditions)requestConditions).ValidateConditionsNotPresent(invalidConditions, ref invalidList);
if ((invalidConditions & BlobRequestConditionProperty.IfAppendPositionEqual) == BlobRequestConditionProperty.IfAppendPositionEqual && requestConditions.IfAppendPositionEqual.HasValue) {
if (invalidList == null)
invalidList = new List<string>();
invalidList.Add("IfAppendPositionEqual");
}
if ((invalidConditions & BlobRequestConditionProperty.IfMaxSizeLessThanOrEqual) == BlobRequestConditionProperty.IfMaxSizeLessThanOrEqual && requestConditions.IfMaxSizeLessThanOrEqual.HasValue) {
if (invalidList == null)
invalidList = new List<string>();
invalidList.Add("IfMaxSizeLessThanOrEqual");
}
if (invalidList != null && invalidList.Count > 0) {
string str = string.Join(", ", invalidList);
throw new ArgumentException(operationName + " does not support the " + str + " condition(s).", parameterName);
}
}
}
internal static void ValidateConditionsNotPresent(this PageBlobRequestConditions requestConditions, BlobRequestConditionProperty invalidConditions, string operationName, string parameterName)
{
if (!CompatSwitches.DisableRequestConditionsValidation && requestConditions != null) {
List<string> invalidList = null;
((BlobRequestConditions)requestConditions).ValidateConditionsNotPresent(invalidConditions, ref invalidList);
if ((invalidConditions & BlobRequestConditionProperty.IfSequenceNumberLessThan) == BlobRequestConditionProperty.IfSequenceNumberLessThan && requestConditions.IfSequenceNumberLessThan.HasValue) {
if (invalidList == null)
invalidList = new List<string>();
invalidList.Add("IfSequenceNumberLessThan");
}
if ((invalidConditions & BlobRequestConditionProperty.IfSequenceNumberLessThanOrEqual) == BlobRequestConditionProperty.IfSequenceNumberLessThanOrEqual && requestConditions.IfSequenceNumberLessThanOrEqual.HasValue) {
if (invalidList == null)
invalidList = new List<string>();
invalidList.Add("IfSequenceNumberLessThanOrEqual");
}
if ((invalidConditions & BlobRequestConditionProperty.IfSequenceNumberEqual) == BlobRequestConditionProperty.IfSequenceNumberEqual && requestConditions.IfSequenceNumberEqual.HasValue) {
if (invalidList == null)
invalidList = new List<string>();
invalidList.Add("IfSequenceNumberEqual");
}
if (invalidList != null && invalidList.Count > 0) {
string str = string.Join(", ", invalidList);
throw new ArgumentException(operationName + " does not support the " + str + " condition(s).", parameterName);
}
}
}
internal static void ValidateConditionsNotPresent(this RequestConditions requestConditions, BlobRequestConditionProperty invalidConditions, ref List<string> invalidList)
{
if (requestConditions != null) {
if ((invalidConditions & BlobRequestConditionProperty.IfModifiedSince) == BlobRequestConditionProperty.IfModifiedSince && requestConditions.get_IfModifiedSince().HasValue) {
if (invalidList == null)
invalidList = new List<string>();
invalidList.Add("IfModifiedSince");
}
if ((invalidConditions & BlobRequestConditionProperty.IfUnmodifiedSince) == BlobRequestConditionProperty.IfUnmodifiedSince && requestConditions.get_IfUnmodifiedSince().HasValue) {
if (invalidList == null)
invalidList = new List<string>();
invalidList.Add("IfUnmodifiedSince");
}
if ((invalidConditions & BlobRequestConditionProperty.IfMatch) == BlobRequestConditionProperty.IfMatch && requestConditions.get_IfMatch().HasValue) {
if (invalidList == null)
invalidList = new List<string>();
invalidList.Add("IfMatch");
}
if ((invalidConditions & BlobRequestConditionProperty.IfNoneMatch) == BlobRequestConditionProperty.IfNoneMatch && requestConditions.get_IfNoneMatch().HasValue) {
if (invalidList == null)
invalidList = new List<string>();
invalidList.Add("IfNoneMatch");
}
}
}
internal static void ValidateConditionsNotPresent(this BlobLeaseRequestConditions requestConditions, BlobRequestConditionProperty invalidConditions, ref List<string> invalidList)
{
if (requestConditions != null && (invalidConditions & BlobRequestConditionProperty.TagConditions) == BlobRequestConditionProperty.TagConditions && requestConditions.TagConditions != null) {
if (invalidList == null)
invalidList = new List<string>();
invalidList.Add("TagConditions");
}
}
internal static void ValidateConditionsNotPresent(this BlobRequestConditions requestConditions, BlobRequestConditionProperty invalidConditions, ref List<string> invalidList)
{
if (requestConditions != null) {
BlobExtensions.ValidateConditionsNotPresent(requestConditions, invalidConditions, ref invalidList);
((BlobLeaseRequestConditions)requestConditions).ValidateConditionsNotPresent(invalidConditions, ref invalidList);
if ((invalidConditions & BlobRequestConditionProperty.LeaseId) == BlobRequestConditionProperty.LeaseId && requestConditions.LeaseId != null) {
if (invalidList == null)
invalidList = new List<string>();
invalidList.Add("LeaseId");
}
}
}
internal static BlockListType ToBlockListType(this BlockListTypes options)
{
switch (options) {
case BlockListTypes.Committed:
return BlockListType.Committed;
case BlockListTypes.Uncommitted:
return BlockListType.Uncommitted;
default:
return BlockListType.All;
}
}
internal static IEnumerable<ListContainersIncludeType> AsIncludeItems(BlobContainerTraits traits, BlobContainerStates states)
{
List<ListContainersIncludeType> list = new List<ListContainersIncludeType>();
if ((states & BlobContainerStates.Deleted) == BlobContainerStates.Deleted)
list.Add(ListContainersIncludeType.Deleted);
if ((traits & BlobContainerTraits.Metadata) == BlobContainerTraits.Metadata)
list.Add(ListContainersIncludeType.Metadata);
if ((states & BlobContainerStates.System) == BlobContainerStates.System)
list.Add(ListContainersIncludeType.System);
if (list.Count <= 0)
return null;
return list;
}
internal static IEnumerable<ListBlobsIncludeItem> AsIncludeItems(BlobTraits traits, BlobStates states)
{
List<ListBlobsIncludeItem> list = new List<ListBlobsIncludeItem>();
if ((traits & BlobTraits.CopyStatus) == BlobTraits.CopyStatus)
list.Add(ListBlobsIncludeItem.Copy);
if ((states & BlobStates.Deleted) == BlobStates.Deleted)
list.Add(ListBlobsIncludeItem.Deleted);
if ((traits & BlobTraits.Metadata) == BlobTraits.Metadata)
list.Add(ListBlobsIncludeItem.Metadata);
if ((states & BlobStates.Snapshots) == BlobStates.Snapshots)
list.Add(ListBlobsIncludeItem.Snapshots);
if ((traits & BlobTraits.Tags) == BlobTraits.Tags)
list.Add(ListBlobsIncludeItem.Tags);
if ((traits & BlobTraits.ImmutabilityPolicy) == BlobTraits.ImmutabilityPolicy)
list.Add(ListBlobsIncludeItem.Immutabilitypolicy);
if ((traits & BlobTraits.LegalHold) == BlobTraits.LegalHold)
list.Add(ListBlobsIncludeItem.Legalhold);
if ((states & BlobStates.Uncommitted) == BlobStates.Uncommitted)
list.Add(ListBlobsIncludeItem.Uncommittedblobs);
if ((states & BlobStates.Version) == BlobStates.Version)
list.Add(ListBlobsIncludeItem.Versions);
if ((states & BlobStates.DeletedWithVersions) == BlobStates.DeletedWithVersions)
list.Add(ListBlobsIncludeItem.DeletedWithVersions);
if (list.Count <= 0)
return null;
return list;
}
internal static string ToPermissionsString(this BlobAccountSasPermissions permissions)
{
StringBuilder stringBuilder = new StringBuilder();
if ((permissions & BlobAccountSasPermissions.Read) == BlobAccountSasPermissions.Read)
stringBuilder.Append('r');
if ((permissions & BlobAccountSasPermissions.Add) == BlobAccountSasPermissions.Add)
stringBuilder.Append('a');
if ((permissions & BlobAccountSasPermissions.Create) == BlobAccountSasPermissions.Create)
stringBuilder.Append('c');
if ((permissions & BlobAccountSasPermissions.Write) == BlobAccountSasPermissions.Write)
stringBuilder.Append('w');
if ((permissions & BlobAccountSasPermissions.Delete) == BlobAccountSasPermissions.Delete)
stringBuilder.Append('d');
if ((permissions & BlobAccountSasPermissions.List) == BlobAccountSasPermissions.List)
stringBuilder.Append('l');
return stringBuilder.ToString();
}
internal static string ToPermissionsString(this BlobContainerSasPermissions permissions)
{
StringBuilder stringBuilder = new StringBuilder();
if ((permissions & BlobContainerSasPermissions.Read) == BlobContainerSasPermissions.Read)
stringBuilder.Append('r');
if ((permissions & BlobContainerSasPermissions.Add) == BlobContainerSasPermissions.Add)
stringBuilder.Append('a');
if ((permissions & BlobContainerSasPermissions.Create) == BlobContainerSasPermissions.Create)
stringBuilder.Append('c');
if ((permissions & BlobContainerSasPermissions.Write) == BlobContainerSasPermissions.Write)
stringBuilder.Append('w');
if ((permissions & BlobContainerSasPermissions.Delete) == BlobContainerSasPermissions.Delete)
stringBuilder.Append('d');
if ((permissions & BlobContainerSasPermissions.DeleteBlobVersion) == BlobContainerSasPermissions.DeleteBlobVersion)
stringBuilder.Append('x');
if ((permissions & BlobContainerSasPermissions.List) == BlobContainerSasPermissions.List)
stringBuilder.Append('l');
if ((permissions & BlobContainerSasPermissions.Tag) == BlobContainerSasPermissions.Tag)
stringBuilder.Append('t');
if ((permissions & BlobContainerSasPermissions.Filter) == BlobContainerSasPermissions.Filter)
stringBuilder.Append('f');
if ((permissions & BlobContainerSasPermissions.SetImmutabilityPolicy) == BlobContainerSasPermissions.SetImmutabilityPolicy)
stringBuilder.Append('i');
return stringBuilder.ToString();
}
internal static string ToPermissionsString(this BlobSasPermissions permissions)
{
StringBuilder stringBuilder = new StringBuilder();
if ((permissions & BlobSasPermissions.Read) == BlobSasPermissions.Read)
stringBuilder.Append('r');
if ((permissions & BlobSasPermissions.Add) == BlobSasPermissions.Add)
stringBuilder.Append('a');
if ((permissions & BlobSasPermissions.Create) == BlobSasPermissions.Create)
stringBuilder.Append('c');
if ((permissions & BlobSasPermissions.Write) == BlobSasPermissions.Write)
stringBuilder.Append('w');
if ((permissions & BlobSasPermissions.Delete) == BlobSasPermissions.Delete)
stringBuilder.Append('d');
if ((permissions & BlobSasPermissions.DeleteBlobVersion) == BlobSasPermissions.DeleteBlobVersion)
stringBuilder.Append('x');
if ((permissions & BlobSasPermissions.PermanentDelete) == BlobSasPermissions.PermanentDelete)
stringBuilder.Append('y');
if ((permissions & BlobSasPermissions.List) == BlobSasPermissions.List)
stringBuilder.Append('l');
if ((permissions & BlobSasPermissions.Tag) == BlobSasPermissions.Tag)
stringBuilder.Append('t');
if ((permissions & BlobSasPermissions.Move) == BlobSasPermissions.Move)
stringBuilder.Append('m');
if ((permissions & BlobSasPermissions.Execute) == BlobSasPermissions.Execute)
stringBuilder.Append('e');
if ((permissions & BlobSasPermissions.SetImmutabilityPolicy) == BlobSasPermissions.SetImmutabilityPolicy)
stringBuilder.Append('i');
return stringBuilder.ToString();
}
internal static string ToPermissionsString(this BlobVersionSasPermissions permissions)
{
StringBuilder stringBuilder = new StringBuilder();
if ((permissions & BlobVersionSasPermissions.Delete) == BlobVersionSasPermissions.Delete)
stringBuilder.Append('x');
if ((permissions & BlobVersionSasPermissions.PermanentDelete) == BlobVersionSasPermissions.PermanentDelete)
stringBuilder.Append('y');
if ((permissions & BlobVersionSasPermissions.SetImmutabilityPolicy) == BlobVersionSasPermissions.SetImmutabilityPolicy)
stringBuilder.Append('i');
return stringBuilder.ToString();
}
internal static string ToPermissionsString(this SnapshotSasPermissions permissions)
{
StringBuilder stringBuilder = new StringBuilder();
if ((permissions & SnapshotSasPermissions.Read) == SnapshotSasPermissions.Read)
stringBuilder.Append('r');
if ((permissions & SnapshotSasPermissions.Write) == SnapshotSasPermissions.Write)
stringBuilder.Append('w');
if ((permissions & SnapshotSasPermissions.Delete) == SnapshotSasPermissions.Delete)
stringBuilder.Append('d');
if ((permissions & SnapshotSasPermissions.PermanentDelete) == SnapshotSasPermissions.PermanentDelete)
stringBuilder.Append('y');
if ((permissions & SnapshotSasPermissions.SetImmutabilityPolicy) == SnapshotSasPermissions.SetImmutabilityPolicy)
stringBuilder.Append('i');
return stringBuilder.ToString();
}
}
}