Added modern Azure usage samples

This commit is contained in:
Oubai Bounie 2019-09-23 16:22:05 -07:00
Родитель 8f13e5b8dd
Коммит 383454badc
5 изменённых файлов: 99 добавлений и 16 удалений

Просмотреть файл

@ -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)
};

Просмотреть файл

@ -0,0 +1,39 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerUsageSummary.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
using System.Linq;
namespace Microsoft.Store.PartnerCenter.Samples.RatedUsage
{
/// <summary>
/// A scenario that retrieves all customers usage summaries for usage based services.
/// </summary>
public class GetCustomersUsageSummary : BasePartnerScenario
{
/// <summary>
/// Initializes a new instance of the <see cref="GetCustomersUsageSummary"/> class.
/// </summary>
/// <param name="context">The scenario context.</param>
public GetCustomersUsageSummary(IScenarioContext context) : base("Get all customers usage summaries", context)
{
}
/// <summary>
/// Executes the scenario.
/// </summary>
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");
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="GetSubscriptionResourceUsage.cs" company="Microsoft">
// <copyright file="GetSubscriptionUsageByMeter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
@ -7,15 +7,15 @@
namespace Microsoft.Store.PartnerCenter.Samples.RatedUsage
{
/// <summary>
/// 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.
/// </summary>
public class GetSubscriptionResourceUsage : BasePartnerScenario
public class GetSubscriptionUsageByMeter : BasePartnerScenario
{
/// <summary>
/// Initializes a new instance of the <see cref="GetSubscriptionResourceUsage"/> class.
/// Initializes a new instance of the <see cref="GetSubscriptionUsageByMeter"/> class.
/// </summary>
/// <param name="context">The scenario context.</param>
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");
}
}
}

Просмотреть файл

@ -0,0 +1,40 @@
// -----------------------------------------------------------------------
// <copyright file="GetSubscriptionUsageByResource.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
namespace Microsoft.Store.PartnerCenter.Samples.RatedUsage
{
/// <summary>
/// A scenario that retrieves a single subscription's resource usage records aggregated by resource.
/// </summary>
public class GetSubscriptionUsageByResource : BasePartnerScenario
{
/// <summary>
/// Initializes a new instance of the <see cref="GetSubscriptionUsageByResource"/> class.
/// </summary>
/// <param name="context">The scenario context.</param>
public GetSubscriptionUsageByResource(IScenarioContext context) : base("Get subscription resource usage by resource", context)
{
}
/// <summary>
/// Executes the scenario.
/// </summary>
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");
}
}
}

Просмотреть файл

@ -45,14 +45,14 @@
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.5.2.0\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Store.PartnerCenter, Version=1.13.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Store.PartnerCenter.1.13.1\lib\Net45\Microsoft.Store.PartnerCenter.dll</HintPath>
<Reference Include="Microsoft.Store.PartnerCenter">
<HintPath>..\packages\Microsoft.Store.PartnerCenter.1.15.0\lib\Net45\Microsoft.Store.PartnerCenter.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Store.PartnerCenter.Extensions, Version=1.13.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Store.PartnerCenter.1.13.1\lib\Net45\Microsoft.Store.PartnerCenter.Extensions.dll</HintPath>
<Reference Include="Microsoft.Store.PartnerCenter.Extensions">
<HintPath>..\packages\Microsoft.Store.PartnerCenter.1.15.0\lib\Net45\Microsoft.Store.PartnerCenter.Extensions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Store.PartnerCenter.Models, Version=1.13.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Store.PartnerCenter.1.13.1\lib\Net45\Microsoft.Store.PartnerCenter.Models.dll</HintPath>
<Reference Include="Microsoft.Store.PartnerCenter.Models">
<HintPath>..\packages\Microsoft.Store.PartnerCenter.1.15.0\lib\Net45\Microsoft.Store.PartnerCenter.Models.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
@ -226,8 +226,10 @@
<Compile Include="RateCards\GetAzureRateCard.cs" />
<Compile Include="RateCards\GetAzureSharedRateCard.cs" />
<Compile Include="RatedUsage\GetCustomerSubscriptionsUsage.cs" />
<Compile Include="RatedUsage\GetSubscriptionResourceUsage.cs" />
<Compile Include="RatedUsage\GetCustomersUsageSummary.cs" />
<Compile Include="RatedUsage\GetSubscriptionUsageByMeter.cs" />
<Compile Include="RatedUsage\GetCustomerUsageSummary.cs" />
<Compile Include="RatedUsage\GetSubscriptionUsageByResource.cs" />
<Compile Include="ScenarioExecution\PromptExecutionStrategy.cs" />
<Compile Include="ScenarioExecution\AggregateScenarioExecutionStrategy.cs" />
<Compile Include="ScenarioExecution\IScenarioExecutionStrategy.cs" />