// For public APIs, we do not report error. We let the caller handle/report the error.
        public async Task <RebootCmdDataContract.ResponseValue> IsRebootAllowedBySystem()
        {
            Logger.Log("IsRebootAllowedBySystem()", LoggingLevel.Verbose);

            var request  = new GetWindowsUpdateRebootPolicyRequest();
            var response = await this._systemConfiguratorProxy.SendCommandAsync(request) as GetWindowsUpdateRebootPolicyResponse;

            if (!response.configuration.allow)
            {
                return(RebootCmdDataContract.ResponseValue.Disabled);
            }

            WindowsUpdatePolicyDataContract.WUProperties updatePolicy = await _windowsUpdatePolicyHandler.GetWindowsUpdatePolicyAsync();

            if (updatePolicy != null)
            {
                uint nowHour = (uint)DateTime.Now.Hour;
                if (updatePolicy.activeHoursStart <= nowHour && nowHour < updatePolicy.activeHoursEnd)
                {
                    return(RebootCmdDataContract.ResponseValue.InActiveHours);
                }
            }

            return(RebootCmdDataContract.ResponseValue.Allowed);
        }
        public async Task <WindowsUpdatePolicyDataContract.WUProperties> GetWindowsUpdatePolicyAsync()
        {
            var request  = new Message.GetWindowsUpdatePolicyRequest();
            var response = await _systemConfiguratorProxy.SendCommandAsync(request) as Message.GetWindowsUpdatePolicyResponse;

            WindowsUpdatePolicyDataContract.WUProperties reportedProperties = ResponseToReported(response);
            return(reportedProperties);
        }
        private async Task ReportToDeviceTwin()
        {
            var request  = new Message.GetWindowsUpdatePolicyRequest();
            var response = await _systemConfiguratorProxy.SendCommandAsync(request) as Message.GetWindowsUpdatePolicyResponse;

            if (response.ReportToDeviceTwin == DMJSonConstants.YesString)
            {
                WindowsUpdatePolicyDataContract.WUProperties reportedProperties = ResponseToReported(response);

                await _callback.ReportPropertiesAsync(PropertySectionName, reportedProperties.ToJsonObject());
            }
            else
            {
                await _callback.ReportPropertiesAsync(PropertySectionName, DMJSonConstants.NoReportString);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieve Windows Update Policy via device twin.
        /// </summary>
        private async void GetUpdatePolicyButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            var twinResult = await _mainPage.GetTwinData(WindowsUpdatePolicyDataContract.SectionName);

            if (twinResult != null)
            {
                WindowsUpdatePolicyDataContract.WUProperties reportedProperties = WindowsUpdatePolicyDataContract.WUProperties.FromJsonObject((JObject)twinResult);
                ActiveHoursStart.Text          = reportedProperties.activeHoursStart.ToString();
                ActiveHoursEnd.Text            = reportedProperties.activeHoursEnd.ToString();
                AllowAutoUpdate.Text           = reportedProperties.allowAutoUpdate.ToString();
                AllowUpdateService.Text        = reportedProperties.allowUpdateService.ToString();
                BranchReadinessLevel.Text      = reportedProperties.branchReadinessLevel.ToString();
                DeferFeatureUpdatesPeriod.Text = reportedProperties.deferFeatureUpdatesPeriod.ToString();
                DeferQualityUpdatesPeriod.Text = reportedProperties.deferQualityUpdatesPeriod.ToString();
                PauseFeatureUpdates.Text       = reportedProperties.pauseFeatureUpdates.ToString();
                PauseQualityUpdates.Text       = reportedProperties.pauseQualityUpdates.ToString();
                ScheduledInstallDay.Text       = reportedProperties.scheduledInstallDay.ToString();
                ScheduledInstallTime.Text      = reportedProperties.scheduledInstallTime.ToString();
                Ring.Text           = reportedProperties.ring;
                SourcePriority.Text = reportedProperties.sourcePriority;
            }
        }
        private static WindowsUpdatePolicyDataContract.WUProperties ResponseToReported(Message.GetWindowsUpdatePolicyResponse response)
        {
            WindowsUpdatePolicyDataContract.WUProperties reportedProperties = new WindowsUpdatePolicyDataContract.WUProperties();

            reportedProperties.activeHoursStart     = (int)response.data.activeHoursStart;
            reportedProperties.activeHoursEnd       = (int)response.data.activeHoursEnd;
            reportedProperties.allowAutoUpdate      = (int)response.data.allowAutoUpdate;
            reportedProperties.allowUpdateService   = (int)response.data.allowUpdateService;
            reportedProperties.branchReadinessLevel = (int)response.data.branchReadinessLevel;

            reportedProperties.deferFeatureUpdatesPeriod = (int)response.data.deferFeatureUpdatesPeriod;
            reportedProperties.deferQualityUpdatesPeriod = (int)response.data.deferQualityUpdatesPeriod;
            reportedProperties.pauseFeatureUpdates       = (int)response.data.pauseFeatureUpdates;
            reportedProperties.pauseQualityUpdates       = (int)response.data.pauseQualityUpdates;
            reportedProperties.scheduledInstallDay       = (int)response.data.scheduledInstallDay;

            reportedProperties.scheduledInstallTime = (int)response.data.scheduledInstallTime;

            reportedProperties.ring = response.data.ring;

            reportedProperties.sourcePriority = PolicyHelpers.SourcePriorityFromPolicy(response.data.policy);

            return(reportedProperties);
        }