Beispiel #1
0
        public void LogFileImport(FileInfo fileInfo, DateTime startDate, DateTime endDate, string status, Hand lastImportedHand)
        {
            using (SqlCeConnection conn = new SqlCeConnection(Helper.ConnectionString))
            using (SqlCeCommand comm = new SqlCeCommand())
            {
                conn.Open();
                comm.Connection = conn;
                comm.CommandType = System.Data.CommandType.Text;

                const string SqlCommandString =
                    "insert  into [LogFiles] (FileName, StartDate, EndDate, Status, LastHandId, LastHandDate ) Values ( '{0}', '{1}', '{2}', '{3}', '{4}', '{5}' )";

                comm.CommandText =
                    string.Format(
                        SqlCommandString,
                        fileInfo.Name,
                        startDate.ToString("yyyy/MM/dd HH:mm:ss.fff"),
                        endDate.ToString("yyyy/MM/dd HH:mm:ss.fff"),
                        status,
                        lastImportedHand.HandId,
                        lastImportedHand.Time.ToString("yyyy/MM/dd HH:mm:ss.fff"));

                comm.ExecuteNonQuery();
            }
        }
Beispiel #2
0
        public void SaveHandsSqlCommandTest()
        {
            var hands = new List<Hand>();

            Hand hand =
                new Hand
                    {
                        BigBlind = 1,
                        ButtonPosition = 2,
                        FlopCard1 = "As",
                        FlopCard2 = "Js",
                        FlopCard3 = "Th",
                        HandId = "4545454",
                        RiverCard = "2s",
                        Time = new DateTime(2000, 1, 1),
                        TurnCard = "7s",
                        Players = new List<HandPlayer>()
                    };

            HandPlayer player =
                new HandPlayer
                    {
                        ActionFlop = "action Flop",
                        ActionPreflop = "action Preflop",
                        ActionRiver = "action River",
                        ActionTurn = "action Turn",
                        Card1Str = "2a",
                        Card2Str = "3c",
                        MyMoneyAddedInPot = 2,
                        MyMoneyCollected = 1,
                        PaidFlop = 0.5m,
                        PaidPreflop = 0.6m,
                        PaidRiver = 0.7m,
                        PaidTurn = 0.8m,
                        SeatNumber = 4,
                        Player = "player1",
                        Stack = 6.52m
                    };

            hand.Players.Add(player);
            hands.Add(hand);

            new Hands().SaveHandsSqlCommand(hands);

            using (trackDBEntities2 t = new trackDBEntities2())
            {
                Assert.AreEqual(t.Hands.Count(), 1);
                Assert.AreEqual(t.Hands.First().BB, 1);
                Assert.AreEqual(t.Hands.First().PositionButton, 2);
                Assert.AreEqual(t.Hands.First().Id, "4545454");
                Assert.AreEqual(t.Hands.First().Time, new DateTime(2000, 1, 1));
                Assert.AreEqual(t.Hands.First().Position, 4);
                Assert.AreEqual(t.Hands.First().Stack, 6.52m);
            }
        }
        private static void SetAction(Match match, Hand hand, string step)
        {
            string action = match.Groups[2].Value;
            string playername = match.Groups[1].Value;

            string amount = action == "raises" ? match.Groups[5].Value : match.Groups[3].Value;
            string actionAndAmount = action + " (" + amount + ")";

            switch (step)
            {
                case "preflop":
                    hand[playername].ActionPreflop +=
                        string.IsNullOrEmpty(hand[playername].ActionPreflop) ? actionAndAmount : "," + actionAndAmount;
                    break;
                case "flop":
                    hand[playername].ActionFlop +=
                        string.IsNullOrEmpty(hand[playername].ActionFlop) ? actionAndAmount : "," + actionAndAmount;
                    break;
                case "turn":
                    hand[playername].ActionTurn +=
                        string.IsNullOrEmpty(hand[playername].ActionTurn) ? actionAndAmount : "," + actionAndAmount;
                    break;
                case "river":
                    hand[playername].ActionRiver +=
                        string.IsNullOrEmpty(hand[playername].ActionRiver) ? actionAndAmount : "," + actionAndAmount;
                    break;
            }

            if (action == "checks")
                return;

            if (action == "collected")
            {
                hand[playername].MyMoneyCollected = decimal.Parse(match.Groups[3].Value);
                return;
            }

            decimal f = 0;
            if (action != "raises")
            {
                if (match.Groups[3].Value != string.Empty)
                    f = decimal.Parse(match.Groups[3].Value);
                switch (step)
                {
                    case "preflop":
                        hand[playername].PaidPreflop += f;
                        break;
                    case "flop":
                        hand[playername].PaidFlop += f;
                        break;
                    case "turn":
                        hand[playername].PaidTurn += f;
                        break;
                    case "river":
                        hand[playername].PaidRiver += f;
                        break;
                }
            }
            else
            {
                f = decimal.Parse(match.Groups[5].Value);

                switch (step)
                {
                    case "preflop":
                        hand[playername].PaidPreflop = f;
                        break;
                    case "flop":
                        hand[playername].PaidFlop = f;
                        break;
                    case "turn":
                        hand[playername].PaidTurn = f;
                        break;
                    case "river":
                        hand[playername].PaidRiver = f;
                        break;
                }
            }
        }
 private bool ParseTurnTitle(Hand hand, string line)
 {
     Match matchT = _regexParseTurnTitle.Match(line);
     if (matchT.Success)
     {
         log(line);
         hand.TurnCard = matchT.Groups[4].Value;
         return false;
     }
     return true;
 }
        private bool ParseTurn(Hand hand, string line)
        {
            Match match = _regexParseTurn.Match(line);

            if (match.Success)
            {
                log(line);
                string player = match.Groups[1].Value;
                string action = match.Groups[2].Value;
                     SetAction(match, hand, "turn");
                return false;
            }
            return true;
        }
 private bool ParseTable(Hand hand, string line)
 {
     Match match = _regexParseTable.Match(line);
     if (match.Success)
     {
         hand.TableName = match.Groups[1].Value;
         hand.TypeGame = match.Groups[2].Value;
         hand.ButtonPosition = int.Parse(match.Groups[3].Value);
         log(line);
         return false;
     }
     return true;
 }
 private bool ParseSummaryTitle(Hand hand, string line)
 {
     if (_regexParseSummaryTitle.Match(line).Success)
     {
         log(line);
         return false;
     }
     return true;
 }
 private bool ParseAnteBlinds(Hand hand, string line)
 {
     Match match = _regexParseAnteBlinds.Match(line);
     if (match.Success)
     {
         log(line);
         return false;
     }
     return true;
 }
        private bool ParseShowDown(Hand hand, string line)
        {
            Match matchSD1 = _regexParseShowDown1.Match(line);
            if (matchSD1.Success)
            {
                hand[matchSD1.Groups[1].Value].Card1Str = matchSD1.Groups[3].Value;
                hand[matchSD1.Groups[1].Value].Card2Str = matchSD1.Groups[4].Value;

                log(line);
                return false;
            }

            Match match = _regexParseShowDown2.Match(line);
            if (match.Success)
            {
                //if (m.Groups[1].Value == me)
                //{
                hand[match.Groups[1].Value].MyMoneyCollected = decimal.Parse(match.Groups[2].Value);
                    log(line);
                //}
                return false;
            }
            return true;
        }
        private bool ParseSeats(Hand hand, string line)
        {
            Match match = _regexParseSeats.Match(line);
            if (match.Success)
            {
                log(line);

                hand.Players.Add(
                    new HandPlayer
                    {
                        Player = match.Groups[2].Value,
                        SeatNumber = int.Parse(match.Groups[1].Value),
                        Stack = decimal.Parse(match.Groups[3].Value)
                    });

                string stack = match.Groups[3].Value;
                return false;
            }

            return true;
        }
 private bool ParseRiverTitle(Hand hand, string line)
 {
     Match matchR = _regexParseRiverTitle.Match(line);
     if (matchR.Success)
     {
         log(line);
         hand.RiverCard = matchR.Groups[5].Value;
         return false;
     }
     return true;
 }
        private bool ParsePostsBlind(Hand hand, string line)
        {
            Match match = _regexParsePostsBlind.Match(line);
            if (match.Success)
            {
                log(line);

                hand[match.Groups[1].Value].ActionBlind = line.Replace(match.Groups[1].Value, "").TrimStart();

                if (match.Groups[4].Value != string.Empty)
                {
                    hand[match.Groups[1].Value].PaidPreflop = decimal.Parse(match.Groups[4].Value);
                }
                return false;
            }
            return true;
        }
        private bool ParseHeader(Hand hand, string line)
        {
            if (_regexParseHeader0.Match(line).Success)
            {
                throw new FormatException("this is not a cashgame file");
            }

            Match match = _regexParseHeader.Match(line);
            if (match.Success)
            {
                if (match.Groups[1].Value != "CashGame")
                {
                    throw new FormatException("this is not a cashgame file");
                }

                log(line);

                string gameType = match.Groups[1].Value;
                string handId = match.Groups[2].Value;
                string typeDetails = match.Groups[3].Value;
                string bigBlind = match.Groups[4].Value;

                string gameDatetime = match.Groups[5].Value;

                hand.Time = DateTime.ParseExact(
                    gameDatetime,
                    "yyyy/MM/dd HH:mm:ss UTC",
                    CultureInfo.InvariantCulture);

                hand.BigBlind = float.Parse(bigBlind,
                    CultureInfo.InvariantCulture);
                hand.HandId = handId;
                return false;
            }
            return true;
        }
        private bool ParseFlopTitle(Hand hand, string line)
        {
            Match matchPF = _regexParseFlopTitle.Match(line);
            if (matchPF.Success)
            {
                log(line);
                hand.FlopCard1 = matchPF.Groups[1].Value;
                hand.FlopCard2 = matchPF.Groups[2].Value;
                hand.FlopCard3 = matchPF.Groups[3].Value;

                return false;
            }
            return true;
        }
        private bool ParseDealtToMe(Hand hand, string line)
        {
            Match match = _regexParseDealtToMe.Match(line);
            if (match.Success)
            {
                log(line);

                string card1 = match.Groups[2].Value;
                string card2 = match.Groups[3].Value;

                hand[match.Groups[1].Value].Card1Str = card1;
                hand[match.Groups[1].Value].Card2Str = card2;
                return false;
            }
            return true;
        }
 public NewFileProcessedEventArgs(string newFile, int nbHands, Hand lastHand)
 {
     _newFile = newFile;
     _lastHand = lastHand;
     _nbHands = nbHands;
 }
        private bool ParseSummary(Hand hand, string line)
        {
            Match match = _regexParseSummary.Match(line);
            if (match.Success)
            {
                log(line);
                string player = match.Groups[1].Value;
                string action = match.Groups[2].Value;
                return false;
            }

            match = _regexParseSummary2.Match(line);
            if (match.Success)
            {
                log(line);
                string player = match.Groups[1].Value;
                string action = match.Groups[2].Value;
                return false;
            }

            return true;
        }
        private IList<Hand> GetHandsFromFile(string filePath, DateTime lastImport)
        {
            IList<Hand> hands = new List<Hand>();
            using (var streamReader =
                new StreamReader(
                    new FileStream(
                        filePath,
                        FileMode.Open, FileAccess.Read, FileShare.Read),
                    Encoding.UTF8))
            {
                int stepNumber = 0;

                // hand initialization
                var hand = new Hand { Players = new List<HandPlayer>() };

                string line = streamReader.ReadLine();

                while (streamReader.Peek() >= 0)
                {
                    // Each step returns:
                    // false, if the line processed matches the step, meaning the next line can be processed by the same step
                    // true, if the line processed doesn't match, meaning the next step must process the same line
                    bool expressionNotFoundGoToFollowingStepWithTheSameLine = _executeStep[stepNumber](hand, line);
                    // next step
                    if (expressionNotFoundGoToFollowingStepWithTheSameLine)
                    {

                        if (stepNumber != _executeStep.Count() - 1)
                        {
                            stepNumber++;
                        }
                        // last step:
                        else
                        {
                            // add the hand to Hands
                            if (hand.Time.Ticks > lastImport.Ticks)
                            {
                                hands.Add(hand);
                            }
                            // reinitialize a new hand
                            // starting on the first step
                            hand = new Hand { Players = new List<HandPlayer>() };
                            stepNumber = 0;
                        }
                    }
                    // next line
                    else
                    {
                        line = streamReader.ReadLine();
                    }
                }

                if (hand.Time.Ticks > lastImport.Ticks)
                {
                    hands.Add(hand);
                }
            }
            return hands;
        }