Beispiel #1
0
        public void FromJson(JObject json)
        {
            TimeServiceDataContract.ReportedProperties reportedProperties = TimeServiceDataContract.ReportedProperties.FromJsonObject(json);

            ServiceEnabled.Text  = reportedProperties.enabled;
            ServiceStartup.Text  = reportedProperties.startup;
            ServiceStarted.Text  = reportedProperties.started;
            ServicePriority.Text = reportedProperties.sourcePriority;
        }
        public static TimeServiceState AsState(this TimeServiceDataContract.ReportedProperties reportedProperties)
        {
            TimeServiceState state = new TimeServiceState();

            state.enabled          = reportedProperties.enabled == TimeServiceDataContract.JsonYes;
            state.startup          = reportedProperties.startup == TimeServiceDataContract.JsonAuto ? ServiceStartup.Auto : ServiceStartup.Manual;
            state.started          = reportedProperties.started == TimeServiceDataContract.JsonYes;
            state.settingsPriority = PolicyHelpers.SettingsPriorityFromString(reportedProperties.sourcePriority);
            return(state);
        }
Beispiel #3
0
        /// <summary>
        /// Retrieve Time Service setting from device twin.
        /// </summary>
        private async void GetTimeSettingButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            var twinResult = await _mainPage.GetTwinData(TimeServiceDataContract.SectionName);

            if (twinResult != null)
            {
                TimeServiceDataContract.ReportedProperties reportedProperties = TimeServiceDataContract.ReportedProperties.FromJsonObject((JObject)twinResult);
                Enabled.Text        = reportedProperties.enabled;
                Startup.Text        = reportedProperties.startup;
                Started.Text        = reportedProperties.started;
                SourcePriority.Text = reportedProperties.sourcePriority;
            }
        }
        private async Task <TimeServiceDataContract.ReportedProperties> GetTimeServiceAsync()
        {
            // Get the current state....
            var getRequest = new Message.GetTimeServiceRequest();
            var response   = await this._systemConfiguratorProxy.SendCommandAsync(getRequest) as Message.GetTimeServiceResponse;

            // Report it to the device twin...
            TimeServiceDataContract.ReportedProperties reportedProperties = new TimeServiceDataContract.ReportedProperties();
            reportedProperties.started        = response.data.started;
            reportedProperties.startup        = response.data.startup;
            reportedProperties.enabled        = response.data.enabled;
            reportedProperties.sourcePriority = PolicyHelpers.SourcePriorityFromPolicy(response.data.policy);

            return(reportedProperties);
        }
        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());
        }
        public async Task <TimeServiceState> GetTimeServiceStateAsync()
        {
            TimeServiceDataContract.ReportedProperties reportedProperties = await GetTimeServiceAsync();

            return(reportedProperties.AsState());
        }