/// <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");
        }
コード例 #2
0
        public ActivationReportSubscribedSKUOutputItem()
        {
            SubscribedSKU    = new SubscribedSku();
            SKUSubscriptions = new List <PartnerSdkModels.Subscriptions.Subscription>();

            ActionType    = string.Empty;
            ActionSubType = string.Empty;
        }
コード例 #3
0
        /// <summary>
        /// Addtional operations to be performed when cloning an instance of <see cref="SubscribedSku"/> to an instance of <see cref="PSSubscribedSku" />.
        /// </summary>
        /// <param name="sku">The sku being cloned.</param>
        private void CloneAdditionalOperations(SubscribedSku sku)
        {
            ServicePlans.AddRange(sku.ServicePlans);

            LicenseGroupId = sku.ProductSku.LicenseGroupId;
            ProductName    = sku.ProductSku.Name;
            SkuId          = sku.ProductSku.Id;
            SkuPartNumber  = sku.ProductSku.SkuPartNumber;
            TargetType     = sku.ProductSku.TargetType;
        }
コード例 #4
0
        /// <summary>
        /// Add new entity to subscribedSkus
        /// <param name="body"></param>
        /// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
        /// </summary>
        public RequestInformation CreatePostRequestInformation(SubscribedSku body, Action <SubscribedSkusRequestBuilderPostRequestConfiguration> requestConfiguration = default)
        {
            _ = body ?? throw new ArgumentNullException(nameof(body));
            var requestInfo = new RequestInformation {
                HttpMethod     = Method.POST,
                UrlTemplate    = UrlTemplate,
                PathParameters = PathParameters,
            };

            requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
            if (requestConfiguration != null)
            {
                var requestConfig = new SubscribedSkusRequestBuilderPostRequestConfiguration();
                requestConfiguration.Invoke(requestConfig);
                requestInfo.AddRequestOptions(requestConfig.Options);
                requestInfo.AddHeaders(requestConfig.Headers);
            }
            return(requestInfo);
        }
コード例 #5
0
        /// <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");
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
 public static SubscribedSku CreateSubscribedSku(string objectId, global::System.Collections.ObjectModel.Collection<ServicePlanInfo> servicePlans)
 {
     SubscribedSku subscribedSku = new SubscribedSku();
     subscribedSku.objectId = objectId;
     if ((servicePlans == null))
     {
         throw new global::System.ArgumentNullException("servicePlans");
     }
     subscribedSku.servicePlans = servicePlans;
     return subscribedSku;
 }
コード例 #9
0
 public void AddTosubscribedSkus(SubscribedSku subscribedSku)
 {
     base.AddObject("subscribedSkus", subscribedSku);
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PSSubscribedSku" /> class.
 /// </summary>
 /// <param name="sku">The base sku for this instance.</param>
 public PSSubscribedSku(SubscribedSku sku)
 {
     ServicePlans = new List <ServicePlan>();
     this.CopyFrom(sku, CloneAdditionalOperations);
 }
コード例 #11
0
 /// <summary>
 /// Addtional operations to be performed when cloning an instance of <see cref="SubscribedSku"/> to an instance of <see cref="PSSubscribedSku" />.
 /// </summary>
 /// <param name="sku">The sku being cloned.</param>
 private void CloneAdditionalOperations(SubscribedSku sku)
 {
     ServicePlans.AddRange(sku.ServicePlans);
 }
コード例 #12
0
        public override async Task ReportItemProcessorFunctionAsync(
            BlockingCollection <ReportOutputItem> results,
            List <PartnerSdkModels.Customers.Customer> customers, PartnerSdkModels.Customers.Customer customer,
            int currentPage)
        {
            _logger.Info(string.Format("Thread: {0} Batch: {1}. Processing customer: {2} ({3}/{4}) / (ID: {5} - CID: {6} - TD: {7})",
                                       Thread.CurrentThread.ManagedThreadId, currentPage,
                                       customer.CompanyProfile.CompanyName, customers.IndexOf(customer) + 1, customers.Count,
                                       customer.Id, customer.CommerceId, customer.CompanyProfile.Domain));

            CustomerUsageReportOutputItem reportOutputItem = new CustomerUsageReportOutputItem()
            {
                Customer = customer
            };

            #region Execute base customer validations

            if (ExecuteReportItemProcessorCustomerBaseValidations(reportOutputItem, results, customer))
            {
                // Customer matched one of the validations. Return
                return;
            }

            #endregion

            try
            {
                #region Get customer domains

                // NOTE: We always include the customer domains, to include this info in the report,
                // even if the customer does not have any subscribed SKUs

                _logger.Debug("GetCustomerDomains");
                List <Domain> customerDomains = Program.GetCustomerDomains(customer);
                // Extract domains information
                reportOutputItem.OnMicrosoftDomain = customerDomains.FirstOrDefault(domain => domain.IsInitial && domain.IsVerified).Name;
                reportOutputItem.DefaultDomain     = customerDomains.FirstOrDefault(domain => domain.IsDefault && domain.IsVerified).Name;

                #endregion

                #region Get Subscribed Skus information

                _logger.Debug("GetCustomerSubscribedSkus");
                List <SubscribedSku> customerSubscribedSkus = await Program.GetCustomerSubscribedSkus(customer);

                #region Execute base subscribed Skus validations

                if (ExecuteReportItemProcessorSubscribedSkusBaseValidations(reportOutputItem, results, customer, customerSubscribedSkus))
                {
                    // Matched one of the validations. Return
                    return;
                }

                #endregion

                #endregion

                #region Get Subscriptions information

                _logger.Debug("GetCustomerSubscriptions");
                List <PartnerSdkModels.Subscriptions.Subscription> customerSubscriptions =
                    await Program.GetCustomerSubscriptions(customer);

                #region Execute base subscriptions validations

                if (ExecuteReportItemProcessorSubscriptionsBaseValidations(reportOutputItem, results, customer, customerSubscriptions))
                {
                    // Matched one of the validations. Return
                    return;
                }

                #endregion

                #endregion

                #region Extract information from each subscription

                foreach (PartnerSdkModels.Subscriptions.Subscription subscription in customerSubscriptions)
                {
                    _logger.Info(string.Format("Processing subscription: {0} ({1}/{2})",
                                               subscription.FriendlyName, customerSubscriptions.IndexOf(subscription) + 1,
                                               customerSubscriptions.Count));

                    reportOutputItem.SubscriptionId       = Guid.Parse(subscription.Id);
                    reportOutputItem.SubscriptionStatus   = subscription.Status.ToString();
                    reportOutputItem.SubscriptionQuantity = (uint)subscription.Quantity;

                    if (subscription.Status != PartnerSdkModels.Subscriptions.SubscriptionStatus.Active)
                    {
                        // Subscription is not active. Nothing to do
                        reportOutputItem.GlobalActionType    = "ACTIVATION OPPORTUNITY";
                        reportOutputItem.GlobalActionSubType = "Subscription state: " + subscription.Status.ToString();
                        results.Add(Program.Clone(reportOutputItem));
                        return;
                    }

                    // Subscription Offer information
                    // This is necessary to match Subscribed SKU to a Subscription
                    // Subscribed SKU has the SKU Product ID field
                    // Subscription has the Offer ID field
                    // The Offer detail is the connection between them, because the Offer has the Offer ID and the Product ID
                    _logger.Debug("GetSubscriptionOffer");
                    PartnerSdkModels.Offers.Offer subscriptionOffer = await Program.GetOfferById(subscription.OfferId.ToString());

                    reportOutputItem.OfferName = subscriptionOffer.Name;

                    // Subscription SKU
                    SubscribedSku subscriptionSubscribedSku = customerSubscribedSkus.FirstOrDefault(sku =>
                                                                                                    sku.SkuId.ToString().Equals(subscriptionOffer.Product.Id, StringComparison.InvariantCultureIgnoreCase));

                    if (subscriptionSubscribedSku == null)
                    {
                        reportOutputItem.GlobalActionType    = "Not supported";
                        reportOutputItem.GlobalActionSubType = "Subscription Offer does not map to any CSP Subscribed SKU Product";
                        results.Add(Program.Clone(reportOutputItem));
                        continue;
                    }

                    reportOutputItem.SKUPartNumber    = subscriptionSubscribedSku.SkuPartNumber;
                    reportOutputItem.SKUTotalServices = subscriptionSubscribedSku.ServicePlans.Count();
                    reportOutputItem.SKUAssignedSeats = subscriptionSubscribedSku.ConsumedUnits;

                    #region Extract global user's information (in terms of number of users, not detailed user's information)

                    // For tenant level information
                    // Ex: Subscription is for 20 seats, but only 5 are using each of the services?

                    foreach (ServicePlanInfo servicePlan in subscriptionSubscribedSku.ServicePlans)
                    {
                        _logger.Info(string.Format("Processing SKU Service Plan: {0} ({1}/{2})",
                                                   servicePlan.ServicePlanName, subscriptionSubscribedSku.ServicePlans.IndexOf(servicePlan) + 1,
                                                   subscriptionSubscribedSku.ServicePlans.Count));

                        reportOutputItem.SKUService = servicePlan.ServicePlanName;
                        reportOutputItem.SKUServiceProvisioningStatus = servicePlan.ProvisioningStatus.ToString();

                        switch (servicePlan.ServicePlanName)
                        {
                        case "EXCHANGE_S_STANDARD":
                        case "EXCHANGE_S_DESKLESS":
                            CustomerMailboxUsageReport customerMailboxUsageReport = Program.GetCustomerMailboxUsageReport(customer);
                            reportOutputItem.SKUServiceActiveUsers = customerMailboxUsageReport.TotalMailboxCount;
                            break;

                        case "MCOSTANDARD":
                            CustomerCsActiveUserReport customerCsActiveUserReport = Program.GetCustomerCsActiveUserReport(customer);
                            reportOutputItem.SKUServiceActiveUsers = customerCsActiveUserReport.ActiveUsers;
                            break;

                        case "SHAREPOINTSTANDARD":
                            CustomerSPOActiveUserReport customerSPOActiveUserReport = Program.GetCustomerSPOActiveUserReport(customer);
                            reportOutputItem.SKUServiceActiveUsers = customerSPOActiveUserReport.UniqueUsers;

                            // Also has OneDrive ?????
                            // CustomerSPOSkyDriveProDeployedReport customerSPOSkyDriveProDeployedReport = await Program.GetCustomerSPOSkyDriveProDeployedReport(customer);
                            //reportOutputItem.SKUServiceActiveUsers = customerSPOSkyDriveProDeployedReport.Active;
                            break;

                        case "SHAREPOINTWAC":
                        case "OFFICE_BUSINESS":
                        case "OFFICESUBSCRIPTION":
                        case "ONEDRIVEENTERPRISE":
                        case "ONEDRIVESTANDARD":
                        case "SWAY":
                        case "INTUNE_O365":
                        case "YAMMER_ENTERPRISE":
                        default:
                            reportOutputItem.GlobalActionType    = "Not supported";
                            reportOutputItem.GlobalActionSubType = "Service Plan information extraction not supported";
                            results.Add(Program.Clone(reportOutputItem));
                            continue;
                        }

                        if (reportOutputItem.SKUServiceActiveUsers < reportOutputItem.SKUAssignedSeats)
                        {
                            reportOutputItem.GlobalActionType    = "ACTIVATION OPPORTUNITY";
                            reportOutputItem.GlobalActionSubType = "Not all users are active on the service";
                        }
                        else
                        {
                            reportOutputItem.GlobalActionType    = "NO ACTION NEEDED";
                            reportOutputItem.GlobalActionSubType = "All users are active on the service";
                        }

                        results.Add(Program.Clone(reportOutputItem));
                    }

                    #endregion
                }

                #endregion
            }
            catch (Exception ex)
            {
                _logger.Warn("Error: " + ex.ToString());

                reportOutputItem.GlobalActionType    = "ERROR";
                reportOutputItem.GlobalActionSubType = ex.ToString().Replace("\r\n", " ").Replace("\n", " ").Replace("\t", " ");
                results.Add(Program.Clone(reportOutputItem));
            }
        }