Ejemplo n.º 1
0
        private void SaveGP(string grandPrixUrl, string webId)
        {
            Uri url = new Uri(grandPrixUrl);
            HtmlReader reader = new HtmlReader();
            string html = reader.GetHtmlFromUrl(url);
            object[] grandPrixRead = F1HtmlParserHelper.ParseRacesHtml(html);

            GrandPrix gp = new GrandPrix()
            {
                Name = (string)grandPrixRead[0],
                CircuitName = (string)grandPrixRead[1],
                CelebrationDate = (DateTime)grandPrixRead[2],
                CircuitLength = Convert.ToDecimal((double)grandPrixRead[4]),
                LapsNo = Convert.ToInt32((byte)grandPrixRead[3]),
                WebId = webId
            };

            var grandPrixRepo = this.container.Resolve<IGenericRepository<GrandPrix>>();
            List<GrandPrix> existing = grandPrixRepo.GetAll().Where(x => x.CelebrationDate == gp.CelebrationDate).ToList<GrandPrix>();
            if (existing.Count == 0)
            {
                grandPrixRepo.Save(gp);
            }
        }
Ejemplo n.º 2
0
        private IList<RaceResult> GetResultsFromWeb(int season, GrandPrix gp)
        {
            IList<RaceResult> results = new List<RaceResult>();

            Uri url = new Uri("http://www.formula1.com/results/season/" + season.ToString(CultureInfo.GetCultureInfo("en-US")) + "/" + gp.WebId + "/");
            HtmlReader reader = new HtmlReader();
            string html = reader.GetHtmlFromUrl(url);

            Collection<object[]> resultsRead = F1HtmlParserHelper.ParseRaceResultHtml(html);

            var carRepo = this.container.Resolve<IVehicleRepository>();
            TimeSpan pos1Time = new TimeSpan();
            foreach (var item in resultsRead)
            {
                // Vehicle car = carRepo.GetByDriverName((string)item[2]);
                Vehicle car = carRepo.GetByCarNo(Convert.ToInt32((byte)item[1]));
                RaceResult rr = new RaceResult()
                {
                    GrandPrix = gp,
                    Position = Convert.ToInt32((byte)item[0], CultureInfo.GetCultureInfo("en-US")),
                    Vehicle = car,
                    LapsNo = Convert.ToInt32((byte)item[4], CultureInfo.GetCultureInfo("en-US")),
                    Time = pos1Time.Add((TimeSpan)item[5]),
                    Description = (string)item[6]
                };

                if (((TimeSpan)item[5]).TotalMilliseconds == 0d)
                {
                    rr.Time = TimeSpan.FromMilliseconds(-1);
                }

                if (rr.Position == 1)
                {
                    pos1Time = rr.Time;
                }

                results.Add(rr);
            }

            return results;
        }