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

            bool registed = false;
            if (registered != null && registered.Count > 0)
            {
                foreach (var re in registered)
                {
                    if (re.ServiceAvailable)
                    {
                        MSIoTKiTHoLJP.IoTHoLConfig.IoTHubEndpoint = re.IoTHubEndpoint;
                        MSIoTKiTHoLJP.IoTHoLConfig.DeviceKey      = re.DeviceKey;
                        Debug.WriteLine("IoT Hub Service Avaliabled");
                    }
                    IoTServiceAvailabled = re.ServiceAvailable;
                    registed             = true;
                    break;
                }
            }
            if (!registed)
            {
                var entry = new Models.DeviceEntry()
                {
                    DeviceId         = deviceId.ToString(),
                    ServiceAvailable = false,
                    IoTHubEndpoint   = MSIoTKiTHoLJP.IoTHoLConfig.IoTHubEndpoint,
                    DeviceKey        = MSIoTKiTHoLJP.IoTHoLConfig.DeviceKey
                };
                await table.InsertAsync(entry);
            }
#else
            if (!string.IsNullOrEmpty(MSIoTKiTHoLJP.IoTHoLConfig.DeviceKey))
            {
                IoTServiceAvailabled = true;
            }
#endif
        }
Example #2
0
        private async Task EntryDevice()
        {
#if (ACCESS_MOBILE_SERVICE)
            if (mobileService == null)
            {
                mobileService = new MobileServiceClient(MSIoTKiTHoLJP.IoTHoLConfig.DeviceEntryEndPoint);
            }
            var table = mobileService.GetTable<Models.DeviceEntry>();
            var registered = await table.Where((de) => de.DeviceId == deviceId.ToString()).ToListAsync();

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