/// <summary>
        /// Gets the container's properties from the response.
        /// </summary>
        /// <param name="response">The web response.</param>
        /// <returns>The container's attributes.</returns>
        public static BlobContainerProperties GetProperties(HttpWebResponse response)
        {
            CommonUtility.AssertNotNull("response", response);

            // Set the container properties
            BlobContainerProperties containerProperties = new BlobContainerProperties();

            containerProperties.ETag = HttpResponseParsers.GetETag(response);

#if WINDOWS_PHONE
            containerProperties.LastModified = HttpResponseParsers.GetLastModified(response);
#else
            containerProperties.LastModified = response.LastModified.ToUniversalTime();
#endif

            // Get lease properties
            containerProperties.LeaseStatus   = BlobHttpResponseParsers.GetLeaseStatus(response);
            containerProperties.LeaseState    = BlobHttpResponseParsers.GetLeaseState(response);
            containerProperties.LeaseDuration = BlobHttpResponseParsers.GetLeaseDuration(response);

            // Reading public access
            containerProperties.PublicAccess = GetAcl(response);

            // WORM policies
            string hasImmutability = response.Headers[Constants.HeaderConstants.HasImmutabilityPolicyHeader];
            containerProperties.HasImmutabilityPolicy = string.IsNullOrEmpty(hasImmutability) ? (bool?)null : bool.Parse(hasImmutability);

            string hasLegalHold = response.Headers[Constants.HeaderConstants.HasLegalHoldHeader];
            containerProperties.HasLegalHold = string.IsNullOrEmpty(hasLegalHold) ? (bool?)null : bool.Parse(hasLegalHold);

            return(containerProperties);
        }
        /// <summary>
        /// Gets the file's properties from the response.
        /// </summary>
        /// <param name="response">The web response.</param>
        /// <returns>The file's properties.</returns>
        public static FileProperties GetProperties(HttpWebResponse response)
        {
            CommonUtility.AssertNotNull("response", response);

            FileProperties properties = new FileProperties();

            properties.ETag = HttpResponseParsers.GetETag(response);

#if WINDOWS_PHONE
            properties.LastModified    = HttpResponseParsers.GetLastModified(response);
            properties.ContentLanguage = response.Headers[Constants.HeaderConstants.ContentLanguageHeader];
#else
            properties.LastModified    = response.LastModified.ToUniversalTime();
            properties.ContentLanguage = response.Headers[HttpResponseHeader.ContentLanguage];
#endif

            properties.ContentDisposition = response.Headers[Constants.HeaderConstants.ContentDispositionResponseHeader];
            properties.ContentEncoding    = response.Headers[HttpResponseHeader.ContentEncoding];

            // For range gets, only look at 'x-ms-content-md5' for overall MD5
            if (response.Headers[HttpResponseHeader.ContentRange] != null)
            {
                properties.ContentMD5 = response.Headers[Constants.HeaderConstants.FileContentMD5Header];
            }
            else
            {
                properties.ContentMD5 = response.Headers[HttpResponseHeader.ContentMd5];
            }

            properties.ContentType  = response.Headers[HttpResponseHeader.ContentType];
            properties.CacheControl = response.Headers[HttpResponseHeader.CacheControl];

            string fileEncryption = response.Headers[Constants.HeaderConstants.ServerEncrypted];
            properties.IsServerEncrypted = string.Equals(fileEncryption, Constants.HeaderConstants.TrueHeader, StringComparison.OrdinalIgnoreCase);

            // Get the content length. Prioritize range and x-ms over content length for the special cases.
            string rangeHeader             = response.Headers[HttpResponseHeader.ContentRange];
            string contentLengthHeader     = response.Headers[Constants.HeaderConstants.ContentLengthHeader];
            string fileContentLengthHeader = response.Headers[Constants.HeaderConstants.FileContentLengthHeader];
            if (!string.IsNullOrEmpty(rangeHeader))
            {
                properties.Length = long.Parse(rangeHeader.Split('/')[1], CultureInfo.InvariantCulture);
            }
            else if (!string.IsNullOrEmpty(fileContentLengthHeader))
            {
                properties.Length = long.Parse(fileContentLengthHeader, CultureInfo.InvariantCulture);
            }
            else if (!string.IsNullOrEmpty(contentLengthHeader))
            {
                // On Windows Phone, ContentLength property is not always same as Content-Length header,
                // so we try to parse the header first.
                properties.Length = long.Parse(contentLengthHeader, CultureInfo.InvariantCulture);
            }
            else
            {
                properties.Length = response.ContentLength;
            }

            return(properties);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the directory's properties from the response.
        /// </summary>
        /// <param name="response">The web response.</param>
        /// <returns>The directory's attributes.</returns>
        public static FileDirectoryProperties GetProperties(HttpWebResponse response)
        {
            CommonUtility.AssertNotNull("response", response);

            FileDirectoryProperties directoryProperties = new FileDirectoryProperties();

            directoryProperties.ETag = HttpResponseParsers.GetETag(response);

#if WINDOWS_PHONE
            directoryProperties.LastModified = HttpResponseParsers.GetLastModified(response);
#else
            directoryProperties.LastModified = response.LastModified.ToUniversalTime();
#endif

            return(directoryProperties);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the share's properties from the response.
        /// </summary>
        /// <param name="response">The web response.</param>
        /// <returns>The share's attributes.</returns>
        public static FileShareProperties GetProperties(HttpWebResponse response)
        {
            CommonUtility.AssertNotNull("response", response);

            // Set the share properties
            FileShareProperties shareProperties = new FileShareProperties();

            shareProperties.ETag = HttpResponseParsers.GetETag(response);

#if WINDOWS_PHONE
            shareProperties.LastModified = HttpResponseParsers.GetLastModified(response);
#else
            shareProperties.LastModified = response.LastModified.ToUniversalTime();
#endif

            return(shareProperties);
        }
        /// <summary>
        /// Gets the directory's properties from the response.
        /// </summary>
        /// <param name="response">The web response.</param>
        /// <returns>The directory's attributes.</returns>
        public static FileDirectoryProperties GetProperties(HttpWebResponse response)
        {
            CommonUtility.AssertNotNull("response", response);

            FileDirectoryProperties directoryProperties = new FileDirectoryProperties();

            directoryProperties.ETag = HttpResponseParsers.GetETag(response);
            string directoryEncryption = response.Headers[Constants.HeaderConstants.ServerEncrypted];

            directoryProperties.IsServerEncrypted = string.Equals(directoryEncryption, Constants.HeaderConstants.TrueHeader, StringComparison.OrdinalIgnoreCase);

#if WINDOWS_PHONE
            directoryProperties.LastModified = HttpResponseParsers.GetLastModified(response);
#else
            directoryProperties.LastModified = response.LastModified.ToUniversalTime();
#endif

            return(directoryProperties);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the container's properties from the response.
        /// </summary>
        /// <param name="response">The web response.</param>
        /// <returns>The container's attributes.</returns>
        public static BlobContainerProperties GetProperties(HttpWebResponse response)
        {
            CommonUtility.AssertNotNull("response", response);

            // Set the container properties
            BlobContainerProperties containerProperties = new BlobContainerProperties();

            containerProperties.ETag = HttpResponseParsers.GetETag(response);

#if WINDOWS_PHONE
            containerProperties.LastModified = HttpResponseParsers.GetLastModified(response);
#else
            containerProperties.LastModified = response.LastModified.ToUniversalTime();
#endif

            // Get lease properties
            containerProperties.LeaseStatus   = BlobHttpResponseParsers.GetLeaseStatus(response);
            containerProperties.LeaseState    = BlobHttpResponseParsers.GetLeaseState(response);
            containerProperties.LeaseDuration = BlobHttpResponseParsers.GetLeaseDuration(response);

            return(containerProperties);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the share's properties from the response.
        /// </summary>
        /// <param name="response">The web response.</param>
        /// <returns>The share's attributes.</returns>
        public static FileShareProperties GetProperties(HttpWebResponse response)
        {
            CommonUtility.AssertNotNull("response", response);

            // Set the share properties
            FileShareProperties shareProperties = new FileShareProperties();

            shareProperties.ETag = HttpResponseParsers.GetETag(response);

#if WINDOWS_PHONE
            shareProperties.LastModified = HttpResponseParsers.GetLastModified(response);
#else
            shareProperties.LastModified = response.LastModified.ToUniversalTime();
#endif

            string quota = response.Headers[Constants.HeaderConstants.ShareQuota];
            if (!string.IsNullOrEmpty(quota))
            {
                shareProperties.Quota = int.Parse(quota, CultureInfo.InvariantCulture);
            }

            return(shareProperties);
        }
        /// <summary>
        /// Gets the blob's properties from the response.
        /// </summary>
        /// <param name="response">The web response.</param>
        /// <returns>The blob's properties.</returns>
        public static BlobProperties GetProperties(HttpWebResponse response)
        {
            CommonUtility.AssertNotNull("response", response);

            BlobProperties properties = new BlobProperties();

            properties.ETag = HttpResponseParsers.GetETag(response);

#if WINDOWS_PHONE
            properties.Created         = HttpResponseParsers.GetCreated(response);
            properties.LastModified    = HttpResponseParsers.GetLastModified(response);
            properties.ContentLanguage = response.Headers[Constants.HeaderConstants.ContentLanguageHeader];
#else
            string created = response.Headers[Constants.HeaderConstants.CreationTimeHeader];
            properties.Created = string.IsNullOrEmpty(created) ? (DateTimeOffset?)null : DateTimeOffset.Parse(created).ToUniversalTime();

            properties.LastModified    = response.LastModified.ToUniversalTime();
            properties.ContentLanguage = response.Headers[HttpResponseHeader.ContentLanguage];
#endif

            properties.ContentDisposition = response.Headers[Constants.HeaderConstants.ContentDispositionResponseHeader];
            properties.ContentEncoding    = response.Headers[HttpResponseHeader.ContentEncoding];

            // For range gets, only look at 'x-ms-blob-content-md5' for overall MD5
            if (response.Headers[HttpResponseHeader.ContentRange] != null)
            {
                properties.ContentMD5 = response.Headers[Constants.HeaderConstants.BlobContentMD5Header];
            }
            else
            {
                properties.ContentMD5 = response.Headers[HttpResponseHeader.ContentMd5];
            }

            properties.ContentType  = response.Headers[HttpResponseHeader.ContentType];
            properties.CacheControl = response.Headers[HttpResponseHeader.CacheControl];

            string blobEncryption = response.Headers[Constants.HeaderConstants.ServerEncrypted];
            properties.IsServerEncrypted = string.Equals(blobEncryption, Constants.HeaderConstants.TrueHeader, StringComparison.OrdinalIgnoreCase);

            string incrementalCopy = response.Headers[Constants.HeaderConstants.IncrementalCopyHeader];
            properties.IsIncrementalCopy = string.Equals(incrementalCopy, Constants.HeaderConstants.TrueHeader, StringComparison.OrdinalIgnoreCase);

            // Get blob type
            string blobType = response.Headers[Constants.HeaderConstants.BlobType];
            if (!string.IsNullOrEmpty(blobType))
            {
                properties.BlobType = (BlobType)Enum.Parse(typeof(BlobType), blobType, true);
            }

            // Get lease properties
            properties.LeaseStatus   = GetLeaseStatus(response);
            properties.LeaseState    = GetLeaseState(response);
            properties.LeaseDuration = GetLeaseDuration(response);

            // Get the content length. Prioritize range and x-ms over content length for the special cases.
            string rangeHeader             = response.Headers[HttpResponseHeader.ContentRange];
            string contentLengthHeader     = response.Headers[Constants.HeaderConstants.ContentLengthHeader];
            string blobContentLengthHeader = response.Headers[Constants.HeaderConstants.BlobContentLengthHeader];
            if (!string.IsNullOrEmpty(rangeHeader))
            {
                properties.Length = long.Parse(rangeHeader.Split('/')[1], CultureInfo.InvariantCulture);
            }
            else if (!string.IsNullOrEmpty(blobContentLengthHeader))
            {
                properties.Length = long.Parse(blobContentLengthHeader, CultureInfo.InvariantCulture);
            }
            else if (!string.IsNullOrEmpty(contentLengthHeader))
            {
                // On Windows Phone, ContentLength property is not always same as Content-Length header,
                // so we try to parse the header first.
                properties.Length = long.Parse(contentLengthHeader, CultureInfo.InvariantCulture);
            }
            else
            {
                properties.Length = response.ContentLength;
            }

            // Get sequence number
            string sequenceNumber = response.Headers[Constants.HeaderConstants.BlobSequenceNumber];
            if (!string.IsNullOrEmpty(sequenceNumber))
            {
                properties.PageBlobSequenceNumber = long.Parse(sequenceNumber, CultureInfo.InvariantCulture);
            }

            // Get committed block count
            string comittedBlockCount = response.Headers[Constants.HeaderConstants.BlobCommittedBlockCount];
            if (!string.IsNullOrEmpty(comittedBlockCount))
            {
                properties.AppendBlobCommittedBlockCount = int.Parse(comittedBlockCount, CultureInfo.InvariantCulture);
            }

            // Get the tier of the blob
            string premiumPageBlobTierInferredString = response.Headers[Constants.HeaderConstants.AccessTierInferredHeader];
            if (!string.IsNullOrEmpty(premiumPageBlobTierInferredString))
            {
                properties.BlobTierInferred = Convert.ToBoolean(premiumPageBlobTierInferredString);
            }

            string blobTierString = response.Headers[Constants.HeaderConstants.AccessTierHeader];

            StandardBlobTier?   standardBlobTier;
            PremiumPageBlobTier?premiumPageBlobTier;
            BlobHttpResponseParsers.GetBlobTier(properties.BlobType, blobTierString, out standardBlobTier, out premiumPageBlobTier);
            properties.StandardBlobTier    = standardBlobTier;
            properties.PremiumPageBlobTier = premiumPageBlobTier;

            if ((properties.PremiumPageBlobTier.HasValue || properties.StandardBlobTier.HasValue) && !properties.BlobTierInferred.HasValue)
            {
                properties.BlobTierInferred = false;
            }

            // Get the rehydration status
            string rehydrationStatusString = response.Headers[Constants.HeaderConstants.ArchiveStatusHeader];
            properties.RehydrationStatus = BlobHttpResponseParsers.GetRehydrationStatus(rehydrationStatusString);

            // Get the time the tier of the blob was last modified
            string accessTierChangeTimeString = response.Headers[Constants.HeaderConstants.AccessTierChangeTimeHeader];
            if (!string.IsNullOrEmpty(accessTierChangeTimeString))
            {
                properties.BlobTierLastModifiedTime = DateTimeOffset.Parse(accessTierChangeTimeString, CultureInfo.InvariantCulture);
            }

            return(properties);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the blob's properties from the response.
        /// </summary>
        /// <param name="response">The web response.</param>
        /// <returns>The blob's properties.</returns>
        public static BlobProperties GetProperties(HttpWebResponse response)
        {
            CommonUtility.AssertNotNull("response", response);

            BlobProperties properties = new BlobProperties();

            properties.ETag = HttpResponseParsers.GetETag(response);

#if WINDOWS_PHONE
            properties.LastModified    = HttpResponseParsers.GetLastModified(response);
            properties.ContentLanguage = response.Headers[Constants.HeaderConstants.ContentLanguageHeader];
#else
            properties.LastModified    = response.LastModified.ToUniversalTime();
            properties.ContentLanguage = response.Headers[HttpResponseHeader.ContentLanguage];
#endif

            properties.ContentDisposition = response.Headers[Constants.HeaderConstants.ContentDispositionResponseHeader];
            properties.ContentEncoding    = response.Headers[HttpResponseHeader.ContentEncoding];
            properties.ContentMD5         = response.Headers[HttpResponseHeader.ContentMd5];
            properties.ContentType        = response.Headers[HttpResponseHeader.ContentType];
            properties.CacheControl       = response.Headers[HttpResponseHeader.CacheControl];

            // Get blob type
            string blobType = response.Headers[Constants.HeaderConstants.BlobType];
            if (!string.IsNullOrEmpty(blobType))
            {
                properties.BlobType = (BlobType)Enum.Parse(typeof(BlobType), blobType, true);
            }

            // Get lease properties
            properties.LeaseStatus   = GetLeaseStatus(response);
            properties.LeaseState    = GetLeaseState(response);
            properties.LeaseDuration = GetLeaseDuration(response);

            // Get the content length. Prioritize range and x-ms over content length for the special cases.
            string rangeHeader             = response.Headers[HttpResponseHeader.ContentRange];
            string contentLengthHeader     = response.Headers[Constants.HeaderConstants.ContentLengthHeader];
            string blobContentLengthHeader = response.Headers[Constants.HeaderConstants.BlobContentLengthHeader];
            if (!string.IsNullOrEmpty(rangeHeader))
            {
                properties.Length = long.Parse(rangeHeader.Split('/')[1], CultureInfo.InvariantCulture);
            }
            else if (!string.IsNullOrEmpty(blobContentLengthHeader))
            {
                properties.Length = long.Parse(blobContentLengthHeader, CultureInfo.InvariantCulture);
            }
            else if (!string.IsNullOrEmpty(contentLengthHeader))
            {
                // On Windows Phone, ContentLength property is not always same as Content-Length header,
                // so we try to parse the header first.
                properties.Length = long.Parse(contentLengthHeader, CultureInfo.InvariantCulture);
            }
            else
            {
                properties.Length = response.ContentLength;
            }

            // Get sequence number
            string sequenceNumber = response.Headers[Constants.HeaderConstants.BlobSequenceNumber];
            if (!string.IsNullOrEmpty(sequenceNumber))
            {
                properties.PageBlobSequenceNumber = long.Parse(sequenceNumber, CultureInfo.InvariantCulture);
            }

            // Get committed block count
            string comittedBlockCount = response.Headers[Constants.HeaderConstants.BlobCommittedBlockCount];
            if (!string.IsNullOrEmpty(comittedBlockCount))
            {
                properties.AppendBlobCommittedBlockCount = int.Parse(comittedBlockCount, CultureInfo.InvariantCulture);
            }

            return(properties);
        }