From e7d40f58399dd265cddd895c2bd630f2f002140d Mon Sep 17 00:00:00 2001 From: Ali Khudhair Date: Fri, 31 Aug 2018 08:13:52 -0700 Subject: [PATCH] migrating the repo --- .gitattributes | 0 Partner Center SDK Samples.sln | 27 + .../AggregatePartnerScenario.cs | 44 ++ .../Agreements/CreateCustomerAgreement.cs | 75 +++ .../Agreements/GetAgreementDetails.cs | 39 ++ .../Agreements/GetCustomerAgreements.cs | 51 ++ .../GetCustomerLicensesDeploymentAnalytics.cs | 38 ++ .../GetCustomerLicensesUsageAnalytics.cs | 38 ++ .../GetPartnerLicensesDeploymentAnalytics.cs | 36 ++ .../GetPartnerLicensesUsageAnalytics.cs | 36 ++ Source/Partner Center SDK Samples/App.config | 134 ++++ .../Auditing/QueryAuditRecords.cs | 65 ++ .../Auditing/SearchAuditRecords.cs | 78 +++ .../SearchAuditRecordsByCustomerId.cs | 78 +++ .../SearchAuditRecordsByResourceType.cs | 121 ++++ .../BasePartnerScenario.cs | 519 ++++++++++++++++ .../Carts/CheckoutCart.cs | 41 ++ .../Carts/CreateCart.cs | 78 +++ .../Carts/UpdateCart.cs | 48 ++ .../ApplicationAuthenticationSection.cs | 55 ++ .../Configuration/ConfigurationManager.cs | 103 +++ .../PartnerServiceSettingsSection.cs | 67 ++ .../Configuration/ScenarioSettingsSection.cs | 403 ++++++++++++ .../Configuration/Section.cs | 43 ++ .../UserAuthenticationSection.cs | 79 +++ .../Context/ScenarioContext.cs | 153 +++++ .../AddUserMemberToDirectoryRole.cs | 61 ++ .../GetCustomerDirectoryRoleUserMembers.cs | 43 ++ .../GetCustomerDirectoryRoles.cs | 40 ++ ...moveCustomerUserMemberFromDirectoryRole.cs | 47 ++ .../GetCustomerAvailabilities.cs | 41 ++ ...etCustomerAvailabilitiesByTargetSegment.cs | 42 ++ .../GetCustomerAvailability.cs | 42 ++ .../CustomerProducts/GetCustomerProduct.cs | 40 ++ .../CustomerProducts/GetCustomerProducts.cs | 40 ++ .../GetCustomerProductsByTargetSegment.cs | 41 ++ .../CustomerProducts/GetCustomerSku.cs | 41 ++ .../GetCustomerSkuDownloadOptions.cs | 41 ++ .../CustomerProducts/GetCustomerSkus.cs | 40 ++ .../GetCustomerSkusByTargetSegment.cs | 41 ++ .../GetCustomerServiceCostsLineItems.cs | 42 ++ .../GetCustomerServiceCostsSummary.cs | 42 ++ .../GetCustomerSubscribedSkus.cs | 44 ++ .../CustomerUser/CreateCustomerUser.cs | 61 ++ .../CustomerUserAssignGroup1Licenses.cs | 82 +++ .../CustomerUserAssignGroup2Licenses.cs | 104 ++++ .../CustomerUserAssignLicenses.cs | 72 +++ ...omerUserAssignedGroup1AndGroup2Licenses.cs | 48 ++ .../CustomerUserAssignedGroup1Licenses.cs | 47 ++ .../CustomerUserAssignedGroup2Licenses.cs | 47 ++ .../CustomerUserAssignedLicenses.cs | 43 ++ .../CustomerUser/CustomerUserRestore.cs | 50 ++ .../CustomerUser/DeleteCustomerUser.cs | 43 ++ .../CustomerUser/GetCustomerInactiveUsers.cs | 75 +++ .../CustomerUser/GetCustomerUserCollection.cs | 40 ++ .../CustomerUser/GetCustomerUserDetails.cs | 42 ++ .../GetCustomerUserDirectoryRoles.cs | 50 ++ .../CustomerUser/GetPagedCustomerUsers.cs | 75 +++ .../CustomerUser/SortCustomerUsers.cs | 58 ++ .../CustomerUser/UpdateCustomerUser.cs | 69 +++ .../Customers/CheckDomainAvailability.cs | 44 ++ .../Customers/CreateCustomer.cs | 70 +++ .../Customers/DeleteCustomerFromTipAccount.cs | 50 ++ .../DeletePartnerCustomerRelationship.cs | 70 +++ .../Customers/FilterCustomers.cs | 56 ++ .../Customers/GetCustomerDetails.cs | 38 ++ .../Customers/GetCustomerManagedServices.cs | 38 ++ .../Customers/GetCustomerQualification.cs | 38 ++ .../GetCustomerRelationshipRequest.cs | 36 ++ .../Customers/GetPagedCustomers.cs | 68 ++ .../Customers/UpdateCustomerBillingProfile.cs | 51 ++ .../Customers/UpdateCustomerQualification.cs | 42 ++ .../Customers/ValidateCustomerAddress.cs | 36 ++ .../CreateConfigurationPolicy.cs | 50 ++ .../DevicesDeployment/CreateDeviceBatch.cs | 60 ++ .../DevicesDeployment/CreateDevices.cs | 63 ++ .../DeleteConfigurationPolicy.cs | 42 ++ .../DevicesDeployment/DeleteDevice.cs | 44 ++ .../GetAllConfigurationPolicies.cs | 39 ++ .../DevicesDeployment/GetBatchUploadStatus.cs | 41 ++ .../DevicesDeployment/GetDevices.cs | 41 ++ .../DevicesDeployment/GetDevicesBatches.cs | 39 ++ .../UpdateConfigurationPolicy.cs | 51 ++ .../DevicesDeployment/UpdateDevicesPolicy.cs | 66 ++ .../Entitlements/GetEntitlements.cs | 70 +++ .../Helpers/ConsoleHelper.cs | 311 ++++++++++ .../IPartnerScenario.cs | 36 ++ .../IScenarioContext.cs | 38 ++ .../CreateCustomerForIndirectReseller.cs | 77 +++ .../GetCustomersOfIndirectReseller.cs | 76 +++ .../IndirectModel/GetIndirectResellers.cs | 38 ++ .../GetIndirectResellersOfCustomer.cs | 42 ++ .../IndirectModel/GetSubscriptionsByMpnId.cs | 43 ++ .../IndirectModel/PlaceOrderForCustomer.cs | 71 +++ .../IndirectModel/VerifyPartnerMpnId.cs | 47 ++ .../GetSubscriptionsByMpnId.cs | 44 ++ .../IndirectPartners/VerifyPartnerMpnId.cs | 48 ++ .../Invoice/GetAccountBalance.cs | 37 ++ .../Invoice/GetInvoice.cs | 60 ++ .../Invoice/GetInvoiceLineItems.cs | 95 +++ .../Invoice/GetInvoiceStatement.cs | 51 ++ .../Invoice/GetInvoiceSummaries.cs | 49 ++ .../Invoice/GetPagedInvoices.cs | 70 +++ .../Offers/GetCustomerOfferCategories.cs | 37 ++ .../Offers/GetCustomerOffers.cs | 38 ++ .../Offers/GetOffer.cs | 44 ++ .../Offers/GetOfferCategories.cs | 39 ++ .../Offers/GetOffers.cs | 40 ++ .../Offers/GetPagedOffers.cs | 71 +++ .../Orders/CreateAzureReservationOrder.cs | 89 +++ .../Orders/CreateOrder.cs | 58 ++ .../Orders/GetOrderDetails.cs | 40 ++ .../Orders/GetOrderProvisioningStatus.cs | 50 ++ .../Orders/GetOrders.cs | 39 ++ .../Orders/GetOrdersByBillingCycleType.cs | 45 ++ .../Orders/UpdateOrder.cs | 47 ++ .../Partner Center SDK Samples.csproj | 261 ++++++++ .../Products/CheckInventory.cs | 54 ++ .../Products/GetAvailabilities.cs | 41 ++ .../GetAvailabilitiesByTargetSegment.cs | 42 ++ .../Products/GetAvailability.cs | 42 ++ .../Products/GetProduct.cs | 40 ++ .../Products/GetProducts.cs | 40 ++ .../Products/GetProductsByTargetSegment.cs | 41 ++ .../Products/GetSku.cs | 41 ++ .../Products/GetSkuDownloadOptions.cs | 41 ++ .../Products/GetSkus.cs | 40 ++ .../Products/GetSkusByTargetSegment.cs | 41 ++ .../Profile/GetBillingProfile.cs | 37 ++ .../Profile/GetMPNProfile.cs | 37 ++ .../Profile/GetOrganizationProfile.cs | 37 ++ .../Profile/GetSupportProfile.cs | 37 ++ .../Profile/GetlegalBusinessProfile.cs | 37 ++ .../Profile/UpdateBillingProfile.cs | 48 ++ .../Profile/UpdateLegalBusinessProfile.cs | 49 ++ .../Profile/UpdateOrganizationProfile.cs | 49 ++ .../Profile/UpdateSupportProfile.cs | 55 ++ Source/Partner Center SDK Samples/Program.cs | 586 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 41 ++ .../RateCards/GetAzureRateCard.cs | 36 ++ .../RateCards/GetAzureSharedRateCard.cs | 36 ++ .../GetCustomerSubscriptionsUsage.cs | 38 ++ .../RatedUsage/GetCustomerUsageSummary.cs | 38 ++ .../GetSubscriptionResourceUsage.cs | 40 ++ .../RatedUsage/GetSubscriptionUsageRecords.cs | 39 ++ .../RatedUsage/GetSubscriptionUsageSummary.cs | 40 ++ .../AggregateScenarioExecutionStrategy.cs | 99 +++ .../IScenarioExecutionStrategy.cs | 21 + .../PromptExecutionStrategy.cs | 36 ++ .../ServiceIncidents/GetServiceIncidents.cs | 41 ++ .../CreatePartnerServiceRequest.cs | 68 ++ .../GetCustomerServiceRequests.cs | 63 ++ .../GetPagedPartnerServiceRequests.cs | 66 ++ .../GetPartnerServiceRequestDetails.cs | 50 ++ .../GetServiceRequestSupportTopics.cs | 41 ++ .../UpdatePartnerServiceRequest.cs | 63 ++ .../Settings.StyleCop | 15 + .../Subscriptions/AddSubscriptionAddOn.cs | 75 +++ .../Subscriptions/ConvertTrialSubscription.cs | 54 ++ .../Subscriptions/GetSubscription.cs | 40 ++ .../GetSubscriptionProvisioningStatus.cs | 40 ++ .../GetSubscriptionSupportContact.cs | 40 ++ .../Subscriptions/GetSubscriptions.cs | 39 ++ .../Subscriptions/GetSubscriptionsByOrder.cs | 40 ++ .../Subscriptions/UpdateSubscription.cs | 44 ++ .../UpdateSubscriptionSupportContact.cs | 43 ++ .../Subscriptions/UpgradeSubscription.cs | 70 +++ .../GetAzureSubscriptionUtilization.cs | 69 +++ .../Validations/AddressValidation.cs | 72 +++ .../Validations/ValidateAddress.cs | 72 +++ .../packages.config | 7 + nuget.config | 7 + 172 files changed, 10575 insertions(+) create mode 100644 .gitattributes create mode 100644 Partner Center SDK Samples.sln create mode 100644 Source/Partner Center SDK Samples/AggregatePartnerScenario.cs create mode 100644 Source/Partner Center SDK Samples/Agreements/CreateCustomerAgreement.cs create mode 100644 Source/Partner Center SDK Samples/Agreements/GetAgreementDetails.cs create mode 100644 Source/Partner Center SDK Samples/Agreements/GetCustomerAgreements.cs create mode 100644 Source/Partner Center SDK Samples/Analytics/GetCustomerLicensesDeploymentAnalytics.cs create mode 100644 Source/Partner Center SDK Samples/Analytics/GetCustomerLicensesUsageAnalytics.cs create mode 100644 Source/Partner Center SDK Samples/Analytics/GetPartnerLicensesDeploymentAnalytics.cs create mode 100644 Source/Partner Center SDK Samples/Analytics/GetPartnerLicensesUsageAnalytics.cs create mode 100644 Source/Partner Center SDK Samples/App.config create mode 100644 Source/Partner Center SDK Samples/Auditing/QueryAuditRecords.cs create mode 100644 Source/Partner Center SDK Samples/Auditing/SearchAuditRecords.cs create mode 100644 Source/Partner Center SDK Samples/Auditing/SearchAuditRecordsByCustomerId.cs create mode 100644 Source/Partner Center SDK Samples/Auditing/SearchAuditRecordsByResourceType.cs create mode 100644 Source/Partner Center SDK Samples/BasePartnerScenario.cs create mode 100644 Source/Partner Center SDK Samples/Carts/CheckoutCart.cs create mode 100644 Source/Partner Center SDK Samples/Carts/CreateCart.cs create mode 100644 Source/Partner Center SDK Samples/Carts/UpdateCart.cs create mode 100644 Source/Partner Center SDK Samples/Configuration/ApplicationAuthenticationSection.cs create mode 100644 Source/Partner Center SDK Samples/Configuration/ConfigurationManager.cs create mode 100644 Source/Partner Center SDK Samples/Configuration/PartnerServiceSettingsSection.cs create mode 100644 Source/Partner Center SDK Samples/Configuration/ScenarioSettingsSection.cs create mode 100644 Source/Partner Center SDK Samples/Configuration/Section.cs create mode 100644 Source/Partner Center SDK Samples/Configuration/UserAuthenticationSection.cs create mode 100644 Source/Partner Center SDK Samples/Context/ScenarioContext.cs create mode 100644 Source/Partner Center SDK Samples/CustomerDirectoryRoles/AddUserMemberToDirectoryRole.cs create mode 100644 Source/Partner Center SDK Samples/CustomerDirectoryRoles/GetCustomerDirectoryRoleUserMembers.cs create mode 100644 Source/Partner Center SDK Samples/CustomerDirectoryRoles/GetCustomerDirectoryRoles.cs create mode 100644 Source/Partner Center SDK Samples/CustomerDirectoryRoles/RemoveCustomerUserMemberFromDirectoryRole.cs create mode 100644 Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailabilities.cs create mode 100644 Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailabilitiesByTargetSegment.cs create mode 100644 Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailability.cs create mode 100644 Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProduct.cs create mode 100644 Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProducts.cs create mode 100644 Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProductsByTargetSegment.cs create mode 100644 Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSku.cs create mode 100644 Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkuDownloadOptions.cs create mode 100644 Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkus.cs create mode 100644 Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkusByTargetSegment.cs create mode 100644 Source/Partner Center SDK Samples/CustomerServiceCosts/GetCustomerServiceCostsLineItems.cs create mode 100644 Source/Partner Center SDK Samples/CustomerServiceCosts/GetCustomerServiceCostsSummary.cs create mode 100644 Source/Partner Center SDK Samples/CustomerSubscribedSkus/GetCustomerSubscribedSkus.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/CreateCustomerUser.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignGroup1Licenses.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignGroup2Licenses.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignLicenses.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup1AndGroup2Licenses.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup1Licenses.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup2Licenses.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedLicenses.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/CustomerUserRestore.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/DeleteCustomerUser.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/GetCustomerInactiveUsers.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserCollection.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserDetails.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserDirectoryRoles.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/GetPagedCustomerUsers.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/SortCustomerUsers.cs create mode 100644 Source/Partner Center SDK Samples/CustomerUser/UpdateCustomerUser.cs create mode 100644 Source/Partner Center SDK Samples/Customers/CheckDomainAvailability.cs create mode 100644 Source/Partner Center SDK Samples/Customers/CreateCustomer.cs create mode 100644 Source/Partner Center SDK Samples/Customers/DeleteCustomerFromTipAccount.cs create mode 100644 Source/Partner Center SDK Samples/Customers/DeletePartnerCustomerRelationship.cs create mode 100644 Source/Partner Center SDK Samples/Customers/FilterCustomers.cs create mode 100644 Source/Partner Center SDK Samples/Customers/GetCustomerDetails.cs create mode 100644 Source/Partner Center SDK Samples/Customers/GetCustomerManagedServices.cs create mode 100644 Source/Partner Center SDK Samples/Customers/GetCustomerQualification.cs create mode 100644 Source/Partner Center SDK Samples/Customers/GetCustomerRelationshipRequest.cs create mode 100644 Source/Partner Center SDK Samples/Customers/GetPagedCustomers.cs create mode 100644 Source/Partner Center SDK Samples/Customers/UpdateCustomerBillingProfile.cs create mode 100644 Source/Partner Center SDK Samples/Customers/UpdateCustomerQualification.cs create mode 100644 Source/Partner Center SDK Samples/Customers/ValidateCustomerAddress.cs create mode 100644 Source/Partner Center SDK Samples/DevicesDeployment/CreateConfigurationPolicy.cs create mode 100644 Source/Partner Center SDK Samples/DevicesDeployment/CreateDeviceBatch.cs create mode 100644 Source/Partner Center SDK Samples/DevicesDeployment/CreateDevices.cs create mode 100644 Source/Partner Center SDK Samples/DevicesDeployment/DeleteConfigurationPolicy.cs create mode 100644 Source/Partner Center SDK Samples/DevicesDeployment/DeleteDevice.cs create mode 100644 Source/Partner Center SDK Samples/DevicesDeployment/GetAllConfigurationPolicies.cs create mode 100644 Source/Partner Center SDK Samples/DevicesDeployment/GetBatchUploadStatus.cs create mode 100644 Source/Partner Center SDK Samples/DevicesDeployment/GetDevices.cs create mode 100644 Source/Partner Center SDK Samples/DevicesDeployment/GetDevicesBatches.cs create mode 100644 Source/Partner Center SDK Samples/DevicesDeployment/UpdateConfigurationPolicy.cs create mode 100644 Source/Partner Center SDK Samples/DevicesDeployment/UpdateDevicesPolicy.cs create mode 100644 Source/Partner Center SDK Samples/Entitlements/GetEntitlements.cs create mode 100644 Source/Partner Center SDK Samples/Helpers/ConsoleHelper.cs create mode 100644 Source/Partner Center SDK Samples/IPartnerScenario.cs create mode 100644 Source/Partner Center SDK Samples/IScenarioContext.cs create mode 100644 Source/Partner Center SDK Samples/IndirectModel/CreateCustomerForIndirectReseller.cs create mode 100644 Source/Partner Center SDK Samples/IndirectModel/GetCustomersOfIndirectReseller.cs create mode 100644 Source/Partner Center SDK Samples/IndirectModel/GetIndirectResellers.cs create mode 100644 Source/Partner Center SDK Samples/IndirectModel/GetIndirectResellersOfCustomer.cs create mode 100644 Source/Partner Center SDK Samples/IndirectModel/GetSubscriptionsByMpnId.cs create mode 100644 Source/Partner Center SDK Samples/IndirectModel/PlaceOrderForCustomer.cs create mode 100644 Source/Partner Center SDK Samples/IndirectModel/VerifyPartnerMpnId.cs create mode 100644 Source/Partner Center SDK Samples/IndirectPartners/GetSubscriptionsByMpnId.cs create mode 100644 Source/Partner Center SDK Samples/IndirectPartners/VerifyPartnerMpnId.cs create mode 100644 Source/Partner Center SDK Samples/Invoice/GetAccountBalance.cs create mode 100644 Source/Partner Center SDK Samples/Invoice/GetInvoice.cs create mode 100644 Source/Partner Center SDK Samples/Invoice/GetInvoiceLineItems.cs create mode 100644 Source/Partner Center SDK Samples/Invoice/GetInvoiceStatement.cs create mode 100644 Source/Partner Center SDK Samples/Invoice/GetInvoiceSummaries.cs create mode 100644 Source/Partner Center SDK Samples/Invoice/GetPagedInvoices.cs create mode 100644 Source/Partner Center SDK Samples/Offers/GetCustomerOfferCategories.cs create mode 100644 Source/Partner Center SDK Samples/Offers/GetCustomerOffers.cs create mode 100644 Source/Partner Center SDK Samples/Offers/GetOffer.cs create mode 100644 Source/Partner Center SDK Samples/Offers/GetOfferCategories.cs create mode 100644 Source/Partner Center SDK Samples/Offers/GetOffers.cs create mode 100644 Source/Partner Center SDK Samples/Offers/GetPagedOffers.cs create mode 100644 Source/Partner Center SDK Samples/Orders/CreateAzureReservationOrder.cs create mode 100644 Source/Partner Center SDK Samples/Orders/CreateOrder.cs create mode 100644 Source/Partner Center SDK Samples/Orders/GetOrderDetails.cs create mode 100644 Source/Partner Center SDK Samples/Orders/GetOrderProvisioningStatus.cs create mode 100644 Source/Partner Center SDK Samples/Orders/GetOrders.cs create mode 100644 Source/Partner Center SDK Samples/Orders/GetOrdersByBillingCycleType.cs create mode 100644 Source/Partner Center SDK Samples/Orders/UpdateOrder.cs create mode 100644 Source/Partner Center SDK Samples/Partner Center SDK Samples.csproj create mode 100644 Source/Partner Center SDK Samples/Products/CheckInventory.cs create mode 100644 Source/Partner Center SDK Samples/Products/GetAvailabilities.cs create mode 100644 Source/Partner Center SDK Samples/Products/GetAvailabilitiesByTargetSegment.cs create mode 100644 Source/Partner Center SDK Samples/Products/GetAvailability.cs create mode 100644 Source/Partner Center SDK Samples/Products/GetProduct.cs create mode 100644 Source/Partner Center SDK Samples/Products/GetProducts.cs create mode 100644 Source/Partner Center SDK Samples/Products/GetProductsByTargetSegment.cs create mode 100644 Source/Partner Center SDK Samples/Products/GetSku.cs create mode 100644 Source/Partner Center SDK Samples/Products/GetSkuDownloadOptions.cs create mode 100644 Source/Partner Center SDK Samples/Products/GetSkus.cs create mode 100644 Source/Partner Center SDK Samples/Products/GetSkusByTargetSegment.cs create mode 100644 Source/Partner Center SDK Samples/Profile/GetBillingProfile.cs create mode 100644 Source/Partner Center SDK Samples/Profile/GetMPNProfile.cs create mode 100644 Source/Partner Center SDK Samples/Profile/GetOrganizationProfile.cs create mode 100644 Source/Partner Center SDK Samples/Profile/GetSupportProfile.cs create mode 100644 Source/Partner Center SDK Samples/Profile/GetlegalBusinessProfile.cs create mode 100644 Source/Partner Center SDK Samples/Profile/UpdateBillingProfile.cs create mode 100644 Source/Partner Center SDK Samples/Profile/UpdateLegalBusinessProfile.cs create mode 100644 Source/Partner Center SDK Samples/Profile/UpdateOrganizationProfile.cs create mode 100644 Source/Partner Center SDK Samples/Profile/UpdateSupportProfile.cs create mode 100644 Source/Partner Center SDK Samples/Program.cs create mode 100644 Source/Partner Center SDK Samples/Properties/AssemblyInfo.cs create mode 100644 Source/Partner Center SDK Samples/RateCards/GetAzureRateCard.cs create mode 100644 Source/Partner Center SDK Samples/RateCards/GetAzureSharedRateCard.cs create mode 100644 Source/Partner Center SDK Samples/RatedUsage/GetCustomerSubscriptionsUsage.cs create mode 100644 Source/Partner Center SDK Samples/RatedUsage/GetCustomerUsageSummary.cs create mode 100644 Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionResourceUsage.cs create mode 100644 Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionUsageRecords.cs create mode 100644 Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionUsageSummary.cs create mode 100644 Source/Partner Center SDK Samples/ScenarioExecution/AggregateScenarioExecutionStrategy.cs create mode 100644 Source/Partner Center SDK Samples/ScenarioExecution/IScenarioExecutionStrategy.cs create mode 100644 Source/Partner Center SDK Samples/ScenarioExecution/PromptExecutionStrategy.cs create mode 100644 Source/Partner Center SDK Samples/ServiceIncidents/GetServiceIncidents.cs create mode 100644 Source/Partner Center SDK Samples/ServiceRequests/CreatePartnerServiceRequest.cs create mode 100644 Source/Partner Center SDK Samples/ServiceRequests/GetCustomerServiceRequests.cs create mode 100644 Source/Partner Center SDK Samples/ServiceRequests/GetPagedPartnerServiceRequests.cs create mode 100644 Source/Partner Center SDK Samples/ServiceRequests/GetPartnerServiceRequestDetails.cs create mode 100644 Source/Partner Center SDK Samples/ServiceRequests/GetServiceRequestSupportTopics.cs create mode 100644 Source/Partner Center SDK Samples/ServiceRequests/UpdatePartnerServiceRequest.cs create mode 100644 Source/Partner Center SDK Samples/Settings.StyleCop create mode 100644 Source/Partner Center SDK Samples/Subscriptions/AddSubscriptionAddOn.cs create mode 100644 Source/Partner Center SDK Samples/Subscriptions/ConvertTrialSubscription.cs create mode 100644 Source/Partner Center SDK Samples/Subscriptions/GetSubscription.cs create mode 100644 Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionProvisioningStatus.cs create mode 100644 Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionSupportContact.cs create mode 100644 Source/Partner Center SDK Samples/Subscriptions/GetSubscriptions.cs create mode 100644 Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionsByOrder.cs create mode 100644 Source/Partner Center SDK Samples/Subscriptions/UpdateSubscription.cs create mode 100644 Source/Partner Center SDK Samples/Subscriptions/UpdateSubscriptionSupportContact.cs create mode 100644 Source/Partner Center SDK Samples/Subscriptions/UpgradeSubscription.cs create mode 100644 Source/Partner Center SDK Samples/Utilization/GetAzureSubscriptionUtilization.cs create mode 100644 Source/Partner Center SDK Samples/Validations/AddressValidation.cs create mode 100644 Source/Partner Center SDK Samples/Validations/ValidateAddress.cs create mode 100644 Source/Partner Center SDK Samples/packages.config create mode 100644 nuget.config diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e69de29 diff --git a/Partner Center SDK Samples.sln b/Partner Center SDK Samples.sln new file mode 100644 index 0000000..af8a941 --- /dev/null +++ b/Partner Center SDK Samples.sln @@ -0,0 +1,27 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Partner Center SDK Samples", "Source\Partner Center SDK Samples\Partner Center SDK Samples.csproj", "{AC93E5CC-549C-4F13-9675-A86860918C2B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9445B986-021F-44FE-BA08-92C43301F8AF}" + ProjectSection(SolutionItems) = preProject + nuget.config = nuget.config + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AC93E5CC-549C-4F13-9675-A86860918C2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC93E5CC-549C-4F13-9675-A86860918C2B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC93E5CC-549C-4F13-9675-A86860918C2B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC93E5CC-549C-4F13-9675-A86860918C2B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Source/Partner Center SDK Samples/AggregatePartnerScenario.cs b/Source/Partner Center SDK Samples/AggregatePartnerScenario.cs new file mode 100644 index 0000000..b20f970 --- /dev/null +++ b/Source/Partner Center SDK Samples/AggregatePartnerScenario.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using ScenarioExecution; + + /// + /// A scenarios that is composed of one or more sub-scenarios. + /// + public class AggregatePartnerScenario : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario title. + /// A list of child scenarios. + /// The scenario context. + public AggregatePartnerScenario( + string title, + IEnumerable childScenarios, + IScenarioContext context) : base(title, context, new AggregateScenarioExecutionStrategy(), new List(childScenarios)) + { + } + + /// + /// Runs the aggregate scenario. + /// + protected override void RunScenario() + { + // display the child scenarios + for (int i = 0; i < this.Children.Count; ++i) + { + Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}: {1}", i + 1, this.Children[i].Title)); + } + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Agreements/CreateCustomerAgreement.cs b/Source/Partner Center SDK Samples/Agreements/CreateCustomerAgreement.cs new file mode 100644 index 0000000..bea67b3 --- /dev/null +++ b/Source/Partner Center SDK Samples/Agreements/CreateCustomerAgreement.cs @@ -0,0 +1,75 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Agreements +{ + using System; + using System.Collections.Generic; + using Models.Agreements; + + /// + /// Showcases creation of a customer agreement. + /// + public class CreateCustomerAgreement : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CreateCustomerAgreement(IScenarioContext context) : base("Create a new customer agreement", context) + { + } + + /// + /// executes the create customer agreement scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to create the agreement for"); + string selectedUserId = + this.ObtainUserMemberId("Enter the user ID of the partner to create customer's agreement"); + + string agreementTemplateId = this.Context.Configuration.Scenario.DefaultAgreementTemplateId; + + // Currently, the only supported value is “998b88de-aa99-4388-a42c-1b3517d49490”, which is the unique identifier for the Microsoft Cloud Agreement. + if (string.IsNullOrWhiteSpace(agreementTemplateId)) + { + // The value was not set in the configuration, prompt the user the enter value + agreementTemplateId = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the agreement template ID", "The agreement template ID can't be empty"); + } + else + { + Console.WriteLine("Found {0}: {1} in configuration.", "Agreement template Id", agreementTemplateId); + } + + var partnerOperations = this.Context.UserPartnerOperations; + + var agreement = new Agreement + { + UserId = selectedUserId, + DateAgreed = DateTime.UtcNow, + Type = AgreementType.MicrosoftCloudAgreement, + TemplateId = agreementTemplateId, + PrimaryContact = new Contact + { + FirstName = "First", + LastName = "Last", + Email = "first.last@outlook.com", + PhoneNumber = "4123456789" + } + }; + + this.Context.ConsoleHelper.WriteObject(agreement, "New Agreement"); + this.Context.ConsoleHelper.StartProgress("Creating Agreement"); + + var newlyCreatedagreement = partnerOperations.Customers.ById(selectedCustomerId).Agreements.Create(agreement); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.Success("Create new agreement successfully!"); + this.Context.ConsoleHelper.WriteObject(newlyCreatedagreement, "Newly created agreement Information"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Agreements/GetAgreementDetails.cs b/Source/Partner Center SDK Samples/Agreements/GetAgreementDetails.cs new file mode 100644 index 0000000..31911c1 --- /dev/null +++ b/Source/Partner Center SDK Samples/Agreements/GetAgreementDetails.cs @@ -0,0 +1,39 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Agreements +{ + using Models; + using Models.Agreements; + + /// + /// Showcases getting the list of agreement details. + /// + public class GetAgreementDetails : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetAgreementDetails(IScenarioContext context) : base("Get agreement details.", context) + { + } + + /// + /// Executes the get agreement details scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Retrieving agreement details"); + + ResourceCollection agreementDetails = partnerOperations.AgreementDetails.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(agreementDetails, "Agreement details:"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Agreements/GetCustomerAgreements.cs b/Source/Partner Center SDK Samples/Agreements/GetCustomerAgreements.cs new file mode 100644 index 0000000..18dcc66 --- /dev/null +++ b/Source/Partner Center SDK Samples/Agreements/GetCustomerAgreements.cs @@ -0,0 +1,51 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Agreements +{ + using System; + using System.Linq; + using Models; + using Models.Agreements; + + /// + /// Showcases the retrieval of customer agreements. + /// + public class GetCustomerAgreements : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerAgreements(IScenarioContext context) : base("Get all customer agreements.", context) + { + } + + /// + /// Executes the get customer agreements scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to create the agreement for"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer's agreements"); + + ResourceCollection customerAgreements = partnerOperations.Customers.ById(selectedCustomerId) + .Agreements.Get(); + + this.Context.ConsoleHelper.StopProgress(); + + if (!customerAgreements.Items.Any()) + { + Console.WriteLine("No Service requests found for the given customer."); + } + else + { + this.Context.ConsoleHelper.WriteObject(customerAgreements, "Customer agreements:"); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Analytics/GetCustomerLicensesDeploymentAnalytics.cs b/Source/Partner Center SDK Samples/Analytics/GetCustomerLicensesDeploymentAnalytics.cs new file mode 100644 index 0000000..8b452d0 --- /dev/null +++ b/Source/Partner Center SDK Samples/Analytics/GetCustomerLicensesDeploymentAnalytics.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Analytics +{ + /// + /// Gets a single customer's licenses deployment analytics. + /// + public class GetCustomerLicensesDeploymentAnalytics : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerLicensesDeploymentAnalytics(IScenarioContext context) : base("Get customer licenses deployment analytics", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + string customerIdToRetrieve = this.ObtainCustomerId("Enter the ID of the customer to retrieve"); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Retrieving customer licenses deployment analytics"); + + var customerLicensesDeploymentAnalytics = partnerOperations.Customers.ById(customerIdToRetrieve).Analytics.Licenses.Deployment.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerLicensesDeploymentAnalytics, "Customer licenses deployment analytics"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Analytics/GetCustomerLicensesUsageAnalytics.cs b/Source/Partner Center SDK Samples/Analytics/GetCustomerLicensesUsageAnalytics.cs new file mode 100644 index 0000000..d5cf34a --- /dev/null +++ b/Source/Partner Center SDK Samples/Analytics/GetCustomerLicensesUsageAnalytics.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Analytics +{ + /// + /// Gets a single customer's licenses usage analytics. + /// + public class GetCustomerLicensesUsageAnalytics : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerLicensesUsageAnalytics(IScenarioContext context) : base("Get customer licenses usage analytics", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + string customerIdToRetrieve = this.ObtainCustomerId("Enter the ID of the customer to retrieve"); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Retrieving customer licenses usage analytics"); + + var customerLicensesDeploymentAnalytics = partnerOperations.Customers.ById(customerIdToRetrieve).Analytics.Licenses.Usage.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerLicensesDeploymentAnalytics, "Customer licenses usage analytics"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Analytics/GetPartnerLicensesDeploymentAnalytics.cs b/Source/Partner Center SDK Samples/Analytics/GetPartnerLicensesDeploymentAnalytics.cs new file mode 100644 index 0000000..8e585d9 --- /dev/null +++ b/Source/Partner Center SDK Samples/Analytics/GetPartnerLicensesDeploymentAnalytics.cs @@ -0,0 +1,36 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Analytics +{ + /// + /// Gets partner's licenses deployment analytics. + /// + public class GetPartnerLicensesDeploymentAnalytics : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetPartnerLicensesDeploymentAnalytics(IScenarioContext context) : base("Get partner licenses deployment analytics", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Retrieving partner licenses deployment analytics"); + + var partnerLicensesDeploymentAnalytics = partnerOperations.Analytics.Licenses.Deployment.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(partnerLicensesDeploymentAnalytics, "Partner licenses deployment analytics"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Analytics/GetPartnerLicensesUsageAnalytics.cs b/Source/Partner Center SDK Samples/Analytics/GetPartnerLicensesUsageAnalytics.cs new file mode 100644 index 0000000..bfce907 --- /dev/null +++ b/Source/Partner Center SDK Samples/Analytics/GetPartnerLicensesUsageAnalytics.cs @@ -0,0 +1,36 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Analytics +{ + /// + /// Gets partner's licenses usage analytics. + /// + public class GetPartnerLicensesUsageAnalytics : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetPartnerLicensesUsageAnalytics(IScenarioContext context) : base("Get partner licenses usage analytics", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Retrieving partner licenses usage analytics"); + + var partnerLicensesUsageAnalytics = partnerOperations.Analytics.Licenses.Usage.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(partnerLicensesUsageAnalytics, "Partner licenses usage analytics"); + } + } +} diff --git a/Source/Partner Center SDK Samples/App.config b/Source/Partner Center SDK Samples/App.config new file mode 100644 index 0000000..6c5cf29 --- /dev/null +++ b/Source/Partner Center SDK Samples/App.config @@ -0,0 +1,134 @@ + + + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Auditing/QueryAuditRecords.cs b/Source/Partner Center SDK Samples/Auditing/QueryAuditRecords.cs new file mode 100644 index 0000000..e7d2a45 --- /dev/null +++ b/Source/Partner Center SDK Samples/Auditing/QueryAuditRecords.cs @@ -0,0 +1,65 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + using System; + using System.Globalization; + using Models.Query; + + /// + /// A scenario that retrieves a partner's audit records. + /// + public class QueryAuditRecords : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public QueryAuditRecords(IScenarioContext context) : base("Query for the partner's audit records.", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + const int PageSize = 10; + var startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 01); + + this.Context.ConsoleHelper.StartProgress( + string.Format(CultureInfo.InvariantCulture, "Retrieving the partner's audit records - start date: {0} | page size: {1}", startDate, PageSize)); + + var auditRecordsPage = partnerOperations.AuditRecords.Query(startDate.Date, query: QueryFactory.Instance.BuildIndexedQuery(PageSize)); + this.Context.ConsoleHelper.StopProgress(); + + // create a customer enumerator which will aid us in traversing the customer pages + var auditRecordEnumerator = partnerOperations.Enumerators.AuditRecords.Create(auditRecordsPage); + + int pageNumber = 1; + + while (auditRecordEnumerator.HasValue) + { + // print the current audit record results page + this.Context.ConsoleHelper.WriteObject(auditRecordEnumerator.Current, string.Format(CultureInfo.InvariantCulture, "Audit Record Page: {0}", pageNumber++)); + + Console.WriteLine(); + Console.Write("Press any key to retrieve the next set of audit records"); + Console.ReadKey(); + + this.Context.ConsoleHelper.StartProgress("Getting next audit records page"); + + // get the next page of audit records + auditRecordEnumerator.Next(); + + this.Context.ConsoleHelper.StopProgress(); + Console.Clear(); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Auditing/SearchAuditRecords.cs b/Source/Partner Center SDK Samples/Auditing/SearchAuditRecords.cs new file mode 100644 index 0000000..f38877a --- /dev/null +++ b/Source/Partner Center SDK Samples/Auditing/SearchAuditRecords.cs @@ -0,0 +1,78 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + using System; + using System.Globalization; + using Microsoft.Store.PartnerCenter.Models.Auditing; + using Models.Query; + + /// + /// A scenario that retrieves a partner's audit records and filter by customer company name. + /// + public class SearchAuditRecords : BasePartnerScenario + { + /// + /// The search field. + /// + private readonly AuditRecordSearchField auditRecordSearchField; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario title. + /// The search field. + /// The scenario context. + public SearchAuditRecords(string title, AuditRecordSearchField auditRecordSearchField, IScenarioContext context) : base(title, context) + { + this.auditRecordSearchField = auditRecordSearchField; + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string searchPrefix = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the prefix to search for", "The entered prefix is empty"); + var startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 01); + + this.Context.ConsoleHelper.StartProgress( + string.Format(CultureInfo.InvariantCulture, "Retrieving the partner's audit records - start date: {0}", startDate)); + + var filter = new SimpleFieldFilter(AuditRecordSearchField.CompanyName.ToString(), FieldFilterOperation.Substring, searchPrefix); + + var auditRecordsPage = partnerOperations.AuditRecords.Query(startDate.Date, query: QueryFactory.Instance.BuildSimpleQuery(filter)); + + this.Context.ConsoleHelper.StopProgress(); + + // create a customer enumerator which will aid us in traversing the customer pages + var auditRecordEnumerator = partnerOperations.Enumerators.AuditRecords.Create(auditRecordsPage); + + int pageNumber = 1; + + while (auditRecordEnumerator.HasValue) + { + // print the current audit record results page + this.Context.ConsoleHelper.WriteObject(auditRecordEnumerator.Current, string.Format(CultureInfo.InvariantCulture, "Audit Record Page: {0}", pageNumber++)); + + Console.WriteLine(); + Console.Write("Press any key to retrieve the next set of audit records"); + Console.ReadKey(); + + this.Context.ConsoleHelper.StartProgress("Getting next audit records page"); + + // get the next page of audit records + auditRecordEnumerator.Next(); + + this.Context.ConsoleHelper.StopProgress(); + Console.Clear(); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Auditing/SearchAuditRecordsByCustomerId.cs b/Source/Partner Center SDK Samples/Auditing/SearchAuditRecordsByCustomerId.cs new file mode 100644 index 0000000..0efef23 --- /dev/null +++ b/Source/Partner Center SDK Samples/Auditing/SearchAuditRecordsByCustomerId.cs @@ -0,0 +1,78 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + using System; + using System.Globalization; + using Microsoft.Store.PartnerCenter.Models.Auditing; + using Models.Query; + + /// + /// A scenario that retrieves a partner's audit records and filter by customer company name. + /// + public class SearchAuditRecordsByCustomerId : BasePartnerScenario + { + /// + /// The search field. + /// + private readonly AuditRecordSearchField auditRecordSearchField; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario title. + /// The search field. + /// The scenario context. + public SearchAuditRecordsByCustomerId(string title, AuditRecordSearchField auditRecordSearchField, IScenarioContext context) : base(title, context) + { + this.auditRecordSearchField = auditRecordSearchField; + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.Context.ConsoleHelper.ReadNonEmptyString("Enter a Customer Id to search for", "No Customer Id entered"); + var startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 01); + + this.Context.ConsoleHelper.StartProgress( + string.Format(CultureInfo.InvariantCulture, "Retrieving the partner's audit records - start date: {0}", startDate)); + + var filter = new SimpleFieldFilter(AuditRecordSearchField.CustomerId.ToString(), FieldFilterOperation.Equals, customerId); + + var auditRecordsPage = partnerOperations.AuditRecords.Query(startDate.Date, query: QueryFactory.Instance.BuildSimpleQuery(filter)); + + this.Context.ConsoleHelper.StopProgress(); + + // create a customer enumerator which will aid us in traversing the customer pages + var auditRecordEnumerator = partnerOperations.Enumerators.AuditRecords.Create(auditRecordsPage); + + int pageNumber = 1; + + while (auditRecordEnumerator.HasValue) + { + // print the current audit record results page + this.Context.ConsoleHelper.WriteObject(auditRecordEnumerator.Current, string.Format(CultureInfo.InvariantCulture, "Audit Record Page: {0}", pageNumber++)); + + Console.WriteLine(); + Console.Write("Press any key to retrieve the next set of audit records"); + Console.ReadKey(); + + this.Context.ConsoleHelper.StartProgress("Getting next audit records page"); + + // get the next page of audit records + auditRecordEnumerator.Next(); + + this.Context.ConsoleHelper.StopProgress(); + Console.Clear(); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Auditing/SearchAuditRecordsByResourceType.cs b/Source/Partner Center SDK Samples/Auditing/SearchAuditRecordsByResourceType.cs new file mode 100644 index 0000000..fb17b93 --- /dev/null +++ b/Source/Partner Center SDK Samples/Auditing/SearchAuditRecordsByResourceType.cs @@ -0,0 +1,121 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + using System; + using System.Globalization; + using Microsoft.Store.PartnerCenter.Models.Auditing; + using Models.Query; + + /// + /// A scenario that retrieves a partner's audit records and filter by customer company name. + /// + public class SearchAuditRecordsByResourceType : BasePartnerScenario + { + /// + /// The search field. + /// + private readonly AuditRecordSearchField auditRecordSearchField; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario title. + /// The search field. + /// The scenario context. + public SearchAuditRecordsByResourceType(string title, AuditRecordSearchField auditRecordSearchField, IScenarioContext context) : base(title, context) + { + this.auditRecordSearchField = auditRecordSearchField; + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string[] resourceTypes = Enum.GetNames(typeof(ResourceType)); + + int resourceTypesMaxIndex; + + for (resourceTypesMaxIndex = 0; resourceTypesMaxIndex < resourceTypes.Length; resourceTypesMaxIndex++) + { + Console.WriteLine(resourceTypesMaxIndex.ToString() + ": " + resourceTypes[resourceTypesMaxIndex]); + } + + // decrement max index by 1 to account for zero-based start + resourceTypesMaxIndex--; + + Console.WriteLine(); + + while (true) + { + string resourceType = this.Context.ConsoleHelper.ReadNonEmptyString( + "Enter the number corresponding to the Resource Type to search for", + string.Format(CultureInfo.InvariantCulture, "Please enter a number between 0 and {0}", resourceTypesMaxIndex)); + + int resourceTypeInt = -1; + + if (int.TryParse(resourceType, out resourceTypeInt)) + { + if (resourceTypeInt < 0 || resourceTypeInt > resourceTypesMaxIndex) + { + this.Context.ConsoleHelper.Error( + string.Format(CultureInfo.InvariantCulture, "The number must be between 0 and {0}", resourceTypesMaxIndex)); + + break; + } + } + else + { + this.Context.ConsoleHelper.Error( + string.Format(CultureInfo.InvariantCulture, "The number must be a valid integer between 0 and {0}", resourceTypesMaxIndex)); + + break; + } + + var startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 01); + + this.Context.ConsoleHelper.StartProgress( + string.Format(CultureInfo.InvariantCulture, "Retrieving the partner's audit records - start date: {0}", startDate)); + + string searchField = Enum.GetName(typeof(ResourceType), resourceTypeInt); + var filter = new SimpleFieldFilter(AuditRecordSearchField.ResourceType.ToString(), FieldFilterOperation.Equals, searchField); + + var auditRecordsPage = partnerOperations.AuditRecords.Query(startDate.Date, query: QueryFactory.Instance.BuildSimpleQuery(filter)); + + this.Context.ConsoleHelper.StopProgress(); + + // create a customer enumerator which will aid us in traversing the customer pages + var auditRecordEnumerator = partnerOperations.Enumerators.AuditRecords.Create(auditRecordsPage); + + int pageNumber = 1; + + while (auditRecordEnumerator.HasValue) + { + // print the current audit record results page + this.Context.ConsoleHelper.WriteObject(auditRecordEnumerator.Current, string.Format(CultureInfo.InvariantCulture, "Audit Record Page: {0}", pageNumber++)); + + Console.WriteLine(); + Console.Write("Press any key to retrieve the next set of audit records"); + Console.ReadKey(); + + this.Context.ConsoleHelper.StartProgress("Getting next audit records page"); + + // get the next page of audit records + auditRecordEnumerator.Next(); + + this.Context.ConsoleHelper.StopProgress(); + Console.Clear(); + } + + break; + } + } + } +} diff --git a/Source/Partner Center SDK Samples/BasePartnerScenario.cs b/Source/Partner Center SDK Samples/BasePartnerScenario.cs new file mode 100644 index 0000000..0492d8c --- /dev/null +++ b/Source/Partner Center SDK Samples/BasePartnerScenario.cs @@ -0,0 +1,519 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples +{ + using System; + using System.Collections.Generic; + using ScenarioExecution; + + /// + /// The base class for partner scenarios. Provides common behavior for all partner scenarios. + /// + public abstract class BasePartnerScenario : IPartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario title. + /// The scenario context. + /// The scenario execution strategy. + /// The child scenarios attached to the current scenario. + public BasePartnerScenario(string title, IScenarioContext context, IScenarioExecutionStrategy executionStrategy = null, IReadOnlyList childScenarios = null) + { + if (string.IsNullOrWhiteSpace(title)) + { + throw new ArgumentException("title has to be set"); + } + + if (context == null) + { + throw new ArgumentNullException("context"); + } + + this.Title = title; + this.Context = context; + + this.ExecutionStrategy = executionStrategy ?? new PromptExecutionStrategy(); + this.Children = childScenarios; + } + + /// + /// Gets the scenario title. + /// + public string Title { get; private set; } + + /// + /// Gets the children scenarios of the current scenario. + /// + public IReadOnlyList Children { get; private set; } + + /// + /// Gets the scenario context. + /// + public IScenarioContext Context { get; private set; } + + /// + /// Gets or sets the scenario execution behavior. + /// + private IScenarioExecutionStrategy ExecutionStrategy { get; set; } + + /// + /// Runs the scenario. + /// + public void Run() + { + do + { + Console.Clear(); + this.Context.ConsoleHelper.WriteColored(this.Title, ConsoleColor.DarkCyan); + this.Context.ConsoleHelper.WriteColored(new string('-', 80), ConsoleColor.DarkCyan); + Console.WriteLine(); + + try + { + this.RunScenario(); + } + catch (Exception exception) + { + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.Error(exception.ToString()); + } + + Console.WriteLine(); + } + while (!this.ExecutionStrategy.IsScenarioComplete(this)); + } + + /// + /// Obtains a customer ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// A customer ID. + protected string ObtainCustomerId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultCustomerId, + "Customer Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the customer ID" : promptMessage, + "The customer ID can't be empty"); + } + + /// + /// Obtains a configuration policy ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// A configuration policy ID. + protected string ObtainConfigurationPolicyId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultConfigurationPolicyId, + "Configuration Policy Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the configuration policy ID" : promptMessage, + "The configuration policy ID can't be empty"); + } + + /// + /// Obtains a device batch ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// A device batch ID. + protected string ObtainDeviceBatchId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultDeviceBatchId, + "Device Batch Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the device batch ID" : promptMessage, + "The device batch ID can't be empty"); + } + + /// + /// Obtains a device ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// A device ID. + protected string ObtainDeviceId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultDeviceId, + "Device Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the device ID" : promptMessage, + "The device ID can't be empty"); + } + + /// + /// Obtains a tracking ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// A batch upload status tracking ID. + protected string ObtainBatchUploadStatusTrackingId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultBatchUploadStatusTrackingId, + "Batch Upload Status Tracking Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the Batch Upload Status Tracking ID" : promptMessage, + "The Batch Upload Status Tracking ID can't be empty"); + } + + /// + /// Obtains an indirect reseller ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// An indirect reseller ID. + protected string ObtainIndirectResellerId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultIndirectResellerId, + "Indirect Reseller Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the indirect reseller ID" : promptMessage, + "The indirect reseller ID can't be empty"); + } + + /// + /// Obtains a directory role ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// A directory role ID. + protected string ObtainDirectoryRoleId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultDirectoryRoleId, + "Directory Role Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the Directory Role ID" : promptMessage, + "The Directory Role ID can't be empty"); + } + + /// + /// Obtains a customer user ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// A customer user ID. + protected string ObtainCustomerUserId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultCustomerUserId, + "Customer User Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the customer user ID" : promptMessage, + "The customer user ID can't be empty"); + } + + /// + /// Obtains a user member ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// A user member ID. + protected string ObtainUserMemberId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultUserMemberId, + "User Member Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the User Member ID" : promptMessage, + "The User Member ID can't be empty"); + } + + /// + /// Obtains a customer user ID to delete from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// A customer user ID. + protected string ObtainCustomerUserIdDelete(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.CustomerUserIdToDelete, + "Customer User Id To Delete", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the customer user ID to delete" : promptMessage, + "The customer user ID can't be empty"); + } + + /// + /// Obtains a customer user page size to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// A customer user page size. + protected string ObtainCustomerUserPageSize(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.CustomerUserPageSize, + "Customer user page size", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the customer user page size" : promptMessage, + "The customer user page size can't be empty"); + } + + /// + /// Obtains an MPN ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// The MPN ID. + protected string ObtainMpnId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.PartnerMpnId, + "MPN Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the MPN ID" : promptMessage, + "The MPN ID can't be empty"); + } + + /// + /// Obtains an offer ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// The offer ID. + protected string ObtainOfferId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultOfferId, + "Offer Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the offer ID" : promptMessage, + "The Offer ID can't be empty"); + } + + /// + /// Obtains a product ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// The product ID. + protected string ObtainProductId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultProductId, + "Product Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the product ID" : promptMessage, + "The Product ID can't be empty"); + } + + /// + /// Obtains a SKU ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// The SKU ID. + protected string ObtainSkuId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultSkuId, + "Sku Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the sku ID" : promptMessage, + "The Sku ID can't be empty"); + } + + /// + /// Obtains the availability ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// The availability ID. + protected string ObtainAvailabilityId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultAvailabilityId, + "Availability Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the availability ID" : promptMessage, + "The Availability ID can't be empty"); + } + + /// + /// Obtains a catalogItemId to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// The catalog Item ID. + protected string ObtainCatalogItemId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultCatalogItemId, + "Catalog Item Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the catalog item ID" : promptMessage, + "The catalog item ID can't be empty"); + } + + /// + /// Obtains a scope for provisioning status to work with from the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message. + /// The scope. + protected string ObtainScope(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultScope, + "Scope", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the Scope" : promptMessage, + "The Scope can't be empty"); + } + + /// + /// Obtain an order ID to work with the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message + /// The order ID + protected string ObtainOrderID(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultOrderId, + "Order Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the order ID" : promptMessage, + "The Order ID can't be empty"); + } + + /// + /// Obtain an cart ID to work with the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message + /// The cart ID + protected string ObtainCartID(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultCartId, + "Cart Id", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the cart ID" : promptMessage, + "The cart ID can't be empty"); + } + + /// + /// Obtain a quantity to update order with the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message + /// The quantity to update + protected string ObtainQuantity(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultQuantity, + "Quantity", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the Quantity" : promptMessage, + "The Quantity can't be empty"); + } + + /// + /// Obtain billing cycle type to create the order with the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message + /// The quantity to update + protected string ObtainBillingCycle(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultBillingCycle, + "Billing Cycle", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the Billing Cycle" : promptMessage, + "The Billing Cycle can't be empty"); + } + + /// + /// Obtain an Azure Subscription Id for provision status with the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message + /// Azure subscription Id + protected string ObtainAzureSubscriptionId(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultAzureSubscriptionId, + "Quantity", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the Azure Subscription Id" : promptMessage, + "The Azure Subscription Id can't be empty"); + } + + /// + /// Obtains a subscription ID to work with from the configuration if set there or prompts the user to enter it. + /// + /// The customer ID who owns the subscription. + /// An optional custom prompt message. + /// The subscription ID. + protected string ObtainSubscriptionId(string customerId, string promptMessage = default(string)) + { + var partnerOperations = this.Context.UserPartnerOperations; + var subscriptionId = this.Context.Configuration.Scenario.DefaultSubscriptionId; + + if (string.IsNullOrWhiteSpace(subscriptionId)) + { + // get the customer subscriptions and let the user enter the subscription Id afterwards + this.Context.ConsoleHelper.StartProgress("Retrieving customer subscriptions"); + var subscriptions = partnerOperations.Customers.ById(customerId).Subscriptions.Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(subscriptions, "Customer subscriptions"); + + Console.WriteLine(); + subscriptionId = this.Context.ConsoleHelper.ReadNonEmptyString( + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the subscription ID" : promptMessage, "Subscription ID can't be empty"); + } + else + { + Console.WriteLine("Found subscription ID: {0} in configuration.", subscriptionId); + } + + return subscriptionId.Trim(); + } + + /// + /// Obtains the product SKU ID by asking the user to enter it after displaying customer subscribed SKUs. + /// + /// The customer identifier of the customer that has the subscribed SKUs. + /// An optional custom prompt message. + /// The product SKU identifier. + protected string ObtainProductSkuId(string customerId, string promptMessage = default(string)) + { + var partnerOperations = this.Context.UserPartnerOperations; + string productSkuId = string.Empty; + + if (string.IsNullOrWhiteSpace(productSkuId)) + { + // get the customer subscribed Skus and let the user enter the productSku Id afterwards + this.Context.ConsoleHelper.StartProgress("Retrieving customer subscribed SKUs"); + var customerSubscribedSkus = partnerOperations.Customers.ById(customerId).SubscribedSkus.Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerSubscribedSkus, "Customer Subscribed SKUs"); + + Console.WriteLine(); + productSkuId = this.Context.ConsoleHelper.ReadNonEmptyString( + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the product SKU ID" : promptMessage, "Product SKU ID can't be empty"); + } + else + { + Console.WriteLine("Found product SKU ID: {0} in configuration.", productSkuId); + } + + return productSkuId.Trim(); + } + + /// + /// Runs the scenario logic. This is delegated to the implementing sub class. + /// + protected abstract void RunScenario(); + + /// + /// Obtain billing cycle type to work with the configuration if set there or prompts the user to enter it. + /// + /// An optional custom prompt message + /// Billing cycle type + protected string ObtainBillingCycleType(string promptMessage = default(string)) + { + return this.ObtainValue( + this.Context.Configuration.Scenario.DefaultBillingCycle, + "Billing cycle type", + string.IsNullOrWhiteSpace(promptMessage) ? "Enter the billing cycle type" : promptMessage, + "The billing cycle type can't be empty"); + } + + /// + /// Obtains a value to work with from the configuration if set there or prompts the user to enter it. + /// + /// The value read from the configuration. + /// The title of the value. + /// The prompt message to use if the value was not set in the configuration. + /// The error message to use if the user did not enter a value. + /// A string value. + private string ObtainValue(string configuredValue, string title, string promptMessage, string errorMessage) + { + string value = configuredValue; + + if (string.IsNullOrWhiteSpace(value)) + { + // The value was not set in the configuration, prompt the user the enter value + value = this.Context.ConsoleHelper.ReadNonEmptyString(promptMessage, errorMessage); + } + else + { + Console.WriteLine("Found {0}: {1} in configuration.", title, value); + } + + return value.Trim(); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Carts/CheckoutCart.cs b/Source/Partner Center SDK Samples/Carts/CheckoutCart.cs new file mode 100644 index 0000000..e07e652 --- /dev/null +++ b/Source/Partner Center SDK Samples/Carts/CheckoutCart.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Carts +{ + /// + /// A scenario that checkout a cart for a customer. + /// + public class CheckoutCart : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CheckoutCart(IScenarioContext context) : base("Checkout a Cart", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer making the purchase"); + string cartId = this.ObtainCartID("Enter the ID of cart to checkout"); + + var existingCart = partnerOperations.Customers.ById(customerId).Carts.ById(cartId).Get(); + + this.Context.ConsoleHelper.WriteObject(existingCart, "Cart to be checked out"); + this.Context.ConsoleHelper.StartProgress("Checking out cart"); + var checkoutResult = partnerOperations.Customers.ById(customerId).Carts.ById(cartId).Checkout(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(checkoutResult, "Final Cart: "); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Carts/CreateCart.cs b/Source/Partner Center SDK Samples/Carts/CreateCart.cs new file mode 100644 index 0000000..a639432 --- /dev/null +++ b/Source/Partner Center SDK Samples/Carts/CreateCart.cs @@ -0,0 +1,78 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Carts +{ + using System.Collections.Generic; + using System.Linq; + using Models.Carts; + + /// + /// A scenario that creates a new cart for a customer. + /// + public class CreateCart : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CreateCart(IScenarioContext context) : base("Create a Cart", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer making the purchase"); + string catalogItemId = this.ObtainCatalogItemId("Enter the catalog Item Id"); + string productId = catalogItemId.Split(':')[0]; + string skuId = catalogItemId.Split(':')[1]; + string scope = string.Empty; + string subscriptionId = string.Empty; + string duration = string.Empty; + var sku = partnerOperations.Products.ByCountry("US").ById(productId).Skus.ById(skuId).Get(); + + if (sku.ProvisioningVariables != null) + { + scope = this.ObtainScope("Enter the Scope for the Provisioning status"); + subscriptionId = this.ObtainAzureSubscriptionId("Enter the Subscription Id"); + duration = (string)sku.DynamicAttributes["duration"]; + } + + var cart = new Cart() + { + LineItems = new List() + { + new CartLineItem() + { + CatalogItemId = catalogItemId, + FriendlyName = "Myofferpurchase", + Quantity = 1, + BillingCycle = sku.SupportedBillingCycles.ToArray().First(), + ProvisioningContext = (sku.ProvisioningVariables == null) ? null : new Dictionary + { + { "subscriptionId", subscriptionId }, + { "scope", scope }, + { "duration", duration } + } + } + } + }; + + this.Context.ConsoleHelper.WriteObject(cart, "Cart to be created"); + this.Context.ConsoleHelper.StartProgress("Creating cart"); + + var createdCart = partnerOperations.Customers.ById(customerId).Carts.Create(cart); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(createdCart, "Created cart"); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Carts/UpdateCart.cs b/Source/Partner Center SDK Samples/Carts/UpdateCart.cs new file mode 100644 index 0000000..47ec39d --- /dev/null +++ b/Source/Partner Center SDK Samples/Carts/UpdateCart.cs @@ -0,0 +1,48 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Carts +{ + using System.Linq; + using Store.PartnerCenter.Models.Carts; + + /// + /// A scenario that updates a new cart for a customer. + /// + public class UpdateCart : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateCart(IScenarioContext context) : base("Update a Cart", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer making the purchase"); + string cartId = this.ObtainCartID("Enter the ID of cart for which changes are to be made"); + int quantityChange = int.Parse(this.ObtainQuantity("Enter the amount the quantity has to be changed")); + + Cart existingCart = partnerOperations.Customers.ById(customerId).Carts.ById(cartId).Get(); + + this.Context.ConsoleHelper.WriteObject(existingCart, "Cart to be updated"); + this.Context.ConsoleHelper.StartProgress("Updating cart"); + + existingCart.LineItems.ToArray()[0].Quantity += quantityChange; + + var updatedCart = partnerOperations.Customers.ById(customerId).Carts.ById(cartId).Put(existingCart); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedCart, "Updated cart"); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Configuration/ApplicationAuthenticationSection.cs b/Source/Partner Center SDK Samples/Configuration/ApplicationAuthenticationSection.cs new file mode 100644 index 0000000..a3a9c6b --- /dev/null +++ b/Source/Partner Center SDK Samples/Configuration/ApplicationAuthenticationSection.cs @@ -0,0 +1,55 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Configuration +{ + /// + /// Holds an application authentication section settings. + /// + public class ApplicationAuthenticationSection : Section + { + /// + /// Initializes a new instance of the class. + /// + /// The application authentication section name. + public ApplicationAuthenticationSection(string sectionName) : base(sectionName) + { + } + + /// + /// Gets the AAD application ID. + /// + public string ApplicationId + { + get + { + return this.ConfigurationSection["ApplicationId"]; + } + } + + /// + /// Gets AAD application secret. + /// + public string ApplicationSecret + { + get + { + return this.ConfigurationSection["ApplicationSecret"]; + } + } + + /// + /// Gets AAD Domain which hosts the application. + /// + public string Domain + { + get + { + return this.ConfigurationSection["Domain"]; + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Configuration/ConfigurationManager.cs b/Source/Partner Center SDK Samples/Configuration/ConfigurationManager.cs new file mode 100644 index 0000000..8701360 --- /dev/null +++ b/Source/Partner Center SDK Samples/Configuration/ConfigurationManager.cs @@ -0,0 +1,103 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Configuration +{ + using System; + + /// + /// Encapsulates the sample application configuration read from app.config. + /// + public class ConfigurationManager + { + /// + /// A lazy reference to a instance. + /// + private static Lazy instance = new Lazy(() => new ConfigurationManager()); + + /// + /// A reference to the partner service settings. + /// + private Lazy partnerServiceSettings = new Lazy(() => new PartnerServiceSettingsSection()); + + /// + /// A reference to the user authentication configuration. + /// + private Lazy userAuthentication = new Lazy(() => new UserAuthenticationSection("UserAuthentication")); + + /// + /// A reference to the application authentication configuration. + /// + private Lazy appAuthentication = new Lazy(() => new ApplicationAuthenticationSection("AppAuthentication")); + + /// + /// A reference to the scenario settings. + /// + private Lazy scenarioSettings = new Lazy(() => new ScenarioSettingsSection()); + + /// + /// Prevents a default instance of the class from being created. + /// + private ConfigurationManager() + { + } + + /// + /// Gets the singleton instance of the class. + /// + public static ConfigurationManager Instance + { + get + { + return ConfigurationManager.instance.Value; + } + } + + /// + /// Gets the partner service settings section. + /// + public PartnerServiceSettingsSection PartnerService + { + get + { + return this.partnerServiceSettings.Value; + } + } + + /// + /// Gets the user authentication section. + /// + public UserAuthenticationSection UserAuthentication + { + get + { + return this.userAuthentication.Value; + } + } + + /// + /// Gets the application authentication section. + /// + public ApplicationAuthenticationSection ApplicationAuthentication + { + get + { + return this.appAuthentication.Value; + } + } + + /// + /// Gets the scenario settings section. + /// + public ScenarioSettingsSection Scenario + { + get + { + return this.scenarioSettings.Value; + } + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Configuration/PartnerServiceSettingsSection.cs b/Source/Partner Center SDK Samples/Configuration/PartnerServiceSettingsSection.cs new file mode 100644 index 0000000..2a1c051 --- /dev/null +++ b/Source/Partner Center SDK Samples/Configuration/PartnerServiceSettingsSection.cs @@ -0,0 +1,67 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Configuration +{ + using System; + + /// + /// Holds the partner service settings section. + /// + public class PartnerServiceSettingsSection : Section + { + /// + /// Initializes a new instance of the class. + /// + public PartnerServiceSettingsSection() : base("PartnerServiceSettings") + { + } + + /// + /// Gets the partner service API endpoint. + /// + public Uri PartnerServiceApiEndpoint + { + get + { + return new Uri(this.ConfigurationSection["PartnerServiceApiEndpoint"]); + } + } + + /// + /// Gets the authentication authority (AAD) endpoint. + /// + public Uri AuthenticationAuthorityEndpoint + { + get + { + return new Uri(this.ConfigurationSection["AuthenticationAuthorityEndpoint"]); + } + } + + /// + /// Gets the graph API end point. + /// + public Uri GraphEndpoint + { + get + { + return new Uri(this.ConfigurationSection["GraphEndpoint"]); + } + } + + /// + /// Gets the AAD common domain. + /// + public string CommonDomain + { + get + { + return this.ConfigurationSection["CommonDomain"]; + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Configuration/ScenarioSettingsSection.cs b/Source/Partner Center SDK Samples/Configuration/ScenarioSettingsSection.cs new file mode 100644 index 0000000..8104236 --- /dev/null +++ b/Source/Partner Center SDK Samples/Configuration/ScenarioSettingsSection.cs @@ -0,0 +1,403 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Configuration +{ + /// + /// Holds the scenario specific settings section. + /// + public class ScenarioSettingsSection : Section + { + /// + /// Initializes a new instance of the class. + /// + public ScenarioSettingsSection() : base("ScenarioSettings") + { + } + + /// + /// Gets the customer domain suffix. + /// + public string CustomerDomainSuffix + { + get + { + return this.ConfigurationSection["CustomerDomainSuffix"]; + } + } + + /// + /// Gets the ID of the customer to delete from the TIP account. + /// + public string CustomerIdToDelete + { + get + { + return this.ConfigurationSection["CustomerIdToDelete"]; + } + } + + /// + /// Gets the ID of the customer user to delete. + /// + public string CustomerUserIdToDelete + { + get + { + return this.ConfigurationSection["CustomerUserIdToDelete"]; + } + } + + /// + /// Gets the ID of the directory role whose details should be read. + /// + public string DefaultDirectoryRoleId + { + get + { + return this.ConfigurationSection["DefaultDirectoryRoleId"]; + } + } + + /// + /// Gets the ID of the user member whose details should be read. + /// + public string DefaultUserMemberId + { + get + { + return this.ConfigurationSection["DefaultUserMemberId"]; + } + } + + /// + /// Gets the ID of the customer whose details should be read. + /// + public string DefaultCustomerId + { + get + { + return this.ConfigurationSection["DefaultCustomerId"]; + } + } + + /// + /// Gets the configured ID of the configuration policy. + /// + public string DefaultConfigurationPolicyId + { + get + { + return this.ConfigurationSection["DefaultConfigurationPolicyId"]; + } + } + + /// + /// Gets the configured ID of the Devices Batch. + /// + public string DefaultDeviceBatchId + { + get + { + return this.ConfigurationSection["DefaultDeviceBatchId"]; + } + } + + /// + /// Gets the configured ID of the Device. + /// + public string DefaultDeviceId + { + get + { + return this.ConfigurationSection["DefaultDeviceId"]; + } + } + + /// + /// Gets the configured ID of the Batch Upload Status Tracking. + /// + public string DefaultBatchUploadStatusTrackingId + { + get + { + return this.ConfigurationSection["DefaultBatchUploadStatusTrackingId"]; + } + } + + /// + /// Gets the ID of the indirect reseller id whose details should be read. + /// + public string DefaultIndirectResellerId + { + get + { + return this.ConfigurationSection["DefaultIndirectResellerId"]; + } + } + + /// + /// Gets the ID of the default customer user. + /// + public string DefaultCustomerUserId + { + get + { + return this.ConfigurationSection["DefaultCustomerUserId"]; + } + } + + /// + /// Gets the number of customers to return in each customer page. + /// + public int CustomerPageSize + { + get + { + return int.Parse(this.ConfigurationSection["CustomerPageSize"]); + } + } + + /// + /// Gets the number of customer users to return in each customer user page. + /// + public string CustomerUserPageSize + { + get + { + return this.ConfigurationSection["CustomerUserPageSize"]; + } + } + + /// + /// Gets the number of offers to return in each offer page. + /// + public int DefaultOfferPageSize + { + get + { + return int.Parse(this.ConfigurationSection["DefaultOfferPageSize"]); + } + } + + /// + /// Gets the number of invoices to return in each invoice page. + /// + public int InvoicePageSize + { + get + { + return int.Parse(this.ConfigurationSection["InvoicePageSize"]); + } + } + + /// + /// Gets the configured Invoice ID. + /// + public string DefaultInvoiceId + { + get + { + return this.ConfigurationSection["DefaultInvoiceId"]; + } + } + + /// + /// Gets the configured partner MPD ID. + /// + public string PartnerMpnId + { + get + { + return this.ConfigurationSection["PartnerMpnId"]; + } + } + + /// + /// Gets the configured offer ID. + /// + public string DefaultOfferId + { + get + { + return this.ConfigurationSection["DefaultOfferId"]; + } + } + + /// + /// Gets the configured product ID. + /// + public string DefaultProductId + { + get + { + return this.ConfigurationSection["DefaultProductId"]; + } + } + + /// + /// Gets the configured SKU ID. + /// + public string DefaultSkuId + { + get + { + return this.ConfigurationSection["DefaultSkuId"]; + } + } + + /// + /// Gets the configured availability ID. + /// + public string DefaultAvailabilityId + { + get + { + return this.ConfigurationSection["DefaultAvailabilityId"]; + } + } + + /// + /// Gets the configured order ID. + /// + public string DefaultOrderId + { + get + { + return this.ConfigurationSection["DefaultOrderId"]; + } + } + + /// + /// Gets the configured subscription ID. + /// + public string DefaultSubscriptionId + { + get + { + return this.ConfigurationSection["DefaultSubscriptionId"]; + } + } + + /// + /// Gets the service request ID. + /// + public string DefaultServiceRequestId + { + get + { + return this.ConfigurationSection["DefaultServiceRequestId"]; + } + } + + /// + /// Gets the number of service requests to return in each service request page. + /// + public int ServiceRequestPageSize + { + get + { + return int.Parse(this.ConfigurationSection["ServiceRequestPageSize"]); + } + } + + /// + /// Gets the configured support topic ID for creating new service request. + /// + public string DefaultSupportTopicId + { + get + { + return this.ConfigurationSection["DefaultSupportTopicId"]; + } + } + + /// + /// Gets the configured agreement template ID for create new customer agreements. + /// + public string DefaultAgreementTemplateId + { + get { return this.ConfigurationSection["DefaultAgreementTemplateId"]; } + } + + /// + /// Gets the partner's user ID for creating new customer agreement. + /// + public string DefaultPartnerUserId + { + get + { + return this.ConfigurationSection["DefaultPartnerUserId"]; + } + } + + /// + /// Gets the cart Id for an existing cart + /// + public string DefaultCartId + { + get + { + return this.ConfigurationSection["DefaultCartId"]; + } + } + + /// + /// Gets the Quantity for updating an existing cart + /// + public string DefaultQuantity + { + get + { + return this.ConfigurationSection["DefaultQuantity"]; + } + } + + /// + /// Gets the Catalog Item Id for an item from catalog + /// + public string DefaultCatalogItemId + { + get + { + return this.ConfigurationSection["DefaultCatalogItemId"]; + } + } + + /// + /// Gets the scope for provisioning status + /// + public string DefaultScope + { + get + { + return this.ConfigurationSection["DefaultScope"]; + } + } + + /// + /// Gets the Azure Subscription Id for provision status + /// + public string DefaultAzureSubscriptionId + { + get + { + return this.ConfigurationSection["DefaultAzureSubscriptionId"]; + } + } + + /// + /// Gets the BillingCycle for creating a cart + /// + public string DefaultBillingCycle + { + get + { + return this.ConfigurationSection["DefaultBillingCycle"]; + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Configuration/Section.cs b/Source/Partner Center SDK Samples/Configuration/Section.cs new file mode 100644 index 0000000..5a74e0c --- /dev/null +++ b/Source/Partner Center SDK Samples/Configuration/Section.cs @@ -0,0 +1,43 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Configuration +{ + using System; + using System.Collections.Specialized; + using System.Configuration; + using System.Globalization; + + /// + /// Encapsulates a configuration section read from app.config. + /// + public abstract class Section + { + /// + /// Initializes a new instance of the class. + /// + /// The configuration section name. + protected Section(string sectionName) + { + if (string.IsNullOrWhiteSpace(sectionName)) + { + throw new ArgumentException("sectionName must be set"); + } + + this.ConfigurationSection = System.Configuration.ConfigurationManager.GetSection(sectionName) as NameValueCollection; + + if (this.ConfigurationSection == null) + { + throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture, "Could not read section: {0} from configuration", sectionName)); + } + } + + /// + /// Gets the configuration section. + /// + protected NameValueCollection ConfigurationSection { get; private set; } + } +} diff --git a/Source/Partner Center SDK Samples/Configuration/UserAuthenticationSection.cs b/Source/Partner Center SDK Samples/Configuration/UserAuthenticationSection.cs new file mode 100644 index 0000000..c29a076 --- /dev/null +++ b/Source/Partner Center SDK Samples/Configuration/UserAuthenticationSection.cs @@ -0,0 +1,79 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Configuration +{ + using System; + + /// + /// Holds a user authentication section settings. + /// + public class UserAuthenticationSection : Section + { + /// + /// Initializes a new instance of the class. + /// + /// The application authentication section name. + public UserAuthenticationSection(string sectionName) : base(sectionName) + { + } + + /// + /// Gets the AAD application ID. + /// + public string ApplicationId + { + get + { + return this.ConfigurationSection["ApplicationId"]; + } + } + + /// + /// Gets the resource the application is attempting to access, i.e. the partner API service. + /// + public Uri ResourceUrl + { + get + { + return new Uri(this.ConfigurationSection["ResourceUrl"]); + } + } + + /// + /// Gets the application redirect URL. + /// + public Uri RedirectUrl + { + get + { + return new Uri(this.ConfigurationSection["RedirectUrl"]); + } + } + + /// + /// Gets AAD user name. + /// + public string UserName + { + get + { + return this.ConfigurationSection["UserName"]; + } + } + + /// + /// Gets AAD password. + /// + public string Password + { + get + { + return this.ConfigurationSection["Password"]; + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Context/ScenarioContext.cs b/Source/Partner Center SDK Samples/Context/ScenarioContext.cs new file mode 100644 index 0000000..9a5401c --- /dev/null +++ b/Source/Partner Center SDK Samples/Context/ScenarioContext.cs @@ -0,0 +1,153 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Context +{ + using System; + using System.Threading.Tasks; + using Configuration; + using Helpers; + using IdentityModel.Clients.ActiveDirectory; + using Store.PartnerCenter; + using Store.PartnerCenter.Extensions; + + /// + /// Scenario context implementation class. + /// + public class ScenarioContext : IScenarioContext + { + /// + /// A lazy reference to an user based partner operations. + /// + private IAggregatePartner userPartnerOperations = null; + + /// + /// A lazy reference to an application based partner operations. + /// + private IAggregatePartner appPartnerOperations = null; + + /// + /// Initializes a new instance of the class. + /// + public ScenarioContext() + { + PartnerService.Instance.ApiRootUrl = this.Configuration.PartnerService.PartnerServiceApiEndpoint.ToString(); + PartnerService.Instance.ApplicationName = "Partner Center .NET SDK Samples"; + } + + /// + /// Gets a partner operations instance which is application based authenticated. + /// + public IAggregatePartner AppPartnerOperations + { + get + { + if (this.appPartnerOperations == null) + { + this.ConsoleHelper.StartProgress("Authenticating application"); + + IPartnerCredentials appCredentials = PartnerCredentials.Instance.GenerateByApplicationCredentials( + this.Configuration.ApplicationAuthentication.ApplicationId, + this.Configuration.ApplicationAuthentication.ApplicationSecret, + this.Configuration.ApplicationAuthentication.Domain, + this.Configuration.PartnerService.AuthenticationAuthorityEndpoint.OriginalString, + this.Configuration.PartnerService.GraphEndpoint.OriginalString); + + this.ConsoleHelper.StopProgress(); + this.ConsoleHelper.Success("Authenticated!"); + + this.appPartnerOperations = PartnerService.Instance.CreatePartnerOperations(appCredentials); + } + + return this.appPartnerOperations; + } + } + + /// + /// Gets a configuration instance. + /// + public ConfigurationManager Configuration + { + get + { + return ConfigurationManager.Instance; + } + } + + /// + /// Gets a console helper instance. + /// + public ConsoleHelper ConsoleHelper + { + get + { + return ConsoleHelper.Instance; + } + } + + /// + /// Gets a partner operations instance which is user based authenticated. + /// + public IAggregatePartner UserPartnerOperations + { + get + { + if (this.userPartnerOperations == null) + { + this.ConsoleHelper.StartProgress("Authenticating user"); + var aadAuthenticationResult = this.LoginUserToAad(); + + // Authenticate by user context with the partner service + IPartnerCredentials userCredentials = PartnerCredentials.Instance.GenerateByUserCredentials( + this.Configuration.UserAuthentication.ApplicationId, + new AuthenticationToken( + aadAuthenticationResult.AccessToken, + aadAuthenticationResult.ExpiresOn), + delegate + { + // token has expired, re-Login to Azure Active Directory + this.ConsoleHelper.StartProgress("Token expired. Re-authenticating user"); + var aadToken = this.LoginUserToAad(); + this.ConsoleHelper.StopProgress(); + + // give the partner SDK the new add token information + return Task.FromResult(new AuthenticationToken(aadToken.AccessToken, aadToken.ExpiresOn)); + }); + + this.ConsoleHelper.StopProgress(); + this.ConsoleHelper.Success("Authenticated!"); + + this.userPartnerOperations = PartnerService.Instance.CreatePartnerOperations(userCredentials); + } + + return this.userPartnerOperations; + } + } + + /// + /// Logs in to AAD as a user and obtains the user authentication token. + /// + /// The user authentication result. + private AuthenticationResult LoginUserToAad() + { + var addAuthority = new UriBuilder(this.Configuration.PartnerService.AuthenticationAuthorityEndpoint) + { + Path = this.Configuration.PartnerService.CommonDomain + }; + + UserCredential userCredentials = new UserCredential( + this.Configuration.UserAuthentication.UserName, + this.Configuration.UserAuthentication.Password); + + AuthenticationContext authContext = new AuthenticationContext(addAuthority.Uri.AbsoluteUri); + + return authContext.AcquireToken( + this.Configuration.UserAuthentication.ResourceUrl.OriginalString, + this.Configuration.UserAuthentication.ApplicationId, + userCredentials); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/CustomerDirectoryRoles/AddUserMemberToDirectoryRole.cs b/Source/Partner Center SDK Samples/CustomerDirectoryRoles/AddUserMemberToDirectoryRole.cs new file mode 100644 index 0000000..d7b7b2a --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerDirectoryRoles/AddUserMemberToDirectoryRole.cs @@ -0,0 +1,61 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerDirectoryRoles +{ + using System; + using Models.Roles; + + /// + /// Adds user member to a directory role. + /// + public class AddUserMemberToDirectoryRole : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public AddUserMemberToDirectoryRole(IScenarioContext context) : base("Add user member to a directory role", context) + { + } + + /// + /// Executes the add user member to a directory role scenario. + /// + protected override void RunScenario() + { + // get customer user Id. + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to get details for creating user member"); + + // get customer Id of the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer whose customer user details should be used for user member"); + + // get directory role Id. + string selectedDirectoryRoleId = this.ObtainDirectoryRoleId("Enter the ID of the directory role"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting Customer User Details"); + + // getting customer user details + var selectedCustomer = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Get(); + this.Context.ConsoleHelper.StopProgress(); + UserMember userMemberToAdd = new UserMember() + { + UserPrincipalName = selectedCustomer.UserPrincipalName, + DisplayName = selectedCustomer.DisplayName, + Id = selectedCustomer.Id + }; + this.Context.ConsoleHelper.StartProgress("Adding user member to directory roles"); + + // Add this customer user to the selected directory role. + var userMemberAdded = partnerOperations.Customers.ById(selectedCustomerId).DirectoryRoles.ById(selectedDirectoryRoleId).UserMembers.Create(userMemberToAdd); + this.Context.ConsoleHelper.StopProgress(); + Console.WriteLine("Below Customer user was added to directory role with id: {0}", selectedDirectoryRoleId); + this.Context.ConsoleHelper.WriteObject(userMemberAdded, "Added Customer User Member to Directory Role Details"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerDirectoryRoles/GetCustomerDirectoryRoleUserMembers.cs b/Source/Partner Center SDK Samples/CustomerDirectoryRoles/GetCustomerDirectoryRoleUserMembers.cs new file mode 100644 index 0000000..75d094d --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerDirectoryRoles/GetCustomerDirectoryRoleUserMembers.cs @@ -0,0 +1,43 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerDirectoryRoles +{ + /// + /// Showcases get customer users by directory role service. + /// + public class GetCustomerDirectoryRoleUserMembers : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerDirectoryRoleUserMembers(IScenarioContext context) : base("Get customer user by directory role", context) + { + } + + /// + /// Executes the get customer users by directory role service scenario. + /// + protected override void RunScenario() + { + // get customer Id to get directory role user members. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to get directory role user members"); + + // get directory role Id. + string selectedDirectoryRoleId = this.ObtainDirectoryRoleId("Enter the ID of the directory role"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting user members by directory roles"); + + // Get all user members having the selected directory role. + var userMembers = partnerOperations.Customers.ById(selectedCustomerId).DirectoryRoles.ById(selectedDirectoryRoleId).UserMembers.Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(userMembers, "User Members who are having the selected directory role"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerDirectoryRoles/GetCustomerDirectoryRoles.cs b/Source/Partner Center SDK Samples/CustomerDirectoryRoles/GetCustomerDirectoryRoles.cs new file mode 100644 index 0000000..bfc1328 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerDirectoryRoles/GetCustomerDirectoryRoles.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerDirectoryRoles +{ + /// + /// Gets customer directory roles details. + /// + public class GetCustomerDirectoryRoles : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerDirectoryRoles(IScenarioContext context) : base("Get customer directory roles", context) + { + } + + /// + /// Executes the get customer directory roles scenario. + /// + protected override void RunScenario() + { + // get customer Id. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to get directory roles"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting customer directory roles"); + + // get directory roles of customer. + var directoryRoles = partnerOperations.Customers.ById(selectedCustomerId).DirectoryRoles.Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(directoryRoles, "Customer Directory Role Details"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerDirectoryRoles/RemoveCustomerUserMemberFromDirectoryRole.cs b/Source/Partner Center SDK Samples/CustomerDirectoryRoles/RemoveCustomerUserMemberFromDirectoryRole.cs new file mode 100644 index 0000000..5724336 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerDirectoryRoles/RemoveCustomerUserMemberFromDirectoryRole.cs @@ -0,0 +1,47 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerDirectoryRoles +{ + using System; + + /// + /// Showcases remove customer user from directory role service. + /// + public class RemoveCustomerUserMemberFromDirectoryRole : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public RemoveCustomerUserMemberFromDirectoryRole(IScenarioContext context) : base("Remove customer user from a directory role", context) + { + } + + /// + /// Executes the remove customer user from a directory role scenario. + /// + protected override void RunScenario() + { + // get user member Id. + string selectedUserMemberId = this.ObtainUserMemberId("Enter the ID of the user member of directory role user to remove"); + + // get directory role Id of the entered user member. + string selectedDirectoryRoleId = this.ObtainDirectoryRoleId("Enter the ID of the directory role to remove customer user"); + + // get customer Id of the entered directory roles. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer whose customer user to remove from a directory role"); + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Removing user member from directory role"); + + // Remove user member from selected directory role. + partnerOperations.Customers.ById(selectedCustomerId).DirectoryRoles.ById(selectedDirectoryRoleId).UserMembers.ById(selectedUserMemberId).Delete(); + this.Context.ConsoleHelper.StopProgress(); + Console.WriteLine("The user member with Id: {0} is removed from directory role Id: {1}", selectedUserMemberId, selectedDirectoryRoleId); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailabilities.cs b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailabilities.cs new file mode 100644 index 0000000..ed9a53f --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailabilities.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerProducts +{ + using System.Globalization; + + /// + /// A scenario that retrieves the availabilities of a product's SKU for a customer. + /// + public class GetCustomerAvailabilities : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerAvailabilities(IScenarioContext context) : base("Get availabilities for customer", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var customerId = this.ObtainCustomerId("Enter the ID of the corresponding customer"); + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + var skuId = this.ObtainSkuId("Enter the ID of the corresponding sku"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting availabilities for product {0} and sku {1} for customer {2}", productId, skuId, customerId)); + var skuAvailabilities = partnerOperations.Customers.ById(customerId).Products.ById(productId).Skus.ById(skuId).Availabilities.Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(skuAvailabilities, "Availabilities for customer"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailabilitiesByTargetSegment.cs b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailabilitiesByTargetSegment.cs new file mode 100644 index 0000000..e00fa99 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailabilitiesByTargetSegment.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerProducts +{ + using System.Globalization; + + /// + /// A scenario that retrieves the availabilities of a product's SKU for a customer that target a specific segment. + /// + public class GetCustomerAvailabilitiesByTargetSegment : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerAvailabilitiesByTargetSegment(IScenarioContext context) : base("Get availabilities for customer by segment", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var customerId = this.ObtainCustomerId("Enter the ID of the corresponding customer"); + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + var skuId = this.ObtainSkuId("Enter the ID of the corresponding sku"); + string segment = this.Context.ConsoleHelper.ReadNonEmptyString("The segment to filter the availabilities on", "The segment can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting sku availabilities for product {0} and sku {1} by segment {2} for customer {3}", productId, skuId, segment, customerId)); + var skuAvailabilities = partnerOperations.Customers.ById(customerId).Products.ById(productId).Skus.ById(skuId).Availabilities.ByTargetSegment(segment).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(skuAvailabilities, "Availabilities for customer by segment"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailability.cs b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailability.cs new file mode 100644 index 0000000..322c261 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerAvailability.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerProducts +{ + using System.Globalization; + + /// + /// A scenario that retrieves the availability of a product's SKU for a customer. + /// + public class GetCustomerAvailability : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerAvailability(IScenarioContext context) : base("Get availability for customer", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var customerId = this.ObtainCustomerId("Enter the ID of the corresponding customer"); + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + var skuId = this.ObtainSkuId("Enter the ID of the corresponding sku"); + var availabilityId = this.ObtainAvailabilityId("Enter the ID of the availability"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting availability {0} for product {1} and sku {2} for customer {3}", availabilityId, productId, skuId, customerId)); + var skuAvailability = partnerOperations.Customers.ById(customerId).Products.ById(productId).Skus.ById(skuId).Availabilities.ById(availabilityId).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(skuAvailability, "Availability for customer"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProduct.cs b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProduct.cs new file mode 100644 index 0000000..831bc51 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProduct.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerProducts +{ + using System.Globalization; + + /// + /// A scenario that retrieves product details for a customer. + /// + public class GetCustomerProduct : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerProduct(IScenarioContext context) : base("Get product for customer", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var customerId = this.ObtainCustomerId("Enter the ID of the corresponding customer"); + var productId = this.ObtainProductId("Enter the ID of the product"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting product {0} details for customer {1}", productId, customerId)); + var product = partnerOperations.Customers.ById(customerId).Products.ById(productId).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(product, "Product details for customer"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProducts.cs b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProducts.cs new file mode 100644 index 0000000..e273466 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProducts.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerProducts +{ + using System.Globalization; + + /// + /// A scenario that retrieves all the products in a catalog view that apply to a costumer. + /// + public class GetCustomerProducts : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerProducts(IScenarioContext context) : base("Get products for customer", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var customerId = this.ObtainCustomerId("Enter the ID of the corresponding customer"); + string targetView = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the target view to get its supported products", "The target view can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting products in catalog view {0} for customer {1}", targetView, customerId)); + var products = partnerOperations.Customers.ById(customerId).Products.ByTargetView(targetView).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(products, "Products for customer"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProductsByTargetSegment.cs b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProductsByTargetSegment.cs new file mode 100644 index 0000000..1930d86 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerProductsByTargetSegment.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerProducts +{ + using System.Globalization; + + /// + /// A scenario that retrieves all the products in a catalog view that apply to a customer and that target a specific segment. + /// + public class GetCustomerProductsByTargetSegment : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerProductsByTargetSegment(IScenarioContext context) : base("Get products for customer by segment", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var customerId = this.ObtainCustomerId("Enter the ID of the corresponding customer"); + string targetView = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the target view to get its supported products", "The target view can't be empty"); + string segment = this.Context.ConsoleHelper.ReadNonEmptyString("The segment to filter the products on", "The segment can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting products in catalog view {0} by segment {1} for customer {2}", targetView, segment, customerId)); + var products = partnerOperations.Customers.ById(customerId).Products.ByTargetView(targetView).ByTargetSegment(segment).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(products, "Products for customer by segment"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSku.cs b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSku.cs new file mode 100644 index 0000000..e381e8f --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSku.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerProducts +{ + using System.Globalization; + + /// + /// A scenario that retrieves details of a product's SKU for a customer. + /// + public class GetCustomerSku : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerSku(IScenarioContext context) : base("Get sku for customer", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var customerId = this.ObtainCustomerId("Enter the ID of the corresponding customer"); + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + var skuId = this.ObtainSkuId("Enter the ID of the sku"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting sku details for sku {0} from product {1} for customer {2}", skuId, productId, customerId)); + var sku = partnerOperations.Customers.ById(customerId).Products.ById(productId).Skus.ById(skuId).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(sku, "Sku details for customer"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkuDownloadOptions.cs b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkuDownloadOptions.cs new file mode 100644 index 0000000..ea02b19 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkuDownloadOptions.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerProducts +{ + using System.Globalization; + + /// + /// A scenario that retrieves the download options of a product's SKU for a customer. + /// + public class GetCustomerSkuDownloadOptions : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerSkuDownloadOptions(IScenarioContext context) : base("Get sku download options for customer", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var customerId = this.ObtainCustomerId("Enter the ID of the corresponding customer"); + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + var skuId = this.ObtainSkuId("Enter the ID of the corresponding sku"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting sku download options for sku {0} from product {1} for customer {2}", skuId, productId, customerId)); + var sku = partnerOperations.Customers.ById(customerId).Products.ById(productId).Skus.ById(skuId).DownloadOptions.Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(sku, "Sku download options for customer"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkus.cs b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkus.cs new file mode 100644 index 0000000..4954216 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkus.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerProducts +{ + using System.Globalization; + + /// + /// A scenario that retrieves all the SKUs related to a product that apply to a customer. + /// + public class GetCustomerSkus : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerSkus(IScenarioContext context) : base("Get skus for customer", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var customerId = this.ObtainCustomerId("Enter the ID of the corresponding customer"); + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting skus from product {0} for customer {1}", productId, customerId)); + var skus = partnerOperations.Customers.ById(customerId).Products.ById(productId).Skus.Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(skus, "Skus for customer"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkusByTargetSegment.cs b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkusByTargetSegment.cs new file mode 100644 index 0000000..ff3a2ab --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerProducts/GetCustomerSkusByTargetSegment.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerProducts +{ + using System.Globalization; + + /// + /// A scenario that retrieves all the SKUs related to a product that apply to a customer and that target a specific segment. + /// + public class GetCustomerSkusByTargetSegment : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerSkusByTargetSegment(IScenarioContext context) : base("Get skus for customer by segment", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var customerId = this.ObtainCustomerId("Enter the ID of the corresponding customer"); + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + string segment = this.Context.ConsoleHelper.ReadNonEmptyString("The segment to filter the skus on", "The segment can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting skus from product {0} by segment {1} for customer {2}", productId, segment, customerId)); + var skus = partnerOperations.Customers.ById(customerId).Products.ById(productId).Skus.ByTargetSegment(segment).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(skus, string.Format(CultureInfo.InvariantCulture, "Skus for customer {0} by segment {1}", productId, segment)); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerServiceCosts/GetCustomerServiceCostsLineItems.cs b/Source/Partner Center SDK Samples/CustomerServiceCosts/GetCustomerServiceCostsLineItems.cs new file mode 100644 index 0000000..200bc87 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerServiceCosts/GetCustomerServiceCostsLineItems.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerServiceCosts +{ + using Models.ServiceCosts; + + /// + /// Gets Customer Service Costs Line Items. + /// + public class GetCustomerServiceCostsLineItems : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerServiceCostsLineItems(IScenarioContext context) : base("Get customer service costs line items", context) + { + } + + /// + /// Executes the get Customer Service Costs Line Items. + /// + protected override void RunScenario() + { + // get a customer Id. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to get service costs line items"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting customer service costs line items"); + + // get the customer's Service Costs Line Items. + var customerServiceCostsLineItems = partnerOperations.Customers.ById(selectedCustomerId).ServiceCosts.ByBillingPeriod(ServiceCostsBillingPeriod.MostRecent).LineItems.Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerServiceCostsLineItems, "Customer Service Costs Line Items"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerServiceCosts/GetCustomerServiceCostsSummary.cs b/Source/Partner Center SDK Samples/CustomerServiceCosts/GetCustomerServiceCostsSummary.cs new file mode 100644 index 0000000..e050849 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerServiceCosts/GetCustomerServiceCostsSummary.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerServiceCosts +{ + using Models.ServiceCosts; + + /// + /// Gets Customer Service Costs Summary. + /// + public class GetCustomerServiceCostsSummary : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerServiceCostsSummary(IScenarioContext context) : base("Get customer service costs summary", context) + { + } + + /// + /// Executes the get Customer Service Costs scenario. + /// + protected override void RunScenario() + { + // get a customer Id. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to get service costs summary"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting customer service costs summary"); + + // get the customer's Service Costs Summary. + var customerServiceCostsSummary = partnerOperations.Customers.ById(selectedCustomerId).ServiceCosts.ByBillingPeriod(ServiceCostsBillingPeriod.MostRecent).Summary.Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerServiceCostsSummary, "Customer Service Costs Summary"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerSubscribedSkus/GetCustomerSubscribedSkus.cs b/Source/Partner Center SDK Samples/CustomerSubscribedSkus/GetCustomerSubscribedSkus.cs new file mode 100644 index 0000000..5584955 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerSubscribedSkus/GetCustomerSubscribedSkus.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerSubscribedSkus +{ + using System; + + /// + /// Gets Customer Subscribed SKUs details. + /// + public class GetCustomerSubscribedSkus : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerSubscribedSkus(IScenarioContext context) : base("Get customer subscribed SKUs", context) + { + } + + /// + /// Executes the get Customer Subscribed SKUs scenario. + /// + protected override void RunScenario() + { + // get customer Id. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to get subscribed skus"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting customer subscribed SKUs"); + + // get Customer Subscribed SKUs information. + var customerSubscribedSkus = partnerOperations.Customers.ById(selectedCustomerId).SubscribedSkus.Get(); + this.Context.ConsoleHelper.StopProgress(); + + Console.Out.WriteLine("Customer Subscribed Skus Count: " + customerSubscribedSkus.TotalCount); + this.Context.ConsoleHelper.WriteObject(customerSubscribedSkus, "Customer Subscribed Sku"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/CreateCustomerUser.cs b/Source/Partner Center SDK Samples/CustomerUser/CreateCustomerUser.cs new file mode 100644 index 0000000..26a9cc2 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/CreateCustomerUser.cs @@ -0,0 +1,61 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using System; + using Models.Users; + + /// + /// Creates a new customer user. + /// + public class CreateCustomerUser : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CreateCustomerUser(IScenarioContext context) : base("Create a new customer user", context) + { + } + + /// + /// Executes the create customer user scenario. + /// + protected override void RunScenario() + { + // get customer Id. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to create customer user"); + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting customer of selected customer Id"); + + // get customer. + var selectedCustomer = partnerOperations.Customers.ById(selectedCustomerId).Get(); + this.Context.ConsoleHelper.StopProgress(); + + var customerUserToCreate = new CustomerUser() + { + PasswordProfile = new PasswordProfile() { ForceChangePassword = true, Password = "Password!1" }, + DisplayName = "Kate", + FirstName = "Kate", + LastName = "Nichols", + UsageLocation = "US", + UserPrincipalName = Guid.NewGuid().ToString("N") + "@" + selectedCustomer.CompanyProfile.Domain + }; + this.Context.ConsoleHelper.WriteObject(customerUserToCreate, "New customer user Information"); + + this.Context.ConsoleHelper.StartProgress("Creating customer user"); + + // Create a customer user. + var createdUser = partnerOperations.Customers.ById(selectedCustomerId).Users.Create(customerUserToCreate); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.Success("Success!"); + this.Context.ConsoleHelper.WriteObject(createdUser, "Created User Information"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignGroup1Licenses.cs b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignGroup1Licenses.cs new file mode 100644 index 0000000..62b8f3a --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignGroup1Licenses.cs @@ -0,0 +1,82 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Models.Licenses; + + /// + /// Assign customer user a group1 license. + /// + public class CustomerUserAssignGroup1Licenses : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CustomerUserAssignGroup1Licenses(IScenarioContext context) : base("Assign customer user a group1 license", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + // Get customer Id of the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer"); + + // Get customer user Id. + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to assign license"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting Subscribed Skus"); + + // A list of the groupids + // Group1 – This group has all products whose license can be managed in the Azure Active Directory (AAD). + List groupIds = new List() { LicenseGroupId.Group1 }; + + // Get customer's group1 subscribed skus information. + var customerGroup1SubscribedSkus = partnerOperations.Customers.ById(selectedCustomerId).SubscribedSkus.Get(groupIds); + this.Context.ConsoleHelper.StopProgress(); + + // Prepare license request. + LicenseUpdate updateLicense = new LicenseUpdate(); + LicenseAssignment license = new LicenseAssignment(); + + // Select the first subscribed sku. + SubscribedSku sku = customerGroup1SubscribedSkus.Items.First(); + + // Assigning first subscribed sku as the license + license.SkuId = sku.ProductSku.Id; + license.ExcludedPlans = null; + + List licenseList = new List(); + licenseList.Add(license); + updateLicense.LicensesToAssign = licenseList; + + this.Context.ConsoleHelper.StartProgress("Assigning License"); + + // Assign licenses to the user. + var assignLicense = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).LicenseUpdates.Create(updateLicense); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.StartProgress("Getting Assigned License"); + + // Get customer user assigned licenses information after assigning the license. + var customerUserAssignedLicenses = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Licenses.Get(groupIds); + this.Context.ConsoleHelper.StopProgress(); + + License userLicense = customerUserAssignedLicenses.Items.First(licenseItem => licenseItem.ProductSku.Id == license.SkuId); + Console.WriteLine("License was successfully assigned to the user."); + this.Context.ConsoleHelper.WriteObject(userLicense, "Assigned License"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignGroup2Licenses.cs b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignGroup2Licenses.cs new file mode 100644 index 0000000..1309057 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignGroup2Licenses.cs @@ -0,0 +1,104 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Models.Licenses; + + /// + /// Assign customer user a Group2 license + /// + public class CustomerUserAssignGroup2Licenses : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CustomerUserAssignGroup2Licenses(IScenarioContext context) : base("Assign customer user a Group2 license", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + // A sample License Group2 Id - Minecraft product id. + string minecraftProductSkuId = "984df360-9a74-4647-8cf8-696749f6247a"; + + // Subscribed Sku for minecraft; + SubscribedSku minecraftSubscribedSku = null; + + // Get customer Id of the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer"); + + // Get customer user Id. + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to assign license"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting Subscribed Skus"); + + // Group2 – This group contains products that cant be managed in Azure Active Directory + List groupIds = new List() { LicenseGroupId.Group2 }; + + // Get customer's subscribed skus information. + var customerSubscribedSkus = partnerOperations.Customers.ById(selectedCustomerId).SubscribedSkus.Get(groupIds); + + // Check if a minecraft exists for a given user + foreach (var customerSubscribedSku in customerSubscribedSkus.Items) + { + if (customerSubscribedSku.ProductSku.Id.ToString() == minecraftProductSkuId) + { + minecraftSubscribedSku = customerSubscribedSku; + } + } + + if (minecraftSubscribedSku == null) + { + Console.WriteLine("Customer user doesnt have subscribed sku"); + this.Context.ConsoleHelper.StopProgress(); + return; + } + + this.Context.ConsoleHelper.StopProgress(); + + // Prepare license request. + LicenseUpdate updateLicense = new LicenseUpdate(); + + // Select the license + SubscribedSku sku = minecraftSubscribedSku; + LicenseAssignment license = new LicenseAssignment(); + + // Assigning subscribed sku as the license + license.SkuId = sku.ProductSku.Id; + license.ExcludedPlans = null; + + List licenseList = new List(); + licenseList.Add(license); + updateLicense.LicensesToAssign = licenseList; + + this.Context.ConsoleHelper.StartProgress("Assigning License"); + + // Assign licenses to the user. + var assignLicense = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).LicenseUpdates.Create(updateLicense); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.StartProgress("Getting Assigned License"); + + // Get customer user assigned licenses information after assigning the license. + var customerUserAssignedLicenses = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Licenses.Get(groupIds); + this.Context.ConsoleHelper.StopProgress(); + + Console.WriteLine("License was successfully assigned to the user."); + License userLicense = customerUserAssignedLicenses.Items.First(licenseItem => licenseItem.ProductSku.Id == license.SkuId); + this.Context.ConsoleHelper.WriteObject(userLicense, "Assigned License"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignLicenses.cs b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignLicenses.cs new file mode 100644 index 0000000..beb48b3 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignLicenses.cs @@ -0,0 +1,72 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Models.Licenses; + + /// + /// Assign customer user a license. + /// + public class CustomerUserAssignLicenses : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CustomerUserAssignLicenses(IScenarioContext context) : base("Assign customer user a license", context) + { + } + + /// + /// Executes the assign customer user a license scenario. + /// + protected override void RunScenario() + { + // Get the customer user ID. + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to assign license"); + + // Get the customer ID for the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer"); + + // Get the product SKU for the license. + string selectedProductSkuId = this.ObtainProductSkuId(selectedCustomerId, "Enter the ID of the product SKU for the license"); + + var partnerOperations = this.Context.UserPartnerOperations; + + // Prepare license request. + LicenseUpdate updateLicense = new LicenseUpdate(); + + LicenseAssignment license = new LicenseAssignment(); + + license.SkuId = selectedProductSkuId; + license.ExcludedPlans = null; + + List licenseList = new List(); + licenseList.Add(license); + updateLicense.LicensesToAssign = licenseList; + + this.Context.ConsoleHelper.StartProgress("Assigning License"); + + // Assign licenses to the user. + var assignLicense = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).LicenseUpdates.Create(updateLicense); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.StartProgress("Getting Assigned License"); + + // Get customer user assigned licenses information after assigning the license. + var customerUserAssignedLicenses = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Licenses.Get(); + this.Context.ConsoleHelper.StopProgress(); + + Console.WriteLine("License was successfully assigned to the user."); + License userLicense = customerUserAssignedLicenses.Items.First(); + this.Context.ConsoleHelper.WriteObject(userLicense, "Assigned License"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup1AndGroup2Licenses.cs b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup1AndGroup2Licenses.cs new file mode 100644 index 0000000..016ffa9 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup1AndGroup2Licenses.cs @@ -0,0 +1,48 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using System.Collections.Generic; + using Models.Licenses; + + /// + /// Get customer user assigned group1 and group2 licenses + /// + public class CustomerUserAssignedGroup1AndGroup2Licenses : BasePartnerScenario + { + /// + /// Initializes a new instance of the class + /// + /// The scenario context + public CustomerUserAssignedGroup1AndGroup2Licenses(IScenarioContext context) : base("Get customer user assigned group1 and group2 licenses", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + // Get the customer user Id + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to get assigned licenses"); + + // Get the customer Id of the entered customer user + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer"); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting customer user assigned licenses"); + + // Get the customer user assigned group1 and group2 licenses information + // Group1 – This group has all products whose license can be managed in the Azure Active Directory (AAD). + // Group2 – This group contains products that cant be managed in Azure Active Directory + List groupIds = new List() { LicenseGroupId.Group1, LicenseGroupId.Group2 }; + var customerUserAssignedGroup1Group2Licenses = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Licenses.Get(groupIds); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerUserAssignedGroup1Group2Licenses, "Customer User Assigned Group1 and Group2 Licenses"); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup1Licenses.cs b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup1Licenses.cs new file mode 100644 index 0000000..54913fe --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup1Licenses.cs @@ -0,0 +1,47 @@ +// ------------------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// -------------------------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using System.Collections.Generic; + using Models.Licenses; + + /// + /// Get customer user assigned group1 licenses + /// + public class CustomerUserAssignedGroup1Licenses : BasePartnerScenario + { + /// + /// Initializes a new instance of the class + /// + /// The scenario context + public CustomerUserAssignedGroup1Licenses(IScenarioContext context) : base("Get customer user assigned group1 licenses", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + // Get the customer Id of the entered customer user + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer"); + + // Get the customer user Id + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to get assigned licenses"); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting customer user assigned licenses"); + + // Get the customer user assigned group1 licenses information + // Group1 – This group has all products whose license can be managed in the Azure Active Directory (AAD). + List groupIds = new List() { LicenseGroupId.Group1 }; + var customerUserAssignedGroup1Licenses = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Licenses.Get(groupIds); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerUserAssignedGroup1Licenses, "Customer User Assigned Group1 Licenses"); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup2Licenses.cs b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup2Licenses.cs new file mode 100644 index 0000000..1bdd558 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedGroup2Licenses.cs @@ -0,0 +1,47 @@ +// ------------------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// -------------------------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using System.Collections.Generic; + using Models.Licenses; + + /// + /// Get customer user assigned group2 licenses + /// + public class CustomerUserAssignedGroup2Licenses : BasePartnerScenario + { + /// + /// Initializes a new instance of the class + /// + /// The scenario context + public CustomerUserAssignedGroup2Licenses(IScenarioContext context) : base("Get customer user assinged group2 licenses", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + // Get the customer Id of the entered customer user + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer"); + + // Get the customer user Id + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to get assigned licenses"); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting customer user assigned licenses"); + + // Get the customer user assigned group2 licenses information + // Group2 – This group contains products that cant be managed in Azure Active Directory + List groupIds = new List() { LicenseGroupId.Group2 }; + var customerUserAssignedGroup2Licenses = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Licenses.Get(groupIds); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerUserAssignedGroup2Licenses, "Customer User Assigned Group2 Licenses"); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedLicenses.cs b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedLicenses.cs new file mode 100644 index 0000000..5a19c9c --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserAssignedLicenses.cs @@ -0,0 +1,43 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + /// + /// Gets customer user assigned licenses. + /// + public class CustomerUserAssignedLicenses : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CustomerUserAssignedLicenses(IScenarioContext context) : base("Get customer user assigned licenses", context) + { + } + + /// + /// Executes the get customer user assigned licenses scenario. + /// + protected override void RunScenario() + { + // get customer user Id. + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to get assigned licenses"); + + // get customer Id of the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting customer user assigned licenses"); + + // get customer user assigned licenses information. + var customerUserAssignedLicenses = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Licenses.Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerUserAssignedLicenses, "Customer User Assigned Licenses"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/CustomerUserRestore.cs b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserRestore.cs new file mode 100644 index 0000000..fdd8d9a --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/CustomerUserRestore.cs @@ -0,0 +1,50 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using Models.Users; + + /// + /// Showcases customer user restore API. + /// + public class CustomerUserRestore : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CustomerUserRestore(IScenarioContext context) : base("Restore a deleted customer user", context) + { + } + + /// + /// Executes the restore customer user scenario. + /// + protected override void RunScenario() + { + // get customer Id of the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the corresponding customer to restore customer user details"); + + // get customer user Id. + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to restore"); + + var partnerOperations = this.Context.UserPartnerOperations; + + var updatedCustomerUser = new CustomerUser() + { + State = UserState.Active + }; + + this.Context.ConsoleHelper.StartProgress("Restoring the customer user"); + + // restore customer user information using older upn. + var restoredCustomerUserInfo = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Patch(updatedCustomerUser); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(restoredCustomerUserInfo, "Restored customer user."); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/DeleteCustomerUser.cs b/Source/Partner Center SDK Samples/CustomerUser/DeleteCustomerUser.cs new file mode 100644 index 0000000..87dba96 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/DeleteCustomerUser.cs @@ -0,0 +1,43 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + /// + /// Deletes a customer user. + /// + public class DeleteCustomerUser : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public DeleteCustomerUser(IScenarioContext context) : base("Delete customer user", context) + { + } + + /// + /// Executes the delete customer user scenario. + /// + protected override void RunScenario() + { + // get customer user to delete. + string customerUserIdToDelete = this.ObtainCustomerUserIdDelete("Enter the ID of the customer user to delete"); + + // get customer Id of the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the corresponding customer whose customer user to delete"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Deleting customer user"); + + // delete customer user + partnerOperations.Customers.ById(selectedCustomerId).Users.ById(customerUserIdToDelete).Delete(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.Success("Customer User successfully deleted"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/GetCustomerInactiveUsers.cs b/Source/Partner Center SDK Samples/CustomerUser/GetCustomerInactiveUsers.cs new file mode 100644 index 0000000..e780315 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/GetCustomerInactiveUsers.cs @@ -0,0 +1,75 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using System; + using Models.Query; + + /// + /// Gets inactive customer users in pages. + /// + public class GetCustomerInactiveUsers : BasePartnerScenario + { + /// + /// The customer user page size. + /// + private int customerUserPageSize; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + /// The number of inactive customer users to return per page. + public GetCustomerInactiveUsers(IScenarioContext context, int customeruserPageSize = 0) : base("Get Paged inactive customer users", context) + { + this.customerUserPageSize = customeruserPageSize; + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + // get customer Id of the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to get all inactive customer users in pages"); + + var partnerOperations = this.Context.UserPartnerOperations; + + // get customer user page size + string customerUserPageSize = this.ObtainCustomerUserPageSize(); + this.customerUserPageSize = int.Parse(customerUserPageSize); + + var filter = new SimpleFieldFilter("UserStatus", FieldFilterOperation.Equals, "Inactive"); + + // Read inactive customer users in a batch + this.Context.ConsoleHelper.StartProgress("Querying first page of inactive customer users"); + var simpleQueryWithFilter = QueryFactory.Instance.BuildIndexedQuery(this.customerUserPageSize, 0, filter); + var customerUsers = partnerOperations.Customers.ById(selectedCustomerId).Users.Query(simpleQueryWithFilter); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.StartProgress("Creating customer user Enumerator"); + var customerUsersEnumerator = partnerOperations.Enumerators.CustomerUsers.Create(customerUsers); + this.Context.ConsoleHelper.StopProgress(); + + while (customerUsersEnumerator.HasValue) + { + // print the current customer user results + this.Context.ConsoleHelper.WriteObject(customerUsersEnumerator.Current); + + Console.WriteLine(); + Console.Write("Press any key to retrieve the next customer users page"); + Console.ReadKey(); + Console.WriteLine(); + Console.WriteLine("Getting Next Page"); + + // get the next page of customer users + customerUsersEnumerator.Next(); + Console.Clear(); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserCollection.cs b/Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserCollection.cs new file mode 100644 index 0000000..6cf8361 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserCollection.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + /// + /// Gets customer user collection. + /// + public class GetCustomerUserCollection : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerUserCollection(IScenarioContext context) : base("Get a customer user collection", context) + { + } + + /// + /// Executes the get customer user collection scenario. + /// + protected override void RunScenario() + { + // get customer Id. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to get customer user collection"); + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting customer users collection"); + + // get customer users collection + var customerUsers = partnerOperations.Customers.ById(selectedCustomerId).Users.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerUsers, "Customer Users collection"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserDetails.cs b/Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserDetails.cs new file mode 100644 index 0000000..28a3453 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserDetails.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + /// + /// Gets a single customer user details. + /// + public class GetCustomerUserDetails : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerUserDetails(IScenarioContext context) : base("Get a customer user details", context) + { + } + + /// + /// Executes the get customer user details scenario. + /// + protected override void RunScenario() + { + // get customer user Id. + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to get details"); + + // get customer Id of the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the corresponding customer to get customer user details"); + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting customer user detail"); + + // Get customer user detail + var selectedCustomerUser = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(selectedCustomerUser, "Customer User detail"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserDirectoryRoles.cs b/Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserDirectoryRoles.cs new file mode 100644 index 0000000..98ed051 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/GetCustomerUserDirectoryRoles.cs @@ -0,0 +1,50 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + /// + /// Gets customer user directory roles details. + /// + public class GetCustomerUserDirectoryRoles : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerUserDirectoryRoles(IScenarioContext context) : base("Get customer user directory roles", context) + { + } + + /// + /// Executes the get customer user directory roles scenario. + /// + protected override void RunScenario() + { + // get customer user Id. + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to get directory roles"); + + // get customer Id of the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the corresponding customer to get directory roles of customer user"); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting selected customer user"); + + // get customer user. + var selectedCustomerUser = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(selectedCustomerUser, "Selected Customer User"); + this.Context.ConsoleHelper.StartProgress("Getting customer user directory roles"); + + // get customer user directory roles. + var userMemberships = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).DirectoryRoles.Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(userMemberships, "Customer User directory roles"); + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/GetPagedCustomerUsers.cs b/Source/Partner Center SDK Samples/CustomerUser/GetPagedCustomerUsers.cs new file mode 100644 index 0000000..73a81d3 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/GetPagedCustomerUsers.cs @@ -0,0 +1,75 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using System; + using System.Globalization; + using Models.Query; + + /// + /// Gets customer users in pages. + /// + public class GetPagedCustomerUsers : BasePartnerScenario + { + /// + /// The customer user page size. + /// + private int customerUserPageSize; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + /// The number of customer users to return per page. + public GetPagedCustomerUsers(IScenarioContext context, int customeruserPageSize = 0) : base("Get Paged customer users", context) + { + this.customerUserPageSize = customeruserPageSize; + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + // get customer Id of the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to get all customer users in pages"); + + var partnerOperations = this.Context.UserPartnerOperations; + + // get customer user page size + string customerUserPageSize = this.ObtainCustomerUserPageSize(); + this.customerUserPageSize = int.Parse(customerUserPageSize); + + this.Context.ConsoleHelper.StartProgress("Querying first page of customer users"); + + // query the customers, get the first page if a page size was set, otherwise get all customers + var customerUsersPage = (this.customerUserPageSize <= 0) ? partnerOperations.Customers.ById(selectedCustomerId).Users.Get() : partnerOperations.Customers.ById(selectedCustomerId).Users.Query(QueryFactory.Instance.BuildIndexedQuery(this.customerUserPageSize)); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.StartProgress("Creating customer user Enumerator"); + + // create a customer user enumerator which will aid us in traversing the customer user pages + var customerUsersEnumerator = partnerOperations.Enumerators.CustomerUsers.Create(customerUsersPage); + this.Context.ConsoleHelper.StopProgress(); + int pageNumber = 1; + while (customerUsersEnumerator.HasValue) + { + // print the current customer user result page + this.Context.ConsoleHelper.WriteObject(customerUsersEnumerator.Current, string.Format(CultureInfo.InvariantCulture, "Customer User Page: {0}", pageNumber++)); + Console.WriteLine(); + Console.Write("Press any key to retrieve the next customer users page"); + Console.ReadKey(); + Console.WriteLine(); + Console.WriteLine("Getting Next Page"); + + // get the next page of customer users + customerUsersEnumerator.Next(); + Console.Clear(); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/CustomerUser/SortCustomerUsers.cs b/Source/Partner Center SDK Samples/CustomerUser/SortCustomerUsers.cs new file mode 100644 index 0000000..c109024 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/SortCustomerUsers.cs @@ -0,0 +1,58 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using System.Globalization; + using Models.Query; + + /// + /// Sorts the customer users. + /// + public class SortCustomerUsers : BasePartnerScenario + { + /// + /// The sort direction. + /// + private readonly SortDirection sortDirection; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario title. + /// The sort direction. + /// The scenario context. + public SortCustomerUsers(string title, SortDirection sortDirection, IScenarioContext context) : base(title, context) + { + this.sortDirection = sortDirection; + } + + /// + /// Executes the sort customer users scenario. + /// + protected override void RunScenario() + { + // get customer Id. + string selectedCustomerId = this.ObtainCustomerId("Enter the customer ID"); + var partnerOperations = this.Context.UserPartnerOperations; + + // get sort field. + string sortField = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the sort field (DisplayName,UserPrincipalName)", "The entered sort field is empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting customer users sorted by {0} in {1} order", sortField, this.sortDirection.ToString())); + + // get sorted customer users. + var customerUsers = partnerOperations.Customers + .ById(selectedCustomerId) + .Users + .Query(QueryFactory.Instance.BuildIndexedQuery(20, sortOption: new Sort(sortField, this.sortDirection))); + + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(customerUsers, string.Format(CultureInfo.InvariantCulture, "Sorted Customer Users by {0} in {1} order", sortField, this.sortDirection.ToString())); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/CustomerUser/UpdateCustomerUser.cs b/Source/Partner Center SDK Samples/CustomerUser/UpdateCustomerUser.cs new file mode 100644 index 0000000..66684d2 --- /dev/null +++ b/Source/Partner Center SDK Samples/CustomerUser/UpdateCustomerUser.cs @@ -0,0 +1,69 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.CustomerUser +{ + using System; + using Models.Users; + + /// + /// A scenario that updates a customer user. + /// + public class UpdateCustomerUser : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateCustomerUser(IScenarioContext context) : base("Update customer user", context) + { + } + + /// + /// Executes the update customer user scenario. + /// + protected override void RunScenario() + { + // get customer user Id. + string selectedCustomerUserId = this.ObtainCustomerUserId("Enter the ID of the customer user to update details"); + + // get customer Id of the entered customer user. + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the corresponding customer to update customer user"); + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting customer user"); + + // get customer user. + var selectedCustomerUser = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(selectedCustomerUser, "Selected customer User"); + + this.Context.ConsoleHelper.StartProgress("Getting customer"); + + // get customer. + var selectedCustomer = partnerOperations.Customers.ById(selectedCustomerId).Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(selectedCustomer, "Selected Customer"); + + var updatedCustomerUser = new CustomerUser() + { + PasswordProfile = new PasswordProfile() { ForceChangePassword = true, Password = "Password!1" }, + DisplayName = "Shubham Bharti", + FirstName = "Shubham", + LastName = "Bharti", + UsageLocation = "US", + UserPrincipalName = Guid.NewGuid().ToString("N") + "@" + selectedCustomer.CompanyProfile.Domain + }; + + this.Context.ConsoleHelper.StartProgress("Updating the customer user"); + + // update customer user information + var updatedCustomerUserInfo = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Patch(updatedCustomerUser); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedCustomerUserInfo, "Updated customer user information"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/CheckDomainAvailability.cs b/Source/Partner Center SDK Samples/Customers/CheckDomainAvailability.cs new file mode 100644 index 0000000..bdbdc2c --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/CheckDomainAvailability.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + /// + /// A scenario that checks if a domain is still available for a customer or not. + /// + public class CheckDomainAvailability : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CheckDomainAvailability(IScenarioContext context) : base("Check domain availability", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string domainPrefix = this.Context.ConsoleHelper.ReadNonEmptyString("Enter a domain prefix to check its availability", "The entered domain is empty"); + + this.Context.ConsoleHelper.StartProgress("Checking"); + bool isDomainAvailable = !partnerOperations.Domains.ByDomain(domainPrefix).Exists(); + this.Context.ConsoleHelper.StopProgress(); + + if (isDomainAvailable) + { + this.Context.ConsoleHelper.Success("This domain prefix is available!"); + } + else + { + this.Context.ConsoleHelper.Warning("This domain prefix is unavailable."); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/CreateCustomer.cs b/Source/Partner Center SDK Samples/Customers/CreateCustomer.cs new file mode 100644 index 0000000..65e053c --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/CreateCustomer.cs @@ -0,0 +1,70 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + using System; + using System.Globalization; + using Store.PartnerCenter.Models; + using Store.PartnerCenter.Models.Customers; + + /// + /// Creates a new customer for a partner. + /// + public class CreateCustomer : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CreateCustomer(IScenarioContext context) : base("Create a new customer", context) + { + } + + /// + /// Executes the create customer scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + var customerToCreate = new Customer() + { + CompanyProfile = new CustomerCompanyProfile() + { + Domain = string.Format(CultureInfo.InvariantCulture, "SampleApplication{0}.{1}", new Random().Next(), this.Context.Configuration.Scenario.CustomerDomainSuffix) + }, + BillingProfile = new CustomerBillingProfile() + { + Culture = "en-US", + Email = "gena@relecloud2.com", + Language = "en", + CompanyName = "Relecloud" + new Random().Next(), + DefaultAddress = new Address() + { + FirstName = "Gena", + LastName = "Soto", + AddressLine1 = "4567 Main Street", + City = "Redmond", + State = "WA", + Country = "US", + PhoneNumber = "4255550101", + PostalCode = "98052" + } + } + }; + + this.Context.ConsoleHelper.WriteObject(customerToCreate, "New user Information"); + this.Context.ConsoleHelper.StartProgress("Creating user"); + + var newCustomer = partnerOperations.Customers.Create(customerToCreate); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.Success("Success!"); + this.Context.ConsoleHelper.WriteObject(newCustomer, "Created user Information"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/DeleteCustomerFromTipAccount.cs b/Source/Partner Center SDK Samples/Customers/DeleteCustomerFromTipAccount.cs new file mode 100644 index 0000000..fde8d1a --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/DeleteCustomerFromTipAccount.cs @@ -0,0 +1,50 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + using System; + + /// + /// Deletes a customer from a testing in production account. + /// + public class DeleteCustomerFromTipAccount : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public DeleteCustomerFromTipAccount(IScenarioContext context) : base("Delete customer from TIP account", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + string customerIdToDelete = this.Context.Configuration.Scenario.CustomerIdToDelete; + + if (string.IsNullOrWhiteSpace(customerIdToDelete)) + { + // prompt the user the enter the customer ID + customerIdToDelete = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the ID of the customer to delete", "The customer ID can't be empty"); + } + else + { + Console.WriteLine("Found customer ID: {0} in configuration.", customerIdToDelete); + } + + var partnerOperations = this.Context.AppPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Deleting customer"); + partnerOperations.Customers.ById(customerIdToDelete).Delete(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.Success("Customer successfully deleted"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/DeletePartnerCustomerRelationship.cs b/Source/Partner Center SDK Samples/Customers/DeletePartnerCustomerRelationship.cs new file mode 100644 index 0000000..3179442 --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/DeletePartnerCustomerRelationship.cs @@ -0,0 +1,70 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + using System.Collections.Generic; + using Models; + using Models.Customers; + using Models.Subscriptions; + + /// + /// Deletes a partner customer Relationship production account. + /// + public class DeletePartnerCustomerRelationship : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public DeletePartnerCustomerRelationship(IScenarioContext context) : base("Delete Partner Relationship", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + // prompt the user the enter the customer ID + var customerIdToDeleteRelationshipOf = this.Context.ConsoleHelper.ReadNonEmptyString("Please enter the ID of the customer you want to delete the relationship with", "The customer ID can't be empty"); + + // Verify that there are no active subscriptions + ResourceCollection customerSubscriptions = partnerOperations.Customers.ById(customerIdToDeleteRelationshipOf).Subscriptions.Get(); + IList subscriptions = new List(customerSubscriptions.Items); + + foreach (Subscription customerSubscription in subscriptions) + { + if (customerSubscription.Status == SubscriptionStatus.Active) + { + this.Context.ConsoleHelper.Warning(string.Format("Subscription with ID :{0} OfferName: {1} cannot be in active state, ", customerSubscription.Id, customerSubscription.OfferName)); + this.Context.ConsoleHelper.Warning("Please Suspend all the Subscriptions and try again. Aborting the delete customer relationship operation"); + this.Context.ConsoleHelper.StopProgress(); + return; + } + } + + // Delete the customer relationship to partner + this.Context.ConsoleHelper.StartProgress("Deleting customer Partner Relationship"); + + Customer customer = new Customer + { + RelationshipToPartner = CustomerPartnerRelationship.None + }; + + customer = partnerOperations.Customers.ById(customerIdToDeleteRelationshipOf).Patch(customer); + + if (customer.RelationshipToPartner == CustomerPartnerRelationship.None) + { + this.Context.ConsoleHelper.Success("Customer Partner Relationship successfully deleted"); + } + + this.Context.ConsoleHelper.StopProgress(); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Customers/FilterCustomers.cs b/Source/Partner Center SDK Samples/Customers/FilterCustomers.cs new file mode 100644 index 0000000..3f62183 --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/FilterCustomers.cs @@ -0,0 +1,56 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + using Store.PartnerCenter.Models.Customers; + using Store.PartnerCenter.Models.Query; + + /// + /// Returns customers according to a provided filter. + /// + public class FilterCustomers : BasePartnerScenario + { + /// + /// The search field. + /// + private readonly CustomerSearchField customerSearchField; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario title. + /// The search field. + /// The scenario context. + public FilterCustomers(string title, CustomerSearchField customerSearchField, IScenarioContext context) : base(title, context) + { + this.customerSearchField = customerSearchField; + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string searchPrefix = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the prefix to search for", "The entered prefix is empty"); + + this.Context.ConsoleHelper.StartProgress("Filtering"); + + var fieldFilter = new SimpleFieldFilter( + this.customerSearchField.ToString(), + FieldFilterOperation.StartsWith, + searchPrefix); + + var myQuery = QueryFactory.Instance.BuildSimpleQuery(fieldFilter); + + var customers = partnerOperations.Customers.Query(myQuery); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customers, "Customer matches"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/GetCustomerDetails.cs b/Source/Partner Center SDK Samples/Customers/GetCustomerDetails.cs new file mode 100644 index 0000000..003753f --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/GetCustomerDetails.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + /// + /// Gets a single customer details. + /// + public class GetCustomerDetails : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerDetails(IScenarioContext context) : base("Get a customer details", context) + { + } + + /// + /// Executes the get customer details scenario. + /// + protected override void RunScenario() + { + string customerIdToRetrieve = this.ObtainCustomerId("Enter the ID of the customer to retrieve"); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Retrieving customer"); + + var customerDetails = partnerOperations.Customers.ById(customerIdToRetrieve).Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerDetails, "Customer details"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/GetCustomerManagedServices.cs b/Source/Partner Center SDK Samples/Customers/GetCustomerManagedServices.cs new file mode 100644 index 0000000..5c738c4 --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/GetCustomerManagedServices.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + /// + /// Gets a customer list of managed services. + /// + public class GetCustomerManagedServices : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerManagedServices(IScenarioContext context) : base("Get customer managed services", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + string customerId = this.ObtainCustomerId(); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting the customer's managed services"); + + var managedServices = partnerOperations.Customers.ById(customerId).ManagedServices.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(managedServices, "Customer managed services"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/GetCustomerQualification.cs b/Source/Partner Center SDK Samples/Customers/GetCustomerQualification.cs new file mode 100644 index 0000000..080bc9f --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/GetCustomerQualification.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + /// + /// Gets a single customer qualification. + /// + public class GetCustomerQualification : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerQualification(IScenarioContext context) : base("Get customer qualification", context) + { + } + + /// + /// Executes the get customer qualification scenario. + /// + protected override void RunScenario() + { + string customerIdToRetrieve = this.ObtainCustomerId("Enter the ID of the customer to retrieve qualification for"); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Retrieving customer qualification"); + + var customerQualification = partnerOperations.Customers.ById(customerIdToRetrieve).Qualification.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerQualification, "Customer Qualification"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/GetCustomerRelationshipRequest.cs b/Source/Partner Center SDK Samples/Customers/GetCustomerRelationshipRequest.cs new file mode 100644 index 0000000..60112bd --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/GetCustomerRelationshipRequest.cs @@ -0,0 +1,36 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + /// + /// Gets the request which establishes a relationship between the partner and their customers. + /// + public class GetCustomerRelationshipRequest : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerRelationshipRequest(IScenarioContext context) : base("Get customer relationship request", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Retrieving customer relationship request"); + var customerRelationshipRequest = partnerOperations.Customers.RelationshipRequest.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerRelationshipRequest, "Customer relationship request"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/GetPagedCustomers.cs b/Source/Partner Center SDK Samples/Customers/GetPagedCustomers.cs new file mode 100644 index 0000000..25d07d8 --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/GetPagedCustomers.cs @@ -0,0 +1,68 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + using System; + using System.Globalization; + using Store.PartnerCenter.Models.Query; + + /// + /// Gets a partner customers in pages. + /// + public class GetPagedCustomers : BasePartnerScenario + { + /// + /// The customer page size. + /// + private readonly int customerPageSize; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + /// The number of customers to return per page. + public GetPagedCustomers(IScenarioContext context, int customerPageSize = 0) : base("Get Paged customers", context) + { + this.customerPageSize = customerPageSize; + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Querying customers"); + + // query the customers, get the first page if a page size was set, otherwise get all customers + var customersPage = (this.customerPageSize <= 0) ? partnerOperations.Customers.Get() : partnerOperations.Customers.Query(QueryFactory.Instance.BuildIndexedQuery(this.customerPageSize)); + this.Context.ConsoleHelper.StopProgress(); + + // create a customer enumerator which will aid us in traversing the customer pages + var customersEnumerator = partnerOperations.Enumerators.Customers.Create(customersPage); + int pageNumber = 1; + + while (customersEnumerator.HasValue) + { + // print the current customer results page + this.Context.ConsoleHelper.WriteObject(customersEnumerator.Current, string.Format(CultureInfo.InvariantCulture, "Customer Page: {0}", pageNumber++)); + + Console.WriteLine(); + Console.Write("Press any key to retrieve the next customers page"); + Console.ReadKey(); + + this.Context.ConsoleHelper.StartProgress("Getting next customers page"); + + // get the next page of customers + customersEnumerator.Next(); + + this.Context.ConsoleHelper.StopProgress(); + Console.Clear(); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/UpdateCustomerBillingProfile.cs b/Source/Partner Center SDK Samples/Customers/UpdateCustomerBillingProfile.cs new file mode 100644 index 0000000..842c5a0 --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/UpdateCustomerBillingProfile.cs @@ -0,0 +1,51 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + /// + /// A scenario that updates a customer's billing profile. + /// + public class UpdateCustomerBillingProfile : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateCustomerBillingProfile(IScenarioContext context) : base("Update customer billing profile", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + string customerId = this.ObtainCustomerId(); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting customer billing profile"); + + var billingProfile = partnerOperations.Customers.ById(customerId).Profiles.Billing.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(billingProfile, "Customer billing profile"); + + this.Context.ConsoleHelper.StartProgress("Updating the customer billing profile"); + + // append some A's to some of the customer's billing profile properties + billingProfile.FirstName = billingProfile.FirstName + "A"; + billingProfile.LastName = billingProfile.LastName + "A"; + billingProfile.CompanyName = billingProfile.CompanyName + "A"; + + // update the billing profile + var updatedBillingProfile = partnerOperations.Customers.ById(customerId).Profiles.Billing.Update(billingProfile); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedBillingProfile, "Updated customer billing profile"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/UpdateCustomerQualification.cs b/Source/Partner Center SDK Samples/Customers/UpdateCustomerQualification.cs new file mode 100644 index 0000000..c1a4695 --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/UpdateCustomerQualification.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + using Microsoft.Store.PartnerCenter.Models.Customers; + + /// + /// Updates a single customer qualification. + /// + public class UpdateCustomerQualification : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateCustomerQualification(IScenarioContext context) : base("Update customer qualification", context) + { + } + + /// + /// Executes the update customer qualification scenario. + /// + protected override void RunScenario() + { + string customerIdToRetrieve = this.ObtainCustomerId($"Enter the ID of the customer to update qualification to {CustomerQualification.Education}"); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Updating customer qualification"); + + var customerQualification = + partnerOperations.Customers.ById(customerIdToRetrieve) + .Qualification.Update(CustomerQualification.Education); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerQualification, "Customer Qualification"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Customers/ValidateCustomerAddress.cs b/Source/Partner Center SDK Samples/Customers/ValidateCustomerAddress.cs new file mode 100644 index 0000000..a627af9 --- /dev/null +++ b/Source/Partner Center SDK Samples/Customers/ValidateCustomerAddress.cs @@ -0,0 +1,36 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + /// + /// A scenario that showcases country validation rules. + /// + public class ValidateCustomerAddress : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public ValidateCustomerAddress(IScenarioContext context) : base("Validate customer address.", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code to get its validation rules", "The country code can't be empty"); + + this.Context.ConsoleHelper.StartProgress("Retrieving country validation rules"); + var countryValidationRules = partnerOperations.CountryValidationRules.ByCountry(countryCode).Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(countryValidationRules, " Country validation rules"); + } + } +} diff --git a/Source/Partner Center SDK Samples/DevicesDeployment/CreateConfigurationPolicy.cs b/Source/Partner Center SDK Samples/DevicesDeployment/CreateConfigurationPolicy.cs new file mode 100644 index 0000000..b5bcc40 --- /dev/null +++ b/Source/Partner Center SDK Samples/DevicesDeployment/CreateConfigurationPolicy.cs @@ -0,0 +1,50 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.DevicesDeployment +{ + using System.Collections.Generic; + using Microsoft.Store.PartnerCenter.Models.DevicesDeployment; + + /// + /// Creates a new configuration policy for devices. + /// + public class CreateConfigurationPolicy : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CreateConfigurationPolicy(IScenarioContext context) : base("Create a new configuration policy", context) + { + } + + /// + /// Executes the create configuration policy scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to create the configuration policy for"); + + var configurationPolicyToCreate = new ConfigurationPolicy + { + Name = "Test Config Policy", + Description = "This configuration policy is created by the SDK samples", + PolicySettings = new List() { PolicySettingsType.OobeUserNotLocalAdmin, PolicySettingsType.SkipEula } + }; + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.WriteObject(configurationPolicyToCreate, "New configuration policy Information"); + this.Context.ConsoleHelper.StartProgress("Creating Configuration Policy"); + + var createdConfigurationPolicy = partnerOperations.Customers.ById(selectedCustomerId).ConfigurationPolicies.Create(configurationPolicyToCreate); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.Success("Success!"); + this.Context.ConsoleHelper.WriteObject(createdConfigurationPolicy, "Created configuration policy Information"); + } + } +} diff --git a/Source/Partner Center SDK Samples/DevicesDeployment/CreateDeviceBatch.cs b/Source/Partner Center SDK Samples/DevicesDeployment/CreateDeviceBatch.cs new file mode 100644 index 0000000..7483d11 --- /dev/null +++ b/Source/Partner Center SDK Samples/DevicesDeployment/CreateDeviceBatch.cs @@ -0,0 +1,60 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.DevicesDeployment +{ + using System.Collections.Generic; + using Microsoft.Store.PartnerCenter.Models.DevicesDeployment; + + /// + /// Creates a new device batch with devices. + /// + public class CreateDeviceBatch : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CreateDeviceBatch(IScenarioContext context) : base("Create a new Device Batch", context) + { + } + + /// + /// Executes the create device batch scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to create the device batch for"); + + List devicesToBeUploaded = new List + { + new Device + { + HardwareHash = "DummyHash123", + ProductKey = "00329-00000-0003-AA606", + SerialNumber = "1R9-ZNP67" + } + }; + + DeviceBatchCreationRequest newDeviceBatch = new DeviceBatchCreationRequest + { + BatchId = "SDKTestDeviceBatch", + Devices = devicesToBeUploaded + }; + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.WriteObject(newDeviceBatch, "New Device Batch"); + this.Context.ConsoleHelper.StartProgress("Creating Device Batch"); + + var trackingLocation = partnerOperations.Customers.ById(selectedCustomerId).DeviceBatches.Create(newDeviceBatch); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(trackingLocation, "Tracking Location to track the status"); + this.Context.ConsoleHelper.Success("Create Device Batch Request submitted successfully!"); + } + } +} diff --git a/Source/Partner Center SDK Samples/DevicesDeployment/CreateDevices.cs b/Source/Partner Center SDK Samples/DevicesDeployment/CreateDevices.cs new file mode 100644 index 0000000..f40aa00 --- /dev/null +++ b/Source/Partner Center SDK Samples/DevicesDeployment/CreateDevices.cs @@ -0,0 +1,63 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.DevicesDeployment +{ + using System.Collections.Generic; + using Microsoft.Store.PartnerCenter.Models.DevicesDeployment; + + /// + /// Creates new devices under an existing device batch. + /// + public class CreateDevices : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CreateDevices(IScenarioContext context) : base("Create new Devices", context) + { + } + + /// + /// Executes the create device batch scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to create the devices for"); + + string selectedDeviceBatchId = this.ObtainDeviceBatchId("Enter the ID of the Device batch to add the devices to"); + + var partnerOperations = this.Context.UserPartnerOperations; + + List devicesToBeUploaded = new List + { + new Device + { + HardwareHash = "DummyHash1234", + ProductKey = "00329-00000-0003-AA606", + SerialNumber = "2R9-ZNP67" + }, + + new Device + { + HardwareHash = "DummyHash12345", + ProductKey = "00329-00000-0003-AA606", + SerialNumber = "2R9-ZNP67" + } + }; + + this.Context.ConsoleHelper.WriteObject(devicesToBeUploaded, "New Devices"); + this.Context.ConsoleHelper.StartProgress("Creating Devices"); + + var trackingLocation = partnerOperations.Customers.ById(selectedCustomerId).DeviceBatches.ById(selectedDeviceBatchId).Devices.Create(devicesToBeUploaded); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(trackingLocation, "Tracking Location to track the status"); + this.Context.ConsoleHelper.Success("Create Devices Request submitted successfully!"); + } + } +} diff --git a/Source/Partner Center SDK Samples/DevicesDeployment/DeleteConfigurationPolicy.cs b/Source/Partner Center SDK Samples/DevicesDeployment/DeleteConfigurationPolicy.cs new file mode 100644 index 0000000..b1fe6b6 --- /dev/null +++ b/Source/Partner Center SDK Samples/DevicesDeployment/DeleteConfigurationPolicy.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.DevicesDeployment +{ + /// + /// Deletes a configuration policy. + /// + public class DeleteConfigurationPolicy : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public DeleteConfigurationPolicy(IScenarioContext context) : base("Delete a configuration policy", context) + { + } + + /// + /// Executes the create device batch scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to delete a configuration policy"); + + string selectedPolicyId = this.ObtainConfigurationPolicyId("Enter the ID of the configuration policy to delete"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.WriteObject(selectedPolicyId, "Configuration policy to be deleted"); + this.Context.ConsoleHelper.StartProgress("Deleting Configuration policy"); + + partnerOperations.Customers.ById(selectedCustomerId).ConfigurationPolicies.ById(selectedPolicyId).Delete(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.Success("Delete Configuration policy request submitted successfully!"); + } + } +} diff --git a/Source/Partner Center SDK Samples/DevicesDeployment/DeleteDevice.cs b/Source/Partner Center SDK Samples/DevicesDeployment/DeleteDevice.cs new file mode 100644 index 0000000..d37e684 --- /dev/null +++ b/Source/Partner Center SDK Samples/DevicesDeployment/DeleteDevice.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.DevicesDeployment +{ + /// + /// Deletes a device. + /// + public class DeleteDevice : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public DeleteDevice(IScenarioContext context) : base("Deletes a device", context) + { + } + + /// + /// Executes the delete device scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to delete a device"); + + string selectedDeviceBatchId = this.ObtainDeviceBatchId("Enter the ID of the Device batch to retrieve the devices of"); + + string selectedDeviceId = this.ObtainDeviceId("Enter the ID of the device to delete"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.WriteObject(selectedDeviceId, "Device to be deleted"); + this.Context.ConsoleHelper.StartProgress("Deleting device"); + + partnerOperations.Customers.ById(selectedCustomerId).DeviceBatches.ById(selectedDeviceBatchId).Devices.ById(selectedDeviceId).Delete(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.Success("Deleted the device successfully!"); + } + } +} diff --git a/Source/Partner Center SDK Samples/DevicesDeployment/GetAllConfigurationPolicies.cs b/Source/Partner Center SDK Samples/DevicesDeployment/GetAllConfigurationPolicies.cs new file mode 100644 index 0000000..02020a9 --- /dev/null +++ b/Source/Partner Center SDK Samples/DevicesDeployment/GetAllConfigurationPolicies.cs @@ -0,0 +1,39 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.DevicesDeployment +{ + /// + /// Gets all configuration policies of a customer. + /// + public class GetAllConfigurationPolicies : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetAllConfigurationPolicies(IScenarioContext context) : base("Get all configuration policies", context) + { + } + + /// + /// Executes get all configuration policies scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the ID of the customer to get the configuration policies"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Querying Configuration policies"); + + var configPolicies = partnerOperations.Customers.ById(selectedCustomerId).ConfigurationPolicies.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(configPolicies, "Configuration Policies"); + } + } +} diff --git a/Source/Partner Center SDK Samples/DevicesDeployment/GetBatchUploadStatus.cs b/Source/Partner Center SDK Samples/DevicesDeployment/GetBatchUploadStatus.cs new file mode 100644 index 0000000..d95d762 --- /dev/null +++ b/Source/Partner Center SDK Samples/DevicesDeployment/GetBatchUploadStatus.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.DevicesDeployment +{ + /// + /// Gets batch upload status. + /// + public class GetBatchUploadStatus : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetBatchUploadStatus(IScenarioContext context) : base("Get Batch Upload Status", context) + { + } + + /// + /// Executes the create device batch scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the Customer Id to get the status for"); + + string selectedTrackingId = this.ObtainBatchUploadStatusTrackingId("Enter the batch upload status tracking Id to get the status of"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Querying the status"); + + var status = partnerOperations.Customers.ById(selectedCustomerId).BatchUploadStatus.ById(selectedTrackingId).Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(status, "Tracking Status"); + } + } +} diff --git a/Source/Partner Center SDK Samples/DevicesDeployment/GetDevices.cs b/Source/Partner Center SDK Samples/DevicesDeployment/GetDevices.cs new file mode 100644 index 0000000..0fdf4e0 --- /dev/null +++ b/Source/Partner Center SDK Samples/DevicesDeployment/GetDevices.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.DevicesDeployment +{ + /// + /// Gets devices of a device batch. + /// + public class GetDevices : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetDevices(IScenarioContext context) : base("Get Devices", context) + { + } + + /// + /// Executes the create device batch scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the Customer Id to get the devices for"); + + string selectedDeviceBatchId = this.ObtainDeviceBatchId("Enter the ID of the Device batch to retrieve the devices of"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Querying for the devices"); + + var devices = partnerOperations.Customers.ById(selectedCustomerId).DeviceBatches.ById(selectedDeviceBatchId).Devices.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(devices, "Devices"); + } + } +} diff --git a/Source/Partner Center SDK Samples/DevicesDeployment/GetDevicesBatches.cs b/Source/Partner Center SDK Samples/DevicesDeployment/GetDevicesBatches.cs new file mode 100644 index 0000000..57c5c7f --- /dev/null +++ b/Source/Partner Center SDK Samples/DevicesDeployment/GetDevicesBatches.cs @@ -0,0 +1,39 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.DevicesDeployment +{ + /// + /// Gets devices batches. + /// + public class GetDevicesBatches : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetDevicesBatches(IScenarioContext context) : base("Get Devices Batches", context) + { + } + + /// + /// Executes the create device batch scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the Customer Id to get the devices batches for"); + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Querying for the devices batches"); + + var devicesBatches = partnerOperations.Customers.ById(selectedCustomerId).DeviceBatches.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(devicesBatches, "Device Batches"); + } + } +} diff --git a/Source/Partner Center SDK Samples/DevicesDeployment/UpdateConfigurationPolicy.cs b/Source/Partner Center SDK Samples/DevicesDeployment/UpdateConfigurationPolicy.cs new file mode 100644 index 0000000..b93270d --- /dev/null +++ b/Source/Partner Center SDK Samples/DevicesDeployment/UpdateConfigurationPolicy.cs @@ -0,0 +1,51 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.DevicesDeployment +{ + using System.Collections.Generic; + using Microsoft.Store.PartnerCenter.Models.DevicesDeployment; + + /// + /// Updates configuration policy. + /// + public class UpdateConfigurationPolicy : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateConfigurationPolicy(IScenarioContext context) : base("Update configuration policy", context) + { + } + + /// + /// Executes the update configuration policy scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the Customer Id to update the configuration policy for"); + + string selectedConfigurationPolicyId = this.ObtainConfigurationPolicyId("Enter the ID of the Configuration Policy to update"); + + ConfigurationPolicy configPolicyToBeUpdated = new ConfigurationPolicy() + { + Name = "Test Config Policy", + Id = selectedConfigurationPolicyId, + PolicySettings = new List() { PolicySettingsType.OobeUserNotLocalAdmin, PolicySettingsType.RemoveOemPreinstalls } + }; + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Updating Configuration Policy"); + + ConfigurationPolicy updatedConfigurationPolicy = partnerOperations.Customers.ById(selectedCustomerId).ConfigurationPolicies.ById(selectedConfigurationPolicyId).Patch(configPolicyToBeUpdated); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedConfigurationPolicy, "Updated Configuration Policy"); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/DevicesDeployment/UpdateDevicesPolicy.cs b/Source/Partner Center SDK Samples/DevicesDeployment/UpdateDevicesPolicy.cs new file mode 100644 index 0000000..e1a9983 --- /dev/null +++ b/Source/Partner Center SDK Samples/DevicesDeployment/UpdateDevicesPolicy.cs @@ -0,0 +1,66 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.DevicesDeployment +{ + using System.Collections.Generic; + using Microsoft.Store.PartnerCenter.Models.DevicesDeployment; + + /// + /// Updates devices with configuration policy. + /// + public class UpdateDevicesPolicy : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateDevicesPolicy(IScenarioContext context) : base("Update configuration policy of devices", context) + { + } + + /// + /// Executes the update devices scenario. + /// + protected override void RunScenario() + { + string selectedCustomerId = this.ObtainCustomerId("Enter the Customer Id to update the devices for"); + + string selectedConfigurationPolicyId = this.ObtainConfigurationPolicyId("Enter the ID of the Configuration Policy to update the device with"); + + string selectedDeviceId = this.ObtainDeviceId("Enter the Device Id to update"); + + List> policyToBeAdded = new List> + { + new KeyValuePair(PolicyCategory.OOBE, selectedConfigurationPolicyId) + }; + + List devices = new List + { + new Device + { + Id = selectedDeviceId, + Policies = policyToBeAdded + } + }; + + DevicePolicyUpdateRequest devicePolicyUpdateRequest = new DevicePolicyUpdateRequest + { + Devices = devices + }; + + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Updating Devices with Configuration Policy"); + + var trackingLocation = partnerOperations.Customers.ById(selectedCustomerId).DevicePolicy.Update(devicePolicyUpdateRequest); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(trackingLocation, "Tracking Location to track the status"); + this.Context.ConsoleHelper.Success("Update Devices Request submitted successfully!"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Entitlements/GetEntitlements.cs b/Source/Partner Center SDK Samples/Entitlements/GetEntitlements.cs new file mode 100644 index 0000000..50c0d1d --- /dev/null +++ b/Source/Partner Center SDK Samples/Entitlements/GetEntitlements.cs @@ -0,0 +1,70 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Entitlements +{ + using System; + using System.Linq; + using Models.Entitlements; + + /// + /// Get customer entitlements. + /// + public class GetEntitlements : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetEntitlements(IScenarioContext context) : base("Get entitlements", context) + { + } + + /// + /// Executes the get customer entitlements scenario. + /// + protected override void RunScenario() + { + string customerIdToRetrieve = this.ObtainCustomerId("Enter the ID of the customer to retrieve entitlements for"); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Retrieving customer entitlements"); + + var entitlements = partnerOperations.Customers.ById(customerIdToRetrieve).Entitlements.Get(); + this.Context.ConsoleHelper.StopProgress(); + + foreach (var entitlement in entitlements.Items) + { + this.Context.ConsoleHelper.WriteObject(entitlement, "Entitlement details"); + + try + { + switch (entitlement.EntitlementType.ToLowerInvariant()) + { + case "reservedinstance": + var reservedInstanceArtifactDetailsLink = + ((ReservedInstanceArtifact)entitlement.EntitledArtifacts.FirstOrDefault(x => string.Equals(x.ArtifactType, "ReservedInstance", StringComparison.OrdinalIgnoreCase)))?.Link; + + if (reservedInstanceArtifactDetailsLink != null) + { + var reservedInstanceArtifactDetails = + reservedInstanceArtifactDetailsLink + .InvokeAsync(partnerOperations) + .Result; + this.Context.ConsoleHelper.WriteObject(reservedInstanceArtifactDetails); + } + + break; + } + } + catch (Exception ex) + { + this.Context.ConsoleHelper.WriteObject(ex.Message, "Artifact Details"); + } + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Helpers/ConsoleHelper.cs b/Source/Partner Center SDK Samples/Helpers/ConsoleHelper.cs new file mode 100644 index 0000000..069878e --- /dev/null +++ b/Source/Partner Center SDK Samples/Helpers/ConsoleHelper.cs @@ -0,0 +1,311 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Helpers +{ + using System; + using System.Collections; + using System.Globalization; + using System.Reflection; + using System.Threading; + using System.Threading.Tasks; + using Store.PartnerCenter.Models; + + /// + /// Provides useful helpers that aid in writing to the console. + /// + public class ConsoleHelper : IDisposable + { + /// + /// A lazy reference to the singleton console helper instance. + /// + private static Lazy instance = new Lazy(() => new ConsoleHelper()); + + /// + /// A task that displays progress indicator on the console. + /// + private Task progressBackgroundTask; + + /// + /// A token source which controls cancelling the progress indicator. + /// + private CancellationTokenSource progressCancellationTokenSource = new CancellationTokenSource(); + + /// + /// Prevents a default instance of the class from being created. + /// + private ConsoleHelper() + { + } + + /// + /// Gets the single instance of the . + /// + public static ConsoleHelper Instance + { + get + { + return ConsoleHelper.instance.Value; + } + } + + /// + /// Writes a success message to the console. + /// + /// The message to write. + /// Whether or not to write a new line after the message. + public void Success(string message, bool newLine = true) + { + this.WriteColored(message, ConsoleColor.Green, newLine); + } + + /// + /// Writes a progress message to the console and starts a progress animation. + /// + /// The progress message to write. + public void StartProgress(string message) + { + if (this.progressBackgroundTask == null || this.progressBackgroundTask.Status != TaskStatus.Running) + { + this.progressBackgroundTask = new Task(() => + { + int dotCounter = 0; + + while (!this.progressCancellationTokenSource.Token.IsCancellationRequested) + { + var initialCursorPositionX = Console.CursorLeft; + var initialCursorPositionY = Console.CursorTop; + + for (dotCounter = 0; dotCounter < 5; dotCounter++) + { + this.WriteColored(".", ConsoleColor.DarkCyan, false); + Thread.Sleep(200); + + if (this.progressCancellationTokenSource.Token.IsCancellationRequested) + { + return; + } + } + + // Erase dots. + Console.SetCursorPosition(initialCursorPositionX, initialCursorPositionY); + for (int i = 0; i < dotCounter; ++i) + { + Console.Write(" "); + } + + Console.SetCursorPosition(initialCursorPositionX, initialCursorPositionY); + } + }); + + Console.WriteLine(); + this.WriteColored(message, ConsoleColor.DarkCyan, false); + this.progressBackgroundTask.Start(); + } + } + + /// + /// Stops the progress animation. + /// + public void StopProgress() + { + if (this.progressBackgroundTask != null && this.progressBackgroundTask.Status == TaskStatus.Running) + { + this.progressCancellationTokenSource.Cancel(); + this.progressBackgroundTask.Wait(); + this.progressBackgroundTask.Dispose(); + this.progressBackgroundTask = null; + + this.progressCancellationTokenSource.Dispose(); + this.progressCancellationTokenSource = new CancellationTokenSource(); + + Console.WriteLine(); + Console.WriteLine(); + } + } + + /// + /// Writes a warning message to the console. + /// + /// The message to write. + /// Whether or not to write a new line after the message. + public void Warning(string message, bool newLine = true) + { + this.WriteColored(message, ConsoleColor.Yellow, newLine); + } + + /// + /// Writes an error message to the console. + /// + /// The message to write. + /// Whether or not to write a new line after the message. + public void Error(string message, bool newLine = true) + { + this.WriteColored(message, ConsoleColor.Red, newLine); + } + + /// + /// Writes a message with the requested color to the console. + /// + /// The message to write. + /// The console color to use. + /// Whether or not to write a new line after the message. + public void WriteColored(string message, ConsoleColor color, bool newLine = true) + { + Console.ForegroundColor = color; + Console.Write(message + (newLine ? "\n" : string.Empty)); + Console.ResetColor(); + } + + /// + /// Reads a non empty string from the console. + /// + /// The prompt message to display. + /// The error message to show in case of user input error. + /// The string input from the console. + public string ReadNonEmptyString(string promptMessage, string validationMessage = default(string)) + { + string input = string.Empty; + validationMessage = validationMessage ?? "Enter a non-empty value"; + + while (true) + { + Console.Write("{0}: ", promptMessage); + input = Console.ReadLine(); + + if (string.IsNullOrWhiteSpace(input)) + { + this.Error(validationMessage); + } + else + { + break; + } + } + + return input; + } + + /// + /// Reads a string from the console (it can be empty as it is intended to be used with optional values). + /// + /// The prompt message to display. + /// The string input from the console. + public string ReadOptionalString(string promptMessage) + { + string input = string.Empty; + Console.Write("{0}: ", promptMessage); + input = Console.ReadLine(); + return input; + } + + /// + /// Writes an object and its properties recursively to the console. Properties are automatically indented. + /// + /// The object to print to the console. + /// An optional title to display. + /// The starting indentation. + public void WriteObject(object @object, string title = default(string), int indent = 0) + { + if (@object == null) + { + return; + } + + const int TabSize = 4; + bool isTitlePresent = !string.IsNullOrWhiteSpace(title); + string indentString = new string(' ', indent * TabSize); + Type objectType = @object.GetType(); + var collection = @object as ICollection; + + if (objectType.Assembly.FullName == typeof(ResourceBase).Assembly.FullName && objectType.IsClass) + { + // this is a partner SDK model class, iterate over it's properties recursively + if (indent == 0 && !string.IsNullOrWhiteSpace(title)) + { + Console.WriteLine(title); + Console.WriteLine(new string('-', 90)); + } + else if (isTitlePresent) + { + this.WriteColored(string.Format(CultureInfo.InvariantCulture, "{0}{1}: ", indentString, title), ConsoleColor.Yellow); + } + else + { + // since the current element does not have a title, we do not want to shift it's children causing a double shift appearance + // to the user + indent--; + } + + PropertyInfo[] properties = objectType.GetProperties(); + + foreach (PropertyInfo property in properties) + { + this.WriteObject(property.GetValue(@object), property.Name, indent + 1); + } + + if (indent == 0 && !string.IsNullOrWhiteSpace(title)) + { + Console.WriteLine(new string('-', 90)); + } + } + else if (collection != null) + { + // this is a collection, loop through its element and print them recursively + this.WriteColored(string.Format(CultureInfo.InvariantCulture, isTitlePresent ? "{0}{1}: " : string.Empty, indentString, title), ConsoleColor.Yellow); + + foreach (var element in collection) + { + this.WriteObject(element, indent: indent + 1); + var elementType = element.GetType(); + + if (indent == 1) + { + Console.WriteLine(new string('-', 80)); + } + } + } + else + { + // print the object as is + this.WriteColored(string.Format(CultureInfo.InvariantCulture, isTitlePresent ? "{0}{1}: " : "{0}", indentString, title), ConsoleColor.DarkYellow, false); + Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}", @object)); + } + } + + /// + /// Disposes of the console helper instance. + /// + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Disposes of the console helper instance. + /// + /// Whether to dispose the object or not. + private void Dispose(bool shouldDispose) + { + if (shouldDispose) + { + this.StopProgress(); + + if (this.progressBackgroundTask != null) + { + this.progressBackgroundTask.Dispose(); + } + + if (this.progressCancellationTokenSource != null) + { + this.progressCancellationTokenSource.Dispose(); + this.progressCancellationTokenSource = null; + } + } + } + } +} diff --git a/Source/Partner Center SDK Samples/IPartnerScenario.cs b/Source/Partner Center SDK Samples/IPartnerScenario.cs new file mode 100644 index 0000000..8612242 --- /dev/null +++ b/Source/Partner Center SDK Samples/IPartnerScenario.cs @@ -0,0 +1,36 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples +{ + using System.Collections.Generic; + + /// + /// Represents a partner scenario that demos one or more related partner center APIs. + /// + public interface IPartnerScenario + { + /// + /// Gets the scenario title. + /// + string Title { get; } + + /// + /// Gets the children scenarios of the current scenario. + /// + IReadOnlyList Children { get; } + + /// + /// Gets the scenario context. + /// + IScenarioContext Context { get; } + + /// + /// Runs the scenario. + /// + void Run(); + } +} diff --git a/Source/Partner Center SDK Samples/IScenarioContext.cs b/Source/Partner Center SDK Samples/IScenarioContext.cs new file mode 100644 index 0000000..d1edcab --- /dev/null +++ b/Source/Partner Center SDK Samples/IScenarioContext.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples +{ + using Configuration; + using Helpers; + using Store.PartnerCenter; + + /// + /// Holds context properties useful to the scenarios. + /// + public interface IScenarioContext + { + /// + /// Gets a partner operations instance which is user based authenticated. + /// + IAggregatePartner UserPartnerOperations { get; } + + /// + /// Gets a partner operations instance which is application based authenticated. + /// + IAggregatePartner AppPartnerOperations { get; } + + /// + /// Gets a configuration instance. + /// + ConfigurationManager Configuration { get; } + + /// + /// Gets a console helper instance. + /// + ConsoleHelper ConsoleHelper { get; } + } +} diff --git a/Source/Partner Center SDK Samples/IndirectModel/CreateCustomerForIndirectReseller.cs b/Source/Partner Center SDK Samples/IndirectModel/CreateCustomerForIndirectReseller.cs new file mode 100644 index 0000000..d5a80bd --- /dev/null +++ b/Source/Partner Center SDK Samples/IndirectModel/CreateCustomerForIndirectReseller.cs @@ -0,0 +1,77 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Customers +{ + using System; + using System.Globalization; + using Models; + using Models.Customers; + + /// + /// Creates a new customer for an indirect reseller. + /// + public class CreateCustomerForIndirectReseller : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CreateCustomerForIndirectReseller(IScenarioContext context) : base("Create a new customer for an indirect reseller", context) + { + } + + /// + /// executes the create customer scenario. + /// + protected override void RunScenario() + { + var indirectResellerId = this.ObtainIndirectResellerId("Enter the ID of the indirect reseller: "); + + var partnerOperations = this.Context.UserPartnerOperations; + + var customerToCreate = new Customer() + { + CompanyProfile = new CustomerCompanyProfile() + { + Domain = string.Format( + CultureInfo.InvariantCulture, + "WingtipToys{0}.{1}", + new Random().Next(), + this.Context.Configuration.Scenario.CustomerDomainSuffix) + }, + BillingProfile = new CustomerBillingProfile() + { + Culture = "EN-US", + Email = "Gena@wingtiptoys.com", + Language = "En", + CompanyName = "Wingtip Toys" + new Random().Next(), + DefaultAddress = new Address() + { + FirstName = "Gena", + LastName = "Soto", + AddressLine1 = "One Microsoft Way", + City = "Redmond", + State = "WA", + Country = "US", + PostalCode = "98052", + PhoneNumber = "4255550101" + } + }, + AssociatedPartnerId = indirectResellerId + }; + + this.Context.ConsoleHelper.WriteObject(customerToCreate, "New user Information"); + this.Context.ConsoleHelper.StartProgress("Creating user"); + + var newCustomer = partnerOperations.Customers.Create(customerToCreate); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.Success("Success!"); + this.Context.ConsoleHelper.WriteObject(newCustomer, "Created user Information"); + } + } +} diff --git a/Source/Partner Center SDK Samples/IndirectModel/GetCustomersOfIndirectReseller.cs b/Source/Partner Center SDK Samples/IndirectModel/GetCustomersOfIndirectReseller.cs new file mode 100644 index 0000000..d7ea1c4 --- /dev/null +++ b/Source/Partner Center SDK Samples/IndirectModel/GetCustomersOfIndirectReseller.cs @@ -0,0 +1,76 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.IndirectModel +{ + using System; + using System.Globalization; + using Models.Customers; + using Models.Query; + + /// + /// A scenario that retrieves the list of customers associated to an indirect reseller. + /// + public class GetCustomersOfIndirectReseller : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomersOfIndirectReseller(IScenarioContext context) : base("Get customers of indirect reseller", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var indirectResellerId = this.ObtainIndirectResellerId("Enter the ID of the indirect reseller: "); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting customers of the indirect reseller"); + + // Create a simple field filter. + var filter = new SimpleFieldFilter( + CustomerSearchField.IndirectReseller.ToString(), + FieldFilterOperation.StartsWith, + indirectResellerId); + + // Create an iQuery object to pass to the Query method. + var myQuery = QueryFactory.Instance.BuildSimpleQuery(filter); + + // Get the collection of matching customers. + var customersPage = partnerOperations.Customers.Query(myQuery); + + this.Context.ConsoleHelper.StopProgress(); + + // Create a customer enumerator which will aid us in traversing the customer pages. + var customersEnumerator = partnerOperations.Enumerators.Customers.Create(customersPage); + int pageNumber = 1; + + Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Customers of indirect reseller: {0}", indirectResellerId)); + + while (customersEnumerator.HasValue) + { + // Print the current customer results page. + this.Context.ConsoleHelper.WriteObject(customersEnumerator.Current, string.Format(CultureInfo.InvariantCulture, "Customer Page: {0}", pageNumber++)); + + Console.WriteLine(); + Console.Write("Press any key to retrieve the next customers page"); + Console.ReadKey(); + + this.Context.ConsoleHelper.StartProgress("Getting next customers page"); + + // Get the next page of customers. + customersEnumerator.Next(); + + this.Context.ConsoleHelper.StopProgress(); + Console.Clear(); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/IndirectModel/GetIndirectResellers.cs b/Source/Partner Center SDK Samples/IndirectModel/GetIndirectResellers.cs new file mode 100644 index 0000000..62cdbad --- /dev/null +++ b/Source/Partner Center SDK Samples/IndirectModel/GetIndirectResellers.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.IndirectModel +{ + using Models.Relationships; + + /// + /// A scenario that retrieves the list of indirect resellers associated to the indirect CSP partner + /// + public class GetIndirectResellers : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetIndirectResellers(IScenarioContext context) : base("Get indirect resellers", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting indirect resellers"); + + var indirectResellers = partnerOperations.Relationships.Get(PartnerRelationshipType.IsIndirectCloudSolutionProviderOf); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(indirectResellers, "Indirect Resellers"); + } + } +} diff --git a/Source/Partner Center SDK Samples/IndirectModel/GetIndirectResellersOfCustomer.cs b/Source/Partner Center SDK Samples/IndirectModel/GetIndirectResellersOfCustomer.cs new file mode 100644 index 0000000..639e65a --- /dev/null +++ b/Source/Partner Center SDK Samples/IndirectModel/GetIndirectResellersOfCustomer.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.IndirectModel +{ + using System.Globalization; + + /// + /// A scenario that retrieves the list of indirect resellers associated to the indirect CSP partner of a customer. + /// + public class GetIndirectResellersOfCustomer : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetIndirectResellersOfCustomer(IScenarioContext context) : base("Get indirect resellers of a customer", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var customerId = this.ObtainCustomerId("Enter the ID of the customer: "); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting indirect resellers of a customer"); + + var indirectResellers = partnerOperations.Customers[customerId].Relationships.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject( + indirectResellers, + string.Format(CultureInfo.InvariantCulture, "Indirect Resellers of customer: {0}", customerId)); + } + } +} diff --git a/Source/Partner Center SDK Samples/IndirectModel/GetSubscriptionsByMpnId.cs b/Source/Partner Center SDK Samples/IndirectModel/GetSubscriptionsByMpnId.cs new file mode 100644 index 0000000..c8085c7 --- /dev/null +++ b/Source/Partner Center SDK Samples/IndirectModel/GetSubscriptionsByMpnId.cs @@ -0,0 +1,43 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.IndirectModel +{ + using System.Globalization; + + /// + /// A scenario that gets a customer's subscriptions which belong to a partner MPN ID. + /// + public class GetSubscriptionsByMpnId : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSubscriptionsByMpnId(IScenarioContext context) : base("Get customer subscriptions by partner MPN ID", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + string customerId = this.ObtainCustomerId(); + string partnerMpnId = this.ObtainMpnId(); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting subscriptions"); + + var customerSubscriptionsByMpnId = partnerOperations.Customers.ById(customerId).Subscriptions.ByPartner(partnerMpnId).Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject( + customerSubscriptionsByMpnId, + string.Format(CultureInfo.InvariantCulture, "Customer subscriptions by MPN ID: {0}", partnerMpnId)); + } + } +} diff --git a/Source/Partner Center SDK Samples/IndirectModel/PlaceOrderForCustomer.cs b/Source/Partner Center SDK Samples/IndirectModel/PlaceOrderForCustomer.cs new file mode 100644 index 0000000..0b6d115 --- /dev/null +++ b/Source/Partner Center SDK Samples/IndirectModel/PlaceOrderForCustomer.cs @@ -0,0 +1,71 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Models.Orders; + using Models.Relationships; + + /// + /// A scenario that creates a new order for a customer with an indirect reseller. + /// + public class PlaceOrderForCustomer : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public PlaceOrderForCustomer(IScenarioContext context) : base("Create an order for a customer of an indirect reseller", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer making the purchase"); + string offerId = this.ObtainOfferId("Enter the ID of the offer to purchase"); + string indirectResellerId = this.ObtainIndirectResellerId("Enter the ID of the indirect reseller: "); + + this.Context.ConsoleHelper.StartProgress("Getting list of indirect resellers"); + var indirectResellers = partnerOperations.Relationships.Get(PartnerRelationshipType.IsIndirectCloudSolutionProviderOf); + this.Context.ConsoleHelper.StopProgress(); + + var selectedIndirectReseller = (indirectResellers != null && indirectResellers.Items.Any()) ? + indirectResellers.Items.FirstOrDefault(reseller => reseller.Id.Equals(indirectResellerId, StringComparison.OrdinalIgnoreCase)) : + null; + + var order = new Order() + { + ReferenceCustomerId = customerId, + LineItems = new List() + { + new OrderLineItem() + { + OfferId = offerId, + FriendlyName = "new offer purchase", + Quantity = 5, + PartnerIdOnRecord = selectedIndirectReseller != null ? selectedIndirectReseller.MpnId : null + } + } + }; + + this.Context.ConsoleHelper.WriteObject(order, "Order to be placed"); + this.Context.ConsoleHelper.StartProgress("Placing order"); + + var createdOrder = partnerOperations.Customers.ById(customerId).Orders.Create(order); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(createdOrder, "Created order"); + } + } +} diff --git a/Source/Partner Center SDK Samples/IndirectModel/VerifyPartnerMpnId.cs b/Source/Partner Center SDK Samples/IndirectModel/VerifyPartnerMpnId.cs new file mode 100644 index 0000000..1637824 --- /dev/null +++ b/Source/Partner Center SDK Samples/IndirectModel/VerifyPartnerMpnId.cs @@ -0,0 +1,47 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.IndirectModel +{ + using System.Globalization; + + /// + /// A scenario that verifies a partner MPN ID. + /// + public class VerifyPartnerMpnId : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public VerifyPartnerMpnId(IScenarioContext context) : base("Verify partner MPN ID", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting the logged in partner's profile"); + + var currentPartnerProfile = partnerOperations.Profiles.MpnProfile.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(currentPartnerProfile, "Logged in partner profile"); + + string partnerMpnId = this.ObtainMpnId("Enter the MPN ID to verify"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting the partner profile for MPN ID: {0}", partnerMpnId)); + + var partnerProfile = partnerOperations.Profiles.MpnProfile.Get(partnerMpnId); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(partnerProfile, "Partner profile"); + } + } +} diff --git a/Source/Partner Center SDK Samples/IndirectPartners/GetSubscriptionsByMpnId.cs b/Source/Partner Center SDK Samples/IndirectPartners/GetSubscriptionsByMpnId.cs new file mode 100644 index 0000000..c3ea5ce --- /dev/null +++ b/Source/Partner Center SDK Samples/IndirectPartners/GetSubscriptionsByMpnId.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.IndirectPartners +{ + using System; + using System.Globalization; + + /// + /// A scenario that gets a customer's subscriptions which belong to a partner MPN ID. + /// + public class GetSubscriptionsByMpnId : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSubscriptionsByMpnId(IScenarioContext context) : base("Get customer subscriptions by partner MPN ID", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + string customerId = this.ObtainCustomerId(); + string partnerMpnId = this.ObtainMpnId(); + + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting subscriptions"); + + var customerSubscriptionsByMpnId = partnerOperations.Customers.ById(customerId).Subscriptions.ByPartner(partnerMpnId).Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject( + customerSubscriptionsByMpnId, + string.Format(CultureInfo.InvariantCulture, "Customer subscriptions by MPN ID: {0}", partnerMpnId)); + } + } +} diff --git a/Source/Partner Center SDK Samples/IndirectPartners/VerifyPartnerMpnId.cs b/Source/Partner Center SDK Samples/IndirectPartners/VerifyPartnerMpnId.cs new file mode 100644 index 0000000..c9fe9fb --- /dev/null +++ b/Source/Partner Center SDK Samples/IndirectPartners/VerifyPartnerMpnId.cs @@ -0,0 +1,48 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.IndirectPartners +{ + using System; + using System.Globalization; + + /// + /// A scenario that verifies a partner MPN ID. + /// + public class VerifyPartnerMpnId : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public VerifyPartnerMpnId(IScenarioContext context) : base("Verify partner MPN ID", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting the logged in partner's profile"); + + var currentPartnerProfile = partnerOperations.Profiles.MpnProfile.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(currentPartnerProfile, "Logged in partner profile"); + + string partnerMpnId = this.ObtainMpnId("Enter the MPN ID to verify"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting the partner profile for MPN ID: {0}", partnerMpnId)); + + var partnerProfile = partnerOperations.Profiles.MpnProfile.Get(partnerMpnId); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(partnerProfile, "Partner profile"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Invoice/GetAccountBalance.cs b/Source/Partner Center SDK Samples/Invoice/GetAccountBalance.cs new file mode 100644 index 0000000..05d2fce --- /dev/null +++ b/Source/Partner Center SDK Samples/Invoice/GetAccountBalance.cs @@ -0,0 +1,37 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Invoice +{ + /// + /// Gets the account balance for a partner. + /// + public class GetAccountBalance : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetAccountBalance(IScenarioContext context) : base("Get account balance", context) + { + } + + /// + /// executes the get account balance scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting account balance"); + + // Getting the account balance + var accountBalance = partnerOperations.Invoices.Summary.Get().BalanceAmount; + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(accountBalance, "Account Balance"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Invoice/GetInvoice.cs b/Source/Partner Center SDK Samples/Invoice/GetInvoice.cs new file mode 100644 index 0000000..f68344c --- /dev/null +++ b/Source/Partner Center SDK Samples/Invoice/GetInvoice.cs @@ -0,0 +1,60 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Invoice +{ + using System; + + /// + /// Gets a single partner invoice. + /// + public class GetInvoice : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetInvoice(IScenarioContext context) : base("Get partner's invoice details", context) + { + } + + /// + /// executes the get invoice scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string invoiceId = this.Context.Configuration.Scenario.DefaultInvoiceId; + + if (string.IsNullOrWhiteSpace(invoiceId)) + { + // prompt the user the enter the invoice ID + invoiceId = this.Context.ConsoleHelper.ReadNonEmptyString("Please enter the invoice ID to retrieve ", "The invoice ID can't be empty"); + } + else + { + Console.WriteLine("Found Invoice ID: {0} in configuration.", invoiceId); + } + + this.Context.ConsoleHelper.StartProgress("Retrieving invoice"); + + // Retrieving invoice + var invoice = partnerOperations.Invoices.ById(invoiceId).Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(invoice, "Invoice details"); + + // Retrieving invoice line items + if (invoice.InvoiceDetails != null) + { + foreach (var invoiceDetail in invoice.InvoiceDetails) + { + this.Context.ConsoleHelper.WriteObject(invoiceDetail, "Invoice Line Items"); + } + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Invoice/GetInvoiceLineItems.cs b/Source/Partner Center SDK Samples/Invoice/GetInvoiceLineItems.cs new file mode 100644 index 0000000..b91e5ed --- /dev/null +++ b/Source/Partner Center SDK Samples/Invoice/GetInvoiceLineItems.cs @@ -0,0 +1,95 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Invoice +{ + using System; + using System.Globalization; + using System.Linq; + + /// + /// Gets an invoice's line items. + /// + public class GetInvoiceLineItems : BasePartnerScenario + { + /// + /// The invoice page size. + /// + private readonly int invoicePageSize; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + /// The number of invoice line items to return per page. + public GetInvoiceLineItems(IScenarioContext context, int invoicePageSize = 0) : base("Get an invoice's line items", context) + { + this.invoicePageSize = invoicePageSize; + } + + /// + /// executes the get invoice line items scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string invoiceId = this.Context.Configuration.Scenario.DefaultInvoiceId; + + if (string.IsNullOrWhiteSpace(invoiceId)) + { + // prompt the user the enter the invoice ID + invoiceId = this.Context.ConsoleHelper.ReadNonEmptyString("Please enter the ID of the invoice to retrieve ", "The ID can't be empty"); + } + else + { + Console.WriteLine("Found Invoice ID: {0} in configuration.", invoiceId); + } + + this.Context.ConsoleHelper.StartProgress("Retrieving Invoice Line Items"); + + // Retrieve the invoice + var invoiceOperations = partnerOperations.Invoices.ById(invoiceId); + var invoice = invoiceOperations.Get(); + + this.Context.ConsoleHelper.StopProgress(); + + if ((invoice.InvoiceDetails == null) || (invoice.InvoiceDetails.Count() <= 0)) + { + this.Context.ConsoleHelper.Warning(string.Format(CultureInfo.InvariantCulture, "Invoice {0} does not have any invoice line items", invoice.Id)); + } + else + { + foreach (var invoiceDetail in invoice.InvoiceDetails) + { + this.Context.ConsoleHelper.StartProgress(string.Format("Getting invoice line item for product {0} and line item type {1}", invoiceDetail.BillingProvider, invoiceDetail.InvoiceLineItemType)); + + // Get the invoice line items + var invoiceLineItemsCollection = (this.invoicePageSize <= 0) ? invoiceOperations.By(invoiceDetail.BillingProvider, invoiceDetail.InvoiceLineItemType).Get() : invoiceOperations.By(invoiceDetail.BillingProvider, invoiceDetail.InvoiceLineItemType).Get(this.invoicePageSize, 0); + + var invoiceLineItemEnumerator = partnerOperations.Enumerators.InvoiceLineItems.Create(invoiceLineItemsCollection); + this.Context.ConsoleHelper.StopProgress(); + int pageNumber = 1; + + while (invoiceLineItemEnumerator.HasValue) + { + this.Context.ConsoleHelper.WriteObject(invoiceLineItemEnumerator.Current, string.Format(CultureInfo.InvariantCulture, "Invoice Line Item Page: {0}", pageNumber++)); + Console.WriteLine(); + Console.Write("Press any key to retrieve the next invoice line items page"); + Console.ReadKey(); + + this.Context.ConsoleHelper.StartProgress("Getting next invoice line items page"); + + // Get the next list of invoice line items + invoiceLineItemEnumerator.Next(); + + this.Context.ConsoleHelper.StopProgress(); + Console.Clear(); + } + } + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Invoice/GetInvoiceStatement.cs b/Source/Partner Center SDK Samples/Invoice/GetInvoiceStatement.cs new file mode 100644 index 0000000..a406767 --- /dev/null +++ b/Source/Partner Center SDK Samples/Invoice/GetInvoiceStatement.cs @@ -0,0 +1,51 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Invoice +{ + using System; + + /// + /// Gets the invoice statement for an invoice id. + /// + public class GetInvoiceStatement : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetInvoiceStatement(IScenarioContext context) : base("Get Invoice Statement by Id", context) + { + } + + /// + /// executes the get invoice statement scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Getting Invoice Statement"); + + string invoiceId = this.Context.Configuration.Scenario.DefaultInvoiceId; + if (string.IsNullOrWhiteSpace(invoiceId)) + { + // prompt the user the enter the invoice ID + invoiceId = this.Context.ConsoleHelper.ReadNonEmptyString("Please enter the invoice ID to retrieve ", "The invoice ID can't be empty"); + } + else + { + Console.WriteLine("Found Invoice ID: {0} in configuration.", invoiceId); + } + + // // Retrieving invoice statement for an invoice id + var invoiceStatement = partnerOperations.Invoices.ById(invoiceId).Documents.Statement.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(invoiceId, "Invoice Id"); + this.Context.ConsoleHelper.WriteObject(invoiceStatement.Length, "Invoice Statement Size"); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Invoice/GetInvoiceSummaries.cs b/Source/Partner Center SDK Samples/Invoice/GetInvoiceSummaries.cs new file mode 100644 index 0000000..4d6f06b --- /dev/null +++ b/Source/Partner Center SDK Samples/Invoice/GetInvoiceSummaries.cs @@ -0,0 +1,49 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Invoice +{ + /// + /// Gets a single partner invoice summaries. + /// + public class GetInvoiceSummaries : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetInvoiceSummaries(IScenarioContext context) : base("Get partner's invoice summaries", context) + { + } + + /// + /// executes the get invoice summaries scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Retrieving invoice summaries"); + + // Retrieving invoice summaries + var invoiceSummaries = partnerOperations.Invoices.Summaries.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(invoiceSummaries, "Invoice Summaries"); + + // Retrieving invoice summaries details + if (invoiceSummaries.TotalCount > 0) + { + foreach (var summary in invoiceSummaries.Items) + { + foreach (var detail in summary.Details) + { + this.Context.ConsoleHelper.WriteObject(detail, "Invoice Summaries Details"); + } + } + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Invoice/GetPagedInvoices.cs b/Source/Partner Center SDK Samples/Invoice/GetPagedInvoices.cs new file mode 100644 index 0000000..6237c26 --- /dev/null +++ b/Source/Partner Center SDK Samples/Invoice/GetPagedInvoices.cs @@ -0,0 +1,70 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Invoice +{ + using System; + using System.Globalization; + using Store.PartnerCenter.Models.Query; + + /// + /// Gets paged invoices for partners. + /// + public class GetPagedInvoices : BasePartnerScenario + { + /// + /// The Invoice page size. + /// + private readonly int invoicePageSize; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + /// The number of invoices to fetch per page. + public GetPagedInvoices(IScenarioContext context, int invoicePageSize) : base("Get paged invoices", context) + { + this.invoicePageSize = invoicePageSize; + } + + /// + /// executes the get paged invoices scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Querying invoices"); + + // query the invoices, get the first page if a page size was set, otherwise get all invoices + var invoicesPage = (this.invoicePageSize <= 0) ? partnerOperations.Invoices.Get() : partnerOperations.Invoices.Query(QueryFactory.Instance.BuildIndexedQuery(this.invoicePageSize)); + this.Context.ConsoleHelper.StopProgress(); + + // create an invoice enumerator which will aid us in traversing the invoice pages + var invoicesEnumerator = partnerOperations.Enumerators.Invoices.Create(invoicesPage); + int pageNumber = 1; + + while (invoicesEnumerator.HasValue) + { + // print the current invoice results page + this.Context.ConsoleHelper.WriteObject(invoicesEnumerator.Current, string.Format(CultureInfo.InvariantCulture, "Invoice Page: {0}", pageNumber++)); + + Console.WriteLine(); + Console.Write("Press any key to retrieve the next invoices page"); + Console.ReadKey(); + + this.Context.ConsoleHelper.StartProgress("Getting next invoices page"); + + // get the next page of invoices + invoicesEnumerator.Next(); + + this.Context.ConsoleHelper.StopProgress(); + Console.Clear(); + } + + this.Context.ConsoleHelper.WriteObject(invoicesPage, "Invoices"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Offers/GetCustomerOfferCategories.cs b/Source/Partner Center SDK Samples/Offers/GetCustomerOfferCategories.cs new file mode 100644 index 0000000..25a8646 --- /dev/null +++ b/Source/Partner Center SDK Samples/Offers/GetCustomerOfferCategories.cs @@ -0,0 +1,37 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Offers +{ + /// + /// A scenario that retrieves all the offer categories available for a customer. + /// + public class GetCustomerOfferCategories : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerOfferCategories(IScenarioContext context) : base("Get customer offer categories", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + string customerIdToRetrieve = this.ObtainCustomerId("Enter the ID of the customer to retrieve offer categories for"); + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress($"Getting offer catgories for customer { customerIdToRetrieve }"); + var offerCategories = partnerOperations.Customers.ById(customerIdToRetrieve).OfferCategories.Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(offerCategories, $"Offer categories for customer { customerIdToRetrieve }"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Offers/GetCustomerOffers.cs b/Source/Partner Center SDK Samples/Offers/GetCustomerOffers.cs new file mode 100644 index 0000000..5420949 --- /dev/null +++ b/Source/Partner Center SDK Samples/Offers/GetCustomerOffers.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Offers +{ + /// + /// A scenario that retrieves all the offers available for a customer. + /// + public class GetCustomerOffers : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerOffers(IScenarioContext context) : base("Get customer offers", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + string customerIdToRetrieve = this.ObtainCustomerId("Enter the ID of the customer to retrieve offers for"); + var pageSize = this.Context.Configuration.Scenario.DefaultOfferPageSize; + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress($"Getting first { pageSize } offers for customer { customerIdToRetrieve }"); + var offers = partnerOperations.Customers.ById(customerIdToRetrieve).Offers.Get(0, pageSize); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(offers, $"First { pageSize } offers for customer { customerIdToRetrieve }"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Offers/GetOffer.cs b/Source/Partner Center SDK Samples/Offers/GetOffer.cs new file mode 100644 index 0000000..70b3ca7 --- /dev/null +++ b/Source/Partner Center SDK Samples/Offers/GetOffer.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Offers +{ + using System.Globalization; + + /// + /// A scenario that retrieves offer details supported in a country. + /// + public class GetOffer : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetOffer(IScenarioContext context) : base("Get offer details", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var offerId = this.ObtainOfferId("Enter the ID of offer to retrieve"); + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code to get its supported offers", "The country code can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting offer details for {0}", countryCode)); + + var offer = partnerOperations.Offers.ByCountry(countryCode).ById(offerId).Get(); + var offerAddOns = partnerOperations.Offers.ByCountry(countryCode).ById(offerId).AddOns.Get(); + + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(offer, string.Format(CultureInfo.InvariantCulture, "Offer in {0}", countryCode)); + this.Context.ConsoleHelper.WriteObject(offerAddOns, string.Format(CultureInfo.InvariantCulture, "Offer add-ons in {0}", countryCode)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Offers/GetOfferCategories.cs b/Source/Partner Center SDK Samples/Offers/GetOfferCategories.cs new file mode 100644 index 0000000..8b6a451 --- /dev/null +++ b/Source/Partner Center SDK Samples/Offers/GetOfferCategories.cs @@ -0,0 +1,39 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Offers +{ + using System.Globalization; + + /// + /// A scenario that gets all offer categories. + /// + public class GetOfferCategories : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetOfferCategories(IScenarioContext context) : base("Get offer categories", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code to get its supported offer categories", "The country code can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting offer categories for {0}", countryCode)); + var offerCategories = partnerOperations.OfferCategories.ByCountry(countryCode).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(offerCategories, string.Format(CultureInfo.InvariantCulture, "Offer categories in {0}", countryCode)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Offers/GetOffers.cs b/Source/Partner Center SDK Samples/Offers/GetOffers.cs new file mode 100644 index 0000000..eb9e7ab --- /dev/null +++ b/Source/Partner Center SDK Samples/Offers/GetOffers.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Offers +{ + using System.Globalization; + + /// + /// A scenario that retrieves all the offers supported in a country. + /// + public class GetOffers : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetOffers(IScenarioContext context) : base("Get offers", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var pageSize = this.Context.Configuration.Scenario.DefaultOfferPageSize; + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code to get its supported offers", "The country code can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting first {0} offers for {1}", pageSize, countryCode)); + var offers = partnerOperations.Offers.ByCountry(countryCode).Get(0, pageSize); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(offers, string.Format(CultureInfo.InvariantCulture, "Offers in {0}", countryCode)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Offers/GetPagedOffers.cs b/Source/Partner Center SDK Samples/Offers/GetPagedOffers.cs new file mode 100644 index 0000000..ffc6276 --- /dev/null +++ b/Source/Partner Center SDK Samples/Offers/GetPagedOffers.cs @@ -0,0 +1,71 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Offers +{ + using System; + using System.Globalization; + + /// + /// Gets a partner offers in pages. + /// + public class GetPagedOffers : BasePartnerScenario + { + /// + /// The offer page size. + /// + private readonly int offersPageSize; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + /// The number of Offers to return per page. + public GetPagedOffers(IScenarioContext context, int offersPageSize = 0) : base("Get paged offers", context) + { + this.offersPageSize = offersPageSize; + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + int offset = 0; + + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code to get its supported offers", "The country code can't be empty"); + + this.Context.ConsoleHelper.StartProgress("Querying Offers"); + + // query the Offers, get the first page if a page size was set, otherwise get all Offers + var offersPage = (this.offersPageSize <= 0) ? partnerOperations.Offers.ByCountry(countryCode).Get() : partnerOperations.Offers.ByCountry(countryCode).Get(offset, this.offersPageSize); + this.Context.ConsoleHelper.StopProgress(); + + // create a customer enumerator which will aid us in traversing the customer pages + var offersEnumerator = partnerOperations.Enumerators.Offers.Create(offersPage); + int pageNumber = 1; + + while (offersEnumerator.HasValue) + { + // print the current customer results page + this.Context.ConsoleHelper.WriteObject(offersEnumerator.Current, string.Format(CultureInfo.InvariantCulture, "Offers Page: {0}", pageNumber++)); + + Console.WriteLine(); + Console.Write("Press any key to retrieve the next offers page"); + Console.ReadKey(); + + this.Context.ConsoleHelper.StartProgress("Getting next offers page"); + + // get the next page of Offers + offersEnumerator.Next(); + + this.Context.ConsoleHelper.StopProgress(); + Console.Clear(); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Orders/CreateAzureReservationOrder.cs b/Source/Partner Center SDK Samples/Orders/CreateAzureReservationOrder.cs new file mode 100644 index 0000000..a61eed5 --- /dev/null +++ b/Source/Partner Center SDK Samples/Orders/CreateAzureReservationOrder.cs @@ -0,0 +1,89 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Microsoft.Store.PartnerCenter.Models.Offers; + using Store.PartnerCenter.Models.Orders; + + /// + /// A scenario that creates a new Azure RI order for a customer. + /// + public class CreateAzureReservationOrder : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CreateAzureReservationOrder(IScenarioContext context) : base("Create an Azure Reservation order", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer making the purchase"); + string productId = this.ObtainProductId(); + string skuId = this.ObtainSkuId(); + string subscriptionId = this.ObtainAzureSubscriptionId(); + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code of the sku", "The country code can't be empty"); + + var sku = partnerOperations.Products.ByCountry(countryCode).ById(productId).Skus.ById(skuId).Get(); + var availabilities = partnerOperations.Products.ByCountry(countryCode).ById(productId).Skus.ById(skuId).Availabilities.Get(); + + if ((sku.DynamicAttributes == null) || string.IsNullOrEmpty(Convert.ToString(sku.DynamicAttributes["duration"]))) + { + this.Context.ConsoleHelper.Warning("Invalid Azure catalog item ID."); + } + else + { + if (!availabilities.Items.Any()) + { + this.Context.ConsoleHelper.Warning("No availabilities found."); + } + else + { + var order = new Order() + { + ReferenceCustomerId = customerId, + BillingCycle = BillingCycleType.OneTime, + LineItems = new List() + { + new OrderLineItem() + { + OfferId = availabilities.Items.First().CatalogItemId, + FriendlyName = "ASampleAzureRI", + Quantity = 1, + LineItemNumber = 0, + ProvisioningContext = new Dictionary() + { + { "subscriptionId", subscriptionId }, + { "scope", "shared" }, + { "duration", Convert.ToString(sku.DynamicAttributes["duration"]) } + } + } + } + }; + + this.Context.ConsoleHelper.WriteObject(order, "Azure Reservation order to be placed"); + this.Context.ConsoleHelper.StartProgress("Placing order"); + + var createdOrder = partnerOperations.Customers.ById(customerId).Orders.Create(order); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(createdOrder, "Created Azure Reservation order"); + } + } + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Orders/CreateOrder.cs b/Source/Partner Center SDK Samples/Orders/CreateOrder.cs new file mode 100644 index 0000000..48a28e4 --- /dev/null +++ b/Source/Partner Center SDK Samples/Orders/CreateOrder.cs @@ -0,0 +1,58 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + using System.Collections.Generic; + using Store.PartnerCenter.Models.Orders; + + /// + /// A scenario that creates a new order for a customer. + /// + public class CreateOrder : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CreateOrder(IScenarioContext context) : base("Create an order", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer making the purchase"); + string offerId = this.ObtainOfferId("Enter the ID of the offer to purchase"); + + var order = new Order() + { + ReferenceCustomerId = customerId, + LineItems = new List() + { + new OrderLineItem() + { + OfferId = offerId, + FriendlyName = "new offer purchase", + Quantity = 5 + } + } + }; + + this.Context.ConsoleHelper.WriteObject(order, "Order to be placed"); + this.Context.ConsoleHelper.StartProgress("Placing order"); + + var createdOrder = partnerOperations.Customers.ById(customerId).Orders.Create(order); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(createdOrder, "Created order"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Orders/GetOrderDetails.cs b/Source/Partner Center SDK Samples/Orders/GetOrderDetails.cs new file mode 100644 index 0000000..aa51498 --- /dev/null +++ b/Source/Partner Center SDK Samples/Orders/GetOrderDetails.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + /// + /// A scenario that retrieves a customer order details. + /// + public class GetOrderDetails : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetOrderDetails(IScenarioContext context) : base("Get customer order details", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their order details"); + string orderId = this.ObtainOrderID("Enter the ID of order to retrieve"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer order details"); + + var customerOrderDetails = partnerOperations.Customers.ById(customerId).Orders.ById(orderId).Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerOrderDetails, "Customer order details"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Orders/GetOrderProvisioningStatus.cs b/Source/Partner Center SDK Samples/Orders/GetOrderProvisioningStatus.cs new file mode 100644 index 0000000..7441e5c --- /dev/null +++ b/Source/Partner Center SDK Samples/Orders/GetOrderProvisioningStatus.cs @@ -0,0 +1,50 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + /// + /// A scenario that retrieves a customer order details. + /// + public class GetOrderProvisioningStatus : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetOrderProvisioningStatus(IScenarioContext context) : base("Get customer order provisioning status", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their order provisioning details"); + string orderId = this.ObtainOrderID("Enter the ID of order to retrieve"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer order provisioning status"); + var customerOrder = partnerOperations.Customers.ById(customerId).Orders.ById(orderId).Get(); + var provisioningStatusList = partnerOperations.Customers.ById(customerId).Orders.ById(customerOrder.Id).ProvisioningStatus.Get(); + + this.Context.ConsoleHelper.StopProgress(); + + foreach (var provisioningStatus in provisioningStatusList.Items) + { + foreach (var orderItem in customerOrder.LineItems) + { + if (orderItem.LineItemNumber == provisioningStatus.LineItemNumber) + { + this.Context.ConsoleHelper.WriteObject(provisioningStatus.Status, "Customer order provisioning status"); + } + } + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Orders/GetOrders.cs b/Source/Partner Center SDK Samples/Orders/GetOrders.cs new file mode 100644 index 0000000..e78e35d --- /dev/null +++ b/Source/Partner Center SDK Samples/Orders/GetOrders.cs @@ -0,0 +1,39 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + /// + /// A scenario that retrieves a customer orders. + /// + public class GetOrders : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetOrders(IScenarioContext context) : base("Get customer orders", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their orders"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer orders"); + + var customerOrders = partnerOperations.Customers.ById(customerId).Orders.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerOrders, "Customer orders"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Orders/GetOrdersByBillingCycleType.cs b/Source/Partner Center SDK Samples/Orders/GetOrdersByBillingCycleType.cs new file mode 100644 index 0000000..2e29c2a --- /dev/null +++ b/Source/Partner Center SDK Samples/Orders/GetOrdersByBillingCycleType.cs @@ -0,0 +1,45 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + using System; + using Models.Offers; + + /// + /// A scenario that retrieves all customer orders by billing cycle type. + /// + public class GetOrdersByBillingCycleType : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetOrdersByBillingCycleType(IScenarioContext context) : base("Get All Orders by billing cycle type", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their order by billing cycle type"); + string billingCycle = this.ObtainBillingCycleType("Enter the billing cycle type"); + + var billingCyle = (BillingCycleType)Enum.Parse(typeof(BillingCycleType), billingCycle, true); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer orders"); + + var customerOrders = partnerOperations.Customers.ById(customerId).Orders.ByBillingCycleType(billingCyle).Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerOrders, "Retrieved Customer orders"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Orders/UpdateOrder.cs b/Source/Partner Center SDK Samples/Orders/UpdateOrder.cs new file mode 100644 index 0000000..ee046bb --- /dev/null +++ b/Source/Partner Center SDK Samples/Orders/UpdateOrder.cs @@ -0,0 +1,47 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Orders +{ + using System.Linq; + + /// + /// A scenario that updates a customer order. + /// + public class UpdateOrder : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateOrder(IScenarioContext context) : base("Update customer order", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their orders"); + string orderId = this.ObtainOrderID("Enter the ID of order to retrieve"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer order to be updated"); + var customerOrder = partnerOperations.Customers.ById(customerId).Orders.ById(orderId).Get(); + this.Context.ConsoleHelper.StopProgress(); + + // increase the quantity of first line item + customerOrder.LineItems.ToArray()[0].Quantity++; + + this.Context.ConsoleHelper.StartProgress("Updating the customer order"); + var updatedOrder = partnerOperations.Customers.ById(customerId).Orders.ById(customerOrder.Id).Patch(customerOrder); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedOrder, "Updated customer order"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Partner Center SDK Samples.csproj b/Source/Partner Center SDK Samples/Partner Center SDK Samples.csproj new file mode 100644 index 0000000..2fd2288 --- /dev/null +++ b/Source/Partner Center SDK Samples/Partner Center SDK Samples.csproj @@ -0,0 +1,261 @@ + + + + + Debug + AnyCPU + {AC93E5CC-549C-4F13-9675-A86860918C2B} + Exe + Properties + Microsoft.Store.PartnerCenter.Samples + Microsoft.Store.PartnerCenter.Samples + v4.5.1 + 512 + true + + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + true + bin\Debug\Microsoft.Store.PartnerCenter.Samples.xml + true + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + true + bin\Release\Microsoft.Store.PartnerCenter.Samples.xml + + + + ..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.29.0\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + + ..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.29.0\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll + + + ..\..\packages\Microsoft.Store.PartnerCenter.1.9.0\lib\Net45\Microsoft.Store.PartnerCenter.dll + + + ..\..\packages\Microsoft.Store.PartnerCenter.1.9.0\lib\Net45\Microsoft.Store.PartnerCenter.Extensions.dll + + + ..\..\packages\Microsoft.Store.PartnerCenter.1.9.0\lib\Net45\Microsoft.Store.PartnerCenter.Models.dll + + + ..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + Designer + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Products/CheckInventory.cs b/Source/Partner Center SDK Samples/Products/CheckInventory.cs new file mode 100644 index 0000000..73579b7 --- /dev/null +++ b/Source/Partner Center SDK Samples/Products/CheckInventory.cs @@ -0,0 +1,54 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Products +{ + using System.Collections.Generic; + using System.Globalization; + using Models.Products; + + /// + /// A scenario that retrieves inventory validation results for the provided country. + /// + public class CheckInventory : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CheckInventory(IScenarioContext context) : base("Check inventory", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var productId = this.ObtainProductId("Enter the ID of the product to check inventory for"); + var customerId = this.ObtainCustomerId("Enter a customer ID"); + var subscriptionId = this.ObtainSubscriptionId(customerId, "Enter a subscription ID"); + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code", "The country code can't be empty"); + + var inventoryCheckRequest = new InventoryCheckRequest() + { + TargetItems = new InventoryItem[] { new InventoryItem { ProductId = productId } }, + InventoryContext = new Dictionary() + { + { "customerId", customerId }, + { "azureSubscriptionId", subscriptionId } + } + }; + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Checking inventory for product {0} in country {1}", productId, countryCode)); + var inventoryResults = partnerOperations.Extensions.Product.ByCountry(countryCode).CheckInventory(inventoryCheckRequest); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(inventoryResults, string.Format(CultureInfo.InvariantCulture, "Inventory check for product {0}", productId)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Products/GetAvailabilities.cs b/Source/Partner Center SDK Samples/Products/GetAvailabilities.cs new file mode 100644 index 0000000..cb90247 --- /dev/null +++ b/Source/Partner Center SDK Samples/Products/GetAvailabilities.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Products +{ + using System.Globalization; + + /// + /// A scenario that retrieves the availabilities of a product's SKU. + /// + public class GetAvailabilities : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetAvailabilities(IScenarioContext context) : base("Get availabilities", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + var skuId = this.ObtainSkuId("Enter the ID of the corresponding sku"); + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code of the sku", "The country code can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting availabilities for product {0} and sku {1} in country {2}", productId, skuId, countryCode)); + var skuAvailabilities = partnerOperations.Products.ByCountry(countryCode).ById(productId).Skus.ById(skuId).Availabilities.Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(skuAvailabilities, string.Format(CultureInfo.InvariantCulture, "Availabilities for product {0}", productId)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Products/GetAvailabilitiesByTargetSegment.cs b/Source/Partner Center SDK Samples/Products/GetAvailabilitiesByTargetSegment.cs new file mode 100644 index 0000000..fd0b13b --- /dev/null +++ b/Source/Partner Center SDK Samples/Products/GetAvailabilitiesByTargetSegment.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Products +{ + using System.Globalization; + + /// + /// A scenario that retrieves the availabilities of a product's SKU by segment + /// + public class GetAvailabilitiesByTargetSegment : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetAvailabilitiesByTargetSegment(IScenarioContext context) : base("Get availabilities by segment", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + var skuId = this.ObtainSkuId("Enter the ID of the corresponding sku"); + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code of the sku", "The country code can't be empty"); + string segment = this.Context.ConsoleHelper.ReadNonEmptyString("The segment to filter the availabilities on", "The segment can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting availabilities for product {0} and sku {1} in country {2} by segment {3}", productId, skuId, countryCode, segment)); + var skuAvailabilities = partnerOperations.Products.ByCountry(countryCode).ById(productId).Skus.ById(skuId).Availabilities.ByTargetSegment(segment).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(skuAvailabilities, string.Format(CultureInfo.InvariantCulture, "Availabilities for product {0} by segment", productId)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Products/GetAvailability.cs b/Source/Partner Center SDK Samples/Products/GetAvailability.cs new file mode 100644 index 0000000..099e841 --- /dev/null +++ b/Source/Partner Center SDK Samples/Products/GetAvailability.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Products +{ + using System.Globalization; + + /// + /// A scenario that retrieves the availability of a product's SKU. + /// + public class GetAvailability : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetAvailability(IScenarioContext context) : base("Get availability", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + var skuId = this.ObtainSkuId("Enter the ID of the corresponding sku"); + var availabilityId = this.ObtainAvailabilityId("Enter the ID of the availability"); + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code of the availability", "The country code can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting availability {0} for product {1} and sku {2} in country {3}", availabilityId, productId, skuId, countryCode)); + var availability = partnerOperations.Products.ByCountry(countryCode).ById(productId).Skus.ById(skuId).Availabilities.ById(availabilityId).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(availability, "Availability "); + } + } +} diff --git a/Source/Partner Center SDK Samples/Products/GetProduct.cs b/Source/Partner Center SDK Samples/Products/GetProduct.cs new file mode 100644 index 0000000..b21fee7 --- /dev/null +++ b/Source/Partner Center SDK Samples/Products/GetProduct.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Products +{ + using System.Globalization; + + /// + /// A scenario that retrieves product details supported in a country. + /// + public class GetProduct : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetProduct(IScenarioContext context) : base("Get product", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var productId = this.ObtainProductId("Enter the ID of the product"); + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code of the product", "The country code can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting details for product {0} in country {1}", productId, countryCode)); + var product = partnerOperations.Products.ByCountry(countryCode).ById(productId).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(product, string.Format(CultureInfo.InvariantCulture, "Product details of {0}", productId)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Products/GetProducts.cs b/Source/Partner Center SDK Samples/Products/GetProducts.cs new file mode 100644 index 0000000..b78a619 --- /dev/null +++ b/Source/Partner Center SDK Samples/Products/GetProducts.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Products +{ + using System.Globalization; + + /// + /// A scenario that retrieves all the products supported in a country and in a catalog view. + /// + public class GetProducts : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetProducts(IScenarioContext context) : base("Get products", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code to get its supported products", "The country code can't be empty"); + string targetView = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the target view to get its supported products", "The target view can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting products in catalog view {0} in country {1}", targetView, countryCode)); + var products = partnerOperations.Products.ByCountry(countryCode).ByTargetView(targetView).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(products, string.Format(CultureInfo.InvariantCulture, "Products in catalog view {0}", targetView)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Products/GetProductsByTargetSegment.cs b/Source/Partner Center SDK Samples/Products/GetProductsByTargetSegment.cs new file mode 100644 index 0000000..3287b2f --- /dev/null +++ b/Source/Partner Center SDK Samples/Products/GetProductsByTargetSegment.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Products +{ + using System.Globalization; + + /// + /// A scenario that retrieves all the products supported in a country, in a catalog view and in a segment. + /// + public class GetProductsByTargetSegment : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetProductsByTargetSegment(IScenarioContext context) : base("Get products by segment", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code to get its supported products", "The country code can't be empty"); + string targetView = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the target view to get its supported products", "The target view can't be empty"); + string segment = this.Context.ConsoleHelper.ReadNonEmptyString("The segment to filter the products on", "The segment can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting products in catalog view {0}, in country {1} and in segment {2}", targetView, countryCode, segment)); + var products = partnerOperations.Products.ByCountry(countryCode).ByTargetView(targetView).ByTargetSegment(segment).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(products, string.Format(CultureInfo.InvariantCulture, "Products in catalog view {0} by segment {1}", targetView, segment)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Products/GetSku.cs b/Source/Partner Center SDK Samples/Products/GetSku.cs new file mode 100644 index 0000000..e1e78c3 --- /dev/null +++ b/Source/Partner Center SDK Samples/Products/GetSku.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Products +{ + using System.Globalization; + + /// + /// A scenario that retrieves details of a product's SKU. + /// + public class GetSku : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSku(IScenarioContext context) : base("Get sku", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + var skuId = this.ObtainSkuId("Enter the ID of the sku"); + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code of the sku", "The country code can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting sku details for sku {0} and product {1} in country {2}", skuId, productId, countryCode)); + var sku = partnerOperations.Products.ByCountry(countryCode).ById(productId).Skus.ById(skuId).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(sku, string.Format(CultureInfo.InvariantCulture, "Sku details of {0}", skuId)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Products/GetSkuDownloadOptions.cs b/Source/Partner Center SDK Samples/Products/GetSkuDownloadOptions.cs new file mode 100644 index 0000000..3167c31 --- /dev/null +++ b/Source/Partner Center SDK Samples/Products/GetSkuDownloadOptions.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Products +{ + using System.Globalization; + + /// + /// A scenario that retrieves the download options of a product's SKU. + /// + public class GetSkuDownloadOptions : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSkuDownloadOptions(IScenarioContext context) : base("Get sku download options", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + var skuId = this.ObtainSkuId("Enter the ID of the corresponding sku"); + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code of the sku", "The country code can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting sku download options for product {0} and sku {1} in country {2}", productId, skuId, countryCode)); + var sku = partnerOperations.Products.ByCountry(countryCode).ById(productId).Skus.ById(skuId).DownloadOptions.Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(sku, string.Format(CultureInfo.InvariantCulture, "Download options for sku {0}", skuId)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Products/GetSkus.cs b/Source/Partner Center SDK Samples/Products/GetSkus.cs new file mode 100644 index 0000000..bbde584 --- /dev/null +++ b/Source/Partner Center SDK Samples/Products/GetSkus.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Products +{ + using System.Globalization; + + /// + /// A scenario that retrieves all the SKUs related to a product that are supported in a country. + /// + public class GetSkus : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSkus(IScenarioContext context) : base("Get skus", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code to get its supported skus", "The country code can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting skus for product {0} in country {1}", productId, countryCode)); + var skus = partnerOperations.Products.ByCountry(countryCode).ById(productId).Skus.Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(skus, string.Format(CultureInfo.InvariantCulture, "Skus for product {0}", productId)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Products/GetSkusByTargetSegment.cs b/Source/Partner Center SDK Samples/Products/GetSkusByTargetSegment.cs new file mode 100644 index 0000000..829f4e2 --- /dev/null +++ b/Source/Partner Center SDK Samples/Products/GetSkusByTargetSegment.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Products +{ + using System.Globalization; + + /// + /// A scenario that retrieves all the SKUs related to a product that are supported in a country and that target a specific segment. + /// + public class GetSkusByTargetSegment : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSkusByTargetSegment(IScenarioContext context) : base("Get skus by segment", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var productId = this.ObtainProductId("Enter the ID of the corresponding product"); + string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code to get its supported skus", "The country code can't be empty"); + string segment = this.Context.ConsoleHelper.ReadNonEmptyString("The segment to filter the skus on", "The segment can't be empty"); + + this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting skus for product {0} in country {1} and in segment {2}", productId, countryCode, segment)); + var skus = partnerOperations.Products.ByCountry(countryCode).ById(productId).Skus.ByTargetSegment(segment).Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(skus, string.Format(CultureInfo.InvariantCulture, "Skus for product {0} in segment {1}", productId, segment)); + } + } +} diff --git a/Source/Partner Center SDK Samples/Profile/GetBillingProfile.cs b/Source/Partner Center SDK Samples/Profile/GetBillingProfile.cs new file mode 100644 index 0000000..c779ed8 --- /dev/null +++ b/Source/Partner Center SDK Samples/Profile/GetBillingProfile.cs @@ -0,0 +1,37 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Profile +{ + /// + /// A scenario that retrieves the partner's billing profile. + /// + public class GetBillingProfile : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetBillingProfile(IScenarioContext context) : base("Get partner's billing profile", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Retrieving partner's billing profile"); + + var billingProfile = partnerOperations.Profiles.BillingProfile.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(billingProfile, "Partner's billing profile"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Profile/GetMPNProfile.cs b/Source/Partner Center SDK Samples/Profile/GetMPNProfile.cs new file mode 100644 index 0000000..f18da2f --- /dev/null +++ b/Source/Partner Center SDK Samples/Profile/GetMPNProfile.cs @@ -0,0 +1,37 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Profile +{ + /// + /// A scenario that retrieves the partner's MPN profile. + /// + public class GetMPNProfile : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetMPNProfile(IScenarioContext context) : base("Get partner MPN profile", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Retrieving partner MPN profile"); + + var billingProfile = partnerOperations.Profiles.MpnProfile.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(billingProfile, "Partner MPN profile"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Profile/GetOrganizationProfile.cs b/Source/Partner Center SDK Samples/Profile/GetOrganizationProfile.cs new file mode 100644 index 0000000..01f5699 --- /dev/null +++ b/Source/Partner Center SDK Samples/Profile/GetOrganizationProfile.cs @@ -0,0 +1,37 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Profile +{ + /// + /// A scenario that retrieves the partner's organization profile. + /// + public class GetOrganizationProfile : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetOrganizationProfile(IScenarioContext context) : base("Get partner organization profile", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Retrieving partner organization profile"); + + var billingProfile = partnerOperations.Profiles.OrganizationProfile.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(billingProfile, "Partner organization profile"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Profile/GetSupportProfile.cs b/Source/Partner Center SDK Samples/Profile/GetSupportProfile.cs new file mode 100644 index 0000000..075f07c --- /dev/null +++ b/Source/Partner Center SDK Samples/Profile/GetSupportProfile.cs @@ -0,0 +1,37 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Profile +{ + /// + /// A scenario that retrieves the partner's support profile. + /// + public class GetSupportProfile : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSupportProfile(IScenarioContext context) : base("Get partner support profile", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Retrieving partner support profile"); + + var billingProfile = partnerOperations.Profiles.SupportProfile.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(billingProfile, "partner support profile"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Profile/GetlegalBusinessProfile.cs b/Source/Partner Center SDK Samples/Profile/GetlegalBusinessProfile.cs new file mode 100644 index 0000000..298a6a6 --- /dev/null +++ b/Source/Partner Center SDK Samples/Profile/GetlegalBusinessProfile.cs @@ -0,0 +1,37 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Profile +{ + /// + /// A scenario that retrieves the partner's legal business profile. + /// + public class GetLegalBusinessProfile : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetLegalBusinessProfile(IScenarioContext context) : base("Get partner legal business profile", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Retrieving partner legal business profile"); + + var billingProfile = partnerOperations.Profiles.LegalBusinessProfile.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(billingProfile, "Partner legal business profile"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Profile/UpdateBillingProfile.cs b/Source/Partner Center SDK Samples/Profile/UpdateBillingProfile.cs new file mode 100644 index 0000000..238e709 --- /dev/null +++ b/Source/Partner Center SDK Samples/Profile/UpdateBillingProfile.cs @@ -0,0 +1,48 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Profile +{ + using System; + using System.Globalization; + + /// + /// A scenario that updates the partner's billing profile. + /// + public class UpdateBillingProfile : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateBillingProfile(IScenarioContext context) : base("Update partner billing profile", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Retrieving partner billing profile"); + + var billingProfile = partnerOperations.Profiles.BillingProfile.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(billingProfile); + + billingProfile.PurchaseOrderNumber = new Random().Next(9000, 10000).ToString(CultureInfo.InvariantCulture); + + this.Context.ConsoleHelper.StartProgress("Updating partner billing profile"); + var updatedPartnerBillingProfile = partnerOperations.Profiles.BillingProfile.Update(billingProfile); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedPartnerBillingProfile, "Updated partner billing profile"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Profile/UpdateLegalBusinessProfile.cs b/Source/Partner Center SDK Samples/Profile/UpdateLegalBusinessProfile.cs new file mode 100644 index 0000000..6c3f13f --- /dev/null +++ b/Source/Partner Center SDK Samples/Profile/UpdateLegalBusinessProfile.cs @@ -0,0 +1,49 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Profile +{ + using System; + using System.Globalization; + + /// + /// A scenario that updates the partner's legal business profile. + /// + public class UpdateLegalBusinessProfile : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateLegalBusinessProfile(IScenarioContext context) : base("Update partner legal business profile", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Displaying partner legal business profile"); + + var legalBusinessProfile = partnerOperations.Profiles.LegalBusinessProfile.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(legalBusinessProfile); + + // Generating a random phone number to update in the legal busines profile + legalBusinessProfile.CompanyApproverAddress.PhoneNumber = ((long)(new Random().NextDouble() * 9000000000) + 1000000000).ToString(CultureInfo.InvariantCulture); + + this.Context.ConsoleHelper.StartProgress("Updating partner legal business profile"); + var updatedLegalBusinessProfile = partnerOperations.Profiles.LegalBusinessProfile.Update(legalBusinessProfile); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedLegalBusinessProfile, "Updated partner legal business profile"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Profile/UpdateOrganizationProfile.cs b/Source/Partner Center SDK Samples/Profile/UpdateOrganizationProfile.cs new file mode 100644 index 0000000..fe0aa79 --- /dev/null +++ b/Source/Partner Center SDK Samples/Profile/UpdateOrganizationProfile.cs @@ -0,0 +1,49 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Profile +{ + using System; + using System.Globalization; + + /// + /// A scenario that updates the partner's organization profile. + /// + public class UpdateOrganizationProfile : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateOrganizationProfile(IScenarioContext context) : base("Update partner organization profile", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Displaying partner organization profile"); + + var organizationProfile = partnerOperations.Profiles.OrganizationProfile.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(organizationProfile); + + // Generating a random phone number to update in the organization profile + organizationProfile.DefaultAddress.PhoneNumber = ((long)(new Random().NextDouble() * 9000000000) + 1000000000).ToString(CultureInfo.InvariantCulture); + + this.Context.ConsoleHelper.StartProgress("Updating partner organization profile"); + var updatedPartnerOrganizationProfile = partnerOperations.Profiles.OrganizationProfile.Update(organizationProfile); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedPartnerOrganizationProfile, "Updated partner organization profile"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Profile/UpdateSupportProfile.cs b/Source/Partner Center SDK Samples/Profile/UpdateSupportProfile.cs new file mode 100644 index 0000000..0682b94 --- /dev/null +++ b/Source/Partner Center SDK Samples/Profile/UpdateSupportProfile.cs @@ -0,0 +1,55 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Profile +{ + using System.Net.Mail; + + /// + /// A scenario that updates the partner's support profile. + /// + public class UpdateSupportProfile : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateSupportProfile(IScenarioContext context) : base("Update partner support profile", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Displaying partner support profile"); + + var supportProfile = partnerOperations.Profiles.SupportProfile.Get(); + + this.Context.ConsoleHelper.WriteObject(supportProfile); + this.Context.ConsoleHelper.StopProgress(); + + var emailId = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the email ID to be updated in support profile", "Email ID cannot be empty"); + + if (emailId != new MailAddress(emailId).Address) + { + this.Context.ConsoleHelper.Warning("Invalid email ID"); + } + else + { + supportProfile.Email = emailId; + this.Context.ConsoleHelper.StartProgress("Updating partner support profile"); + var updatedPartnerSupportProfile = partnerOperations.Profiles.SupportProfile.Update(supportProfile); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedPartnerSupportProfile, "Updated partner support profile"); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Program.cs b/Source/Partner Center SDK Samples/Program.cs new file mode 100644 index 0000000..203dc20 --- /dev/null +++ b/Source/Partner Center SDK Samples/Program.cs @@ -0,0 +1,586 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples +{ + using Agreements; + using Analytics; + using Carts; + using Context; + using CustomerDirectoryRoles; + using CustomerProducts; + using Customers; + using CustomerServiceCosts; + using CustomerSubscribedSkus; + using CustomerUser; + using DevicesDeployment; + using Entitlements; + using IndirectModel; + using Invoice; + using Models.Auditing; + using Models.Customers; + using Models.Query; + using Offers; + using Orders; + using Products; + using Profile; + using RateCards; + using RatedUsage; + using ServiceIncidents; + using ServiceRequests; + using Subscriptions; + using Utilization; + using Validations; + + /// + /// The main program class for the partner center .NET SDK samples. + /// + public static class Program + { + /// + /// The main entry function. + /// + /// Program arguments. + public static void Main(string[] args) + { + var context = new ScenarioContext(); + + IPartnerScenario[] mainScenarios = new[] + { + Program.GetCustomerScenarios(context), + Program.GetAgreementsScenarios(context), + Program.GetOfferScenarios(context), + Program.GetProductScenarios(context), + Program.GetCustomerProductsScenarios(context), + Program.GetOrderScenarios(context), + Program.GetSubscriptionScenarios(context), + Program.GetRatedUsageScenarios(context), + Program.GetServiceRequestsScenarios(context), + Program.GetInvoiceScenarios(context), + Program.GetProfileScenarios(context), + Program.GetCustomerUserScenarios(context), + Program.GetCustomerSubscribedSkus(context), + Program.GetCustomerDirectoryRolesScenarios(context), + Program.GetAuditingScenarios(context), + Program.GetRateCardScenarios(context), + Program.GetSharedRateCardScenarios(context), + Program.GetIndirectModelScenarios(context), + Program.GetServiceIncidentScenarios(context), + Program.GetUtilizationScenarios(context), + Program.GetPartnerAnalyticsScenarios(context), + Program.GetCustomerServiceCostsScenarios(context), + Program.GetAddressValidationsScenarios(context), + Program.GetDevicesScenarios(context), + Program.GetCartScenarios(context), + Program.GetEntitlementScenarios(context) + }; + + // run the main scenario + new AggregatePartnerScenario("Partner SDK samples", mainScenarios, context).Run(); + } + + /// + /// Gets the Customer Directory Roles scenarios. + /// + /// A scenario context. + /// The Customer Directory Roles scenarios. + private static IPartnerScenario GetCustomerDirectoryRolesScenarios(ScenarioContext context) + { + var customerDirectoryRolesScenarios = new IPartnerScenario[] + { + new GetCustomerDirectoryRoles(context), + new AddUserMemberToDirectoryRole(context), + new GetCustomerDirectoryRoleUserMembers(context), + new RemoveCustomerUserMemberFromDirectoryRole(context) + }; + + return new AggregatePartnerScenario("Customer Directory Roles", customerDirectoryRolesScenarios, context); + } + + /// + /// Gets the Customer Subscribed SKUs scenarios. + /// + /// A scenario context. + /// The Customer Subscribed SKUs scenarios. + private static IPartnerScenario GetCustomerSubscribedSkus(ScenarioContext context) + { + var customerSubscribedSkusScenarios = new IPartnerScenario[] + { + new GetCustomerSubscribedSkus(context) + }; + + return new AggregatePartnerScenario("Customer Subscribed Skus", customerSubscribedSkusScenarios, context); + } + + /// + /// Gets the Devices scenarios. + /// + /// A scenario context. + /// The Devices scenarios. + private static IPartnerScenario GetDevicesScenarios(ScenarioContext context) + { + var devicesScenarios = new IPartnerScenario[] + { + new CreateConfigurationPolicy(context), + new GetAllConfigurationPolicies(context), + new UpdateConfigurationPolicy(context), + new DeleteConfigurationPolicy(context), + new CreateDeviceBatch(context), + new GetDevicesBatches(context), + new CreateDevices(context), + new GetDevices(context), + new UpdateDevicesPolicy(context), + new DeleteDevice(context), + new GetBatchUploadStatus(context) + }; + + return new AggregatePartnerScenario("Devices", devicesScenarios, context); + } + + /// + /// Gets the agreements scenario. + /// + /// A scenario context. + /// The agreements scenarios. + private static IPartnerScenario GetAgreementsScenarios(ScenarioContext context) + { + var agreementsScenario = new IPartnerScenario[] + { + new GetAgreementDetails(context), + new GetCustomerAgreements(context), + new CreateCustomerAgreement(context), + }; + + return new AggregatePartnerScenario("Agreements", agreementsScenario, context); + } + + /// + /// Gets the Entitlement scenarios. + /// + /// A scenario context. + /// The Entitlement scenarios. + private static IPartnerScenario GetEntitlementScenarios(ScenarioContext context) + { + var entitlementScenarios = new IPartnerScenario[] + { + new GetEntitlements(context), + }; + + return new AggregatePartnerScenario("Entitlements", entitlementScenarios, context); + } + + /// + /// Gets the customer user scenarios. + /// + /// A scenario context. + /// The customer user scenarios. + private static IPartnerScenario GetCustomerUserScenarios(ScenarioContext context) + { + var sortScenarios = new IPartnerScenario[] + { + new SortCustomerUsers("Ascending order", SortDirection.Ascending, context), + new SortCustomerUsers("Descending order", SortDirection.Descending, context) + }; + + var customerUserScenarios = new IPartnerScenario[] + { + new GetCustomerUserCollection(context), + new AggregatePartnerScenario("Get sorted customer users", sortScenarios, context), + new CreateCustomerUser(context), + new DeleteCustomerUser(context), + new GetCustomerUserDetails(context), + new UpdateCustomerUser(context), + new GetPagedCustomerUsers(context), + new GetCustomerUserDirectoryRoles(context), + new CustomerUserAssignedLicenses(context), + new CustomerUserAssignedGroup1AndGroup2Licenses(context), + new CustomerUserAssignedGroup1Licenses(context), + new CustomerUserAssignedGroup2Licenses(context), + new CustomerUserAssignLicenses(context), + new CustomerUserAssignGroup1Licenses(context), + new CustomerUserAssignGroup2Licenses(context), + new GetCustomerInactiveUsers(context), + new CustomerUserRestore(context) + }; + + return new AggregatePartnerScenario("Customer User samples", customerUserScenarios, context); + } + + /// + /// Gets the customer scenarios. + /// + /// A scenario context. + /// The customer scenarios. + private static IPartnerScenario GetCustomerScenarios(IScenarioContext context) + { + var customerFilteringScenarios = new IPartnerScenario[] + { + new FilterCustomers("Filter by company name", CustomerSearchField.CompanyName, context), + new FilterCustomers("Filter by domain name", CustomerSearchField.Domain, context) + }; + + var customerScenarios = new IPartnerScenario[] + { + new CreateCustomer(context), + new CheckDomainAvailability(context), + new GetPagedCustomers(context, context.Configuration.Scenario.CustomerPageSize), + new AggregatePartnerScenario("Customer filtering", customerFilteringScenarios, context), + new GetCustomerDetails(context), + new GetCustomerQualification(context), + new UpdateCustomerQualification(context), + new DeleteCustomerFromTipAccount(context), + new GetCustomerManagedServices(context), + new GetCustomerRelationshipRequest(context), + new UpdateCustomerBillingProfile(context), + new ValidateCustomerAddress(context), + new DeletePartnerCustomerRelationship(context) + }; + + return new AggregatePartnerScenario("Customer samples", customerScenarios, context); + } + + /// + /// Gets the offer scenarios. + /// + /// A scenario context. + /// The offer scenarios. + private static IPartnerScenario GetOfferScenarios(IScenarioContext context) + { + var offerScenarios = new IPartnerScenario[] + { + new GetOffer(context), + new GetOfferCategories(context), + new GetOffers(context), + new GetPagedOffers(context, context.Configuration.Scenario.DefaultOfferPageSize), + new GetCustomerOffers(context), + new GetCustomerOfferCategories(context) + }; + + return new AggregatePartnerScenario("Offer samples", offerScenarios, context); + } + + /// + /// Gets the product scenarios. + /// + /// A scenario context. + /// The product scenarios. + private static IPartnerScenario GetProductScenarios(IScenarioContext context) + { + var productScenarios = new IPartnerScenario[] + { + new GetProducts(context), + new GetProductsByTargetSegment(context), + new GetProduct(context), + new GetSkus(context), + new GetSkusByTargetSegment(context), + new GetSku(context), + new GetSkuDownloadOptions(context), + new GetAvailabilities(context), + new GetAvailabilitiesByTargetSegment(context), + new GetAvailability(context), + new CheckInventory(context) + }; + + return new AggregatePartnerScenario("Product samples", productScenarios, context); + } + + /// + /// Gets the customer products scenarios. + /// + /// A scenario context. + /// The products for customer scenarios. + private static IPartnerScenario GetCustomerProductsScenarios(IScenarioContext context) + { + var customerProductsScenarios = new IPartnerScenario[] + { + new GetCustomerProducts(context), + new GetCustomerProductsByTargetSegment(context), + new GetCustomerProduct(context), + new GetCustomerSkus(context), + new GetCustomerSkusByTargetSegment(context), + new GetCustomerSku(context), + new GetCustomerSkuDownloadOptions(context), + new GetCustomerAvailabilities(context), + new GetCustomerAvailabilitiesByTargetSegment(context), + new GetCustomerAvailability(context) + }; + + return new AggregatePartnerScenario("Products for customers samples", customerProductsScenarios, context); + } + + /// + /// Gets the order scenarios. + /// + /// A scenario context. + /// The order scenarios. + private static IPartnerScenario GetOrderScenarios(IScenarioContext context) + { + var orderScenarios = new IPartnerScenario[] + { + new CreateOrder(context), + new GetOrderDetails(context), + new GetOrders(context), + new CreateAzureReservationOrder(context), + new GetOrdersByBillingCycleType(context), + new GetOrderProvisioningStatus(context), + new UpdateOrder(context) + }; + + return new AggregatePartnerScenario("Order samples", orderScenarios, context); + } + + /// + /// Gets the subscription scenarios. + /// + /// A scenario context. + /// The subscription scenarios. + private static IPartnerScenario GetSubscriptionScenarios(IScenarioContext context) + { + var subscriptionScenarios = new IPartnerScenario[] + { + new GetSubscription(context), + new GetSubscriptions(context), + new GetSubscriptionsByOrder(context), + new GetSubscriptionSupportContact(context), + new UpdateSubscriptionSupportContact(context), + new GetSubscriptionProvisioningStatus(context), + new UpdateSubscription(context), + new UpgradeSubscription(context), + new AddSubscriptionAddOn(context), + new ConvertTrialSubscription(context), + }; + + return new AggregatePartnerScenario("Subscription samples", subscriptionScenarios, context); + } + + /// + /// Gets the rated usage scenarios. + /// + /// A scenario context. + /// The rated usage scenarios. + private static IPartnerScenario GetRatedUsageScenarios(IScenarioContext context) + { + var ratedUsageScenarios = new IPartnerScenario[] + { + new GetCustomerUsageSummary(context), + new GetCustomerSubscriptionsUsage(context), + new GetSubscriptionResourceUsage(context), + new GetSubscriptionUsageRecords(context), + new GetSubscriptionUsageSummary(context) + }; + + return new AggregatePartnerScenario("Rated usage samples", ratedUsageScenarios, context); + } + + /// + /// Gets the service request scenarios. + /// + /// A scenario context. + /// The service request scenarios. + private static IPartnerScenario GetServiceRequestsScenarios(IScenarioContext context) + { + var serviceRequestsScenarios = new IPartnerScenario[] + { + new CreatePartnerServiceRequest(context), + new GetCustomerServiceRequests(context), + new GetPagedPartnerServiceRequests(context, context.Configuration.Scenario.ServiceRequestPageSize), + new GetPartnerServiceRequestDetails(context), + new GetServiceRequestSupportTopics(context), + new UpdatePartnerServiceRequest(context) + }; + + return new AggregatePartnerScenario("Service request samples", serviceRequestsScenarios, context); + } + + /// + /// Gets the invoice scenarios. + /// + /// A scenario context. + /// The invoice scenarios. + private static IPartnerScenario GetInvoiceScenarios(IScenarioContext context) + { + var invoiceScenarios = new IPartnerScenario[] + { + new GetAccountBalance(context), + new GetInvoice(context), + new GetInvoiceLineItems(context, context.Configuration.Scenario.InvoicePageSize), + new GetPagedInvoices(context, context.Configuration.Scenario.InvoicePageSize), + new GetInvoiceSummaries(context), + new GetInvoiceStatement(context) + }; + + return new AggregatePartnerScenario("Invoice samples", invoiceScenarios, context); + } + + /// + /// Gets the profile scenarios. + /// + /// A scenario context. + /// The invoice scenarios. + private static IPartnerScenario GetProfileScenarios(IScenarioContext context) + { + var profileScenarios = new IPartnerScenario[] + { + new GetBillingProfile(context), + new GetLegalBusinessProfile(context), + new GetOrganizationProfile(context), + new GetMPNProfile(context), + new GetSupportProfile(context), + new UpdateBillingProfile(context), + new UpdateLegalBusinessProfile(context), + new UpdateOrganizationProfile(context), + new UpdateSupportProfile(context) + }; + + return new AggregatePartnerScenario("Partner profile samples", profileScenarios, context); + } + + /// + /// Gets the auditing scenarios. + /// + /// A scenario context. + /// The auditing scenarios. + private static IPartnerScenario GetAuditingScenarios(IScenarioContext context) + { + var profileScenarios = new IPartnerScenario[] + { + new QueryAuditRecords(context), + new SearchAuditRecords("Filter by company name", AuditRecordSearchField.CompanyName, context), + new SearchAuditRecordsByCustomerId("Filter by Customer Id", AuditRecordSearchField.CustomerId, context), + new SearchAuditRecordsByResourceType("Filter by Resource Type (Eg. Order, Customer, or Subscription)", AuditRecordSearchField.ResourceType, context) + }; + + return new AggregatePartnerScenario("Auditing samples", profileScenarios, context); + } + + /// + /// Gets the rate card scenarios. + /// + /// A scenario context. + /// The rate card scenarios. + private static IPartnerScenario GetRateCardScenarios(ScenarioContext context) + { + return new AggregatePartnerScenario("Rate card samples", new[] { new GetAzureRateCard(context) }, context); + } + + /// + /// Gets the Azure shared services rate card scenarios. + /// + /// A scenario context. + /// Azure shared services rate card scenarios. + private static IPartnerScenario GetSharedRateCardScenarios(ScenarioContext context) + { + return new AggregatePartnerScenario("Azure Shared Services Rate card samples", new[] { new GetAzureSharedRateCard(context) }, context); + } + + /// + /// Gets the indirect model scenarios. + /// + /// A scenario context. + /// The invoice scenarios. + private static IPartnerScenario GetIndirectModelScenarios(IScenarioContext context) + { + var indirectModelScenarios = new IPartnerScenario[] + { + new GetIndirectResellers(context), + new CreateCustomerForIndirectReseller(context), + new GetIndirectResellersOfCustomer(context), + new PlaceOrderForCustomer(context), + new GetCustomersOfIndirectReseller(context), + new VerifyPartnerMpnId(context), + new GetSubscriptionsByMpnId(context) + }; + + return new AggregatePartnerScenario("Indirect model samples", indirectModelScenarios, context); + } + + /// + /// Gets the service incident scenarios. + /// + /// A scenario context. + /// The service incident scenarios. + private static IPartnerScenario GetServiceIncidentScenarios(ScenarioContext context) + { + return new AggregatePartnerScenario("Service incident samples", new[] { new GetServiceIncidents(context) }, context); + } + + /// + /// Gets the Utilization scenarios. + /// + /// A scenario context. + /// The Utilization scenarios. + private static IPartnerScenario GetUtilizationScenarios(ScenarioContext context) + { + return new AggregatePartnerScenario("Utilization samples", new[] { new GetAzureSubscriptionUtilization(context) }, context); + } + + /// + /// Gets the partner analytics scenarios. + /// + /// A scenario context. + /// The Partner Analytics scenarios. + private static IPartnerScenario GetPartnerAnalyticsScenarios(IScenarioContext context) + { + var partnerAnalyticsScenarios = new IPartnerScenario[] + { + new GetPartnerLicensesDeploymentAnalytics(context), + new GetPartnerLicensesUsageAnalytics(context), + new GetCustomerLicensesDeploymentAnalytics(context), + new GetCustomerLicensesUsageAnalytics(context) + }; + + return new AggregatePartnerScenario("Partner Analytics samples", partnerAnalyticsScenarios, context); + } + + /// + /// Gets the customer service costs scenarios. + /// + /// A scenario context. + /// The customer service costs scenarios. + private static IPartnerScenario GetCustomerServiceCostsScenarios(IScenarioContext context) + { + var customerServiceCostsScenarios = new IPartnerScenario[] + { + new GetCustomerServiceCostsSummary(context), + new GetCustomerServiceCostsLineItems(context), + }; + + return new AggregatePartnerScenario("Customer service costs samples", customerServiceCostsScenarios, context); + } + + /// + /// Gets the address validation scenarios. + /// + /// A scenario context. + /// The address validation scenarios. + private static IPartnerScenario GetAddressValidationsScenarios(IScenarioContext context) + { + var addressValidationScenarios = new IPartnerScenario[] + { + new AddressValidation(context) + }; + + return new AggregatePartnerScenario("Address validation samples", addressValidationScenarios, context); + } + + /// + /// Gets the cart scenarios of create, update and checkout + /// + /// A scenario context. + /// The cart scenarios. + private static IPartnerScenario GetCartScenarios(IScenarioContext context) + { + var cartScenarios = new IPartnerScenario[] + { + new CreateCart(context), + new UpdateCart(context), + new CheckoutCart(context) + }; + + return new AggregatePartnerScenario("Cart Scenarios", cartScenarios, context); + } + } +} diff --git a/Source/Partner Center SDK Samples/Properties/AssemblyInfo.cs b/Source/Partner Center SDK Samples/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0fc0d17 --- /dev/null +++ b/Source/Partner Center SDK Samples/Properties/AssemblyInfo.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Partner Center Samples")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Partner Center Samples")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ac93e5cc-549c-4f13-9675-a86860918c2b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Partner Center SDK Samples/RateCards/GetAzureRateCard.cs b/Source/Partner Center SDK Samples/RateCards/GetAzureRateCard.cs new file mode 100644 index 0000000..2b1c062 --- /dev/null +++ b/Source/Partner Center SDK Samples/RateCards/GetAzureRateCard.cs @@ -0,0 +1,36 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.RateCards +{ + /// + /// Gets the Azure rate card. + /// + public class GetAzureRateCard : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetAzureRateCard(IScenarioContext context) : base("Get Azure rate card", context) + { + } + + /// + /// executes the get Azure rate card scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Retrieving Azure rate card"); + var azureRateCard = partnerOperations.RateCards.Azure.Get(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(azureRateCard, "Azure Rate Card"); + } + } +} diff --git a/Source/Partner Center SDK Samples/RateCards/GetAzureSharedRateCard.cs b/Source/Partner Center SDK Samples/RateCards/GetAzureSharedRateCard.cs new file mode 100644 index 0000000..3d16007 --- /dev/null +++ b/Source/Partner Center SDK Samples/RateCards/GetAzureSharedRateCard.cs @@ -0,0 +1,36 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.RateCards +{ + /// + /// Gets the Azure shared rate card. + /// + public class GetAzureSharedRateCard : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetAzureSharedRateCard(IScenarioContext context) : base("Get Azure shared rate card", context) + { + } + + /// + /// executes the get Azure shared rate card scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Retrieving Azure shared rate card"); + var azureSharedRateCard = partnerOperations.RateCards.Azure.GetShared(); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(azureSharedRateCard, "Azure Shared Rate Card"); + } + } +} diff --git a/Source/Partner Center SDK Samples/RatedUsage/GetCustomerSubscriptionsUsage.cs b/Source/Partner Center SDK Samples/RatedUsage/GetCustomerSubscriptionsUsage.cs new file mode 100644 index 0000000..b17d792 --- /dev/null +++ b/Source/Partner Center SDK Samples/RatedUsage/GetCustomerSubscriptionsUsage.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.RatedUsage +{ + /// + /// A scenario that retrieves the usage records for all the subscriptions owned by a customer. + /// + public class GetCustomerSubscriptionsUsage : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerSubscriptionsUsage(IScenarioContext context) : base("Get customer subscriptions usage", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer to retrieve his/her subscriptions usage"); + this.Context.ConsoleHelper.StartProgress("Retrieving customer subscriptions usage"); + + var customerUsageRecords = partnerOperations.Customers.ById(customerId).Subscriptions.UsageRecords.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerUsageRecords, "Customer subscriptions usage records"); + } + } +} diff --git a/Source/Partner Center SDK Samples/RatedUsage/GetCustomerUsageSummary.cs b/Source/Partner Center SDK Samples/RatedUsage/GetCustomerUsageSummary.cs new file mode 100644 index 0000000..a7ff4fa --- /dev/null +++ b/Source/Partner Center SDK Samples/RatedUsage/GetCustomerUsageSummary.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.RatedUsage +{ + /// + /// A scenario that retrieves a single customer usage summary for usage based services. + /// + public class GetCustomerUsageSummary : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerUsageSummary(IScenarioContext context) : base("Get customer usage summary", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer to retrieve his/her usage summary"); + this.Context.ConsoleHelper.StartProgress("Retrieving customer usage summary"); + + var customerUsageSummary = partnerOperations.Customers.ById(customerId).UsageSummary.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerUsageSummary, "Customer usage summary"); + } + } +} diff --git a/Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionResourceUsage.cs b/Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionResourceUsage.cs new file mode 100644 index 0000000..d43a7a6 --- /dev/null +++ b/Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionResourceUsage.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. + /// + public class GetSubscriptionResourceUsage : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSubscriptionResourceUsage(IScenarioContext context) : base("Get subscription resource usage", 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 orders"); + + var usageRecords = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId).UsageRecords.Resources.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(usageRecords, "Subscription resource usage records"); + } + } +} diff --git a/Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionUsageRecords.cs b/Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionUsageRecords.cs new file mode 100644 index 0000000..9d09d96 --- /dev/null +++ b/Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionUsageRecords.cs @@ -0,0 +1,39 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.RatedUsage +{ + /// + /// A scenario that retrieves a customer's subscriptions usage records. + /// + public class GetSubscriptionUsageRecords : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSubscriptionUsageRecords(IScenarioContext context) : base("Get customer subscriptions usage records", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their subscriptions usage records"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer subscriptions usage records"); + + var customerSubscription = partnerOperations.Customers.ById(customerId).Subscriptions.UsageRecords.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerSubscription, "Customer subscriptions usage records"); + } + } +} diff --git a/Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionUsageSummary.cs b/Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionUsageSummary.cs new file mode 100644 index 0000000..2f08f0e --- /dev/null +++ b/Source/Partner Center SDK Samples/RatedUsage/GetSubscriptionUsageSummary.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.RatedUsage +{ + /// + /// A scenario that retrieves the customer's subscription usage summary. + /// + public class GetSubscriptionUsageSummary : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSubscriptionUsageSummary(IScenarioContext context) : base("Get customer Subscription Usage Summary", 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 to retrieve it's usage summary"); + string subscriptionID = this.ObtainSubscriptionId(customerId, "Enter the ID of the subscription to retrieve it's usage summary"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer Subscription Usage Summary"); + + var customerSubscription = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionID).UsageSummary.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerSubscription, "Customer Subscription Usage Summary"); + } + } +} diff --git a/Source/Partner Center SDK Samples/ScenarioExecution/AggregateScenarioExecutionStrategy.cs b/Source/Partner Center SDK Samples/ScenarioExecution/AggregateScenarioExecutionStrategy.cs new file mode 100644 index 0000000..84cd6b7 --- /dev/null +++ b/Source/Partner Center SDK Samples/ScenarioExecution/AggregateScenarioExecutionStrategy.cs @@ -0,0 +1,99 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.ScenarioExecution +{ + using System; + using System.Globalization; + using Helpers; + + /// + /// An execution strategy which prompts the user to select a child scenario or exit the current scenario. + /// + public class AggregateScenarioExecutionStrategy : IScenarioExecutionStrategy + { + /// + /// Initializes a new instance of the class. + /// + public AggregateScenarioExecutionStrategy() + { + } + + /// + /// Determines whether the scenario is complete or it should be repeated. + /// + /// The scenario under consideration. + /// True is the scenario is complete, False is it should be repeated. + public bool IsScenarioComplete(IPartnerScenario scenario) + { + if (scenario == null) + { + throw new ArgumentNullException("scenario"); + } + + if (scenario.Children == null || scenario.Children.Count <= 0) + { + throw new ArgumentException("childScenarios must not be empty."); + } + + int scenarioNumber = AggregateScenarioExecutionStrategy.ReadScenarioNumberFromConsole(scenario.Children.Count); + + if (scenarioNumber > 0) + { + // run the selected child scenario + scenario.Children[scenarioNumber - 1].Run(); + + // the current scenario should be restarted + return false; + } + else + { + // user pressed escape, exit scenario + return true; + } + } + + /// + /// Reads user input from the console and extracts a scenario number from it. Returns 0 if the user entered nothing. + /// + /// The maximum scenario number to allow. + /// The scenario number the user entered or 0 if the user cancelled. + private static int ReadScenarioNumberFromConsole(int maxScenarioNumber) + { + if (maxScenarioNumber < 1) + { + throw new ArgumentException("maxScenarioNumber must be at least 1"); + } + + int scenarioNumber; + + while (true) + { + ConsoleHelper.Instance.Warning("Enter the scenario number to run (press Q to exit to previous screen): "); + string input = Console.ReadLine(); + + if (input.Equals("q", StringComparison.OrdinalIgnoreCase)) + { + scenarioNumber = 0; + break; + } + else if (int.TryParse(input, out scenarioNumber)) + { + if (scenarioNumber >= 1 && scenarioNumber <= maxScenarioNumber) + { + break; + } + else + { + ConsoleHelper.Instance.Error(string.Format(CultureInfo.InvariantCulture, "Enter a scenario number between 1 and {0}", maxScenarioNumber)); + } + } + } + + return scenarioNumber; + } + } +} diff --git a/Source/Partner Center SDK Samples/ScenarioExecution/IScenarioExecutionStrategy.cs b/Source/Partner Center SDK Samples/ScenarioExecution/IScenarioExecutionStrategy.cs new file mode 100644 index 0000000..a9df1a0 --- /dev/null +++ b/Source/Partner Center SDK Samples/ScenarioExecution/IScenarioExecutionStrategy.cs @@ -0,0 +1,21 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.ScenarioExecution +{ + /// + /// Defines the behavior to apply when a scenario is complete. + /// + public interface IScenarioExecutionStrategy + { + /// + /// Determines whether the scenario is complete or it should be repeated. + /// + /// The scenario under consideration. + /// True is the scenario is complete, False is it should be repeated. + bool IsScenarioComplete(IPartnerScenario scenario); + } +} diff --git a/Source/Partner Center SDK Samples/ScenarioExecution/PromptExecutionStrategy.cs b/Source/Partner Center SDK Samples/ScenarioExecution/PromptExecutionStrategy.cs new file mode 100644 index 0000000..4227d8b --- /dev/null +++ b/Source/Partner Center SDK Samples/ScenarioExecution/PromptExecutionStrategy.cs @@ -0,0 +1,36 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.ScenarioExecution +{ + using System; + using Helpers; + + /// + /// An scenario execution strategy that prompts the user repeat or exit the current scenario. + /// + public class PromptExecutionStrategy : IScenarioExecutionStrategy + { + /// + /// Determines whether the scenario is complete or it should be repeated. + /// + /// The scenario under consideration. + /// True is the scenario is complete, False is it should be repeated. + public bool IsScenarioComplete(IPartnerScenario scenario) + { + ConsoleHelper.Instance.Warning("Press Q return to the previous screen or R to repeat the current scenario:", false); + + ConsoleKeyInfo keyRead = Console.ReadKey(true); + + while (keyRead.Key != ConsoleKey.R && keyRead.Key != ConsoleKey.Q) + { + keyRead = Console.ReadKey(true); + } + + return keyRead.Key == ConsoleKey.Q; + } + } +} diff --git a/Source/Partner Center SDK Samples/ServiceIncidents/GetServiceIncidents.cs b/Source/Partner Center SDK Samples/ServiceIncidents/GetServiceIncidents.cs new file mode 100644 index 0000000..55d7b07 --- /dev/null +++ b/Source/Partner Center SDK Samples/ServiceIncidents/GetServiceIncidents.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.ServiceIncidents +{ + using Store.PartnerCenter.Models.Query; + using Store.PartnerCenter.Models.ServiceIncidents; + + /// + /// Gets the list of service incidents for a partner + /// + public class GetServiceIncidents : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetServiceIncidents(IScenarioContext context) : base("Get Service Incidents", context) + { + } + + /// + /// executes the get service incidents scenario. + /// + protected override void RunScenario() + { + const string SearchTerm = "false"; + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Retrieving Service incidents"); + + // Query service incidents based on their active status - resolved or not. resolved = false fetches all the active incidents for all subscribed services. + var serviceIncidents = partnerOperations.ServiceIncidents.Query(QueryFactory.Instance.BuildIndexedQuery(1, 0, new SimpleFieldFilter(ServiceIncidentSearchField.Resolved.ToString(), FieldFilterOperation.Equals, SearchTerm))); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(serviceIncidents, "Service Incidents"); + } + } +} diff --git a/Source/Partner Center SDK Samples/ServiceRequests/CreatePartnerServiceRequest.cs b/Source/Partner Center SDK Samples/ServiceRequests/CreatePartnerServiceRequest.cs new file mode 100644 index 0000000..11fbe63 --- /dev/null +++ b/Source/Partner Center SDK Samples/ServiceRequests/CreatePartnerServiceRequest.cs @@ -0,0 +1,68 @@ +// --------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ---------------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.ServiceRequests +{ + using System; + using Store.PartnerCenter.Models; + using Store.PartnerCenter.Models.ServiceRequests; + + /// + /// Creates a new service request. + /// + public class CreatePartnerServiceRequest : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public CreatePartnerServiceRequest(IScenarioContext context) : base("Create a new partner service request", context) + { + } + + /// + /// executes the create partner service request scenario. + /// + protected override void RunScenario() + { + string supportTopicId = this.Context.Configuration.Scenario.DefaultSupportTopicId; + var partnerOperations = this.Context.UserPartnerOperations; + + if (string.IsNullOrEmpty(supportTopicId.ToString())) + { + this.Context.ConsoleHelper.StartProgress("Fetching support topics"); + + // Get the list of support topics + ResourceCollection supportTopicsCollection = partnerOperations.ServiceRequests.SupportTopics.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(supportTopicsCollection, "Support topics"); + + // prompt the user the enter the support topic ID + supportTopicId = this.Context.ConsoleHelper.ReadNonEmptyString("Please enter the support topic ID ", "The support topic ID can't be empty"); + } + else + { + Console.WriteLine("Found support topic ID: {0} in configuration.", supportTopicId); + } + + ServiceRequest serviceRequestToCreate = new ServiceRequest() + { + Title = "TrialSR", + Description = "Ignore this SR", + Severity = ServiceRequestSeverity.Critical, + SupportTopicId = supportTopicId + }; + + this.Context.ConsoleHelper.StartProgress("Creating Service Request"); + + ServiceRequest serviceRequest = partnerOperations.ServiceRequests.Create(serviceRequestToCreate, "en-US"); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(serviceRequest, "Created Service Request"); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/ServiceRequests/GetCustomerServiceRequests.cs b/Source/Partner Center SDK Samples/ServiceRequests/GetCustomerServiceRequests.cs new file mode 100644 index 0000000..298ecc2 --- /dev/null +++ b/Source/Partner Center SDK Samples/ServiceRequests/GetCustomerServiceRequests.cs @@ -0,0 +1,63 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.ServiceRequests +{ + using System; + using System.Linq; + using Store.PartnerCenter.Models; + using Store.PartnerCenter.Models.ServiceRequests; + + /// + /// Gets customer service requests. + /// + public class GetCustomerServiceRequests : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetCustomerServiceRequests(IScenarioContext context) : base("Get customer service requests", context) + { + } + + /// + /// executes the get customer service requests scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string customerIdToRetrieve = this.Context.Configuration.Scenario.DefaultCustomerId; + + if (string.IsNullOrWhiteSpace(customerIdToRetrieve)) + { + // prompt the user the enter the customer ID + customerIdToRetrieve = this.Context.ConsoleHelper.ReadNonEmptyString("Please enter the ID of the customer to retrieve: ", "The customer ID can't be empty"); + } + else + { + Console.WriteLine("Found customer ID: {0} in configuration.", customerIdToRetrieve); + } + + this.Context.ConsoleHelper.StartProgress("Retrieving Customer's Service Requests"); + + ResourceCollection serviceRequests = + partnerOperations.Customers.ById(customerIdToRetrieve) + .ServiceRequests.Get(); + + this.Context.ConsoleHelper.StopProgress(); + + if (serviceRequests.Items.Count() == 0) + { + Console.WriteLine("No Service requests found for the given customer."); + } + else + { + this.Context.ConsoleHelper.WriteObject(serviceRequests, "Service Request results."); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/ServiceRequests/GetPagedPartnerServiceRequests.cs b/Source/Partner Center SDK Samples/ServiceRequests/GetPagedPartnerServiceRequests.cs new file mode 100644 index 0000000..4526cab --- /dev/null +++ b/Source/Partner Center SDK Samples/ServiceRequests/GetPagedPartnerServiceRequests.cs @@ -0,0 +1,66 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.ServiceRequests +{ + using System; + using System.Globalization; + using Store.PartnerCenter.Models.Query; + + /// + /// Get paged partner service requests. + /// + public class GetPagedPartnerServiceRequests : BasePartnerScenario + { + /// + /// The service requests page size. + /// + private readonly int serviceRequestPageSize; + + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + /// The number of service requests to return per page. + public GetPagedPartnerServiceRequests(IScenarioContext context, int serviceRequestPageSize = 0) : base("Get paged partner service requests", context) + { + this.serviceRequestPageSize = serviceRequestPageSize; + } + + /// + /// executes the get paged partner service requests scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + this.Context.ConsoleHelper.StartProgress("Querying Service Requests"); + + // query the service requests, get the first page if a page size was set + var serviceRequestsPage = partnerOperations.ServiceRequests.Query(QueryFactory.Instance.BuildIndexedQuery(this.serviceRequestPageSize)); + this.Context.ConsoleHelper.StopProgress(); + + // create a service requests enumerator which will aid us in traversing the service requests pages + var serviceRequestsEnumerator = partnerOperations.Enumerators.ServiceRequests.Create(serviceRequestsPage); + int pageNumber = 1; + + while (serviceRequestsEnumerator.HasValue) + { + this.Context.ConsoleHelper.WriteObject(serviceRequestsEnumerator.Current, string.Format(CultureInfo.InvariantCulture, "Service Requests Page: {0}", pageNumber++)); + Console.WriteLine(); + Console.Write("Press any key to retrieve the next service request page"); + Console.ReadKey(); + + this.Context.ConsoleHelper.StartProgress("Getting next service request page"); + + // get the next page of service requests + serviceRequestsEnumerator.Next(); + + this.Context.ConsoleHelper.StopProgress(); + Console.Clear(); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/ServiceRequests/GetPartnerServiceRequestDetails.cs b/Source/Partner Center SDK Samples/ServiceRequests/GetPartnerServiceRequestDetails.cs new file mode 100644 index 0000000..c4252ff --- /dev/null +++ b/Source/Partner Center SDK Samples/ServiceRequests/GetPartnerServiceRequestDetails.cs @@ -0,0 +1,50 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.ServiceRequests +{ + using System; + using Store.PartnerCenter.Models.ServiceRequests; + + /// + /// Gets a service request details for a partner. + /// + public class GetPartnerServiceRequestDetails : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetPartnerServiceRequestDetails(IScenarioContext context) : base("Get service request details", context) + { + } + + /// + /// executes the get service request details scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string serviceRequestIdToRetrieve = this.Context.Configuration.Scenario.DefaultServiceRequestId; + + if (string.IsNullOrWhiteSpace(serviceRequestIdToRetrieve)) + { + // prompt the user the enter the service request ID + serviceRequestIdToRetrieve = this.Context.ConsoleHelper.ReadNonEmptyString("Please enter the ID of the service request to retrieve ", "The ID can't be empty"); + } + else + { + Console.WriteLine("Found service request ID: {0} in configuration.", serviceRequestIdToRetrieve); + } + + this.Context.ConsoleHelper.StartProgress("Retrieving Service Request"); + ServiceRequest serviceRequest = partnerOperations.ServiceRequests.ById(serviceRequestIdToRetrieve).Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(serviceRequest, "Service Request details"); + } + } +} diff --git a/Source/Partner Center SDK Samples/ServiceRequests/GetServiceRequestSupportTopics.cs b/Source/Partner Center SDK Samples/ServiceRequests/GetServiceRequestSupportTopics.cs new file mode 100644 index 0000000..c5ad3ea --- /dev/null +++ b/Source/Partner Center SDK Samples/ServiceRequests/GetServiceRequestSupportTopics.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.ServiceRequests +{ + using Store.PartnerCenter.Models; + using Store.PartnerCenter.Models.ServiceRequests; + + /// + /// Gets the list of support topics. + /// + public class GetServiceRequestSupportTopics : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetServiceRequestSupportTopics(IScenarioContext context) : base("Get a list of service request support topics", context) + { + } + + /// + /// executes the get service request support topics scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + this.Context.ConsoleHelper.StartProgress("Getting support topics"); + + // Get support Topics + ResourceCollection supportTopicsCollection = partnerOperations.ServiceRequests.SupportTopics.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(supportTopicsCollection); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/ServiceRequests/UpdatePartnerServiceRequest.cs b/Source/Partner Center SDK Samples/ServiceRequests/UpdatePartnerServiceRequest.cs new file mode 100644 index 0000000..ae1657c --- /dev/null +++ b/Source/Partner Center SDK Samples/ServiceRequests/UpdatePartnerServiceRequest.cs @@ -0,0 +1,63 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.ServiceRequests +{ + using System; + using Store.PartnerCenter.Models.ServiceRequests; + + /// + /// Updates a partner's service request. + /// + public class UpdatePartnerServiceRequest : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdatePartnerServiceRequest(IScenarioContext context) : base("Update a partner's service request", context) + { + } + + /// + /// executes the update partner service request details scenario. + /// + protected override void RunScenario() + { + ServiceRequestNote note = new ServiceRequestNote { Text = "Sample Note" }; + var partnerOperations = this.Context.UserPartnerOperations; + string serviceRequestIdToUpdate = this.Context.Configuration.Scenario.DefaultServiceRequestId; + + if (string.IsNullOrWhiteSpace(serviceRequestIdToUpdate)) + { + // prompt the user the enter the service request ID + serviceRequestIdToUpdate = this.Context.ConsoleHelper.ReadNonEmptyString("Please enter the ID of the service request to update", "The service request ID can't be empty"); + } + else + { + Console.WriteLine("Found service request ID: {0} in configuration.", serviceRequestIdToUpdate); + } + + this.Context.ConsoleHelper.StartProgress("Retrieving service request to be updated"); + + // Retrieve service request + ServiceRequest serviceRequest = partnerOperations.ServiceRequests.ById(serviceRequestIdToUpdate).Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(serviceRequest, "Service Request to be updated"); + this.Context.ConsoleHelper.StartProgress("Updating Service Request"); + + // Updating service request + ServiceRequest updatedServiceRequest = partnerOperations.ServiceRequests.ById(serviceRequestIdToUpdate).Patch(new ServiceRequest + { + NewNote = note + }); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedServiceRequest, "Updated Service Request details"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Settings.StyleCop b/Source/Partner Center SDK Samples/Settings.StyleCop new file mode 100644 index 0000000..18ba2fd --- /dev/null +++ b/Source/Partner Center SDK Samples/Settings.StyleCop @@ -0,0 +1,15 @@ + + + + + False + + \.g\.cs$ + \.generated\.cs$ + \.g\.i\.cs$ + TemporaryGeneratedFile_.*\.cs$ + + + + + \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Subscriptions/AddSubscriptionAddOn.cs b/Source/Partner Center SDK Samples/Subscriptions/AddSubscriptionAddOn.cs new file mode 100644 index 0000000..13e6b08 --- /dev/null +++ b/Source/Partner Center SDK Samples/Subscriptions/AddSubscriptionAddOn.cs @@ -0,0 +1,75 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Subscriptions +{ + using System.Collections.Generic; + using Store.PartnerCenter.Models.Orders; + + /// + /// A scenario that adds a new add on to an existing subscription. + /// + public class AddSubscriptionAddOn : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public AddSubscriptionAddOn(IScenarioContext context) : base("Add subscription add on", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + // obtain the customer ID, the ID of the subscription to amend with the add on offer and the add on offer ID + var customerId = this.ObtainCustomerId(); + var subscriptionId = this.ObtainSubscriptionId(customerId, "Enter the subscription ID for which to purchase an add on"); + string addOnOfferId = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the ID of the add on offer to purchase", "Offer ID can't be empty"); + + var subscriptionOperations = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId); + + // get the parent subscription details + this.Context.ConsoleHelper.StartProgress("Retrieving order information for existing subscription"); + var parentSubscription = subscriptionOperations.Get(); + this.Context.ConsoleHelper.StopProgress(); + + // in order to buy an add on subscription for this offer, we need to patch/update the order through which the base offer was purchased + // by creating an order object with a single line item which represents the add-on offer purchase. + var orderToUpdate = new Order() + { + ReferenceCustomerId = customerId, + LineItems = new List() + { + new OrderLineItem() + { + LineItemNumber = 0, + OfferId = addOnOfferId, + FriendlyName = "Some friendly name", + Quantity = 2, + ParentSubscriptionId = subscriptionId + } + } + }; + + // update the order to apply the add on purchase + this.Context.ConsoleHelper.StartProgress("Updating parent subscription order"); + Order updatedOrder = partnerOperations.Customers.ById(customerId).Orders.ById(parentSubscription.OrderId).Patch(orderToUpdate); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedOrder, "Updated order"); + + // fetch the subscription add ons and display these + this.Context.ConsoleHelper.StartProgress("Retrieving subscription supported add ons"); + var subscriptionAddOns = subscriptionOperations.AddOns.Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(subscriptionAddOns, "Subscription add ons"); + } + } +} \ No newline at end of file diff --git a/Source/Partner Center SDK Samples/Subscriptions/ConvertTrialSubscription.cs b/Source/Partner Center SDK Samples/Subscriptions/ConvertTrialSubscription.cs new file mode 100644 index 0000000..02ba466 --- /dev/null +++ b/Source/Partner Center SDK Samples/Subscriptions/ConvertTrialSubscription.cs @@ -0,0 +1,54 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Subscriptions +{ + using System.Linq; + + /// + /// A scenario that converts a trial subscription to paid subscription. + /// + public class ConvertTrialSubscription : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public ConvertTrialSubscription(IScenarioContext context) : base("Convert customer trial subscription", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string customerId = this.ObtainCustomerId(); + string subscriptionId = this.ObtainSubscriptionId(customerId, "Enter the ID of the trial subscription to find conversions for"); + var subscriptionOperations = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId); + + this.Context.ConsoleHelper.StartProgress("Retrieving subscription conversions"); + var conversions = subscriptionOperations.Conversions.Get(); + this.Context.ConsoleHelper.StopProgress(); + + if (conversions.TotalCount <= 0) + { + this.Context.ConsoleHelper.Error("This subscription has no conversions"); + } + else + { + // Default to the first conversion. + var selectedConversion = conversions.Items.ToList()[0]; + this.Context.ConsoleHelper.WriteObject(conversions, "Available conversions"); + this.Context.ConsoleHelper.StartProgress("Converting trial subscription"); + var convertResult = subscriptionOperations.Conversions.Create(selectedConversion); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(convertResult, "Conversion details"); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Subscriptions/GetSubscription.cs b/Source/Partner Center SDK Samples/Subscriptions/GetSubscription.cs new file mode 100644 index 0000000..80c944a --- /dev/null +++ b/Source/Partner Center SDK Samples/Subscriptions/GetSubscription.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Subscriptions +{ + /// + /// A scenario that retrieves a customer subscription. + /// + public class GetSubscription : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSubscription(IScenarioContext context) : base("Get customer Subscription", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their Subscription"); + string subscriptionID = this.ObtainSubscriptionId(customerId, "Enter the subscription ID to retrieve"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer Subscription"); + + var customerSubscription = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionID).Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerSubscription, "Customer Subscription"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionProvisioningStatus.cs b/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionProvisioningStatus.cs new file mode 100644 index 0000000..442dfd0 --- /dev/null +++ b/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionProvisioningStatus.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Subscriptions +{ + /// + /// A scenario that retrieves a customer subscription's provisioning status. + /// + public class GetSubscriptionProvisioningStatus : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSubscriptionProvisioningStatus(IScenarioContext context) : base("Get subscription provisioning status", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their Subscription provisioning status"); + string subscriptionID = this.ObtainSubscriptionId(customerId, "Enter the subscription ID to retrieve"); + + this.Context.ConsoleHelper.StartProgress("Retrieving subscription provisioning status"); + + var provisioningStatus = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionID).ProvisioningStatus.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(provisioningStatus, "Subscription provisioning status"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionSupportContact.cs b/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionSupportContact.cs new file mode 100644 index 0000000..86e12b7 --- /dev/null +++ b/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionSupportContact.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Subscriptions +{ + /// + /// A scenario that retrieves the support contact of a customer's subscription. + /// + public class GetSubscriptionSupportContact : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSubscriptionSupportContact(IScenarioContext context) : base("Get subscription support contact", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their Subscription"); + string subscriptionID = this.ObtainSubscriptionId(customerId, "Enter the subscription ID to retrieve"); + + this.Context.ConsoleHelper.StartProgress("Retrieving subscription support contact"); + + var supportContact = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionID).SupportContact.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(supportContact, "Subscription support contact"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptions.cs b/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptions.cs new file mode 100644 index 0000000..838ca64 --- /dev/null +++ b/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptions.cs @@ -0,0 +1,39 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Subscriptions +{ + /// + /// A scenario that retrieves a customer subscription. + /// + public class GetSubscriptions : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSubscriptions(IScenarioContext context) : base("Get customer Subscriptions", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their Subscriptions"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer Subscriptions"); + + var customerSubscription = partnerOperations.Customers.ById(customerId).Subscriptions.Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerSubscription, "Customer Subscriptions"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionsByOrder.cs b/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionsByOrder.cs new file mode 100644 index 0000000..b6c4e95 --- /dev/null +++ b/Source/Partner Center SDK Samples/Subscriptions/GetSubscriptionsByOrder.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Subscriptions +{ + /// + /// A scenario that retrieves a customer subscriptions by order. + /// + public class GetSubscriptionsByOrder : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetSubscriptionsByOrder(IScenarioContext context) : base("Get customer subscriptions by order", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their subscriptions by order"); + string orderID = this.ObtainOrderID("Enter the Order ID to retrieve"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer subscriptions by order"); + + var customerSubscriptionsByOrder = partnerOperations.Customers.ById(customerId).Subscriptions.ByOrder(orderID).Get(); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(customerSubscriptionsByOrder, "Customer Subscriptions By Order"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Subscriptions/UpdateSubscription.cs b/Source/Partner Center SDK Samples/Subscriptions/UpdateSubscription.cs new file mode 100644 index 0000000..b23a79d --- /dev/null +++ b/Source/Partner Center SDK Samples/Subscriptions/UpdateSubscription.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Subscriptions +{ + /// + /// A scenario that updates an existing customer subscription. + /// + public class UpdateSubscription : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateSubscription(IScenarioContext context) : base("Update existing customer subscription", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + var customerId = this.ObtainCustomerId(); + var subscriptionId = this.ObtainSubscriptionId(customerId, "Enter the ID of the subscription to update"); + + this.Context.ConsoleHelper.StartProgress("Retrieving customer subscription"); + var existingSubscription = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId).Get(); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(existingSubscription, "Existing subscription"); + + this.Context.ConsoleHelper.StartProgress("Incrementing subscription quantity"); + existingSubscription.Quantity++; + var updatedSubscription = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId).Patch(existingSubscription); + this.Context.ConsoleHelper.StopProgress(); + + this.Context.ConsoleHelper.WriteObject(updatedSubscription, "Updated subscription"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Subscriptions/UpdateSubscriptionSupportContact.cs b/Source/Partner Center SDK Samples/Subscriptions/UpdateSubscriptionSupportContact.cs new file mode 100644 index 0000000..cb8d3a2 --- /dev/null +++ b/Source/Partner Center SDK Samples/Subscriptions/UpdateSubscriptionSupportContact.cs @@ -0,0 +1,43 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Subscriptions +{ + /// + /// A scenario that retrieves a customer subscription. + /// + public class UpdateSubscriptionSupportContact : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpdateSubscriptionSupportContact(IScenarioContext context) : base("Update subscription support contact", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + string customerId = this.ObtainCustomerId("Enter the ID of the customer whom to retrieve their Subscription"); + string subscriptionID = this.ObtainSubscriptionId(customerId, "Enter the subscription ID to retrieve"); + + this.Context.ConsoleHelper.StartProgress("Retrieving subscription support contact"); + + var supportContact = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionID).SupportContact.Get(); + + // Here we are the updating the support contact with the same object retrieved above. You can update it with a new object that has valid VAR values. + var updatedSupportContact = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionID).SupportContact.Update(supportContact); + + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updatedSupportContact, "Subscription support contact"); + } + } +} diff --git a/Source/Partner Center SDK Samples/Subscriptions/UpgradeSubscription.cs b/Source/Partner Center SDK Samples/Subscriptions/UpgradeSubscription.cs new file mode 100644 index 0000000..ef050f1 --- /dev/null +++ b/Source/Partner Center SDK Samples/Subscriptions/UpgradeSubscription.cs @@ -0,0 +1,70 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Subscriptions +{ + using System.Linq; + + /// + /// A scenario that upgrades a customer subscription to a higher skew. + /// + public class UpgradeSubscription : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public UpgradeSubscription(IScenarioContext context) : base("Upgrade customer subscription", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + string customerId = this.ObtainCustomerId(); + string subscriptionId = this.ObtainSubscriptionId(customerId, "Enter the ID of the subscription to find upgrades for"); + var subscriptionOperations = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId); + + this.Context.ConsoleHelper.StartProgress("Retrieving subscription upgrades"); + var upgrades = subscriptionOperations.Upgrades.Get(); + this.Context.ConsoleHelper.StopProgress(); + + if (upgrades.TotalCount <= 0) + { + this.Context.ConsoleHelper.Error("This subscription has no upgrades"); + } + else + { + this.Context.ConsoleHelper.WriteObject(upgrades, "Available upgrades"); + + // prompt the user to enter the offer ID of the upgrade he wishes to get + string upgradeOfferId = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the upgrade offer ID", "Upgrade offer ID can't be empty"); + var selectedUpgrade = (from upgrade in upgrades.Items where upgrade.TargetOffer.Id == upgradeOfferId select upgrade).FirstOrDefault(); + + if (selectedUpgrade == null) + { + this.Context.ConsoleHelper.Error("The entered upgrade offer ID was not found in the list of upgrades"); + } + else if (!selectedUpgrade.IsEligible) + { + this.Context.ConsoleHelper.Error("The entered upgrade is not eligible for the following reasons:"); + this.Context.ConsoleHelper.WriteObject(selectedUpgrade.UpgradeErrors, indent: 1); + } + else + { + // the selected upgrade is eligible, go ahead and perform the upgrade + this.Context.ConsoleHelper.StartProgress("Upgrading subscription"); + var updgradeResult = subscriptionOperations.Upgrades.Create(selectedUpgrade); + this.Context.ConsoleHelper.StopProgress(); + this.Context.ConsoleHelper.WriteObject(updgradeResult, "Upgrade details"); + } + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Utilization/GetAzureSubscriptionUtilization.cs b/Source/Partner Center SDK Samples/Utilization/GetAzureSubscriptionUtilization.cs new file mode 100644 index 0000000..076a8ef --- /dev/null +++ b/Source/Partner Center SDK Samples/Utilization/GetAzureSubscriptionUtilization.cs @@ -0,0 +1,69 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Utilization +{ + using System; + using System.Globalization; + + /// + /// A scenario that shows retrieving utilization records for an Azure subscription. + /// + public class GetAzureSubscriptionUtilization : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public GetAzureSubscriptionUtilization(IScenarioContext context) : base("Retrieve Azure Subscription Utilization Records", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + // get the customer ID and the Azure subscription ID to retrieve its utilization + string customerId = this.ObtainCustomerId(); + string subscriptionId = this.ObtainSubscriptionId(customerId); + + // retrieve the first 100 utilization records for the last 12 months + this.Context.ConsoleHelper.StartProgress("Retrieving Azure subscription utilization records"); + + var utilizationRecords = this.Context.UserPartnerOperations.Customers[customerId].Subscriptions[subscriptionId].Utilization.Azure.Query( + DateTimeOffset.Now.AddYears(-1), + DateTimeOffset.Now, + size: 100); + + this.Context.ConsoleHelper.StopProgress(); + + // create an Azure utilization enumerator which will aid us in traversing the utilization pages + var utilizationRecordEnumerator = this.Context.UserPartnerOperations.Enumerators.Utilization.Azure.Create(utilizationRecords); + int pageNumber = 1; + + while (utilizationRecordEnumerator.HasValue) + { + // print the current utilization results page + this.Context.ConsoleHelper.WriteObject( + utilizationRecordEnumerator.Current, + string.Format(CultureInfo.InvariantCulture, "Azure Utilization Records Page: {0}", pageNumber++)); + + Console.WriteLine(); + Console.Write("Press any key to retrieve the next Azure utilization records page"); + Console.ReadKey(); + + this.Context.ConsoleHelper.StartProgress("Getting next Azure utilization records page"); + + // get the next page + utilizationRecordEnumerator.Next(); + + this.Context.ConsoleHelper.StopProgress(); + Console.Clear(); + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Validations/AddressValidation.cs b/Source/Partner Center SDK Samples/Validations/AddressValidation.cs new file mode 100644 index 0000000..89d64c1 --- /dev/null +++ b/Source/Partner Center SDK Samples/Validations/AddressValidation.cs @@ -0,0 +1,72 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Validations +{ + using System; + using Models; + + /// + /// A scenario that showcases address validation functionality. + /// + public class AddressValidation : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public AddressValidation(IScenarioContext context) : base("Validate address.", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + // Get the address from the console + var address = new Address() + { + AddressLine1 = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the address line 1", "Address line 1 can't be empty"), + AddressLine2 = this.Context.ConsoleHelper.ReadOptionalString("Enter the address line 2 (optional)"), + City = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the city", "City can't be empty"), + State = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit state code", "State code can't be empty"), + Country = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code", "Country code can't be empty"), + PostalCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the postal/zip code", "Postal/zip code can't be empty") + }; + + this.Context.ConsoleHelper.StartProgress("Validating address"); + + try + { + // Validate the address + var validationResult = partnerOperations.Validations.IsAddressValidAsync(address).Result; + this.Context.ConsoleHelper.StopProgress(); + Console.WriteLine(validationResult ? "The address is valid." : "Invalid address"); + } + catch (Exception exception) + { + this.Context.ConsoleHelper.StopProgress(); + Console.WriteLine("Address is invalid"); + var innerException = exception.InnerException; + if (innerException != null) + { + while (innerException != null) + { + this.Context.ConsoleHelper.WriteObject(innerException.Message); + innerException = innerException.InnerException; + } + } + else if (!string.IsNullOrWhiteSpace(exception.Message)) + { + this.Context.ConsoleHelper.WriteObject(exception.Message); + } + } + } + } +} diff --git a/Source/Partner Center SDK Samples/Validations/ValidateAddress.cs b/Source/Partner Center SDK Samples/Validations/ValidateAddress.cs new file mode 100644 index 0000000..7b2b299 --- /dev/null +++ b/Source/Partner Center SDK Samples/Validations/ValidateAddress.cs @@ -0,0 +1,72 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.Samples.Validations +{ + using System; + using Models; + + /// + /// A scenario that showcases address validation functionality. + /// + public class ValidateAddress : BasePartnerScenario + { + /// + /// Initializes a new instance of the class. + /// + /// The scenario context. + public ValidateAddress(IScenarioContext context) : base("Validate address.", context) + { + } + + /// + /// Executes the scenario. + /// + protected override void RunScenario() + { + var partnerOperations = this.Context.UserPartnerOperations; + + // Get the address from the console + var address = new Address() + { + AddressLine1 = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the address line 1", "Address line 1 can't be empty"), + AddressLine2 = this.Context.ConsoleHelper.ReadOptionalString("Enter the address line 2 (optional)"), + City = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the city", "City can't be empty"), + State = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit state code", "State code can't be empty"), + Country = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code", "Country code can't be empty"), + PostalCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the postal/zip code", "Postal/zip code can't be empty") + }; + + this.Context.ConsoleHelper.StartProgress("Validating address"); + + try + { + // Validate the address + var validationResult = partnerOperations.Validations.IsAddressValidAsync(address).Result; + this.Context.ConsoleHelper.StopProgress(); + Console.WriteLine(validationResult ? "The address is valid." : "Invalid address"); + } + catch (Exception exception) + { + this.Context.ConsoleHelper.StopProgress(); + Console.WriteLine("Address is invalid"); + var innerException = exception.InnerException; + if (innerException != null) + { + while (innerException != null) + { + this.Context.ConsoleHelper.WriteObject(innerException.Message); + innerException = innerException.InnerException; + } + } + else if (!string.IsNullOrWhiteSpace(exception.Message)) + { + this.Context.ConsoleHelper.WriteObject(exception.Message); + } + } + } + } +} diff --git a/Source/Partner Center SDK Samples/packages.config b/Source/Partner Center SDK Samples/packages.config new file mode 100644 index 0000000..a8d7bb5 --- /dev/null +++ b/Source/Partner Center SDK Samples/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..943fade --- /dev/null +++ b/nuget.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file