示例#1
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Scheduler.RunTask(async() =>
            {
                if (ShouldProcess(string.Format(
                                      CultureInfo.CurrentCulture,
                                      Resources.SetPartnerCustomerUserLicenseWhatIf,
                                      UserId)))
                {
                    IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync(CorrelationId, CancellationToken).ConfigureAwait(false);
                    List <LicenseAssignment> licensesToAssign = new List <LicenseAssignment>();

                    foreach (PSLicenseAssignment licenseAssignment in LicenseUpdate.LicensesToAssign)
                    {
                        licensesToAssign.Add(new LicenseAssignment
                        {
                            ExcludedPlans = licenseAssignment.ExcludedPlans,
                            SkuId         = licenseAssignment.SkuId
                        });
                    }

                    LicenseUpdate update = new LicenseUpdate
                    {
                        LicensesToAssign = licensesToAssign,
                        LicensesToRemove = LicenseUpdate.LicensesToRemove
                    };

                    update = await partner.Customers[CustomerId].Users[UserId].LicenseUpdates.CreateAsync(update, CancellationToken).ConfigureAwait(false);

                    WriteObject(new PSLicenseUpdate(update));
                }
            }, true);
        }
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            LicenseUpdate            update;
            List <LicenseAssignment> licensesToAssign;

            if (ShouldProcess(string.Format(
                                  CultureInfo.CurrentCulture,
                                  Resources.SetPartnerCustomerUserLicenseWhatIf,
                                  UserId)))
            {
                licensesToAssign = new List <LicenseAssignment>();

                foreach (PSLicenseAssignment licenseAssignment in LicenseUpdate.LicensesToAssign)
                {
                    licensesToAssign.Add(new LicenseAssignment
                    {
                        ExcludedPlans = licenseAssignment.ExcludedPlans,
                        SkuId         = licenseAssignment.SkuId
                    });
                }

                update = new LicenseUpdate
                {
                    LicensesToAssign = licensesToAssign,
                    LicensesToRemove = LicenseUpdate.LicensesToRemove
                };

                update = Partner.Customers[CustomerId].Users[UserId].LicenseUpdates.CreateAsync(update).GetAwaiter().GetResult();

                WriteObject(new PSLicenseUpdate(update));
            }
        }
示例#3
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);
        }
        public async Task RemoveUserMultiLicenses(string office365CustomerId, string office365UserId, List <string> office365ProductSkuList)
        {
            var updateLicense = new LicenseUpdate {
                LicensesToRemove = office365ProductSkuList
            };

            var requestSuccess = false;
            var attempts       = 1;

            do
            {
                try
                {
                    // Remove licenses from the user on Partner Partal
                    await _partnerOperations.UserPartnerOperations.Customers.ById(office365CustomerId)
                    .Users.ById(office365UserId).LicenseUpdates.CreateAsync(updateLicense);

                    requestSuccess = true;

                    await ConfirmRemoveUserLicens(office365CustomerId, office365UserId, office365ProductSkuList.FirstOrDefault());
                }
                catch (Exception ex)
                {
                    this.Log().Error($"Remove license from user request failed! Attampt: {attempts}", ex);
                    attempts++;
                    await Task.Delay(3000);
                }
            } while (!requestSuccess && attempts < _retryAttempts);

            if (!requestSuccess)
            {
                throw new Exception("Could not remove User Licenses!");
            }
        }
示例#5
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);
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PSLicenseUpdate" /> class.
        /// </summary>
        /// <param name="licenseUpdate">The based license update for this instance.</param>
        public PSLicenseUpdate(LicenseUpdate licenseUpdate)
        {
            LicensesToAssign = new List <PSLicenseAssignment>();
            LicensesToRemove = new List <string>();

            this.CopyFrom(licenseUpdate);
        }
        /// <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");
        }
        private async Task HandleSessionChangedInternalAsync(SessionNotification notification)
        {
            switch (notification.NotificationType)
            {
            case SessionNotificationType.WatchedFolderAdded:
                await SetWatchedFoldersAsync();

                break;

            case SessionNotificationType.WatchedFolderRemoved:
                await SetWatchedFoldersAsync();

                break;

            case SessionNotificationType.SignIn:
            case SessionNotificationType.SignOut:
                LoggedOn = Resolve.KnownIdentities.IsLoggedOn;
                break;

            case SessionNotificationType.WatchedFolderChange:
                FilesArePending = AreFilesPending();
                break;

            case SessionNotificationType.KnownKeyChange:
                if (notification.Identity == LogOnIdentity.Empty)
                {
                    throw new InvalidOperationException("Attempt to add the empty identity as a known key.");
                }
                if (!_fileSystemState.KnownPassphrases.Any(p => p.Thumbprint == notification.Identity.Passphrase.Thumbprint))
                {
                    _fileSystemState.KnownPassphrases.Add(notification.Identity.Passphrase);
                    await _fileSystemState.Save();
                }
                break;

            case SessionNotificationType.SessionStart:
            case SessionNotificationType.ActiveFileChange:
                FilesArePending = AreFilesPending();
                SetRecentFiles();
                break;

            case SessionNotificationType.LicensePolicyChanged:
                LicenseUpdate.Execute(null);
                break;

            case SessionNotificationType.WorkFolderChange:
            case SessionNotificationType.ProcessExit:
            case SessionNotificationType.SessionChange:
            default:
                break;
            }
        }
示例#9
0
        /// <summary>
        /// Assign licenses to a user.
        /// This method serves three scenarios:
        /// 1. Add license to a customer user.
        /// 2. Remove license from a customer user.
        /// 3. Update existing license for a customer user.
        /// </summary>
        /// <param name="entity">License update object.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>An object that represents the license update.</returns>
        public async Task <LicenseUpdate> CreateAsync(LicenseUpdate newEntity, CancellationToken cancellationToken = default)
        {
            newEntity.AssertNotNull(nameof(newEntity));

            return(await Partner.ServiceClient.PostAsync <LicenseUpdate, LicenseUpdate>(
                       new Uri(
                           string.Format(
                               CultureInfo.InvariantCulture,
                               $"/{PartnerService.Instance.ApiVersion}/{PartnerService.Instance.Configuration.Apis.SetCustomerUserLicenseUpdates.Path}",
                               Context.Item1,
                               Context.Item2),
                           UriKind.Relative),
                       newEntity,
                       cancellationToken).ConfigureAwait(false));
        }
示例#10
0
        /// <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");
        }
示例#11
0
        private void BindPropertyChangedEvents()
        {
            BindPropertyChangedInternal(nameof(DragAndDropFiles), (IEnumerable <string> files) => { DragAndDropFilesTypes = DetermineFileTypes(files.Select(f => New <IDataItem>(f))); });
            BindPropertyChangedInternal(nameof(DragAndDropFiles), (IEnumerable <string> files) => { DroppableAsRecent = DetermineDroppableAsRecent(files.Select(f => New <IDataItem>(f))); });
            BindPropertyChangedInternal(nameof(DragAndDropFiles), (IEnumerable <string> files) => { DroppableAsWatchedFolder = DetermineDroppableAsWatchedFolder(files.Select(f => New <IDataItem>(f))); });
            BindPropertyChangedInternal(nameof(RecentFilesComparer), (ActiveFileComparer comparer) => { SetRecentFilesComparer(); });
            BindPropertyChangedInternal(nameof(LoggedOn), (bool loggedOn) => LicenseUpdate.Execute(null));
            BindPropertyChangedInternal(nameof(LoggedOn), async(bool loggedOn) => { if (loggedOn)
                                                                                    {
                                                                                        await AxCryptUpdateCheck.ExecuteAsync(_userSettings.LastUpdateCheckUtc);
                                                                                    }
                                        });

            BindPropertyChanged(nameof(DebugMode), (bool enabled) => { UpdateDebugMode(enabled); });
            BindPropertyChanged(nameof(LoggedOn), (bool loggedOn) => EncryptFileEnabled = loggedOn || !License.Has(LicenseCapability.EncryptNewFiles));
            BindPropertyChanged(nameof(License), async(LicenseCapabilities policy) => await SetWatchedFoldersAsync());
            BindPropertyChanged(nameof(EncryptionUpgradeMode), (EncryptionUpgradeMode mode) => Resolve.UserSettings.EncryptionUpgradeMode = mode);
            BindPropertyChanged(nameof(FolderOperationMode), async(FolderOperationMode mode) => await SetFolderOperationMode(mode));
        }
        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!");
            }
        }
示例#13
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");
        }
        /// <summary>
        /// Modifies the license represented by the instance of <see cref="EditUserModel"/>.
        /// </summary>
        /// <param name="model">An instance of <see cref="EditUserModel"/> that represents the modifications to be made.</param>
        /// <returns>An instance of <see cref="Task"/> that represents the asynchronous operation.</returns>
        private async Task ProcessLicenseModifications(EditUserModel model)
        {
            LicenseUpdate            licenseUpdate;
            LicenseModel             license;
            List <LicenseModel>      current;
            List <LicenseAssignment> assignments;
            List <string>            removals;

            try
            {
                assignments = new List <LicenseAssignment>();
                current     = await this.GetLicenses(model.CustomerId, model.UserId);

                licenseUpdate = new LicenseUpdate();
                removals      = new List <string>();

                foreach (LicenseModel item in current)
                {
                    license = model.Licenses.SingleOrDefault(x => x.Id.Equals(item.Id, StringComparison.CurrentCultureIgnoreCase));

                    if (license == null)
                    {
                        continue;
                    }

                    if (!item.IsAssigned && license.IsAssigned)
                    {
                        assignments.Add(new LicenseAssignment()
                        {
                            ExcludedPlans = null, SkuId = license.Id
                        });
                    }
                    else if (item.IsAssigned && !license.IsAssigned)
                    {
                        removals.Add(license.Id);
                    }
                }

                if (assignments.Count > 0)
                {
                    licenseUpdate.LicensesToAssign = assignments;
                }

                if (removals.Count > 0)
                {
                    licenseUpdate.LicensesToRemove = removals;
                }

                if (assignments.Count > 0 || removals.Count > 0)
                {
                    await this.Service.PartnerCenter.Customers.ById(model.CustomerId)
                    .Users.ById(model.UserId).LicenseUpdates.CreateAsync(licenseUpdate);
                }
            }
            finally
            {
                assignments   = null;
                current       = null;
                license       = null;
                licenseUpdate = null;
                removals      = null;
            }
        }