Esempio n. 1
0
        public Task AddResultAsync(IGetSingleBasket <Types.PairSelection> basket, IVisit visit)
        {
            var date = basket?.DescentPayload?.Filter?.Terms?.FirstOrDefault(
                t => t.PropertyName == nameof(Types.PairSelection.Date))?.Value as DateTime?;

            if (date == null)
            {
                throw new ArgumentException($"Expected filter on '{nameof(Types.PairSelection.Date)}'");
            }

            // only consider males which haven't mated in the past 3 months
            var maleFilter = new Filter <Types.Frog>(new[]
            {
                new FilterTerm(nameof(Types.Frog.IsMale), FilterOperators.Equal, true),
                new FilterTerm(nameof(Types.Frog.DateLastMated), FilterOperators.LessThan, date.Value.AddMonths(-3))
            });

            // ... and the same for females
            var femaleFilter = new Filter <Types.Frog>(new[]
            {
                new FilterTerm(nameof(Types.Frog.IsMale), FilterOperators.Equal, false),
                new FilterTerm(nameof(Types.Frog.DateLastMated), FilterOperators.LessThan, date.Value.AddMonths(-3))
            });

            // Try and find a suitable pair.
            // In a real application you would most likely have a single efficient DB query.  Here I just want to
            // demonstrate operating across different mines.
            // Note that the main basket is pased into these "child" baskets.  This is optional however doing this allows
            // for the baskets to be linked together when exporting tracing information (see FileTraceExporter)
            var getMaleBasket =
                new GetCollectionBasket <Types.Frog>(new GetCollectionRequest <Types.Frog>(maleFilter, 1, 0), basket);
            var getMaleTask = _frogMine.SendAsync(getMaleBasket);

            var getFemaleBasket =
                new GetCollectionBasket <Types.Frog>(new GetCollectionRequest <Types.Frog>(femaleFilter, 1, 0), basket);
            var getFemaleTask = _frogMine.SendAsync(getFemaleBasket);

            Task.WaitAll(getMaleTask, getFemaleTask);

            Types.Frog male = null;
            if (getMaleBasket.AscentPayload.Length > 0)
            {
                male = getMaleBasket.AscentPayload[0];
            }

            Types.Frog female = null;
            if (getFemaleBasket.AscentPayload.Length > 0)
            {
                female = getFemaleBasket.AscentPayload[0];
            }

            basket.AscentPayload = new Types.PairSelection(male, female, date.Value);

            return(Task.CompletedTask);
        }
Esempio n. 2
0
        public Task AddResultAsync(IGetSingleBasket <Frog> basket, IVisit visit)
        {
            basket.AscentPayload = new Frog
            {
                Id          = 465,
                Name        = "Kermit",
                DateOfBirth = DateTime.Today.AddDays(-30)
            };

            return(Task.CompletedTask);
        }
Esempio n. 3
0
 public Task <IGetSingleBasket <Types.PairSelection> > SendAsync(IGetSingleBasket <Types.PairSelection> basket)
 {
     return(new Shaft <IGetSingleBasket <Types.PairSelection> >(TraceExporter, TerminalLayer,
                                                                GetStations <IGetSingleBasket <Types.PairSelection> >())
            .SendAsync(basket));
 }
Esempio n. 4
0
 /// <summary>
 /// No action performed
 /// </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 AscendFromAsync(IGetSingleBasket <T> basket, IVisit visit)
 {
     return(Task.CompletedTask);
 }
Esempio n. 5
0
 public Task <IGetSingleBasket <Types.TadpoleCount> > SendAsync(IGetSingleBasket <Types.TadpoleCount> basket)
 {
     return(new Shaft <IGetSingleBasket <Types.TadpoleCount> >(TraceExporter, TerminalLayer,
                                                               GetStations <IGetSingleBasket <Types.TadpoleCount> >()).SendAsync(basket));
 }
Esempio n. 6
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(IGetSingleBasket basket, IVisit visit)
 {
     EnsureOperationAllowed(Operations.GetSingle, basket, visit);
     return(Task.CompletedTask);
 }
Esempio n. 7
0
 public Task <IGetSingleBasket <Frog> > SendAsync(IGetSingleBasket <Frog> basket)
 {
     return(new Shaft <IGetSingleBasket <Frog> >(TerminalLayer)
            .Add(SecurityLayer)
            .SendAsync(basket));
 }