예제 #1
0
        public IEnumerable <Standing> GetFromClientStandings(ExternalLeagueCode externalLeagueCode)
        {
            IEnumerable <Standing> result = null;
            var idSeason = GetIdSeason(externalLeagueCode);

            if (idSeason > 0)
            {
                StandingsResponse leagueTableResult;
                try
                {
                    //leagueTableResult = await _competitionResultSingleton.FootballDataOrgApiGateway.GetLeagueTableResultAsync(idSeason);
                    leagueTableResult = _competitionResultSingleton.FootballDataOrgApiGateway.GetLeagueTableResult(idSeason);
                }
                catch (AggregateException ex)
                {
                    LogAggregateException(ex);
                    leagueTableResult = new StandingsResponse {
                        Standing = new List <FootballDataOrg.ResponseEntities.Standing> {
                            new FootballDataOrg.ResponseEntities.Standing {
                                TeamName = EntityConstants.PotentialTimeout
                            }
                        }
                    };
                }
                if (leagueTableResult != null)
                {
                    result = GetResultMatchStandings(leagueTableResult);
                }
            }
            return(result);
        }
예제 #2
0
        public IEnumerable <FixtureFuture> GetFromClientFixtureFutures(ExternalLeagueCode externalLeagueCode, string timeFrame)
        {
            IEnumerable <FixtureFuture> result = null;
            var idSeason = GetIdSeason(externalLeagueCode);

            if (idSeason > 0)
            {
                FixturesResponse fixturesResult;
                try
                {
                    fixturesResult = _competitionResultSingleton.FootballDataOrgApiGateway.GetFixturesResultAsync(idSeason, timeFrame).Result;
                }
                catch (AggregateException ex)
                {
                    LogAggregateException(ex);
                    fixturesResult = new FixturesResponse {
                        Fixtures = new List <Fixture> {
                            new Fixture {
                                HomeTeamName = EntityConstants.PotentialTimeout
                            }
                        }
                    };
                }
                if (fixturesResult != null)
                {
                    result = GetFixtureFutures(fixturesResult);//.OrderBy(x => new { x.Date, x.HomeName });
                }
            }
            return(result);
        }
예제 #3
0
        private int GetIdSeason(ExternalLeagueCode externalLeagueCode, bool getViaHttpRequest = true)
        {
            int result;

            var league = _competitionResultSingleton?.CompetitionResult?.competitions?.SingleOrDefault(x => x.Id == (int)externalLeagueCode);

            result = league?.Id ?? 0;

            return(result);
        }
예제 #4
0
 private static LeagueDto GetLeagueDto(
     InternalLeagueCode internalLeagueCode,
     ExternalLeagueCode externalLeagueCode,
     string externalLeagueCodeDescription)
 {
     return(new LeagueDto
     {
         InternalLeagueCode = internalLeagueCode,
         ExternalLeagueCode = externalLeagueCode,
         ExternalLeagueCodeDescription = externalLeagueCodeDescription
     });
 }
 private void AddTargetLeagueToLeagueParents(ExternalLeagueCode externalLeagueCode)
 {
     if (LeagueParents.Count(x => x.ExternalLeagueCode == externalLeagueCode) == 0)
     {
         LeagueParents.Add(new LeagueParent
         {
             ExternalLeagueCode = externalLeagueCode,
             Standings          = Standings,
             FixturePasts       = FixturePasts,
             FixtureFutures     = FixtureFutures,
         });
     }
 }
 private IEnumerable <FixtureFuture> GetFixtureFutures(ExternalLeagueCode externalLeagueCode)
 {
     try
     {
         //throw new Exception();//for debugging
         var gateway = GetFootieDataGateway();
         var result  = gateway.GetFromClientFixtureFutures(externalLeagueCode, $"n{CommonConstants.DaysCount}");
         return(result);
     }
     catch (Exception ex)
     {
         return(new List <FixtureFuture> {
             new FixtureFuture {
                 PoliteError = $"{EntityConstants.UnexpectedErrorOccured} ({nameof(GetFixtureFutures)})"
             }
         });
     }
 }
 private IEnumerable <Standing> GetStandings(ExternalLeagueCode externalLeagueCode)
 {
     try
     {
         //throw new Exception();//for debugging
         var gateway = GetFootieDataGateway();
         var result  = gateway.GetFromClientStandings(externalLeagueCode);
         return(result);
     }
     catch (Exception ex)
     {
         return(new List <Standing> {
             new Standing {
                 PoliteError = $"{EntityConstants.UnexpectedErrorOccured} ({nameof(GetStandings)})"
             }
         });
     }
 }
        public void FetchDataFromGateway(ExternalLeagueCode externalLeagueCode, GridType gridType)
        {
            ThreadPool.QueueUserWorkItem(delegate
            {
                //Debug.WriteLine("Get thread: " + Thread.CurrentThread.ManagedThreadId);
                //Thread.Sleep(TimeSpan.FromSeconds(10));//for debugging

                var leagueParent = new LeagueParent();

                try
                {
                    //throw new Exception(); //for debugging
                    leagueParent = LeagueParents.Single(x => x.ExternalLeagueCode == externalLeagueCode);

                    switch (gridType)
                    {
                    case GridType.Standing:
                        var iEnumerableStandings = GetStandings(externalLeagueCode);
                        leagueParent.Standings.Clear();
                        var standingsList = iEnumerableStandings.ToList();
                        if (standingsList.Any(x => x.Team != null && x.Team.StartsWith(RequestLimitReached)))
                        {
                            var politeRequestLimitReached = standingsList.First(x => x.Team.StartsWith(RequestLimitReached)).Team.Replace(RequestLimitReached, EntityConstants.PoliteRequestLimitReached);
                            leagueParent.Standings.Add(new Standing {
                                PoliteError = EntityConstants.PoliteRequestLimitReached
                            });
                        }
                        else
                        {
                            if (standingsList.Any(x => x.Team != null && x.Team.StartsWith(EntityConstants.PotentialTimeout)))
                            {
                                leagueParent.Standings.Add(new Standing {
                                    PoliteError = EntityConstants.PotentialTimeout
                                });
                            }
                            else
                            {
                                foreach (var standing in iEnumerableStandings)
                                {
                                    leagueParent.Standings.Add(standing);
                                }
                            }
                        }
                        break;

                    case GridType.Result:
                        var iEnumerableFixturePasts = GetFixturePasts(externalLeagueCode);
                        leagueParent.FixturePasts.Clear();
                        var resultsList = iEnumerableFixturePasts.ToList();
                        if (resultsList.Any())
                        {
                            if (resultsList.Any(x => x.HomeName != null && x.HomeName.StartsWith(RequestLimitReached)))
                            {
                                var politeRequestLimitReached = resultsList.First(x => x.HomeName.StartsWith(RequestLimitReached)).HomeName.Replace(RequestLimitReached, EntityConstants.PoliteRequestLimitReached);
                                leagueParent.FixturePasts.Add(new FixturePast {
                                    PoliteError = EntityConstants.PoliteRequestLimitReached
                                });
                            }
                            else
                            {
                                if (resultsList.Any(x => x.HomeName != null && x.HomeName.StartsWith(EntityConstants.PotentialTimeout)))
                                {
                                    leagueParent.FixturePasts.Add(new FixturePast {
                                        PoliteError = EntityConstants.PotentialTimeout
                                    });
                                }
                                else
                                {
                                    foreach (var fixturePast in iEnumerableFixturePasts)
                                    {
                                        leagueParent.FixturePasts.Add(fixturePast);
                                    }
                                }
                            }
                        }
                        else
                        {
                            leagueParent.FixturePasts.Add(new FixturePast {
                                PoliteError = _zeroFixturePasts
                            });
                        }
                        break;

                    case GridType.Fixture:
                        var iEnumerableFixtureFutures = GetFixtureFutures(externalLeagueCode);
                        leagueParent.FixtureFutures.Clear();
                        var fixturesList = iEnumerableFixtureFutures.ToList();
                        if (fixturesList.Any())
                        {
                            if (fixturesList.Any(x => x.HomeName != null && x.HomeName.StartsWith(RequestLimitReached)))
                            {
                                var politeRequestLimitReached = fixturesList.First(x => x.HomeName.StartsWith(RequestLimitReached)).HomeName.Replace(RequestLimitReached, EntityConstants.PoliteRequestLimitReached);
                                leagueParent.FixtureFutures.Add(new FixtureFuture {
                                    PoliteError = EntityConstants.PoliteRequestLimitReached
                                });
                            }
                            else
                            {
                                if (fixturesList.Any(x => x.HomeName != null && x.HomeName.StartsWith(EntityConstants.PotentialTimeout)))
                                {
                                    leagueParent.FixtureFutures.Add(new FixtureFuture {
                                        PoliteError = EntityConstants.PotentialTimeout
                                    });
                                }
                                else
                                {
                                    foreach (var fixtureFuture in iEnumerableFixtureFutures)
                                    {
                                        leagueParent.FixtureFutures.Add(fixtureFuture);
                                    }
                                }
                            }
                        }
                        else
                        {
                            leagueParent.FixtureFutures.Add(new FixtureFuture {
                                PoliteError = _zeroFixtureFutures
                            });
                        }
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception)
                {
                    leagueParent = LeagueParents.FirstOrDefault();
                    leagueParent.ExternalLeagueCode = externalLeagueCode;
                    switch (gridType)
                    {
                    case GridType.Standing:
                        leagueParent.Standings.Clear();
                        leagueParent.Standings.Add(new Standing {
                            PoliteError = EntityConstants.UnexpectedErrorOccured
                        });
                        break;

                    case GridType.Result:
                        leagueParent.FixturePasts.Clear();
                        leagueParent.FixturePasts.Add(new FixturePast {
                            PoliteError = EntityConstants.UnexpectedErrorOccured
                        });
                        break;

                    case GridType.Fixture:
                        leagueParent.FixtureFutures.Clear();
                        leagueParent.FixtureFutures.Add(new FixtureFuture {
                            PoliteError = EntityConstants.UnexpectedErrorOccured
                        });
                        break;
                    }
                }
            });
        }
 public ThreadedDataProvider(ExternalLeagueCode externalLeagueCode)
 {
     InitializeCompetitionResultSingletonInstance();
     AddTargetLeagueToLeagueParents(externalLeagueCode);
 }