// 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); }
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()); }