private static void RemoveLicensesFromCustomerUser(IAggregatePartner partner, string customerId, string customerUserId, SubscribedSku sku) { LicenseAssignment license = new LicenseAssignment(); license.SkuId = sku.ProductSku.Id; license.ExcludedPlans = null; LicenseUpdate licenseUpdate = new LicenseUpdate() { LicensesToAssign = null, LicensesToRemove = new List <string>() { sku.ProductSku.Id } }; var removeLicensesUpdate = partner.Customers.ById(customerId).Users.ById(customerUserId).LicenseUpdates.Create(licenseUpdate); Helpers.WriteObject(removeLicensesUpdate, "Remove License update for customer user: "******"Assigned licenses for customer user: " + customerUserId); }
/// <summary> /// Addtional operations to be performed when cloning an instance of <see cref="LicenseAssignment"/> to an instance of <see cref="PSLicenseAssignment" />. /// </summary> /// <param name="licenseAssignment">The license agreement being cloned.</param> private void CloneAdditionalOperations(LicenseAssignment licenseAssignment) { if (licenseAssignment.ExcludedPlans.Any()) { ExcludedPlans.AddRange(licenseAssignment.ExcludedPlans); } }
private static void AssignLicensesToCustomerUser(IAggregatePartner partner, string customerId, string customerUserId, SubscribedSku sku) { LicenseAssignment license = new LicenseAssignment { SkuId = sku.ProductSku.Id, ExcludedPlans = null }; LicenseUpdate licenseUpdate = new LicenseUpdate() { LicensesToAssign = new List <LicenseAssignment>() { license } }; var assigndLicensesUpdate = partner.Customers.ById(customerId) .Users.ById(customerUserId) .LicenseUpdates.Create(licenseUpdate); Helpers.WriteObject(assigndLicensesUpdate, "Assign License update for customer user : "******"Assigned Licenses for the customer user : " + customerUserId); }
/// <summary> /// Executes the scenario. /// </summary> 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 <LicenseGroupId> groupIds = new List <LicenseGroupId>() { 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 <LicenseAssignment> licenseList = new List <LicenseAssignment>(); 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"); }
/// <summary> /// Executes the assign customer user a license scenario. /// </summary> 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 <LicenseAssignment> licenseList = new List <LicenseAssignment>(); 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"); }
public async Task AssignUserLicense(string office365CustomerId, string office365UserId, string office365ProductSku) { var license = new LicenseAssignment { SkuId = office365ProductSku, ExcludedPlans = null }; var licenseList = new List <LicenseAssignment> { license }; var updateLicense = new LicenseUpdate { LicensesToAssign = licenseList }; var requestSuccess = false; var attempts = 1; do { try { // Assign licenses to the user on Partner Partal await _partnerOperations.UserPartnerOperations.Customers.ById(office365CustomerId) .Users.ById(office365UserId).LicenseUpdates.CreateAsync(updateLicense); await ConfirmAssignUserLicense(office365CustomerId, office365UserId, office365ProductSku); requestSuccess = true; } catch (Exception ex) { this.Log().Error($"Assign license to user request failed! Attampt: {attempts}", ex); attempts++; await Task.Delay(3000); } } while (!requestSuccess && attempts < _retryAttempts); if (!requestSuccess) { throw new Exception("Could not assign User License!"); } }
/// <summary> /// Assign License. /// Documentation https://developers.google.com/licensing/v1/reference/licenseAssignments/update /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated licensing service.</param> /// <param name="productId">Name for product</param> /// <param name="skuId">Name for sku for which license would be revoked</param> /// <param name="userId">email id or unique Id of the user</param> /// <param name="body">A valid licensing v1 body.</param> /// <returns>LicenseAssignmentResponse</returns> public static LicenseAssignment Update(licensingService service, string productId, string skuId, string userId, LicenseAssignment body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (productId == null) { throw new ArgumentNullException(productId); } if (skuId == null) { throw new ArgumentNullException(skuId); } if (userId == null) { throw new ArgumentNullException(userId); } // Make the request. return(service.LicenseAssignments.Update(body, productId, skuId, userId).Execute()); } catch (Exception ex) { throw new Exception("Request LicenseAssignments.Update failed.", ex); } }
/// <summary> /// Executes the scenario. /// </summary> 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 <LicenseGroupId> groupIds = new List <LicenseGroupId>() { 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 <LicenseAssignment> licenseList = new List <LicenseAssignment>(); 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"); }
/// <summary> /// Initializes a new instance of the <see cref="PSLicenseAssignment" /> class. /// </summary> /// <param name="licenseAssignment">The base license assignment for this instance.</param> public PSLicenseAssignment(LicenseAssignment licenseAssignment) { ExcludedPlans = new List <string>(); this.CopyFrom(licenseAssignment, CloneAdditionalOperations); }