// 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);
        }
Ejemplo n.º 2
0
 public string ToJson()
 {
     TimeServiceDataContract.DesiredProperties desiredProperties = new TimeServiceDataContract.DesiredProperties();
     desiredProperties.enabled        = DesiredTimeServiceEnabled.SelectedIndex == 0 ? TimeServiceDataContract.JsonYes : TimeServiceDataContract.JsonNo;
     desiredProperties.startup        = DesiredTimeServiceStartup.SelectedIndex == 0 ? TimeServiceDataContract.JsonAuto : TimeServiceDataContract.JsonManual;
     desiredProperties.started        = DesiredTimeServiceStarted.SelectedIndex == 0 ? TimeServiceDataContract.JsonYes : TimeServiceDataContract.JsonNo;
     desiredProperties.sourcePriority = DesiredTimeServiceSourcePriority.SelectedIndex == 0 ? PolicyDataContract.JsonLocal : PolicyDataContract.JsonRemote;
     return(desiredProperties.ToJsonString());
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Set Time Service setting from device twin.
        /// </summary>
        private async void SetTimeSettingButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            TimeServiceDataContract.DesiredProperties desiredProperties = new TimeServiceDataContract.DesiredProperties();
            desiredProperties.enabled        = EnabledCombobox.SelectedValue.ToString();
            desiredProperties.startup        = StartupCombobox.SelectedValue.ToString();
            desiredProperties.started        = StartedCombobox.SelectedValue.ToString();
            desiredProperties.sourcePriority = SourcePriorityCombobox.SelectedValue.ToString();

            string refreshingValue = "\"refreshing\"";
            string finalValue      = "{" + desiredProperties.ToJsonString() + "}";
            await _mainPage.UpdateTwinData(refreshingValue, finalValue);
        }