Beispiel #1
0
        /// <summary>
        /// After a "Get" request has been processed and the basket with the requested object has ascended
        /// to here the object will be placed in the cache.
        /// </summary>
        /// <param name="basket">The response</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public Task AscendFromAsync(IGetBasket <TId, T> basket, IVisit visit)
        {
            if (basket.AscentPayload != null)
            {
                Cache.Store(basket.DescentPayload, basket.AscentPayload);
            }

            return(Task.CompletedTask);
        }
Beispiel #2
0
        public Task AddResultAsync(IGetBasket <int, Frog> basket, IVisit visit)
        {
            basket.AscentPayload = new Frog
            {
                Id          = basket.DescentPayload,
                Name        = "Kermit",
                DateOfBirth = DateTime.Today.AddDays(-30)
            };

            return(Task.CompletedTask);
        }
Beispiel #3
0
        /// <summary>
        /// When processing a "Get" request the cache will be checked to see if the requested object is there.
        /// If it is then the cached object and a <see cref="ReturnNote"/> will be added to the basket
        /// and this will cause the shaft to pull the basket back up again, saving on the basket having to decend further
        /// down the shaft.
        /// </summary>
        /// <param name="basket">A basket</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public Task DescendToAsync(IGetBasket <TId, T> basket, IVisit visit)
        {
            if (basket.DescentPayload != null)
            {
                if (Cache.TryGet(basket.DescentPayload, out var obj))
                {
                    basket.AscentPayload = obj;
                    basket.ReplaceNote(new ReturnNote());
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #4
0
        /// <summary>
        /// Retreives the requested T from the database and adds it to the baskets AscendPayload
        /// </summary>
        /// <param name="basket">A basket</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public async Task AddResultAsync(IGetBasket <TId, T> basket, IVisit visit)
        {
            if (basket == null)
            {
                throw new ArgumentNullException(nameof(basket));
            }

            var statement = GetSelectDbStatement(basket.DescentPayload);

            visit.Log(statement.ToString());

            using (var rdr = await DbInterface.GetReaderAsync(statement).ConfigureAwait(false))
            {
                if (!await rdr.ReadAsync().ConfigureAwait(false))
                {
                    throw new InvalidOperationException($"No '{typeof(T)}' record found");
                }

                basket.AscentPayload = Mapper.MapObject(rdr);
            }
        }
Beispiel #5
0
 public Task <IGetBasket <TId, T> > SendAsync(IGetBasket <TId, T> basket)
 {
     return(new Shaft <IGetBasket <TId, T> >(TraceExporter, TerminalLayer, GetStations <IGetBasket <TId, T> >())
            .SendAsync(basket));
 }
Beispiel #6
0
 public Task <IGetBasket <int, Frog> > SendAsync(IGetBasket <int, Frog> basket)
 {
     return(new Shaft <IGetBasket <int, Frog> >(TerminalLayer)
            .Add(CacheLayer)
            .SendAsync(basket));
 }
Beispiel #7
0
 /// <summary>
 /// If the user is not allowed to "Get" T's then an UnauthorizedAccessException will be thrown.
 /// </summary>
 /// <param name="basket">The request</param>
 /// <param name="visit">The visit the basket is currently making</param>
 /// <returns>A Task that may be awaited</returns>
 public Task DescendToAsync(IGetBasket basket, IVisit visit)
 {
     EnsureOperationAllowed(Operations.Get, basket, visit);
     return(Task.CompletedTask);
 }
Beispiel #8
0
 /// <summary>
 /// Performs no action
 /// </summary>
 /// <param name="basket">A basket</param>
 /// <param name="visit">The visit the basket is currently making</param>
 /// <returns>A Task that may be awaited</returns>
 public Task AscendFromAsync(IGetBasket basket, IVisit visit)
 {
     return(Task.CompletedTask);
 }