Esempio n. 1
0
        public async Task GetAccountInfoAsync()
        {
            // Arrange
            BlobServiceClient service = GetServiceClient_SharedKey();

            // Act
            Response <AccountInfo> response = await service.GetAccountInfoAsync();

            // Assert
            Assert.IsNotNull(response.GetRawResponse().Headers.RequestId);
        }
Esempio n. 2
0
        public async Task GetAccountInfoAsync_HnsTrue()
        {
            // Arrange
            BlobServiceClient service = GetServiceClient_Hns();

            // Act
            Response <AccountInfo> response = await service.GetAccountInfoAsync();

            // Assert
            Assert.IsTrue(response.Value.IsHierarchicalNamespaceEnabled);
        }
Esempio n. 3
0
        private static async Task ReadInfos(string connString)
        {
            BlobServiceClient storageAccount;

            try
            {
                storageAccount = new BlobServiceClient(connString);
                AccountInfo accountInfo = await storageAccount.GetAccountInfoAsync();

                Console.WriteLine("AccountKind: " + accountInfo.AccountKind);
                Console.WriteLine("AccountSku: " + accountInfo.SkuName);

                if (accountInfo.SkuName == SkuName.StandardRagrs)
                {
                    BlobServiceStatistics stats = await storageAccount.GetStatisticsAsync();

                    Console.WriteLine("Statistics (GeoReplication): " + stats.GeoReplication);
                }

                var containers = storageAccount.GetBlobContainers();

                foreach (var container in containers)
                {
                    Console.WriteLine("checking Container: " + container.Name);

                    if (container.IsDeleted ?? true)
                    {
                        BlobContainerClient     containerClient     = new BlobContainerClient(connString, container.Name);
                        BlobContainerProperties containerProperties = await containerClient.GetPropertiesAsync();

                        Console.WriteLine("Container has LegalHold? " + containerProperties.HasLegalHold);
                        Console.WriteLine("Container is Immutable? " + containerProperties.HasImmutabilityPolicy);

                        await foreach (BlobItem blob in containerClient.GetBlobsAsync())
                        {
                            Console.WriteLine("Blob: " + blob.Name);
                            Console.WriteLine("     Type Of:" + blob.Properties.BlobType);
                            Console.WriteLine(blob.Properties.ContentLength > 1024 ?
                                              "     Size (KB):" + (blob.Properties.ContentLength / 1024) :
                                              "     Size (byte):" + blob.Properties.ContentLength);
                        }
                    }
                    else
                    {
                        Console.WriteLine("    >>>> Is Deleted!" + container.Properties.RemainingRetentionDays);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("OH SNAP!: " + e.Message);
            }
        }
Esempio n. 4
0
        private async Task <bool> TestBlobAccountConnectionAsync(YDataSourceAzureBlob dataSource)
        {
            StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(dataSource.StorageAccountName, dataSource.StorageAccountKey);

            string dfsUri = $"https://{dataSource.StorageAccountName }.blob.core.windows.net";

            var blobServiceClient = new BlobServiceClient(new Uri(dfsUri), sharedKeyCredential);

            var account = await blobServiceClient.GetAccountInfoAsync();

            return(true);
        }
Esempio n. 5
0
        public async Task GetAccountInfoAsync_Error()
        {
            // Arrange
            BlobServiceClient service = InstrumentClient(
                new BlobServiceClient(
                    GetServiceClient_SharedKey().Uri,
                    GetOptions()));

            // Act
            await TestHelper.AssertExpectedExceptionAsync <RequestFailedException>(
                service.GetAccountInfoAsync(),
                e => Assert.AreEqual("ResourceNotFound", e.ErrorCode));
        }
Esempio n. 6
0
    public static async Task Main(string[] args)
    {
        /*
         * Connect to the storage account
         */
        StorageSharedKeyCredential accountCredentials = new StorageSharedKeyCredential(storageAccountName, storageAccountKey);
        BlobServiceClient          serviceClient      = new BlobServiceClient(new Uri(blobServiceEndpoint), accountCredentials);
        AccountInfo info = await serviceClient.GetAccountInfoAsync();

        /*
         * Print out metadata about the storage account
         */
        await Console.Out.WriteLineAsync($"Connected to Azure Storage Account: {storageAccountName}");

        await Console.Out.WriteLineAsync($"Account name:\t{storageAccountName}");

        await Console.Out.WriteLineAsync($"Account kind:\t{info?.AccountKind}");

        await Console.Out.WriteLineAsync($"Account sku:\t{info?.SkuName}");

        /*
         * Invoke the EnumerateContainerAsync Method
         */
        await EnumerateContainersAsync(serviceClient);

        string existingContainerName = "mycontainer1";

        await EnumerateBlobsAsync(serviceClient, existingContainerName);


        /*
         * Create the new container and assign the newContainerName
         */
        string newContainerName             = "mycontainer1-obey";
        BlobContainerClient containerClient = await GetContainerAsync(serviceClient, newContainerName);

        string     uploadedBlobName = "blobname.jpg";
        BlobClient blobClient       = await GetBlobAsync(containerClient, uploadedBlobName);

        await Console.Out.WriteLineAsync($"Blob Url:\t{blobClient.Uri}");
    }
Esempio n. 7
0
        // <Snippet_GetAccountInfo>
        private static async Task GetAccountInfoAsync(string connectStr)
        {
            try
            {
                BlobServiceClient blobServiceClient = new BlobServiceClient(connectStr);

                // Get the blob's storage account properties.
                AccountInfo acctInfo = await blobServiceClient.GetAccountInfoAsync();

                // Display the properties.
                Console.WriteLine("Account info");
                Console.WriteLine($" AccountKind: {acctInfo.AccountKind}");
                Console.WriteLine($"     SkuName: {acctInfo.SkuName}");
            }
            catch (RequestFailedException ex)
            {
                Console.WriteLine($"HTTP error code {ex.Status}: {ex.ErrorCode}");
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
Esempio n. 8
0
        static async Task Main(string[] args)
        {
            StorageSharedKeyCredential accountCredentials = new StorageSharedKeyCredential(config["StorageAccountName"], config["StorageAccountKey"]);

            BlobServiceClient serviceClient = new BlobServiceClient(new Uri(config["ServiceEndpoint"]), accountCredentials);

            AccountInfo info = await serviceClient.GetAccountInfoAsync();

            await EnumerateContainersAsync(serviceClient);

            string existingContainerName = "raster-graphics";

            await EnumerateBlobsAsync(serviceClient, existingContainerName);

            string newContainerName             = "vector-graphics";
            BlobContainerClient containerClient = await GetContainerAsync(serviceClient, newContainerName);

            string     uploadedBlobName = "graph.svg";
            BlobClient blobClient       = await GetBlobAsync(containerClient, uploadedBlobName);

            await Console.Out.WriteLineAsync($"Blob Url:\t{blobClient.Uri}");
        }