private void ProcessRequest(Instance request) { var userLicense = new LicenseAssignmentInsert { UserId = UserId }; try { var service = request.LicensingService.LicenseAssignments.Insert(userLicense, ProductId, SkuId); var license = service.Execute(); if (license == null) return; WriteObject(license); } catch (Exception e) { Console.WriteLine("Failed to Update User License!"); Console.WriteLine("Error: " + e); } }
/// <summary> /// Assign License. /// Documentation https://developers.google.com/licensing/v1/reference/licenseAssignments/insert /// 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</param> /// <param name="body">A valid licensing v1 body.</param> /// <returns>LicenseAssignmentResponse</returns> public static LicenseAssignment Insert(licensingService service, string productId, string skuId, LicenseAssignmentInsert 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); } // Make the request. return(service.LicenseAssignments.Insert(body, productId, skuId).Execute()); } catch (Exception ex) { throw new Exception("Request LicenseAssignments.Insert failed.", ex); } }