public async Task UpdateStatus(BusSnapshotInfo snapshot) { this.State.LatestSnapshot = snapshot; await UpdateMap(snapshot); await UpdateStops(snapshot); }
private void GetStopTimes(BusSnapshotInfo status, out StopTimeInfo last, out StopTimeInfo next) { last = next = null; var times = StaticData.GetStopTimesByTripId(status.TripId); var stoptimes = new LinkedList <StopTimeInfo>(times.OrderBy(st => st.Sequence)); if (stoptimes == null || stoptimes.Count == 0) { return; } var busTime = status.AdjustedTimestamp; LinkedListNode <StopTimeInfo> node = stoptimes.First; while (node != null) { if (busTime < node.Value.Arrival) { next = node.Value; break; } last = node.Value; node = node.Next; } }
public async Task UpdateStatus(BusSnapshotInfo snapshot) { _snapshots.Add(snapshot); await UpdateMap(snapshot); await UpdateStops(snapshot); }
private void GetStopTimes(BusSnapshotInfo status, out StopTimeInfo last, out StopTimeInfo next) { last = next = null; if (_stoptimes == null) { return; } var busTime = status.AdjustedTimestamp; LinkedListNode <StopTimeInfo> node = _stoptimes.First; while (node != null) { if (busTime < node.Value.Arrival) { next = node.Value; break; } last = node.Value; node = node.Next; } }
public Task <Tuple <StopTimeInfo, StopTimeInfo> > GetStopTimes(BusSnapshotInfo status) { StopTimeInfo last = null; StopTimeInfo next = null; GetStopTimes(status, out last, out next); return(Task.FromResult(Tuple.Create(last, next))); }
public async Task UpdateBus(BusSnapshotInfo snapshot) { Init(); var trip = GrainFactory.GetGrain <ITrip>(snapshot.TripId); var tripInfo = await trip.GetInfo(); var headsign = tripInfo == null?string.Format("[{0}]", snapshot.TripId) : tripInfo.Headsign; await Clients.Group("mapViews").updateBus(snapshot, headsign); }
private async Task UpdateMap(BusSnapshotInfo status) { var signalrUri = CloudConfigurationManager.GetSetting("signalrUri"); var conn = new HubConnection(signalrUri); var hub = conn.CreateHubProxy("MapHub"); await conn.Start(); await hub.Invoke("UpdateBus", status); }
public void HandleSnapshot(BusSnapshotInfo snapshot) { var eventHubClient = EventHubClient.CreateFromConnectionString(_ehConnectionString, _ehName); var snapJson = JsonConvert.SerializeObject(snapshot); var data = new EventData(Encoding.UTF8.GetBytes(snapJson)); eventHubClient.Send(data); eventHubClient.Close(); }
public async Task UpdateBus(BusSnapshotInfo snapshot) { var appName = CloudConfigurationManager.GetSetting("sfAppName"); var svcName = CloudConfigurationManager.GetSetting("sfSvcNameTemplate"); var trip = ActorProxy.Create <ITrip>(new ActorId(snapshot.TripId), appName, string.Format(svcName, "Trip")); var tripInfo = await trip.GetInfo(); var headsign = tripInfo == null?string.Format("[{0}]", snapshot.TripId) : tripInfo.Headsign; await Clients.Group("mapViews").updateBus(snapshot, headsign); }
public Task <Tuple <StopTimeInfo, StopTimeInfo> > GetStopTimes(BusSnapshotInfo status) { if (_stoptimes == null) { var times = StaticData.GetStopTimesByTripId((int)this.GetPrimaryKeyLong()); _stoptimes = new LinkedList <StopTimeInfo>(times.OrderBy(st => st.Sequence)); } StopTimeInfo last = null; StopTimeInfo next = null; GetStopTimes(status, out last, out next); return(Task.FromResult(Tuple.Create(last, next))); }
private async Task UpdateStops(BusSnapshotInfo status) { var trip = ActorProxy.Create <ITrip>(new ActorId(status.TripId)); var stoptimes = await trip.GetStopTimes(status); if (this.State.LastStopId != null) { if (stoptimes.Item1 == null || stoptimes.Item1.StopId != this.State.LastStopId) { var lastStop = ActorProxy.Create <IStop>(new ActorId(this.State.LastStopId.Value)); await lastStop.NoLongerDeparted(this); } } this.State.LastStopId = stoptimes.Item1 == null ? null : (long?)stoptimes.Item1.StopId; if (this.State.LastStopId != null) { var lastStop = ActorProxy.Create <IStop>(new ActorId(this.State.LastStopId.Value)); await lastStop.HasDeparted(this, status.AdjustedTimestamp.Subtract(stoptimes.Item1.Departure)); } if (this.State.NextStopId != null) { if (stoptimes.Item2 == null || stoptimes.Item2.StopId != this.State.NextStopId) { var nextStop = ActorProxy.Create <IStop>(new ActorId(this.State.NextStopId.Value)); await nextStop.IsNoLongerApproaching(this); } } this.State.NextStopId = stoptimes.Item2 == null ? null : (long?)stoptimes.Item2.StopId; if (this.State.NextStopId != null) { var nextStop = ActorProxy.Create <IStop>(new ActorId(this.State.NextStopId.Value)); await nextStop.IsApproaching(this, stoptimes.Item2.Arrival.Subtract(status.AdjustedTimestamp)); } }
private async Task UpdateStops(BusSnapshotInfo status) { var trip = GrainFactory.GetGrain <ITrip>(status.TripId); var stoptimes = await trip.GetStopTimes(status); IStop last = stoptimes.Item1 == null ? null : GrainFactory.GetGrain <IStop>(stoptimes.Item1.StopId); if (_lastStop != null) { if (last == null || stoptimes.Item1.StopId != (int)_lastStop.GetPrimaryKeyLong()) { await _lastStop.NoLongerDeparted(this); } } _lastStop = last; if (_lastStop != null) { await _lastStop.HasDeparted(this, status.AdjustedTimestamp.Subtract(stoptimes.Item1.Departure)); } IStop next = stoptimes.Item2 == null ? null : GrainFactory.GetGrain <IStop>(stoptimes.Item2.StopId); if (_nextStop != null) { if (next == null || stoptimes.Item2.StopId != (int)_nextStop.GetPrimaryKeyLong()) { await _nextStop.IsNoLongerApproaching(this); } } _nextStop = next; if (_nextStop != null) { await _nextStop.IsApproaching(this, stoptimes.Item2.Arrival.Subtract(status.AdjustedTimestamp)); } }
public void HandleSnapshot(BusSnapshotInfo snapshot) { var json = JsonConvert.SerializeObject(snapshot, Formatting.Indented); Console.WriteLine(json); }