Beispiel #1
0
        public async Task <KeyValuePair <float, float>?> GetLastReportingLocation(Guid orderId)
        {
            using (var tx = StateManager.CreateTransaction())
            {
                var orderIds = await StateManager.GetOrAddAsync <IReliableDictionary <Guid, ActorId> >("orderIds");

                var orderActorId = await orderIds.TryGetValueAsync(tx, orderId);

                if (!orderActorId.HasValue)
                {
                    return(null);
                }

                var order = OrderConnectionFactory.GetOrder(orderActorId.Value);
                return(await order.GetLatestLocation());
            }
        }
Beispiel #2
0
        public async Task ReportLocation(Location location)
        {
            using (var tx = StateManager.CreateTransaction())
            {
                var timestamps = await StateManager.GetOrAddAsync <IReliableDictionary <Guid, DateTime> >("timestamps");

                var orderActorIds = await StateManager.GetOrAddAsync <IReliableDictionary <Guid, ActorId> >("orderIds");

                var timestamp    = DateTime.UtcNow;
                var orderActorId = await orderActorIds.GetOrAddAsync(tx, location.OrderId, ActorId.CreateRandom());

                await OrderConnectionFactory.GetOrder(orderActorId).SetLocation(timestamp, location.Latitude, location.Longitude);

                await timestamps.AddOrUpdateAsync(tx, location.OrderId, DateTime.UtcNow, (guid, time) => timestamp);

                await tx.CommitAsync();
            }
        }