From 383454badc2a994fed1f4f759bc877b788bcccbf Mon Sep 17 00:00:00 2001 From: Oubai Bounie Date: Mon, 23 Sep 2019 16:22:05 -0700 Subject: [PATCH] Added modern Azure usage samples --- sdk/SdkSamples/Program.cs | 4 +- .../RatedUsage/GetCustomersUsageSummary.cs | 39 ++++++++++++++++++ ...sage.cs => GetSubscriptionUsageByMeter.cs} | 16 ++++---- .../GetSubscriptionUsageByResource.cs | 40 +++++++++++++++++++ sdk/SdkSamples/SdkSamples.csproj | 16 ++++---- 5 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 sdk/SdkSamples/RatedUsage/GetCustomersUsageSummary.cs rename sdk/SdkSamples/RatedUsage/{GetSubscriptionResourceUsage.cs => GetSubscriptionUsageByMeter.cs} (72%) create mode 100644 sdk/SdkSamples/RatedUsage/GetSubscriptionUsageByResource.cs diff --git a/sdk/SdkSamples/Program.cs b/sdk/SdkSamples/Program.cs index fba53a2..2a0e503 100644 --- a/sdk/SdkSamples/Program.cs +++ b/sdk/SdkSamples/Program.cs @@ -370,9 +370,11 @@ namespace Microsoft.Store.PartnerCenter.Samples { var ratedUsageScenarios = new IPartnerScenario[] { + new GetCustomersUsageSummary(context), new GetCustomerUsageSummary(context), new GetCustomerSubscriptionsUsage(context), - new GetSubscriptionResourceUsage(context), + new GetSubscriptionUsageByResource(context), + new GetSubscriptionUsageByMeter(context), new GetSubscriptionUsageRecords(context), new GetSubscriptionUsageSummary(context) }; diff --git a/sdk/SdkSamples/RatedUsage/GetCustomersUsageSummary.cs b/sdk/SdkSamples/RatedUsage/GetCustomersUsageSummary.cs new file mode 100644 index 0000000..87dd1f2 --- /dev/null +++ b/sdk/SdkSamples/RatedUsage/GetCustomersUsageSummary.cs @@ -0,0 +1,39 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +using System.Linq; + +namespace Microsoft.Store.PartnerCenter.Samples.RatedUsage +{ + /// + /// A scenario that retrieves all customers usage summaries for usage based services. + /// + public class GetCustomersUsageSummary : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomersUsageSummary(IScenarioContext context) : base("Get all customers usage summaries", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Retrieving all customers usage summaries"); + + var customersUsageSummary = partnerOperations.Customers.UsageRecords.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customersUsageSummary, "Customer usage summaries"); + } + } +} diff --git a/sdk/SdkSamples/RatedUsage/GetSubscriptionResourceUsage.cs b/sdk/SdkSamples/RatedUsage/GetSubscriptionUsageByMeter.cs similarity index 72% rename from sdk/SdkSamples/RatedUsage/GetSubscriptionResourceUsage.cs rename to sdk/SdkSamples/RatedUsage/GetSubscriptionUsageByMeter.cs index d43a7a6..22045ee 100644 --- a/sdk/SdkSamples/RatedUsage/GetSubscriptionResourceUsage.cs +++ b/sdk/SdkSamples/RatedUsage/GetSubscriptionUsageByMeter.cs @@ -1,5 +1,5 @@ // ----------------------------------------------------------------------- -// +// // Copyright (c) Microsoft Corporation. All rights reserved. // // ----------------------------------------------------------------------- @@ -7,15 +7,15 @@ namespace Microsoft.Store.PartnerCenter.Samples.RatedUsage { /// - /// A scenario that retrieves a single subscription's resource usage records. + /// A scenario that retrieves a single subscription's resource usage records aggregated by meter. /// - public class GetSubscriptionResourceUsage : BasePartnerScenario + public class GetSubscriptionUsageByMeter : BasePartnerScenario { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The scenario context. - public GetSubscriptionResourceUsage(IScenarioContext context) : base("Get subscription resource usage", context) + public GetSubscriptionUsageByMeter(IScenarioContext context) : base("Get subscription resource usage by meter", context) { } @@ -29,12 +29,12 @@ namespace Microsoft.Store.PartnerCenter.Samples.RatedUsage string customerId = this.ObtainCustomerId("Enter the ID of the customer who owns the subscription"); string subscriptionId = this.ObtainSubscriptionId(customerId, "Enter the subscription ID"); - this.Context.ConsoleHelper.StartProgress("Retrieving customer orders"); + this.Context.ConsoleHelper.StartProgress("Retrieving customer usage records"); - var usageRecords = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId).UsageRecords.Resources.Get(); + var usageRecords = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId).UsageRecords.ByMeter.Get(); this.Context.ConsoleHelper.StopProgress(); - this.Context.ConsoleHelper.WriteObject(usageRecords, "Subscription resource usage records"); + this.Context.ConsoleHelper.WriteObject(usageRecords, "Subscription resource usage records by meter"); } } } diff --git a/sdk/SdkSamples/RatedUsage/GetSubscriptionUsageByResource.cs b/sdk/SdkSamples/RatedUsage/GetSubscriptionUsageByResource.cs new file mode 100644 index 0000000..aed81d0 --- /dev/null +++ b/sdk/SdkSamples/RatedUsage/GetSubscriptionUsageByResource.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.RatedUsage +{ + /// + /// A scenario that retrieves a single subscription's resource usage records aggregated by resource. + /// + public class GetSubscriptionUsageByResource : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSubscriptionUsageByResource(IScenarioContext context) : base("Get subscription resource usage by resource", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer who owns the subscription"); + string subscriptionId = this.ObtainSubscriptionId(customerId, "Enter the subscription ID"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer usage records"); + + var usageRecords = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId).UsageRecords.ByResource.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(usageRecords, "Subscription resource usage records by resource"); + } + } +} diff --git a/sdk/SdkSamples/SdkSamples.csproj b/sdk/SdkSamples/SdkSamples.csproj index 70f0f7a..541218d 100644 --- a/sdk/SdkSamples/SdkSamples.csproj +++ b/sdk/SdkSamples/SdkSamples.csproj @@ -45,14 +45,14 @@ ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.5.2.0\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - - ..\packages\Microsoft.Store.PartnerCenter.1.13.1\lib\Net45\Microsoft.Store.PartnerCenter.dll + + ..\packages\Microsoft.Store.PartnerCenter.1.15.0\lib\Net45\Microsoft.Store.PartnerCenter.dll - - ..\packages\Microsoft.Store.PartnerCenter.1.13.1\lib\Net45\Microsoft.Store.PartnerCenter.Extensions.dll + + ..\packages\Microsoft.Store.PartnerCenter.1.15.0\lib\Net45\Microsoft.Store.PartnerCenter.Extensions.dll - - ..\packages\Microsoft.Store.PartnerCenter.1.13.1\lib\Net45\Microsoft.Store.PartnerCenter.Models.dll + + ..\packages\Microsoft.Store.PartnerCenter.1.15.0\lib\Net45\Microsoft.Store.PartnerCenter.Models.dll ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll @@ -226,8 +226,10 @@ - + + +