예제 #1
0
        /// <summary>
        /// The constructor
        /// </summary>
        /// <param name="batchAccountName">Batch account name</param>
        /// <param name="azureOfferDurableId">Azure offer id</param>
        /// <param name="logger">The logger</param>
        public AzureProxy(string batchAccountName, string azureOfferDurableId, ILogger logger)
        {
            this.logger = logger;

            var findBatchAccountResult = FindBatchAccountAsync(batchAccountName).Result;

            subscriptionId = findBatchAccountResult.SubscriptionId;
            location       = findBatchAccountResult.Location;
            batchClient    = BatchClient.Open(new BatchTokenCredentials($"https://{findBatchAccountResult.BatchAccountEndpoint}", () => GetAzureAccessTokenAsync("https://batch.core.windows.net/")));

            getBatchAccountFunc = async() =>
                                  await new BatchManagementClient(new TokenCredentials(await GetAzureAccessTokenAsync()))
            {
                SubscriptionId = findBatchAccountResult.SubscriptionId
            }
            .BatchAccount
            .GetAsync(findBatchAccountResult.ResourceGroupName, batchAccountName);

            this.azureOfferDurableId = azureOfferDurableId;

            if (!AzureRegionUtils.TryGetBillingRegionName(location, out billingRegionName))
            {
                logger.LogWarning($"Azure ARM location '{location}' does not have a corresponding Azure Billing Region.  Prices from the fallback billing region '{DefaultAzureBillingRegionName}' will be used instead.");
                billingRegionName = DefaultAzureBillingRegionName;
            }
        }
        /// <summary>
        /// The constructor
        /// </summary>
        /// <param name="batchAccountName">Batch account name</param>
        /// <param name="logger">The logger</param>
        public AzureProxy(string batchAccountName, string azureOfferDurableId, ILogger logger)
        {
            this.logger           = logger;
            this.batchAccountName = batchAccountName;
            var batchAccount = GetBatchAccountAsync(batchAccountName).Result;

            batchClient              = BatchClient.Open(new BatchTokenCredentials($"https://{batchAccount.AccountEndpoint}", () => GetAzureAccessTokenAsync("https://batch.core.windows.net/")));
            subscriptionId           = batchAccount.Manager.SubscriptionId;
            location                 = batchAccount.RegionName;
            this.azureOfferDurableId = azureOfferDurableId;

            if (AzureRegionUtils.TryGetBillingRegionName(location, out string azureBillingRegionName))
            {
                billingRegionName = azureBillingRegionName;
            }
            else
            {
                logger.LogWarning($"Azure ARM location '{location}' does not have a corresponding Azure Billing Region.  Prices from the fallback billing region '{defaultAzureBillingRegionName}' will be used instead.");
                billingRegionName = defaultAzureBillingRegionName;
            }
        }