// IClientPropertyHandler
        public async Task <CommandStatus> OnDesiredPropertyChange(JToken desiredValue)
        {
            if (!(desiredValue is JObject))
            {
                throw new Error(ErrorCodes.INVALID_DESIRED_JSON_VALUE, "Invalid json value type for the " + PropertySectionName + " node.");
            }

            TimeServiceDataContract.DesiredProperties desiredProperties = TimeServiceDataContract.DesiredProperties.FromJsonObject((JObject)desiredValue);

            // Construct the request and send it...
            Message.Policy policy = new Message.Policy();
            policy.source           = Message.PolicySource.Remote;
            policy.sourcePriorities = desiredProperties.sourcePriority == PolicyDataContract.JsonLocal ? _priorityLocal : _priorityRemote;

            Message.TimeServiceData data = new Message.TimeServiceData();
            data.enabled = desiredProperties.enabled;
            data.startup = desiredProperties.startup;
            data.started = desiredProperties.started;
            data.policy  = policy;

            var request = new Message.SetTimeServiceRequest(data);

            await this._systemConfiguratorProxy.SendCommandAsync(request);

            // Report to the device twin....
            var reportedProperties = await GetTimeServiceAsync();

            await this._callback.ReportPropertiesAsync(PropertySectionName, JObject.FromObject(reportedProperties));

            return(CommandStatus.Committed);
        }
Пример #2
0
        public static string SourcePriorityFromPolicy(Message.Policy policy)
        {
            if (policy == null || policy.sourcePriorities == null || policy.sourcePriorities.Count == 0)
            {
                return(PolicyDataContract.JsonUnknown);
            }

            if (policy.sourcePriorities[0] == Message.PolicySource.Local)
            {
                return(PolicyDataContract.JsonLocal);
            }
            else if (policy.sourcePriorities[0] == Message.PolicySource.Remote)
            {
                return(PolicyDataContract.JsonRemote);
            }
            return(PolicyDataContract.JsonUnknown);
        }
        public async Task SetRingAsync(WindowsUpdateRingState userDesiredState)
        {
            // Construct the request and send it...
            Message.Policy policy = new Message.Policy();
            policy.source           = Message.PolicySource.Local;
            policy.sourcePriorities = userDesiredState.settingsPriority == SettingsPriority.Local ? PolicyHelpers.PriorityLocal : PolicyHelpers.PriorityRemote;

            Message.SetWindowsUpdatePolicyRequest request = new Message.SetWindowsUpdatePolicyRequest();
            request.ApplyFromDeviceTwin = WindowsUpdatePolicyDataContract.JsonYes;
            request.data = new Message.WindowsUpdatePolicyConfiguration();
            request.data.activeFields  = (uint)Message.ActiveFields.Ring;
            request.data.ring          = WindowsUpdateRingState.RingToJsonString(userDesiredState.ring);
            request.data.policy        = policy;
            request.ReportToDeviceTwin = Constants.JsonValueUnspecified;    // Keep whatever already stored.
            await _systemConfiguratorProxy.SendCommandAsync(request);

            await ReportToDeviceTwin();
        }
        public async Task SetTimeServiceAsync(TimeServiceState userDesiredState)
        {
            // Construct the request and send it...
            Message.Policy policy = new Message.Policy();
            policy.source           = Message.PolicySource.Local;
            policy.sourcePriorities = userDesiredState.settingsPriority == SettingsPriority.Local ? _priorityLocal : _priorityRemote;

            Message.TimeServiceData data = new Message.TimeServiceData();
            data.enabled = userDesiredState.enabled ? TimeServiceDataContract.JsonYes : TimeServiceDataContract.JsonNo;
            data.startup = userDesiredState.startup == ServiceStartup.Auto ? TimeServiceDataContract.JsonAuto : TimeServiceDataContract.JsonManual;
            data.started = userDesiredState.started ? TimeServiceDataContract.JsonYes : TimeServiceDataContract.JsonNo;
            data.policy  = policy;

            var setRequest = new Message.SetTimeServiceRequest(data);

            await this._systemConfiguratorProxy.SendCommandAsync(setRequest);

            // Get the current state....
            TimeServiceDataContract.ReportedProperties reportedProperties = await GetTimeServiceAsync();

            await this._callback.ReportPropertiesAsync(PropertySectionName, reportedProperties.ToJsonObject());
        }
        // IClientPropertyHandler
        public async Task <CommandStatus> OnDesiredPropertyChange(JToken desiredValue)
        {
            if (!(desiredValue is JObject))
            {
                throw new Error(ErrorCodes.INVALID_DESIRED_JSON_VALUE, "Invalid json value type for the " + PropertySectionName + " node.");
            }

            WindowsUpdatePolicyDataContract.DesiredProperties desiredProperties = WindowsUpdatePolicyDataContract.DesiredProperties.FromJsonObject((JObject)desiredValue);

            if (desiredProperties.applyProperties != null)
            {
                Message.SetWindowsUpdatePolicyRequest request = new Message.SetWindowsUpdatePolicyRequest();
                request.ApplyFromDeviceTwin = desiredProperties.applyProperties != null ? WindowsUpdatePolicyDataContract.JsonYes : WindowsUpdatePolicyDataContract.JsonNo;
                request.ReportToDeviceTwin  = desiredProperties.reportProperties;
                request.data = new Message.WindowsUpdatePolicyConfiguration();
                request.data.activeFields = 0;

                // Construct the request and send it...
                Message.Policy policy = new Message.Policy();
                policy.source           = Message.PolicySource.Remote;
                policy.sourcePriorities = desiredProperties.applyProperties.sourcePriority == PolicyDataContract.JsonLocal ? _priorityLocal : _priorityRemote;
                request.data.policy     = policy;

                if (desiredProperties.applyProperties.activeHoursStart != -1)
                {
                    request.data.activeHoursStart = (uint)desiredProperties.applyProperties.activeHoursStart;
                    request.data.activeFields    |= (uint)Message.ActiveFields.ActiveHoursStart;
                }

                if (desiredProperties.applyProperties.activeHoursEnd != -1)
                {
                    request.data.activeHoursEnd = (uint)desiredProperties.applyProperties.activeHoursEnd;
                    request.data.activeFields  |= (uint)Message.ActiveFields.ActiveHoursEnd;
                }

                if (desiredProperties.applyProperties.allowAutoUpdate != -1)
                {
                    request.data.allowAutoUpdate = (uint)desiredProperties.applyProperties.allowAutoUpdate;
                    request.data.activeFields   |= (uint)Message.ActiveFields.AllowAutoUpdate;
                }

                if (desiredProperties.applyProperties.allowUpdateService != -1)
                {
                    request.data.allowUpdateService = (uint)desiredProperties.applyProperties.allowUpdateService;
                    request.data.activeFields      |= (uint)Message.ActiveFields.AllowUpdateService;
                }

                if (desiredProperties.applyProperties.branchReadinessLevel != -1)
                {
                    request.data.branchReadinessLevel = (uint)desiredProperties.applyProperties.branchReadinessLevel;
                    request.data.activeFields        |= (uint)Message.ActiveFields.BranchReadinessLevel;
                }

                if (desiredProperties.applyProperties.deferFeatureUpdatesPeriod != -1)
                {
                    request.data.deferFeatureUpdatesPeriod = (uint)desiredProperties.applyProperties.deferFeatureUpdatesPeriod;
                    request.data.activeFields |= (uint)Message.ActiveFields.DeferFeatureUpdatesPeriod;
                }

                if (desiredProperties.applyProperties.deferQualityUpdatesPeriod != -1)
                {
                    request.data.deferQualityUpdatesPeriod = (uint)desiredProperties.applyProperties.deferQualityUpdatesPeriod;
                    request.data.activeFields |= (uint)Message.ActiveFields.DeferQualityUpdatesPeriod;
                }

                if (desiredProperties.applyProperties.pauseFeatureUpdates != -1)
                {
                    request.data.pauseFeatureUpdates = (uint)desiredProperties.applyProperties.pauseFeatureUpdates;
                    request.data.activeFields       |= (uint)Message.ActiveFields.PauseFeatureUpdates;
                }

                if (desiredProperties.applyProperties.pauseQualityUpdates != -1)
                {
                    request.data.pauseQualityUpdates = (uint)desiredProperties.applyProperties.pauseQualityUpdates;
                    request.data.activeFields       |= (uint)Message.ActiveFields.PauseQualityUpdates;
                }

                if (desiredProperties.applyProperties.scheduledInstallDay != -1)
                {
                    request.data.scheduledInstallDay = (uint)desiredProperties.applyProperties.scheduledInstallDay;
                    request.data.activeFields       |= (uint)Message.ActiveFields.ScheduledInstallDay;
                }

                if (desiredProperties.applyProperties.scheduledInstallTime != -1)
                {
                    request.data.scheduledInstallTime = (uint)desiredProperties.applyProperties.scheduledInstallTime;
                    request.data.activeFields        |= (uint)Message.ActiveFields.ScheduledInstallTime;
                }

                if (desiredProperties.applyProperties.ring != WindowsUpdatePolicyDataContract.NotFound)
                {
                    request.data.ring          = desiredProperties.applyProperties.ring;
                    request.data.activeFields |= (uint)Message.ActiveFields.Ring;
                }

                // Always send down to SystemConfigurator because we need to persist the reporting (if specified).
                await _systemConfiguratorProxy.SendCommandAsync(request);
            }

            await ReportToDeviceTwin();

            return(CommandStatus.Committed);
        }