Пример #1
0
        public HostVersion[] ReadAll()
        {
            List <HostVersion> versions = new List <HostVersion>();

            IEnumerable <IListBlobItem> lazyItems = _directory.ListBlobs(
                useFlatBlobListing: true, blobListingDetails: BlobListingDetails.Metadata);

            IListBlobItem[] items;

            try
            {
                items = lazyItems.ToArray();
            }
            catch (StorageException ex)
            {
                // A non-existent container should be treated just like an empty container.
                if (ex.RequestInformation.HttpStatusCode == 404)
                {
                    return(new HostVersion[0]);
                }
                else
                {
                    throw;
                }
            }

            foreach (ICloudBlob blob in items)
            {
                HostVersion version = GetHostVersion(blob);
                versions.Add(version);
            }

            return(versions.ToArray());
        }
Пример #2
0
        private static HostVersion GetHostVersion(ICloudBlob blob)
        {
            // Use the blob name as the HostVersion.Name; any HostVersion will have this property set.
            HostVersion version = new HostVersion
            {
                Label = blob.Name
            };

            // Try to get the link property from the blob contents.
            // HostVersion.Link will only be set when the blob matches this schema.
            if (blob.Properties.ContentType == "application/json")
            {
                Encoding utf8 = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
                string   value;

                using (Stream stream = blob.OpenRead())
                    using (TextReader textReader = new StreamReader(stream, utf8))
                    {
                        value = textReader.ReadToEnd();
                    }

                string link;

                if (TryReadLink(value, out link))
                {
                    version.Link = link;
                }
            }

            return(version);
        }
        private static HostVersion GetHostVersion(ICloudBlob blob)
        {
            // Use the blob name as the HostVersion.Name; any HostVersion will have this property set.
            HostVersion version = new HostVersion
            {
                Label = blob.Name
            };

            // Try to get the link property from the blob contents.
            // HostVersion.Link will only be set when the blob matches this schema.
            if (blob.Properties.ContentType == "application/json")
            {
                Encoding utf8 = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);

                string value;
                Stream stream = blob.OpenRead();
                try
                {
                    using (TextReader textReader = new StreamReader(stream, utf8))
                    {
                        stream = null;
                        value = textReader.ReadToEnd();
                    }
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Dispose();
                    }
                }

                string link;
                if (TryReadLink(value, out link))
                {
                    version.Link = link;
                }
            }

            return version;
        }