コード例 #1
0
        private async Task EntryDevice()
        {
            try
            {
#if (ACCESS_MOBILE_SERVICE)
                if (mobileService == null)
                {
                    mobileService = new MobileServiceClient(IoTHoLConfig.DeviceEntryEndPoint);
                }
                var table      = mobileService.GetTable <Models.DeviceEntry>();
                var registered = await table.Where((de) => de.DeviceId == IoTHoLConfig.deviceId.ToString()).ToListAsync();

                bool registed = false;
                if (registered != null && registered.Count > 0)
                {
                    foreach (var re in registered)
                    {
                        if (re.ServiceAvailable)
                        {
                            IoTHubEndpoint = re.IoTHubEndpoint;
                            DeviceKey      = re.DeviceKey;
                            Debug.WriteLine("IoT Hub Service Avaliabled");
                            txtIoTHubEndpoint.Text = IoTHubEndpoint;
                            txtDeviceKey.Text      = DeviceKey;
                        }
                        registed = true;
                        break;
                    }
                }
                if (!registed)
                {
                    var entry = new Models.DeviceEntry()
                    {
                        DeviceId         = IoTHoLConfig.deviceId.ToString(),
                        ServiceAvailable = IoTServiceAvailabled,
                        IoTHubEndpoint   = IoTHubEndpoint,
                        DeviceKey        = DeviceKey
                    };
                    await table.InsertAsync(entry);
                }
#endif
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
コード例 #2
0
        private async Task EntryDevice()
        {
            try
            {
#if (ACCESS_MOBILE_SERVICE)
                if (mobileService == null)
                {
                    mobileService = new MobileServiceClient(IoTHoLConfig.DeviceEntryEndPoint);
                }
                var table = mobileService.GetTable<Models.DeviceEntry>();
                var registered = await table.Where((de) => de.DeviceId == IoTHoLConfig.deviceId.ToString()).ToListAsync();

                bool registed = false;
                if (registered != null && registered.Count > 0)
                {
                    foreach (var re in registered)
                    {
                        if (re.ServiceAvailable)
                        {
                            IoTHubEndpoint = re.IoTHubEndpoint;
                            DeviceKey = re.DeviceKey;
                            Debug.WriteLine("IoT Hub Service Avaliabled");
                            txtIoTHubEndpoint.Text = IoTHubEndpoint;
                            txtDeviceKey.Text = DeviceKey;
                        }
                        registed = true;
                        break;
                    }
                }
                if (!registed)
                {
                    var entry = new Models.DeviceEntry()
                    {
                        DeviceId = IoTHoLConfig.deviceId.ToString(),
                        ServiceAvailable = IoTServiceAvailabled,
                        IoTHubEndpoint = IoTHubEndpoint,
                        DeviceKey = DeviceKey
                    };
                    await table.InsertAsync(entry);
                }
#endif
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }