/// <summary>
        /// Processes the specified <see cref="PokerBaaziInitResponse"/>
        /// </summary>
        /// <param name="response">Response to process</param>
        private void ProcessInitResponse(PokerBaaziInitResponse response)
        {
            if (!string.IsNullOrEmpty(response.TournamentName))
            {
                response.TournamentName = response.TournamentName.Trim();
            }

            if (!roomsInitResponses.ContainsKey(response.RoomId))
            {
                roomsInitResponses.Add(response.RoomId, response);
                LogProvider.Log.Info(this, $"Init data of room {response.RoomId} has been stored. [{loggerName}]");
                return;
            }

            roomsInitResponses[response.RoomId] = response;

            LogProvider.Log.Info(this, $"Init data of room {response.RoomId} has been updated. [{loggerName}]");
        }
Esempio n. 2
0
        public void InitResponseDeserializationTest(string file, PokerBaaziInitResponse expectedResponse)
        {
            var initResponse = ReadPackageFromFile <PokerBaaziResponse <PokerBaaziInitResponse> >(file);

            Assert.Multiple(() =>
            {
                Assert.That(initResponse.ClassObj.MaxPlayers, Is.EqualTo(expectedResponse.MaxPlayers));
                Assert.That(initResponse.ClassObj.TournamentName, Is.EqualTo(expectedResponse.TournamentName));
                Assert.That(initResponse.ClassObj.RoomId, Is.EqualTo(expectedResponse.RoomId));
                Assert.That(initResponse.ClassObj.SmallBlind, Is.EqualTo(expectedResponse.SmallBlind));
                Assert.That(initResponse.ClassObj.BigBlind, Is.EqualTo(expectedResponse.BigBlind));
                Assert.That(initResponse.ClassObj.UserId, Is.EqualTo(expectedResponse.UserId));
                Assert.That(initResponse.ClassObj.TournamentId, Is.EqualTo(expectedResponse.TournamentId));
                Assert.That(initResponse.ClassObj.Straddle, Is.EqualTo(expectedResponse.Straddle));
                Assert.That(initResponse.ClassObj.GameType, Is.EqualTo(expectedResponse.GameType));
                Assert.That(initResponse.ClassObj.GameLimit, Is.EqualTo(expectedResponse.GameLimit));
                Assert.That(initResponse.ClassObj.TournamentTableName, Is.EqualTo(expectedResponse.TournamentTableName));
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Finds window related to the specified <see cref="PokerBaaziInitResponse"/>
        /// </summary>
        /// <param name="initResponse">Init response</param>
        /// <returns>Handle of window if found; otherwise empty handle</returns>
        protected virtual IntPtr FindWindow(PokerBaaziInitResponse initResponse, HashSet <IntPtr> existingWindows)
        {
            var catcher = importerService.GetImporter <IPokerBaaziCatcher>();

            var pokerClientProcess = catcher.PokerClientProcess;

            try
            {
                if (pokerClientProcess == null || pokerClientProcess.HasExited)
                {
                    return(IntPtr.Zero);
                }

                var windowHandle = IntPtr.Zero;

                var possibleWindowHandles = new List <IntPtr>();

                foreach (ProcessThread thread in pokerClientProcess.Threads)
                {
                    WinApi.EnumThreadWindows(thread.Id, (hWnd, lParam) =>
                    {
                        if (existingWindows.Contains(hWnd) ||
                            WinApi.GetParent(hWnd) != IntPtr.Zero)
                        {
                            return(true);
                        }

                        var windowTitle = WinApi.GetWindowText(hWnd);

                        if (IsAdvancedLogEnabled)
                        {
                            LogProvider.Log.Info(this, $"Checking if window [{windowTitle}, {hWnd}] matches table [{initResponse.TournamentName}, {initResponse.TournamentTableName}, {initResponse.RoomId}]. [{SiteString}]");
                        }

                        if (windowTitle.ContainsIgnoreCase(initResponse.TournamentName) &&
                            (string.IsNullOrEmpty(initResponse.TournamentTableName) ||
                             !string.IsNullOrEmpty(initResponse.TournamentTableName) && windowTitle.ContainsIgnoreCase(initResponse.TournamentTableName)))
                        {
                            if (IsAdvancedLogEnabled)
                            {
                                LogProvider.Log.Info(this, $"Window [{windowTitle}, {hWnd}] does match table [{initResponse.TournamentName}, {initResponse.TournamentTableName}, {initResponse.RoomId}]. [{SiteString}]");
                            }

                            possibleWindowHandles.Add(hWnd);
                        }

                        return(true);
                    }, IntPtr.Zero);
                }

                if (windowHandle == IntPtr.Zero)
                {
                    windowHandle = possibleWindowHandles.FirstOrDefault();
                }

                return(windowHandle);
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, $"Failed to find window for room {initResponse.RoomId}, '{initResponse.TournamentName}' [{SiteString}]", e);
            }

            return(IntPtr.Zero);
        }