Exemple #1
0
        public string ParseResult(string html)
        {
            string resultMessage             = "";
            IEnumerable <HtmlNode> matchesTr = XpathSelector.Get(html, "//table[@class='stat-table']/tbody/tr");

            using (IUnitOfWork uow = unitOfWorkFactory.Create())
            {
                IEnumerable <Match> allMatches = queryFactory.FindAll <Match>().Execute().ToList();
                foreach (HtmlNode matchTr in matchesTr)
                {
                    var scores = XpathSelector.Get(matchTr.OuterHtml, "//td[@class='score-td']//a").Single().InnerText.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

                    int ownersGoals;
                    if (int.TryParse(scores.First(), out ownersGoals) == false)
                    {
                        continue;
                    }

                    var owners     = XpathSelector.Get(matchTr.OuterHtml, "//td[@class='owner-td']//a").Single().InnerText.Replace(" Москва", "");
                    var guests     = XpathSelector.Get(matchTr.OuterHtml, "//td[@class='guests-td']//a").Single().InnerText.Replace(" Москва", "");
                    var dateString = XpathSelector.Get(matchTr.OuterHtml, "//td[@class='name-td alLeft']").Single().InnerText;

                    Match matchFromDb = allMatches.SingleOrDefault(x => x.Guests.Name == guests && x.Owners.Name == owners);
                    if (matchFromDb != null)
                    {
                        var guestsGoals = int.Parse(scores.Last());

                        DateTime date = DateTime.Parse(dateString.Replace("|", " "));

                        if (matchFromDb.OwnersGoals.HasValue && matchFromDb.GuestsGoals.HasValue)
                        {
                            if ((matchFromDb.Guests.Name != guests ||
                                 matchFromDb.GuestsGoals != guestsGoals ||
                                 matchFromDb.Owners.Name != owners ||
                                 matchFromDb.OwnersGoals != ownersGoals))
                            {
                                throw new ArgumentException(string.Format("Результаты матча {0} не совпадают!", owners + "-" + guests));
                            }
                        }
                        else
                        {
                            matchFromDb.GuestsGoals = guestsGoals;
                            matchFromDb.OwnersGoals = ownersGoals;
                            matchFromDb.Date        = date;

                            resultMessage += string.Format("{0}. {1} - {2} {3}:{4}{5}", matchFromDb.Number, owners, guests, ownersGoals, guestsGoals, Environment.NewLine);
                        }
                    }
//                    else
//                    {
//                        uow.Save(new Match
//                                     {
//                                         Number = number,
//                                         OwnersGoals = ownersGoals,
//                                         GuestsGoals = guestsGoals,
//                                         Guests = queryFactory.GetCommandByName(guests).Execute(),
//                                         Owners = queryFactory.GetCommandByName(owners).Execute(),
//                                         Date = date
//                                     });
//                    }
                }
                uow.Commit();
            }
            return(resultMessage);
        }
Exemple #2
0
        private Data LoadData()
        {
            using (unitOfWorkFactory.Create())
            {
                var users        = queryFactory.FindAll <Ljuser>().Execute().ToList();
                var allForecasts = users.SelectMany(x => x.Forecasts).ToList();
                IEnumerable <Match> allMatches = queryFactory.FindAll <Match>().Execute().ToList();

                foreach (Forecast forecast in allForecasts)
                {
                    Match match = allMatches.SingleOrDefault(x => x.Number == forecast.Number);

                    if (match == null || (match.OwnersGoals == null && match.GuestsGoals == null))
                    {
                        continue;
                    }

                    SetScore(forecast, match);
                }
                return(new Data(allForecasts, users, allMatches));
            }
        }