Esempio n. 1
0
        private static bool DeleteContainerMetadata(string key)
        {
            try
            {
                BlobContainerClient containerClient = new BlobContainerClient(connectionString, containerName);

                // Get the container properties
                Azure.Storage.Blobs.Models.BlobContainerProperties properties = containerClient.GetProperties();

                // Check if a metadata with specified key exists.
                if (!properties.Metadata.ContainsKey(key))
                {
                    System.Console.WriteLine($"Metadata with key {{{key}}} doesn't exist in the collection.");
                    return(false);
                }

                properties.Metadata.Remove(key);

                containerClient.SetMetadata(properties.Metadata);

                Console.WriteLine("-----------------------------------");
                Console.WriteLine($" Metadata pair with key {{{key}}} has been deleted.");
                Console.WriteLine("-----------------------------------");

                return(true);
            }
            catch (RequestFailedException e)
            {
                Console.WriteLine($"HTTP error code {e.Status}: {e.ErrorCode}");
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }

            return(false);
        }
Esempio n. 2
0
        private static bool SetContainerMetadata(string key, string value)
        {
            try
            {
                BlobContainerClient containerClient = new BlobContainerClient(connectionString, containerName);

                // Get the container properties
                Azure.Storage.Blobs.Models.BlobContainerProperties properties = containerClient.GetProperties();

                // Add container's metadata
                properties.Metadata.Add(key, value);

                containerClient.SetMetadata(properties.Metadata);

                Console.WriteLine("-----------------------------------");
                Console.WriteLine($" Metadata pair {{ {key} - {value} }} added to container.");
                Console.WriteLine("-----------------------------------");

                return(true);
            }
            catch (RequestFailedException e)
            {
                Console.WriteLine($"HTTP error code {e.Status}: {e.ErrorCode}");
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }

            return(false);
        }
Esempio n. 3
0
        private static void ListContainerMetadata()
        {
            try
            {
                BlobContainerClient containerClient = new BlobContainerClient(connectionString, containerName);

                // Get the container properties
                Azure.Storage.Blobs.Models.BlobContainerProperties properties = containerClient.GetProperties();

                // Display container's metadata values
                Console.WriteLine("-----------------------------------");
                Console.WriteLine($" Container name: {containerClient.Name} - (Metadata)");
                foreach (var entry in properties.Metadata)
                {
                    Console.WriteLine($" Metadata: {{key: {entry.Key} - Value: {entry.Value}}}");
                }
                Console.WriteLine("-----------------------------------");
            }
            catch (RequestFailedException e)
            {
                Console.WriteLine($"HTTP error code {e.Status}: {e.ErrorCode}");
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Update the Metadata property based on the value stored
 /// in the parent XML node
 /// </summary>
 /// <param name="element">XML element</param>
 /// <param name="value">value for element</param>
 static partial void CustomizeFromXml(System.Xml.Linq.XElement element, Azure.Storage.Blobs.Models.BlobContainerProperties value)
 {
     System.Xml.Linq.XElement parent = element.Parent;
     value.Metadata = new System.Collections.Generic.Dictionary <string, string>(System.StringComparer.OrdinalIgnoreCase);
     System.Xml.Linq.XElement child = parent.Element(System.Xml.Linq.XName.Get("Metadata", ""));
     if (child != null)
     {
         foreach (System.Xml.Linq.XElement _pair in child.Elements())
         {
             value.Metadata[_pair.Name.LocalName] = _pair.Value;
         }
     }
 }
Esempio n. 5
0
        public async Task TestAsync()
        {
            string containerName = "container" + Guid.NewGuid();

            Console.WriteLine("Create Container");
            Console.WriteLine(await _blobContainerService.CreateContainerAsync(containerName));

            Console.WriteLine("Get container details");
            Azure.Storage.Blobs.Models.BlobContainerProperties containerDetails = await _blobContainerService.GetContainerProperties(containerName);

            Console.WriteLine(containerDetails);

            Console.WriteLine("List container content");
            Azure.Storage.Blobs.Models.BlobItem[] containerContent = await _blobContainerService.ListContainerContentAsync(containerName);

            Console.WriteLine(containerContent);

            Console.WriteLine("Delete container");
            Console.WriteLine(await _blobContainerService.DeleteContainerAsync(containerName));
        }
Esempio n. 6
0
        private static void ListContainerProperties()
        {
            try
            {
                BlobContainerClient containerClient = new BlobContainerClient(connectionString, containerName);

                // Get the container properties
                Azure.Storage.Blobs.Models.BlobContainerProperties properties = containerClient.GetProperties();

                // Display some of the container's property values
                Console.WriteLine("-----------------------------------");
                Console.WriteLine($" Container name: {containerClient.Name} - (System Properties)");
                Console.WriteLine($" LastModified: {properties.LastModified}");
                Console.WriteLine($" LeaseState: {properties.LeaseState}");
                Console.WriteLine($" PublicAccess: {properties.PublicAccess}");
                Console.WriteLine("-----------------------------------");
            }
            catch (RequestFailedException e)
            {
                Console.WriteLine($"HTTP error code {e.Status}: {e.ErrorCode}");
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }