Пример #1
0
        /// <summary>
        /// Reads a container entry completely including its properties and metadata.
        /// </summary>
        /// <returns>Container listing entry</returns>
        private static async Task <BlobContainerEntry> ParseContainerEntryAsync(XmlReader reader, Uri baseUri, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            string name = null;
            IDictionary <string, string> metadata            = null;
            BlobContainerProperties      containerProperties = new BlobContainerProperties();

            containerProperties.PublicAccess = BlobContainerPublicAccessType.Off;

            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.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.LastModifiedElement:
                                    containerProperties.LastModified = (await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)).ToUTCTime();
                                    break;

                                case Constants.EtagElement:
                                    containerProperties.ETag = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false);

                                    break;

                                case Constants.HasImmutabilityPolicyElement:
                                    containerProperties.HasImmutabilityPolicy = await reader.ReadElementContentAsBooleanAsync().ConfigureAwait(false);

                                    break;

                                case Constants.HasLegalHoldElement:
                                    containerProperties.HasLegalHold = await reader.ReadElementContentAsBooleanAsync().ConfigureAwait(false);

                                    break;

                                case Constants.LeaseStatusElement:
                                    containerProperties.LeaseStatus = BlobHttpResponseParsers.GetLeaseStatus(await reader.ReadElementContentAsStringAsync().ConfigureAwait(false));
                                    break;

                                case Constants.LeaseStateElement:
                                    containerProperties.LeaseState = BlobHttpResponseParsers.GetLeaseState(await reader.ReadElementContentAsStringAsync().ConfigureAwait(false));
                                    break;

                                case Constants.LeaseDurationElement:
                                    containerProperties.LeaseDuration = BlobHttpResponseParsers.GetLeaseDuration(await reader.ReadElementContentAsStringAsync().ConfigureAwait(false));
                                    break;

                                case Constants.PublicAccessElement:
                                    containerProperties.PublicAccess = ContainerHttpResponseParsers.GetContainerAcl(await reader.ReadElementContentAsStringAsync().ConfigureAwait(false));
                                    break;

                                default:
                                    await reader.SkipAsync().ConfigureAwait(false);

                                    break;
                                }
                            }
                        }

                        await reader.ReadEndElementAsync().ConfigureAwait(false);

                        break;

                    case Constants.MetadataElement:
                        metadata = await Response.ParseMetadataAsync(reader).ConfigureAwait(false);

                        break;

                    default:
                        await reader.SkipAsync().ConfigureAwait(false);

                        break;
                    }
                }
            }

            await reader.ReadEndElementAsync().ConfigureAwait(false);

            if (metadata == null)
            {
                metadata = new Dictionary <string, string>();
            }

            return(new BlobContainerEntry
            {
                Properties = containerProperties,
                Name = name,
                Uri = NavigationHelper.AppendPathToSingleUri(baseUri, name),
                Metadata = metadata,
            });
        }
        /// <summary>
        /// Reads a container entry completely including its properties and metadata.
        /// </summary>
        /// <returns>Container listing entry</returns>
        private BlobContainerEntry ParseContainerEntry(Uri baseUri)
        {
            string name = null;
            IDictionary <string, string> metadata            = null;
            BlobContainerProperties      containerProperties = new BlobContainerProperties();

            containerProperties.PublicAccess = BlobContainerPublicAccessType.Off;

            this.reader.ReadStartElement();
            while (this.reader.IsStartElement())
            {
                if (this.reader.IsEmptyElement)
                {
                    this.reader.Skip();
                }
                else
                {
                    switch (this.reader.Name)
                    {
                    case Constants.NameElement:
                        name = this.reader.ReadElementContentAsString();
                        break;

                    case Constants.PropertiesElement:
                        this.reader.ReadStartElement();
                        while (this.reader.IsStartElement())
                        {
                            if (this.reader.IsEmptyElement)
                            {
                                this.reader.Skip();
                            }
                            else
                            {
                                switch (this.reader.Name)
                                {
                                case Constants.LastModifiedElement:
                                    containerProperties.LastModified = reader.ReadElementContentAsString().ToUTCTime();
                                    break;

                                case Constants.EtagElement:
                                    containerProperties.ETag = reader.ReadElementContentAsString();
                                    break;

                                case Constants.HasImmutabilityPolicyElement:
                                    containerProperties.HasImmutabilityPolicy = reader.ReadElementContentAsBoolean();
                                    break;

                                case Constants.HasLegalHoldElement:
                                    containerProperties.HasLegalHold = reader.ReadElementContentAsBoolean();
                                    break;

                                case Constants.LeaseStatusElement:
                                    containerProperties.LeaseStatus = BlobHttpResponseParsers.GetLeaseStatus(reader.ReadElementContentAsString());
                                    break;

                                case Constants.LeaseStateElement:
                                    containerProperties.LeaseState = BlobHttpResponseParsers.GetLeaseState(reader.ReadElementContentAsString());
                                    break;

                                case Constants.LeaseDurationElement:
                                    containerProperties.LeaseDuration = BlobHttpResponseParsers.GetLeaseDuration(reader.ReadElementContentAsString());
                                    break;

                                case Constants.PublicAccessElement:
                                    containerProperties.PublicAccess = ContainerHttpResponseParsers.GetContainerAcl(reader.ReadElementContentAsString());
                                    break;

                                default:
                                    reader.Skip();
                                    break;
                                }
                            }
                        }

                        this.reader.ReadEndElement();
                        break;

                    case Constants.MetadataElement:
                        metadata = Response.ParseMetadata(this.reader);
                        break;

                    default:
                        reader.Skip();
                        break;
                    }
                }
            }

            this.reader.ReadEndElement();

            if (metadata == null)
            {
                metadata = new Dictionary <string, string>();
            }

            return(new BlobContainerEntry
            {
                Properties = containerProperties,
                Name = name,
                Uri = NavigationHelper.AppendPathToSingleUri(baseUri, name),
                Metadata = metadata,
            });
        }