/// <summary>
        /// Gets the current user bookings from the database
        /// </summary>
        /// <returns>An <c>await</c>able <see cref="Task"/> that will complete when the
        /// first set of results are ready</returns>
        public Task FetchBookings()
        {
            var tcs = new TaskCompletionSource <bool>();

            _bookingQuery = Query
                            .Select(FlightsResult)
                            .From(DataSource.Database(UserSession.Database))
                            .Where(UsernameProperty.EqualTo(UserSession.Username));

            var retVal = tcs.Task;

            _cancelToken = _bookingQuery.AddChangeListener(null, (sender, args) =>
            {
                foreach (var row in args.Rows)
                {
                    var bookings  = row.GetArray("flights");
                    var eventArgs = new BookingsUpdateEventArgs(EnumerateBookings(bookings));
                    BookingsChanged?.Invoke(this, eventArgs);
                }

                var oldTcs = Interlocked.Exchange(ref tcs, null);
                oldTcs?.SetResult(true);
            });

            return(retVal);
        }
Esempio n. 2
0
 private void OnBookingsChanged()
 {
     BookingsChanged?.Invoke();
 }