Ejemplo n.º 1
0
        /// <summary>
        /// After a "Get Collection" request has been processed and the basket with the requested objects has ascended
        /// to here the objects 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(IGetCollectionBasket <T> basket, IVisit visit)
        {
            if (basket?.AscentPayload != null && basket.DescentPayload.GetAll)
            {
                Cache.StoreCollection(basket.AscentPayload);
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// When processing a "Get Collection" request the cache will be checked to see if the requested objects are there.
        /// If they are then the cached objects 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">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(IGetCollectionBasket <T> basket, IVisit visit)
        {
            if (basket?.DescentPayload != null && basket.DescentPayload.GetAll)
            {
                if (Cache.TryGetCollection(out var objs))
                {
                    basket.AscentPayload = objs;
                    basket.ReplaceNote(new ReturnNote());
                }
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 3
0
        public Task AddResultAsync(IGetCollectionBasket <Frog> basket, IVisit visit)
        {
            basket.AscentPayload = new[]
            {
                new Frog {
                    Id = 1, Name = "Kermit", DateOfBirth = DateTime.Today.AddDays(-30)
                },
                new Frog {
                    Id = 2, Name = "Frank", DateOfBirth = DateTime.Today.AddDays(-29)
                },
                new Frog {
                    Id = 3, Name = "Freddy", DateOfBirth = DateTime.Today.AddDays(-28)
                }
            };

            return(Task.CompletedTask);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieves the requested collection of T's from the database and adds them 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(IGetCollectionBasket <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))
            {
                var objs = new List <T>();
                while (await rdr.ReadAsync().ConfigureAwait(false))
                {
                    var obj = Mapper.MapObject(rdr);
                    objs.Add(obj);
                }

                basket.AscentPayload = objs.ToArray();
            }
        }
Ejemplo n.º 5
0
 public Task <IGetCollectionBasket <T> > SendAsync(IGetCollectionBasket <T> basket)
 {
     return(new Shaft <IGetCollectionBasket <T> >(TraceExporter, TerminalLayer, GetStations <IGetCollectionBasket <T> >())
            .SendAsync(basket));
 }
Ejemplo n.º 6
0
 public Task <IGetCollectionBasket <Frog> > SendAsync(IGetCollectionBasket <Frog> basket)
 {
     return(new Shaft <IGetCollectionBasket <Frog> >(TerminalLayer)
            .Add(CacheLayer)
            .SendAsync(basket));
 }
Ejemplo n.º 7
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(IGetCollectionBasket basket, IVisit visit)
 {
     return(Task.CompletedTask);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// If the user is not allowed to "Get" collections of 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(IGetCollectionBasket basket, IVisit visit)
 {
     EnsureOperationAllowed(Operations.GetCollection, basket, visit);
     return(Task.CompletedTask);
 }