コード例 #1
0
ファイル: Adda52Importer.cs プロジェクト: Michael-Z/DriveHud
        private void LogPackage(Adda52Package package)
        {
            try
            {
                if (!Adda52JsonPackage.TryParseJsonData(package.Bytes, out string contentJson))
                {
                    return;
                }

                var ignoreList = new[] { "game.keepAlive", "game.Message", "game.usercount", "game.avgstack", "game.account" };

                if (ignoreList.Any(x => contentJson.Contains(x)))
                {
                    return;
                }
#if DEBUG
                Console.WriteLine(contentJson);

                if (contentJson.Contains("game.started"))
                {
                    protectedLogger.Log("-------------------------------------------------------------------------------------");
                }
#endif
                protectedLogger.Log(contentJson);
#if DEBUG
                if (contentJson.Contains("game.roundend"))
                {
                    protectedLogger.Log("-------------------------------------------------------------------------------------");
                }
#endif
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, $"Failed to log package. [{SiteString}]", e);
            }
        }
コード例 #2
0
        //[TestCase(@"Packets\0.0.0.0.8893-127.0.0.1.12032.txt", @"Packets\NotJsonOnlyPacket.json")]
        public void TryParseTest(string file, string expectedResultFile)
        {
            var packets = ReadCapturedPackets(file, null);

            var packetManager = new Adda52PacketManager();

            var actualJson   = string.Empty;
            var expectedJson = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(TestDataFolder, expectedResultFile))), Formatting.Indented);

            var sequenceNumber = 1u;

            using (ShimsContext.Create())
            {
                foreach (var packet in packets)
                {
                    ShimDateTime.NowGet = () => packet.CreatedTimeStamp;

                    packet.SequenceNumber = sequenceNumber++;

                    if (packetManager.TryParse(packet, out IList <Adda52Package> packages))
                    {
                        var package = packages.FirstOrDefault();

                        Assert.IsNotNull(package);

                        Adda52JsonPackage.TryParseJsonData(package.Bytes, out string jsonText);

                        var dynamicObject = JsonConvert.DeserializeObject(jsonText);

                        actualJson = JsonConvert.SerializeObject(dynamicObject, Formatting.Indented);
                    }
                }
            }

            Assert.That(actualJson, Is.EqualTo(expectedJson));
        }