예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="deviceIdentity"></param>
        /// <param name="deviceId"></param>
        private static async void ManageDeviceTwin(DeviceIdentity deviceIdentity, string deviceId)
        {
            var deviceTwin = deviceIdentity.GetDeviceTwin(deviceId).Result;

            Console.WriteLine("Updated desired configuration");

            var results = deviceIdentity.SetDesiredConfigurationAndQuery(deviceTwin).Result;

            foreach (var result in results)
            {
                Console.WriteLine("Configure report for: {0}", result.DeviceId);
                Console.WriteLine("Desired deviceConfig: {0}",
                                  JsonConvert.SerializeObject(result.Properties.Desired["deviceConfig"], Formatting.Indented));
                Console.WriteLine();
            }

            await deviceIdentity.DeleteDeviceAsync(deviceId);

            Console.ReadLine();
            var serviceClient = ServiceClient.CreateFromConnectionString(deviceIdentity.GetConnectionString());

            deviceIdentity.SendCloudToDeviceMessageAsync(deviceId, serviceClient);

            _result = deviceIdentity.InvokeDirectMethodOnDevice(deviceId, serviceClient);
            var response = _result.Result;

            Console.WriteLine("Response status: {0}, payload:", response.Status);
            Console.WriteLine(response.GetPayloadAsJson());

            Console.ReadLine();
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="deviceIdentity"></param>
        /// <param name="deviceId"></param>
        private static async void ManageDeviceTwin(DeviceIdentity deviceIdentity, string deviceId)
        {
            var deviceTwin = deviceIdentity.GetDeviceTwin(deviceId).Result;

            Console.WriteLine("Updated desired configuration");

            var results = deviceIdentity.SetDesiredConfigurationAndQuery(deviceTwin).Result;

            foreach (var result in results)
            {
                Console.WriteLine("Configure report for: {0}", result.DeviceId);
                Console.WriteLine("Desired deviceConfig: {0}",
                                  JsonConvert.SerializeObject(result.Properties.Desired["deviceConfig"], Formatting.Indented));
                Console.WriteLine();
            }

            await deviceIdentity.DeleteDeviceAsync(deviceId);

            Console.ReadLine();
        }