コード例 #1
0
        /// <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);
        }
コード例 #2
0
 private string GetUserDocID()
 {
     using (var userQuery = QueryBuilder
                            .Select(DocIdResult)
                            .From(DataSource.Database(Database))
                            .Where(UsernameProperty.EqualTo(Expression.String(Username)))) {
         var results = userQuery.Execute().ToList();
         return(results.FirstOrDefault()?.GetString("id"));
     }
 }
コード例 #3
0
 private string GetUserDocID()
 {
     using (var userQuery = Query
                            .Select(DocIdResult)
                            .From(DataSource.Database(Database))
                            .Where(UsernameProperty.EqualTo(Username))) {
         using (var results = userQuery.Run()) {
             return(results.FirstOrDefault()?.GetString("id"));
         }
     }
 }