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

                var sheepActorId = await sheepIds.TryGetValueAsync(tx, sheepId);

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

                var sheep = SheepConnectionFactory.GetSheep(sheepActorId.Value);
                return(await sheep.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 sheepIds = await StateManager.GetOrAddAsync <IReliableDictionary <Guid, ActorId> >("sheepIds");

                var timestamp = DateTime.UtcNow;

                // Update sheep
                var sheepActorId = await sheepIds.GetOrAddAsync(tx, location.SheepId, ActorId.CreateRandom());

                await SheepConnectionFactory.GetSheep(sheepActorId).SetLocation(timestamp, location.Latitude, location.Longitude);

                // Update service with new timestamp
                await timestamps.AddOrUpdateAsync(tx, location.SheepId, DateTime.UtcNow, (guid, time) => timestamp);

                await tx.CommitAsync();
            }
        }