コード例 #1
0
        /// <summary>
        /// Set schedule reboot info via device twin.
        /// </summary>
        private async void SetScheduleRebootButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            string dailyReboot  = string.Empty;
            string singleReboot = string.Empty;

            if (RebootInfoDailyChkbx.IsChecked == true)
            {
                var      pickedRebootDate    = RebootInfoDailyRebootDateInput.Date;
                var      pickedRebootTime    = RebootInfoDailyRebootTimeInput.Time;
                DateTime resultDailyDateTime = new DateTime(pickedRebootDate.Year, pickedRebootDate.Month, pickedRebootDate.Day, pickedRebootTime.Hours, pickedRebootTime.Minutes, 0, DateTimeKind.Utc);
                dailyReboot = (resultDailyDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ"));
            }
            if (RebootInfoSingleChkbx.IsChecked == true)
            {
                var      pickedRebootDate    = RebootInfoSingleRebootDateInput.Date;
                var      pickedRebootTime    = RebootInfoSingleRebootTimeInput.Time;
                DateTime resulSingleDateTime = new DateTime(pickedRebootDate.Year, pickedRebootDate.Month, pickedRebootDate.Day, pickedRebootTime.Hours, pickedRebootTime.Minutes, 0, DateTimeKind.Utc);
                singleReboot = (resulSingleDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ"));
            }

            RebootInfoDataContract.DesiredProperties desiredProperties = new RebootInfoDataContract.DesiredProperties();
            desiredProperties.singleRebootTime = singleReboot;
            desiredProperties.dailyRebootTime  = dailyReboot;

            string refreshingValue = "\"refreshing\"";
            string finalValue      = "{" + desiredProperties.ToJsonString() + "}";
            await _mainPage.UpdateTwinData(refreshingValue, finalValue);
        }
コード例 #2
0
        // IClientPropertyHandler
        public async Task <CommandStatus> OnDesiredPropertyChange(JToken desiredValue)
        {
            // Merge with existing to get values that have not changed.
            UpdateCache(desiredValue);

            JToken rebootToken = _desiredCache[PropertySectionName];

            Debug.Assert(rebootToken != null);

            if (!(rebootToken is JObject))
            {
                throw new Error(ErrorCodes.INVALID_DESIRED_JSON_VALUE, "Invalid json value type for the " + PropertySectionName + " node.");
            }

            // Parse json into an object...
            RebootInfoDataContract.DesiredProperties desiredProperties = RebootInfoDataContract.DesiredProperties.FromJsonObject((JObject)rebootToken);

            // Construct the request and send it...
            var request = new SetRebootInfoRequest();

            request.singleRebootTime = desiredProperties.singleRebootTime;
            request.dailyRebootTime  = desiredProperties.dailyRebootTime;
            await _systemConfiguratorProxy.SendCommandAsync(request);

            // Get the current state and report it...
            var currentState = await GetRebootInfoAsync();

            await _deviceManagementClient.ReportPropertiesAsync(PropertySectionName, currentState);

            return(CommandStatus.Committed);
        }
 public string ToJsonString()
 {
     RebootInfoDataContract.DesiredProperties desiredProperties = new RebootInfoDataContract.DesiredProperties();
     desiredProperties.singleRebootTime = SingleRebootTime.Text;
     desiredProperties.dailyRebootTime  = DailyRebootTime.Text;
     return(desiredProperties.ToJsonString());
 }