private async Task <bool> InitaliseRooms() { Rooms.Clear(); IMobileServiceTableQuery <RoomItem> roomQuery; roomQuery = RoomTable.RoomSyncTable.Where(p => p.HomeId == SelectedHomeId); await RoomTable.Read(roomQuery); foreach (RoomItem RoomItem in RoomTable.RoomItems) { Room room = RoomConverter.CreateFrom(RoomItem); IMobileServiceTableQuery <DeviceItem> deviceQuery; deviceQuery = DeviceTable.deviceTable.Where(p => p.RoomId == room.Id); await DeviceTable.Read(deviceQuery); foreach (DeviceItem DeviceItem in DeviceTable.deviceItems) { Device device = DeviceConverter.CreateFrom(DeviceItem); try { device = await Lights.GetLightState(device); } catch (Exception e) { device.HasAccess = false; } } Rooms.Add(room); } return(true); }
private async void HasAccess_ts_Toggled(object sender, RoutedEventArgs e) { ToggleSwitch clickedItem = (ToggleSwitch)e.OriginalSource; try { var item = clickedItem.DataContext; if (item.GetType() == typeof(Home)) { await HomeTable.Update(HomeConverter.CreateFrom((Home)item)); } else if (item.GetType() == typeof(Room)) { await RoomTable.Update(RoomConverter.CreateFrom((Room)item)); } else if (item.GetType() == typeof(Device)) { await DeviceTable.Update(DeviceConverter.CreateFrom((Device)item)); } await Shared.Services.Storage.SyncAsync(); } catch (Exception) { } }
public async Task <bool> GetDevices(string roomid) { Devices.Clear(); IMobileServiceTableQuery <DeviceItem> deviceQuery; deviceQuery = DeviceTable.deviceTable.Where(p => p.RoomId == roomid); await DeviceTable.Read(deviceQuery); foreach (DeviceItem DeviceItem in DeviceTable.deviceItems) { Device device = DeviceConverter.CreateFrom(DeviceItem); Devices.Add(device); } return(true); }
private async void GetFavouriteDevices() { FavouriteDevices.Clear(); IMobileServiceTableQuery <DeviceItem> deviceQuery; deviceQuery = DeviceTable.deviceTable.Where(p => p.HomeId == SelectedHome.Id && p.Deleted == false); if (await DeviceTable.Read(deviceQuery)) { foreach (DeviceItem DeviceItem in DeviceTable.deviceItems) { Device device = DeviceConverter.CreateFrom(DeviceItem); try { device = await Lights.GetLightState(device); } catch (Exception e) { device.HasAccess = false; } FavouriteDevices.Add(device); } } }
public static async Task <bool> CreateSampleDevice(string deviceName, string deviceId) { Device Device = new Device { CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, OwnerId = "sid:79cb2d8a9896fd48bac1f3969a9965cc", UserId = "sid:79cb2d8a9896fd48bac1f3969a9965cc", HomeId = HomeTable.HomeItem.Id, RoomId = RoomTable.RoomItem.Id, HasAccess = true, Name = deviceName, Room = RoomTable.RoomItem.Name, DeviceId = deviceId, Status = false, Level = "40%", Deleted = false }; DeviceItem item = DeviceConverter.CreateFrom(Device); await DeviceTable.Create(item); return(true); }