Пример #1
0
 //private Task<RetrievedData<T>> GenericGetDataAsync<T, F>(string id, DataSourcePreference preference, CancellationToken cancellationToken, Func<Func<Task<RetrievedData<T>>>> runFunction,  )
 //{
 //    var result = new RetrievedData<T>();
 //    foreach (var source in Sources)
 //    {
 //        if (result.HasData)
 //            continue;
 //        if ((preference & DataSourcePreference.MemoryCache) == 0 && source.IsMemoryCache)
 //            continue;
 //        if ((preference & DataSourcePreference.Offline) == 0 && source.IsOfflineSource)
 //            continue;
 //        if ((preference & DataSourcePreference.Online) == 0 && !source.IsOfflineSource)
 //            continue;
 //        if ((source.GetTransitStopFunction & DataSourceFunctionType.Provision) == DataSourceFunctionType.Provision)
 //            result = await source.GetTransitStop(id, cancellationToken);
 //    }
 //    if (result.HasData)
 //    {
 //        foreach (var source in Sources)
 //        {
 //            if (!result.HasData)
 //                continue;
 //            if ((preference & DataSourcePreference.MemoryCache) == 0 && source.IsMemoryCache)
 //                continue;
 //            if ((preference & DataSourcePreference.Offline) == 0 && source.IsOfflineSource)
 //                continue;
 //            if ((preference & DataSourcePreference.Online) == 0 && !source.IsOfflineSource)
 //                continue;
 //            if ((source.GetTransitStopFunction & DataSourceFunctionType.Correction) == DataSourceFunctionType.Correction)
 //                result = await source.CorrectTransitStop(result.Data, cancellationToken);
 //        }
 //    }
 //    return result;
 //}
 
 public static async Task<RetrievedData<TransitStop>> GetTransitStopAsync(string id, DataSourcePreference preference, CancellationToken cancellationToken)
 {
     var result = new RetrievedData<TransitStop>();
     foreach (var source in Sources)
     {
         if (cancellationToken.IsCancellationRequested)
             throw new OperationCanceledException();
         if (result.HasData || !source.IsQualified(preference))
             continue;
         if ((source.GetTransitStopFunction & DataSourceFunctionType.Provision) == DataSourceFunctionType.Provision)
             result = await source.GetTransitStop(id, cancellationToken);
     }
     if (result.HasData)
     {
         if (cancellationToken.IsCancellationRequested)
             throw new OperationCanceledException();
         foreach (var source in Sources)
         {
             if (!result.HasData || !source.IsQualified(preference))
                 continue;
             if ((source.GetTransitStopFunction & DataSourceFunctionType.Correction) == DataSourceFunctionType.Correction)
                 result = await source.CorrectTransitStop(result.Data, cancellationToken);
         }
     }
     return result;
 }
Пример #2
0
 private bool IsQualified(DataSourcePreference preference)
 {
     if (preference == DataSourcePreference.MemoryCacheOnly)
     {
         return(IsMemoryCache);
     }
     if ((preference & DataSourcePreference.MemoryCache) == 0 && IsMemoryCache)
     {
         return(false);
     }
     if ((preference & DataSourcePreference.Offline) == 0 && IsOfflineSource)
     {
         return(false);
     }
     if ((preference & DataSourcePreference.Online) == 0 && !IsOfflineSource)
     {
         return(false);
     }
     return(true);
 }
Пример #3
0
 public static RetrievedData<IEnumerable<TransitStop>> GetTransitStopsForArea(LatLonRect area, DataSourcePreference preference) => RunSync(() => GetTransitStopsForAreaAsync(area, preference, CancellationToken.None));
Пример #4
0
 public static RetrievedData<RealTimeArrival> GetRealTimeArrival(string stopId, string tripId, DataSourcePreference preference) => RunSync(() => GetRealTimeArrivalAsync(stopId, tripId, preference, CancellationToken.None));
Пример #5
0
 public static RetrievedData<TransitRoute> GetTransitRoute(string id, DataSourcePreference preference) => RunSync(() => GetTransitRouteAsync(id, preference, CancellationToken.None));
Пример #6
0
        public static async Task<RetrievedData<IEnumerable<RealTimeArrival>>> GetRealTimeArrivalsForStopAsync(string stopId, int minsBefore, int minsAfter, DataSourcePreference preference, CancellationToken cancellationToken)
        {
            IEnumerable<RealTimeArrival> resultArrivals = null;
            List<string> resultErrors = new List<string>();
            List<Exception> resultExceptions = new List<Exception>();
            foreach (var source in Sources)
            {
                if (!source.IsQualified(preference))
                    continue;

                if (source.CanGetRealTimeArrivalsForStop)
                {
                    var sResult = await source.GetRealTimeArrivalsForStop(stopId, minsBefore, minsAfter, cancellationToken);
                    if (sResult.HasData)
                    {
                        if (resultArrivals == null)
                            resultArrivals = sResult.Data;
                        else
                            resultArrivals = resultArrivals.Union(sResult.Data);
                    }
                    if (sResult.ErrorMessage != null)
                        resultErrors.Add(sResult.ErrorMessage);
                    if (sResult.CaughtException != null)
                        resultExceptions.Add(sResult.CaughtException);
                }
            }
            if (resultArrivals == null)
                resultArrivals = new RealTimeArrival[] { };
            return new RetrievedData<IEnumerable<RealTimeArrival>>(resultArrivals, resultErrors.Count == 0 ? null : resultErrors.Aggregate("", (acc, err) => (acc == "" ? "" : ", ") + err), resultExceptions.Count == 0 ? null : new AggregateException(resultExceptions));
        }
Пример #7
0
 public static async Task<RetrievedData<WeekSchedule>> GetScheduleForStopAsync(string stopId, DataSourcePreference preference, CancellationToken cancellationToken)
 {
     WeekSchedule result = null;
     List<string> resultErrors = new List<string>();
     List<Exception> resultExceptions = new List<Exception>();
     foreach (var source in Sources)
     {
         if (cancellationToken.IsCancellationRequested)
             throw new OperationCanceledException();
         if (!source.IsQualified(preference))
             continue;
         if (source.CanGetScheduleForStop)
         {
             var sResult = await source.GetScheduleForStop(stopId, cancellationToken);
             if (sResult.HasData)
             {
                 if (result == null)
                     result = sResult.Data;
                 else
                     result.Union(sResult.Data);
             }
             if (sResult.ErrorMessage != null)
                 resultErrors.Add(sResult.ErrorMessage);
             if (sResult.CaughtException != null)
                 resultExceptions.Add(sResult.CaughtException);
         }
     }
     //if (result == null)
     //    resultStops = new TransitStop[] { };
     if (result == null)
         return new RetrievedData<WeekSchedule>(resultErrors.Count == 0 ? null : resultErrors.Aggregate("", (acc, err) => (acc == "" ? "" : ", ") + err), resultExceptions.Count == 0 ? null : new AggregateException(resultExceptions));
     return new RetrievedData<WeekSchedule>(result, resultErrors.Count == 0 ? null : resultErrors.Aggregate("", (acc, err) => (acc == "" ? "" : ", ") + err), resultExceptions.Count == 0 ? null : new AggregateException(resultExceptions));
 }
Пример #8
0
        public static async Task <RetrievedData <WeekSchedule> > GetScheduleForStopAsync(string stopId, DataSourcePreference preference, CancellationToken cancellationToken)
        {
            WeekSchedule     result           = null;
            List <string>    resultErrors     = new List <string>();
            List <Exception> resultExceptions = new List <Exception>();

            foreach (var source in Sources)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    throw new OperationCanceledException();
                }
                if (!source.IsQualified(preference))
                {
                    continue;
                }
                if (source.CanGetScheduleForStop)
                {
                    var sResult = await source.GetScheduleForStop(stopId, cancellationToken);

                    if (sResult.HasData)
                    {
                        if (result == null)
                        {
                            result = sResult.Data;
                        }
                        else
                        {
                            result.Union(sResult.Data);
                        }
                    }
                    if (sResult.ErrorMessage != null)
                    {
                        resultErrors.Add(sResult.ErrorMessage);
                    }
                    if (sResult.CaughtException != null)
                    {
                        resultExceptions.Add(sResult.CaughtException);
                    }
                }
            }
            //if (result == null)
            //    resultStops = new TransitStop[] { };
            if (result == null)
            {
                return(new RetrievedData <WeekSchedule>(resultErrors.Count == 0 ? null : resultErrors.Aggregate("", (acc, err) => (acc == "" ? "" : ", ") + err), resultExceptions.Count == 0 ? null : new AggregateException(resultExceptions)));
            }
            return(new RetrievedData <WeekSchedule>(result, resultErrors.Count == 0 ? null : resultErrors.Aggregate("", (acc, err) => (acc == "" ? "" : ", ") + err), resultExceptions.Count == 0 ? null : new AggregateException(resultExceptions)));
        }
Пример #9
0
 private bool IsQualified(DataSourcePreference preference)
 {
     if (preference == DataSourcePreference.MemoryCacheOnly)
         return IsMemoryCache;
     if ((preference & DataSourcePreference.MemoryCache) == 0 && IsMemoryCache)
         return false;
     if ((preference & DataSourcePreference.Offline) == 0 && IsOfflineSource)
         return false;
     if ((preference & DataSourcePreference.Online) == 0 && !IsOfflineSource)
         return false;
     return true;
 }
Пример #10
0
 public static RetrievedData <IEnumerable <RealTimeArrival> > GetRealTimeArrivalsForStop(string stopId, int minsBefore, int minsAfter, DataSourcePreference preference) => RunSync(() => GetRealTimeArrivalsForStopAsync(stopId, minsBefore, minsAfter, preference, CancellationToken.None));
Пример #11
0
 public static RetrievedData <WeekSchedule> GetScheduleForStop(string stopId, DataSourcePreference preference) => RunSync(() => GetScheduleForStopAsync(stopId, preference, CancellationToken.None));
Пример #12
0
 public static RetrievedData <IEnumerable <TransitStop> > GetTransitStopsForArea(LatLonRect area, DataSourcePreference preference) => RunSync(() => GetTransitStopsForAreaAsync(area, preference, CancellationToken.None));
Пример #13
0
 public static RetrievedData <RealTimeArrival> GetRealTimeArrival(string stopId, string tripId, DataSourcePreference preference) => RunSync(() => GetRealTimeArrivalAsync(stopId, tripId, preference, CancellationToken.None));
Пример #14
0
 public static RetrievedData <TransitRoute> GetTransitRoute(string id, DataSourcePreference preference) => RunSync(() => GetTransitRouteAsync(id, preference, CancellationToken.None));
Пример #15
0
        public static async Task <RetrievedData <IEnumerable <RealTimeArrival> > > GetRealTimeArrivalsForStopAsync(string stopId, int minsBefore, int minsAfter, DataSourcePreference preference, CancellationToken cancellationToken)
        {
            IEnumerable <RealTimeArrival> resultArrivals = null;
            List <string>    resultErrors     = new List <string>();
            List <Exception> resultExceptions = new List <Exception>();

            foreach (var source in Sources)
            {
                if (!source.IsQualified(preference))
                {
                    continue;
                }

                if (source.CanGetRealTimeArrivalsForStop)
                {
                    var sResult = await source.GetRealTimeArrivalsForStop(stopId, minsBefore, minsAfter, cancellationToken);

                    if (sResult.HasData)
                    {
                        if (resultArrivals == null)
                        {
                            resultArrivals = sResult.Data;
                        }
                        else
                        {
                            resultArrivals = resultArrivals.Union(sResult.Data);
                        }
                    }
                    if (sResult.ErrorMessage != null)
                    {
                        resultErrors.Add(sResult.ErrorMessage);
                    }
                    if (sResult.CaughtException != null)
                    {
                        resultExceptions.Add(sResult.CaughtException);
                    }
                }
            }
            if (resultArrivals == null)
            {
                resultArrivals = new RealTimeArrival[] { }
            }
            ;
            return(new RetrievedData <IEnumerable <RealTimeArrival> >(resultArrivals, resultErrors.Count == 0 ? null : resultErrors.Aggregate("", (acc, err) => (acc == "" ? "" : ", ") + err), resultExceptions.Count == 0 ? null : new AggregateException(resultExceptions)));
        }
Пример #16
0
 public static RetrievedData<WeekSchedule> GetScheduleForStop(string stopId, DataSourcePreference preference) => RunSync(() => GetScheduleForStopAsync(stopId, preference, CancellationToken.None));
Пример #17
0
 public static RetrievedData<IEnumerable<RealTimeArrival>> GetRealTimeArrivalsForStop(string stopId, int minsBefore, int minsAfter, DataSourcePreference preference) => RunSync(() => GetRealTimeArrivalsForStopAsync(stopId, minsBefore, minsAfter, preference, CancellationToken.None));
Пример #18
0
        //private Task<RetrievedData<T>> GenericGetDataAsync<T, F>(string id, DataSourcePreference preference, CancellationToken cancellationToken, Func<Func<Task<RetrievedData<T>>>> runFunction,  )
        //{
        //    var result = new RetrievedData<T>();
        //    foreach (var source in Sources)
        //    {
        //        if (result.HasData)
        //            continue;
        //        if ((preference & DataSourcePreference.MemoryCache) == 0 && source.IsMemoryCache)
        //            continue;
        //        if ((preference & DataSourcePreference.Offline) == 0 && source.IsOfflineSource)
        //            continue;
        //        if ((preference & DataSourcePreference.Online) == 0 && !source.IsOfflineSource)
        //            continue;
        //        if ((source.GetTransitStopFunction & DataSourceFunctionType.Provision) == DataSourceFunctionType.Provision)
        //            result = await source.GetTransitStop(id, cancellationToken);
        //    }
        //    if (result.HasData)
        //    {
        //        foreach (var source in Sources)
        //        {
        //            if (!result.HasData)
        //                continue;
        //            if ((preference & DataSourcePreference.MemoryCache) == 0 && source.IsMemoryCache)
        //                continue;
        //            if ((preference & DataSourcePreference.Offline) == 0 && source.IsOfflineSource)
        //                continue;
        //            if ((preference & DataSourcePreference.Online) == 0 && !source.IsOfflineSource)
        //                continue;
        //            if ((source.GetTransitStopFunction & DataSourceFunctionType.Correction) == DataSourceFunctionType.Correction)
        //                result = await source.CorrectTransitStop(result.Data, cancellationToken);
        //        }
        //    }
        //    return result;
        //}

        public static async Task <RetrievedData <TransitStop> > GetTransitStopAsync(string id, DataSourcePreference preference, CancellationToken cancellationToken)
        {
            var result = new RetrievedData <TransitStop>();

            foreach (var source in Sources)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    throw new OperationCanceledException();
                }
                if (result.HasData || !source.IsQualified(preference))
                {
                    continue;
                }
                if ((source.GetTransitStopFunction & DataSourceFunctionType.Provision) == DataSourceFunctionType.Provision)
                {
                    result = await source.GetTransitStop(id, cancellationToken);
                }
            }
            if (result.HasData)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    throw new OperationCanceledException();
                }
                foreach (var source in Sources)
                {
                    if (!result.HasData || !source.IsQualified(preference))
                    {
                        continue;
                    }
                    if ((source.GetTransitStopFunction & DataSourceFunctionType.Correction) == DataSourceFunctionType.Correction)
                    {
                        result = await source.CorrectTransitStop(result.Data, cancellationToken);
                    }
                }
            }
            return(result);
        }
Пример #19
0
 public static async Task<RetrievedData<IEnumerable<TransitStop>>> GetTransitStopsForAreaAsync(LatLonRect area, DataSourcePreference preference, CancellationToken cancellationToken)
 {
     IEnumerable<TransitStop> resultStops = null;
     List<string> resultErrors = new List<string>();
     List<Exception> resultExceptions = new List<Exception>();
     foreach (var source in Sources)
     {
         if (cancellationToken.IsCancellationRequested)
             throw new OperationCanceledException();
         if (!source.IsQualified(preference))
             continue;
         if (source.CanGetTransitStopsForArea)
         {
             var sResult = await source.GetTransitStopsForArea(area, cancellationToken);
             if (sResult.HasData)
             {
                 if (resultStops == null)
                     resultStops = sResult.Data;
                 else
                     resultStops = resultStops.Union(sResult.Data);
             }
             if (sResult.ErrorMessage != null)
                 resultErrors.Add(sResult.ErrorMessage);
             if (sResult.CaughtException != null)
                 resultExceptions.Add(sResult.CaughtException);
         }
     }
     if (resultStops == null)
         resultStops = new TransitStop[] { };
     return new RetrievedData<IEnumerable<TransitStop>>(resultStops, resultErrors.Count == 0 ? null : resultErrors.Aggregate("", (acc, err) => (acc == "" ? "" : ", ") + err), resultExceptions.Count == 0 ? null : new AggregateException(resultExceptions));
 }
Пример #20
0
        public static async Task <RetrievedData <IEnumerable <TransitStop> > > GetTransitStopsForAreaAsync(LatLonRect area, DataSourcePreference preference, CancellationToken cancellationToken)
        {
            IEnumerable <TransitStop> resultStops      = null;
            List <string>             resultErrors     = new List <string>();
            List <Exception>          resultExceptions = new List <Exception>();

            foreach (var source in Sources)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    throw new OperationCanceledException();
                }
                if (!source.IsQualified(preference))
                {
                    continue;
                }
                if (source.CanGetTransitStopsForArea)
                {
                    var sResult = await source.GetTransitStopsForArea(area, cancellationToken);

                    if (sResult.HasData)
                    {
                        if (resultStops == null)
                        {
                            resultStops = sResult.Data;
                        }
                        else
                        {
                            resultStops = resultStops.Union(sResult.Data);
                        }
                    }
                    if (sResult.ErrorMessage != null)
                    {
                        resultErrors.Add(sResult.ErrorMessage);
                    }
                    if (sResult.CaughtException != null)
                    {
                        resultExceptions.Add(sResult.CaughtException);
                    }
                }
            }
            if (resultStops == null)
            {
                resultStops = new TransitStop[] { }
            }
            ;
            return(new RetrievedData <IEnumerable <TransitStop> >(resultStops, resultErrors.Count == 0 ? null : resultErrors.Aggregate("", (acc, err) => (acc == "" ? "" : ", ") + err), resultExceptions.Count == 0 ? null : new AggregateException(resultExceptions)));
        }