protected override Task Poll() { if (!API.IsLoggedIn) { return(base.Poll()); } if (room.RoomID.Value == null) { return(base.Poll()); } var tcs = new TaskCompletionSource <bool>(); lastPollRequest?.Cancel(); var req = new GetRoomRequest(room.RoomID.Value.Value); req.Success += result => { result.RemoveExpiredPlaylistItems(); RoomManager.AddOrUpdateRoom(result); tcs.SetResult(true); }; req.Failure += _ => tcs.SetResult(false); API.Queue(req); lastPollRequest = req; return(tcs.Task); }
protected override Task Poll() { if (!API.IsLoggedIn) { return(base.Poll()); } if (selectedRoom.Value?.RoomID.Value == null) { return(base.Poll()); } var tcs = new TaskCompletionSource <bool>(); pollReq?.Cancel(); pollReq = new GetRoomRequest(selectedRoom.Value.RoomID.Value.Value); pollReq.Success += result => { RoomManager.AddOrUpdateRoom(result); tcs.SetResult(true); }; pollReq.Failure += _ => tcs.SetResult(false); API.Queue(pollReq); return(tcs.Task); }
protected override Task Poll() { if (!API.IsLoggedIn) { return(base.Poll()); } if (selectedRoom.Value?.RoomID.Value == null) { return(base.Poll()); } var tcs = new TaskCompletionSource <bool>(); pollReq?.Cancel(); pollReq = new GetRoomRequest(selectedRoom.Value.RoomID.Value.Value); pollReq.Success += result => { // existing rooms need to be ordered by their position because the received of NotifyRoomsReceives expects to be able to sort them based on this order. var rooms = new List <Room>(roomManager.Rooms.OrderBy(r => r.Position.Value)); int index = rooms.FindIndex(r => r.RoomID.Value == result.RoomID.Value); if (index < 0) { return; } rooms[index] = result; NotifyRoomsReceived(rooms); tcs.SetResult(true); }; pollReq.Failure += _ => tcs.SetResult(false); API.Queue(pollReq); return(tcs.Task); }
protected override Task Poll() { if (!API.IsLoggedIn) { return(base.Poll()); } if (selectedRoom.Value?.RoomID.Value == null) { return(base.Poll()); } var tcs = new TaskCompletionSource <bool>(); pollReq?.Cancel(); pollReq = new GetRoomRequest(selectedRoom.Value.RoomID.Value.Value); pollReq.Success += result => { var rooms = new List <Room>(roomManager.Rooms); int index = rooms.FindIndex(r => r.RoomID.Value == result.RoomID.Value); if (index < 0) { return; } rooms[index] = result; NotifyRoomsReceived(rooms); tcs.SetResult(true); }; pollReq.Failure += _ => tcs.SetResult(false); API.Queue(pollReq); return(tcs.Task); }