Beispiel #1
0
        public async Task Import(CompetitionV competitionV, bool includeFixtures, bool includeResults, DateTime viewDate)
        {
            var startDate = Date.LowDate;
            var endDate   = Date.HighDate;

            if (!competitionV.GetCampaignDates(viewDate, ref startDate, ref endDate))
            {
                return;
            }

            // http://www.espn.co.uk/football/sport/match/index.html?event=3;page=5;season=2013%2F14
            // http://www.espn.co.uk/football/sport/match/index.html?event=3;type=fixtures

            var country = competitionV.Competition.GetParentCountry(viewDate);

            countryGuid = country != null ? (Guid?)country.HeaderKey : null;

            var seasonId = string.Format("{0}%2F{1}", startDate.ToString("yyyy"), endDate.ToString("yy"));
            var eventId  = (await Provider.GetLookupCompetition(competitionV.HeaderKey, ImportSite)).LookupId;

            if (includeFixtures)
            {
                var uri = new Uri(string.Format("http://www.espn.co.uk/football/sport/match/index.html?event={0};type=fixtures", eventId));
                await ImportMatches(competitionV, uri, eventId);
            }

            var resultsFound = true;
            var page         = 1;

            if (includeResults)
            {
                while (resultsFound)
                {
                    var uri = new Uri(string.Format("http://www.espn.co.uk/football/sport/match/index.html?event={0};page={1};season={2}", eventId, page, seasonId));
                    resultsFound = await ImportMatches(competitionV, uri, eventId);

                    page++;
                }
            }
        }
Beispiel #2
0
        protected async Task ProcessMatch(string lookupId, DateTime matchDate, CompetitionV competitionV, Guid?venueGuid, int?attendance, Guid team1Guid, short?team1Ht, short?team1Ft, Guid team2Guid, short?team2Ht, short?team2Ft, Guid campaignStageKey)
        {
            if (campaignStageKey == null)
            {
                return;
            }

            var lookupMatchSearch = await Provider.GetLookupMatch(ImportSite, lookupId);

            var startOfDay = matchDate.Date;
            var endOfDay   = matchDate.ToEndOfDay();

            var matchSearch = await Provider.GetMatchByTeams(team1Guid, team2Guid, matchDate);

            var campaign = await Provider.FindCampaignAsync(competitionV.HeaderKey, matchDate);

            if (campaign == null)
            {
                var startDate = Date.LowDate;
                var endDate   = Date.HighDate;

                if (!competitionV.GetCampaignDates(matchDate, ref startDate, ref endDate))
                {
                    return;
                }

                var newCampaign = Campaign.CreateNew(competitionV.HeaderKey, startDate, endDate);
                campaign = newCampaign;

                Provider.Add(newCampaign);
                Provider.SaveChanges();
            }

            if (lookupMatchSearch != null || matchSearch != null)
            {
                MatchV matchV = null;

                if (lookupMatchSearch != null)
                {
                    var lookupMatch = lookupMatchSearch;
                    matchV = (await Provider.GetMatch(lookupMatch.MatchGuid, DateTime.Now));
                }
                else if (matchSearch != null)
                {
                    matchV = matchSearch;
                }

                if (matchV == null || matchV.MatchImportType == MatchImportType.ManualResult)
                {
                    return;
                }

                matchV.MatchDate        = matchDate.Date;
                matchV.MatchTimeTicks   = (matchDate - matchDate.Date).Ticks;
                matchV.VenueGuid        = venueGuid;
                matchV.Attendance       = attendance;
                matchV.Team1Guid        = team1Guid;
                matchV.Team1HT          = team1Ht;
                matchV.Team1FT          = team1Ft;
                matchV.Team2Guid        = team2Guid;
                matchV.Team2HT          = team2Ht;
                matchV.Team2FT          = team2Ft;
                matchV.MatchImportType  = matchV.GetMatchImportType(true);
                matchV.CampaignStageKey = campaignStageKey;
            }
            else
            {
                if (matchDate < DateTime.Now && team1Ft == null && team2Ft == null)
                {
                    return;
                }

                var matchGuid = Guid.NewGuid();

                Provider.Add(new Match()
                {
                    PrimaryKey = matchGuid
                });

                var matchV = MatchV.CreateNew <MatchV>(User.GetUserId());
                matchV.HeaderKey        = matchGuid;
                matchV.MatchDate        = matchDate.Date;
                matchV.MatchTimeTicks   = (matchDate - matchDate.Date).Ticks;
                matchV.VenueGuid        = venueGuid;
                matchV.Attendance       = attendance;
                matchV.Team1Guid        = team1Guid;
                matchV.Team1HT          = team1Ht;
                matchV.Team1FT          = team1Ft;
                matchV.Team2Guid        = team2Guid;
                matchV.Team2HT          = team2Ht;
                matchV.Team2FT          = team2Ft;
                matchV.EffectiveFrom    = Date.LowDate;
                matchV.EffectiveTo      = Date.HighDate;
                matchV.MatchImportType  = matchV.GetMatchImportType(true);
                matchV.CampaignStageKey = campaignStageKey;

                Provider.Add(matchV);

                if (lookupId != string.Empty)
                {
                    Provider.Add(new LookupMatch()
                    {
                        PrimaryKey = Guid.NewGuid(),
                        ImportSite = ImportSite,
                        MatchGuid  = matchGuid,
                        LookupId   = lookupId
                    });
                }
            }

            Provider.SaveChanges();
        }