示例#1
0
        private async void EntryDevice()
        {
#if (ACCESS_MOBILE_SERVICE)
            if (mobileService == null)
            {
                mobileService = new MobileServiceClient(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)
                    {
                        IoTHubEndpoint = re.IoTHubEndpoint;
                        DeviceKey      = re.DeviceKey;
                        Debug.WriteLine("IoT Hub Service Avaliabled");
                    }
                    registed = true;
                    break;
                }
            }
            if (!registed)
            {
                var entry = new Models.DeviceEntry()
                {
                    DeviceId         = deviceId.ToString(),
                    ServiceAvailable = false,
                    IoTHubEndpoint   = IoTHubEndpoint,
                    DeviceKey        = DeviceKey
                };
                await table.InsertAsync(entry);
            }
#else
            IoTServiceAvailabled = true;
#endif
        }
        private async void EntryDevice()
        {
#if (ACCESS_MOBILE_SERVICE)
            if (mobileService == null)
            {
                mobileService = new MobileServiceClient(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)
                    {
                        IoTHubEndpoint = re.IoTHubEndpoint;
                        DeviceKey = re.DeviceKey;
                        Debug.WriteLine("IoT Hub Service Avaliabled");
                    }
                    registed = true;
                    break;
                }
            }
            if (!registed)
            {
                var entry = new Models.DeviceEntry()
                {
                    DeviceId = deviceId.ToString(),
                    ServiceAvailable = false,
                    IoTHubEndpoint = IoTHubEndpoint,
                    DeviceKey = DeviceKey
                };
                await table.InsertAsync(entry);
            }
#else
            IoTServiceAvailabled = true;
#endif
        }