/// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     Operations                       = new Operations(this);
     Skus                             = new SkusOperations(this);
     StorageAccounts                  = new StorageAccountsOperations(this);
     DeletedAccounts                  = new DeletedAccountsOperations(this);
     Usages                           = new UsagesOperations(this);
     ManagementPolicies               = new ManagementPoliciesOperations(this);
     BlobInventoryPolicies            = new BlobInventoryPoliciesOperations(this);
     PrivateEndpointConnections       = new PrivateEndpointConnectionsOperations(this);
     PrivateLinkResources             = new PrivateLinkResourcesOperations(this);
     ObjectReplicationPolicies        = new ObjectReplicationPoliciesOperations(this);
     LocalUsers                       = new LocalUsersOperations(this);
     EncryptionScopes                 = new EncryptionScopesOperations(this);
     BlobServices                     = new BlobServicesOperations(this);
     BlobContainers                   = new BlobContainersOperations(this);
     FileServices                     = new FileServicesOperations(this);
     FileShares                       = new FileSharesOperations(this);
     QueueServices                    = new QueueServicesOperations(this);
     Queue                            = new QueueOperations(this);
     TableServices                    = new TableServicesOperations(this);
     Table                            = new TableOperations(this);
     BaseUri                          = new System.Uri("https://management.azure.com");
     ApiVersion                       = "2021-08-01";
     AcceptLanguage                   = "en-US";
     LongRunningOperationRetryTimeout = 30;
     GenerateClientRequestId          = true;
     SerializationSettings            = new JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     SerializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
     DeserializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
 }
        private async Task<string> GetBlobContainerSasUri(string rg1Name, string storageAccountName)
        {
            string sasUri = "foobar";

            if (Mode == RecordedTestMode.Record)
            {
                StorageAccount storageAccountOutput = await CreateStorageAccount(rg1Name, storageAccountName);
                var accountKeyResult = (await StorageAccountsOperations.ListKeysAsync(rg1Name, storageAccountName)).Value;
                //var accountKeyResult = await StorageAccountsClient.ListKeysWithHttpMessagesAsync(rg1Name, storageAccountName).Result;
                StorageAccount storageAccount = new StorageAccount(DefaultLocation);

                BlobContainer container = await BlobContainersOperations.GetAsync(rg1Name, storageAccountName, "sascontainer");
                //container.CreateIfNotExistsAsync();
                sasUri = GetContainerSasUri(container);
            }

            return sasUri;
        }
        private async Task <string> CreateApplicationMediaLink(string rgName, string fileName)
        {
            string         storageAccountName   = Recording.GenerateAssetName("saforgallery");
            string         asName               = Recording.GenerateAssetName("asforgallery");
            StorageAccount storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); // resource group is also created in this method.

            string applicationMediaLink = @"https://saforgallery1969.blob.core.windows.net/sascontainer/test.txt\";

            if (Mode == RecordedTestMode.Record)
            {
                var            accountKeyResult = await(StorageAccountsOperations.ListKeysAsync(rgName, storageAccountName));
                StorageAccount storageAccount   = new StorageAccount(DefaultLocation);
                //StorageAccount storageAccount = new StorageAccount(new StorageCredentials(storageAccountName, accountKeyResult.Body.Key1), useHttps: true);

                //var blobClient = storageAccount.CreateCloudBlobClient();
                BlobContainer container = await BlobContainersOperations.GetAsync(rgName, storageAccountName, "sascontainer");

                //byte[] blobContent = Encoding.UTF8.GetBytes("Application Package Test");
                //byte[] bytes = new byte[512]; // Page blob must be multiple of 512
                //System.Buffer.BlockCopy(blobContent, 0, bytes, 0, blobContent.Length);
                //var blobClient = storageAccount.CreateCloudBlobClient();
                //CloudBlobContainer container = blobClient.GetContainerReference("sascontainer");
                //bool created = container.CreateIfNotExistsAsync().Result;

                //CloudPageBlob pageBlob = container.GetPageBlobReference(fileName);
                //byte[] blobContent = Encoding.UTF8.GetBytes("Application Package Test");
                //byte[] bytes = new byte[512]; // Page blob must be multiple of 512
                //System.Buffer.BlockCopy(blobContent, 0, bytes, 0, blobContent.Length);
                //pageBlob.UploadFromByteArrayAsync(bytes, 0, bytes.Length);

                //SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
                //sasConstraints.SharedAccessStartTime = Recording.UtcNow.AddDays(-1);
                //sasConstraints.SharedAccessExpiryTime = Recording.UtcNow.AddDays(2);
                //sasConstraints.Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write;

                ////Generate the shared access signature on the blob, setting the constraints directly on the signature.
                //string sasContainerToken = pageBlob.GetSharedAccessSignature(sasConstraints);

                ////Return the URI string for the container, including the SAS token.
                //applicationMediaLink = pageBlob.Uri + sasContainerToken;
            }
            return(applicationMediaLink);
        }
Beispiel #4
0
 /// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     Operations         = new Operations(this);
     Skus               = new SkusOperations(this);
     StorageAccounts    = new StorageAccountsOperations(this);
     Usages             = new UsagesOperations(this);
     BlobServices       = new BlobServicesOperations(this);
     BlobContainers     = new BlobContainersOperations(this);
     ManagementPolicies = new ManagementPoliciesOperations(this);
     BaseUri            = new System.Uri("https://management.azure.com");
     AcceptLanguage     = "en-US";
     LongRunningOperationRetryTimeout = 30;
     GenerateClientRequestId          = true;
     SerializationSettings            = new JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     SerializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
     DeserializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
 }