/// <summary> /// Returns the data of the billing apis (ratecard and usage) connected and /// calculates the costs. /// </summary> /// <param name="offerDurableId">Offer - e.g. MS-AZR-0003p (see: https://azure.microsoft.com/en-us/support/legal/offer-details/) </param> /// <param name="currency">the currency - e.g. EUR or USD</param> /// <param name="locale">the locale - e.g. de-AT or en-US</param> /// <param name="regionInfo">the region - e.g. DE, AT or US</param> /// <param name="startDate">Start date - get usage date from this date</param> /// <param name="endDate">End date - get usage data to this date</param> /// <param name="granularity">The granularity - daily or hourly</param> /// <param name="showDetails">Include instance-level details or not</param> /// <param name="token">the OAuth token</param> /// <returns>The costs of the resources (combined data of ratecard and usage api)</returns> public ResourceCostData GetResourceCosts(string offerDurableId, string currency, string locale, string regionInfo, DateTime startDate, DateTime endDate, AggregationGranularity granularity, bool showDetails, string token = null) { if (string.IsNullOrEmpty(token)) { token = AzureAuthenticationHelper.GetOAuthTokenFromAAD(Globals.SERVICEURL, Tenant, Globals.RESOURCE, RedirectUrl, ClientId, ClientSecret); } var rateCardData = GetRateCardData(offerDurableId, currency, locale, regionInfo, token); // set startdate to the beginning of the period so that the cost calculation will be correct. DateTime start = GetStartOfBillingCycle(startDate); var usageData = GetUsageData(start, endDate, granularity, showDetails, token); var calculated = Combine(rateCardData, usageData); calculated.Costs = calculated.Costs.Where(x => x.UsageValue.Properties.UsageStartTimeAsDate >= startDate).ToList(); return(calculated); }
/// <summary> /// Reads the ratecard data from the REST API. /// </summary> /// <param name="offerDurableId">Offer - e.g. MS-AZR-0003p (see: https://azure.microsoft.com/en-us/support/legal/offer-details/) </param> /// <param name="currency">the currency - e.g. EUR or USD</param> /// <param name="locale">the locale - e.g. de-AT or en-US</param> /// <param name="regionInfo">the region - e.g. DE, AT or US</param> /// <returns>The ratecard information</returns> public RateCardData Get(string offerDurableId, string currency, string locale, string regionInfo) { string token = AzureAuthenticationHelper.GetOAuthTokenFromAAD(Globals.SERVICEURL, Tenant, Globals.RESOURCE, RedirectUrl, ClientId, ClientSecret); return(Get(offerDurableId, currency, locale, regionInfo, token)); }
/// <summary> /// Reads data from the usage REST API. /// </summary> /// <param name="startDate">Start date - get usage date from this date</param> /// <param name="endDate">End date - get usage data to this date</param> /// <param name="granularity">The granularity - daily or hourly</param> /// <param name="showDetails">Include instance-level details or not</param> /// <returns>the usage data for the given time range with the given granularity</returns> public UsageData Get(DateTime startDate, DateTime endDate, AggregationGranularity granularity, bool showDetails) { string token = AzureAuthenticationHelper.GetOAuthTokenFromAAD(Globals.SERVICEURL, Tenant, Globals.RESOURCE, RedirectUrl, ClientId, ClientSecret); return(Get(startDate, endDate, granularity, showDetails, token)); }