Esempio n. 1
0
        private static BattingRecord CreateBattingRecord(BatsmanInnings innings, bool firstInnings)
        {
            var record = new BattingRecord
                             {
                                 PlayerId = innings.PlayerId,
                                 Team = innings.Team,
                                 Runs = innings.Runs,
                                 Minutes = innings.Minutes,
                                 Balls = innings.Balls,
                                 Fours = innings.Fours,
                                 Sixes = innings.Sixes,
                                 Matches = firstInnings ? 1 : 0,
                                 Innings = innings.IsInnings ? 1 : 0,
                                 NotOut = innings.IsInnings && !innings.IsOut ? 1 : 0
                             };
            switch (innings.HowOut)
            {
                case HowOutType.Absent:
                case HowOutType.AbsentHurt:
                case HowOutType.AbsentIll:
                    record.Absent = 1;
                    break;
                case HowOutType.Bowled:
                    record.Bowled = 1;
                    break;
                case HowOutType.Caught:
                    record.Caught = 1;
                    break;
                case HowOutType.LBW:
                    record.Lbw = 1;
                    break;
                case HowOutType.HitWicket:
                    record.HitWicket = 1;
                    break;
                case HowOutType.RunOut:
                    record.RunOut = 1;
                    break;
                case HowOutType.Stumped:
                    record.Stumped = 1;
                    break;
                case HowOutType.HitTheBallTwice:
                case HowOutType.ObstructingTheField:
                case HowOutType.Unknown:
                    record.Other = 1;
                    break;
                case HowOutType.RetiredHurt:
                case HowOutType.RetiredIll:
                case HowOutType.RetiredNotOut:
                case HowOutType.RetiredOut:
                    record.Retired = 1;
                    break;
            }

            return record;
        }
Esempio n. 2
0
        private BatsmanInnings ParseBatsmanInnings(HtmlNode row, bool saveCaptainAndKeeper)
        {
            BatsmanInnings innings = new BatsmanInnings();
            HtmlNodeCollection cells = row.SelectNodes("./td");

            HtmlNode player = cells[0].LastChild;

            if (player.NodeType == HtmlNodeType.Element && player.Name == "a")
            {
                string batsmanId = FindPlayerId(player);
                innings.PlayerId = batsmanId;

                if (saveCaptainAndKeeper)
                {
                    string icons = "";
                    if (cells[0].FirstChild.NodeType == HtmlNodeType.Text)
                    {
                        icons = cells[0].FirstChild.InnerText;
                    }

                    bool isKeeper = icons.Contains("+");
                    bool isCaptain = icons.Contains("*");

                    if (isKeeper)
                        SetKeeper(batsmanId);
                    if (isCaptain)
                        SetCaptain(batsmanId);
                }
            }

            string runs = null;
            if (cells.Count >= 3)
                runs = cells[2].InnerText.Replace(" ", "").Replace("-", "");
            string balls = null;
            if (cells.Count >= 4)
                balls = cells[3].InnerText.Replace(" ", "").Replace("-", "");
            string mins = null;
            if (cells.Count >= 4)
                mins = cells[4].InnerText.Replace(" ", "").Replace("-", "");
            string fours = null;
            if (cells.Count >= 4)
                fours = cells[5].InnerText.Replace(" ", "").Replace("-", "");
            string sixes = null;
            if (cells.Count >= 4)
                sixes = cells[6].InnerText.Replace(" ", "").Replace("-", "");

            innings.NameOnScorecard = player.InnerText;
            innings.HowOutText = cells[1].InnerText;

            if (!string.IsNullOrEmpty(runs) && !string.IsNullOrWhiteSpace(runs))
                innings.Runs = int.Parse(runs);
            if (!string.IsNullOrEmpty(balls) && !string.IsNullOrWhiteSpace(balls))
                innings.Balls = int.Parse(balls);
            if (!string.IsNullOrEmpty(mins) && !string.IsNullOrWhiteSpace(mins))
                innings.Minutes = int.Parse(mins);
            if (!string.IsNullOrEmpty(fours) && !string.IsNullOrWhiteSpace(fours))
                innings.Fours = int.Parse(fours);
            if (!string.IsNullOrEmpty(sixes) && !string.IsNullOrWhiteSpace(sixes))
                innings.Sixes = int.Parse(sixes);

            ProcessHowOut(cells[1], innings);

            return innings;
        }
Esempio n. 3
0
        private static void ProcessHowOut(HtmlNode cell, BatsmanInnings innings)
        {
            List<string> players = new List<string>();
            HtmlNodeCollection playerNodes = cell.SelectNodes("./a");
            if (playerNodes != null && playerNodes.Count > 0)
            {
                players.AddRange(cell.SelectNodes("./a").Select(FindPlayerId));
            }

            IHowOut howOut = HowOutFactory.GetHowOut(GetTrimmedInnerText(cell.FirstChild));
            innings.HowOut = howOut.HowOutType;
            innings.IsInnings = howOut.IsInnings;
            innings.IsOut = howOut.IsOut;
            if (howOut.HasFielder)
                innings.FielderId = howOut.GetFielder(players);
            if (howOut.HasBowler)
                innings.BowlerId = howOut.GetBowler(players);
        }