Esempio n. 1
0
        /// <summary>
        /// Updates the devices with configuration policies.
        /// </summary>
        /// <param name="entity">The device policy update request with devices to be updated.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>The location of the status to track the update.</returns>
        public async Task <string> UpdateAsync(DevicePolicyUpdateRequest entity, CancellationToken cancellationToken = default)
        {
            entity.AssertNotNull(nameof(entity));

            return(await Partner.ServiceClient.PatchAsync <DevicePolicyUpdateRequest, string>(
                       new Uri(
                           string.Format(
                               CultureInfo.InvariantCulture,
                               $"/{PartnerService.Instance.ApiVersion}/{PartnerService.Instance.Configuration.Apis.UpdateDevicesWithPolicies.Path}",
                               Context),
                           UriKind.Relative),
                       entity,
                       cancellationToken).ConfigureAwait(false));
        }
        /// <summary>
        /// Executes the update devices scenario.
        /// </summary>
        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 <KeyValuePair <PolicyCategory, string> > policyToBeAdded = new List <KeyValuePair <PolicyCategory, string> >
            {
                new KeyValuePair <PolicyCategory, string>(PolicyCategory.OOBE, selectedConfigurationPolicyId)
            };

            List <Device> devices = new List <Device>
            {
                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!");
        }