Пример #1
0
        private async Task CollectTripStopPoints(CachedTrip cachedTrip)
        {
            var collectStopTasks = new List <Task>
            {
                CollectStopPoint(StopPointRefTriasIdStopPoint(cachedTrip.OriginStopPointRef)),
                CollectStopPoint(StopPointRefTriasIdStopPoint(cachedTrip.DestinationStopPointRef))
            };

            collectStopTasks.AddRange(cachedTrip.Stops.Select(stop => CollectStopPoint(StopPointRefTriasIdStopPoint(stop.StopPointRef))));
            await Task.WhenAll(collectStopTasks).ConfigureAwait(false);
        }
Пример #2
0
        /// <inheritdoc cref="ICacheAdapter"/>
        public CachedTrip AddTripCache(StopEventResult stopEvent)
        {
            var cacheTrip     = new CachedTrip(stopEvent);
            var uniqueTripKey = $"{cacheTrip.OperatingDayRef}_{cacheTrip.JourneyRef}";

            if (!_tripCache.TryAdd(uniqueTripKey, cacheTrip))
            {
                throw new CacheAlreadyExistsException($"Trip Cache - {uniqueTripKey} - Allredy exist.");
            }

            return(cacheTrip);
        }
Пример #3
0
        /// <summary>
        /// Convert the Cache Data Structure to the Api Output Structure
        /// </summary>
        /// <param name="cache">cached stop point that should be converted</param>
        /// <returns>api output for the stop point</returns>
        public static VehiclePosition ConvertToApiOutput(this CachedTrip cache)
        {
            if (cache is null)
            {
                throw new ArgumentNullException(nameof(cache));
            }

            return(new VehiclePosition
            {
                IdTrip = cache.JourneyRef,
                Stops = GetRelevantStops(cache.Stops).OrderBy(x => x.StopSeqNumber).ConvertToApiOutput()
            });
        }
Пример #4
0
        /// <inheritdoc cref="ICacheAdapter"/>
        public CachedTrip UpdateTripCache(StopEventResult stopEvent)
        {
            var cacheTrip     = new CachedTrip(stopEvent);
            var uniqueTripKey = $"{cacheTrip.OperatingDayRef}_{cacheTrip.JourneyRef}";

            if (!_tripCache.TryGetValue(uniqueTripKey, out var existCacheTrip))
            {
                throw new CacheAlreadyExistsException($"Trip Cache - {uniqueTripKey} - Did not exist.");
            }
            ;
            if (!_tripCache.TryUpdate(uniqueTripKey, cacheTrip, existCacheTrip))
            {
                throw new CacheAlreadyExistsException($"Trip Cache - {uniqueTripKey} - Update failed exist.");
            }
            ;

            return(cacheTrip);
        }