Ejemplo n.º 1
0
        public void TryParseTest(string json, Adda52PackageType packageType)
        {
            var result = Adda52JsonPackage.TryParse(json, out Adda52JsonPackage jsonPackage);

            Assert.IsTrue(result);
            Assert.That(jsonPackage.PackageType, Is.EqualTo(packageType));
        }
Ejemplo n.º 2
0
        private IEnumerable <Adda52JsonPackage> ReadPackages(string testFolder)
        {
            var packages = new List <Adda52JsonPackage>();

            var sourceJsonFile = Path.Combine(TestDataFolder, testFolder, SourceJsonFile);

            FileAssert.Exists(sourceJsonFile);

            var sourceJson = File.ReadAllText(sourceJsonFile);

            var testObject = JsonConvert.DeserializeObject <Adda52TestSourceObject>(sourceJson);

            foreach (var packet in testObject.Packages)
            {
                var json = JsonConvert.SerializeObject(packet);

                if (Adda52JsonPackage.TryParse(json, out Adda52JsonPackage package))
                {
                    packages.Add(package);
                }
            }

            return(packages);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Processes packets in the buffer
        /// </summary>
        protected void ProcessBuffer()
        {
            var packetManager            = ServiceLocator.Current.GetInstance <IPacketManager <Adda52Package> >();
            var handBuilder              = ServiceLocator.Current.GetInstance <IAdda52HandBuilder>();
            var packetManagerFails       = 0;
            var jsonPackageTryParseFails = 0;

            while (!cancellationTokenSource.IsCancellationRequested && !IsDisabled())
            {
                try
                {
                    if (!packetBuffer.TryTake(out CapturedPacket capturedPacket))
                    {
                        Task.Delay(NoDataDelay).Wait();
                        continue;
                    }
#if DEBUG
                    // LogPacket(capturedPacket, ".log");
#endif

                    if (!packetManager.TryParse(capturedPacket, out IList <Adda52Package> packages))
                    {
                        if (IsAdvancedLogEnabled && packetManagerFails < 10)
                        {
                            LogProvider.Log.Warn(this, $"Failed to parse packet: '{Convert.ToBase64String(capturedPacket.Bytes)}' [{SiteString}]");
                            packetManagerFails++;
                        }

                        continue;
                    }

                    foreach (var package in packages)
                    {
                        if (IsAdvancedLogEnabled)
                        {
                            LogPackage(package);
                        }

                        if (!Adda52JsonPackage.TryParse(package.Bytes, out Adda52JsonPackage jsonPackage))
                        {
                            if (IsAdvancedLogEnabled && jsonPackageTryParseFails < 10)
                            {
                                LogProvider.Log.Warn(this, $"Failed to parse json from packet: '{Convert.ToBase64String(capturedPacket.Bytes)}' [{SiteString}]");
                                jsonPackageTryParseFails++;
                            }

                            continue;
                        }

                        if (!handBuilder.TryBuild(jsonPackage, out HandHistory handHistory))
                        {
                            continue;
                        }

                        var handHistoryText = SerializationHelper.SerializeObject(handHistory);

#if DEBUG
                        if (!Directory.Exists("Hands"))
                        {
                            Directory.CreateDirectory("Hands");
                        }

                        File.WriteAllText($"Hands\\adda52_hand_exported_{handHistory.HandId}.xml", handHistoryText);
#endif
                        var windowHandle = tableService.GetWindow(handHistory);

                        var gameInfo = new GameInfo
                        {
                            WindowHandle = windowHandle.ToInt32(),
                            PokerSite    = Site,
                            GameNumber   = handHistory.HandId,
                            Session      = windowHandle.ToString()
                        };

                        ProcessHand(handHistoryText, gameInfo);
                    }
                }
                catch (Exception e)
                {
                    LogProvider.Log.Error(this, $"Failed to process captured packet. [{SiteString}]", e);
                }
            }
        }