コード例 #1
0
 public void On(ISubscriptionContext <GeoLocation> context, DriverEvent evt)
 {
     if (GeoLocation.Equals(context.Key, evt.PreviousAvailability))
     {
         AvailableDrivers.Remove(evt.DriverId);
     }
     else if (GeoLocation.Equals(context.Key, evt.CurrentAvailability))
     {
         AvailableDrivers.Add(evt.DriverId, evt);
         context.ForkOrchestration(new TryMatchDriver()
         {
             AvailableDriver = evt
         });
     }
 }
コード例 #2
0
        public async Task <UnitType> Execute(IOrchestrationContext context)
        {
            var nearbyArea = AvailableRider.CurrentAvailability.Value.GetNearbyAreas();

            DriverEvent candidate = null;

            foreach (var location in nearbyArea)
            {
                candidate = await context.PerformRead(new GetAvailableDriver()
                {
                    Location = location
                });

                if (candidate != null)
                {
                    break;
                }
            }

            if (candidate == null)
            {
                // there are no matches. So we just wait until someone joins and gets matched to us.
                return(UnitType.Value);
            }

            try
            {
                var result = await context.PerformOrchestration(new TryFinalizeMatch()
                {
                    AvailableRider  = AvailableRider,
                    AvailableDriver = candidate
                });

                if (result == TryFinalizeMatch.Response.RiderRemainsUnmatched)
                {
                    // retry in order to find another match
                    context.ForkOrchestration(this);
                }
            }
            catch (TransactionException)
            {
                // transaction ran into trouble for some reason... retry this orchestration
                context.ForkOrchestration(this);
            }

            return(UnitType.Value);
        }
コード例 #3
0
 public void On(ISubscriptionContext <string> context, DriverEvent evt)
 {
     Availability = evt.CurrentAvailability;
 }