public override void Run()
    {
        string propsJson = File.ReadAllText(propsFilePath);
        Dictionary <string, string> props = SerializerService.Deserialize <Dictionary <string, string> >(propsJson);

        string           equipmentJson = File.ReadAllText(equipmentFilePath);
        List <Equipment> equipment     = SerializerService.Deserialize <List <Equipment> >(equipmentJson);

        foreach ((string key, string value) in props)
        {
            string[] parts = value.Split(';', StringSplitOptions.RemoveEmptyEntries);

            string name = parts[0].Trim();
            string?desc = null;

            if (parts.Length == 2)
            {
                desc = parts[1].Trim();
            }

            Equipment eq = new();
            eq.Name        = name;
            eq.Description = desc;
            eq.Id          = key;
            eq.Slot        = Equipment.FitsSlots.Weapons;

            equipment.Add(eq);
        }

        ///equipment.Sort((a, b) => a.Id.CompareTo(b.Id));

        string json = SerializerService.Serialize(equipment);

        File.WriteAllText(equipmentFilePath, json);
    }
Exemple #2
0
        protected override void Serialize(T file, Stream stream)
        {
            using TextWriter writer = new StreamWriter(stream);
            string json = SerializerService.Serialize(file);

            writer.Write(json);
        }
Exemple #3
0
        public static void Test_Can_Serializer_Then_Deserialize_Most_Complex_Test_Possible()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            TestEnum[] arrayOne = new TestEnum[] { TestEnum.Zero, TestEnum.One };
            TestEnum[] arrayTwo = new TestEnum[3] {
                TestEnum.Two, TestEnum.One, TestEnum.Zero
            };
            BasicWireDataContract WireDataContractNested = new BasicWireDataContract(8);

            //act
            serializer.RegisterType <VeryComplexType>();
            serializer.Compile();

            byte[] bytes = serializer.Serialize(new VeryComplexType(6, WireDataContractNested, arrayOne, arrayTwo));
            Assert.NotNull(bytes);
            Assert.False(bytes.Length == 0);
            VeryComplexType message = serializer.Deserialize <VeryComplexType>(bytes);

            //assert
            Assert.NotNull(message);

            //check fields
            for (int i = 0; i < arrayOne.Length; i++)
            {
                Assert.AreEqual(arrayOne[i], message.testEnums[i], $"Failed for index {i}.");
            }

            for (int i = 0; i < arrayTwo.Length; i++)
            {
                Assert.AreEqual(arrayTwo[i], message.testEnumsAnother[i], $"Failed for index {i}.");
            }
        }
        public void Test_Can_Serialize_Then_Deserializer_AuthSessionChallengeEvent_Vanilla_Payload()
        {
            //arrange
            SerializerService otherService = new SerializerService();

            otherService.RegisterType <SessionAuthChallengeEvent>();

            SerializerService serializer = new SerializerService();

            serializer.RegisterType <SessionAuthChallengeEvent_Vanilla>();
            serializer.Compile();
            otherService.Compile();

            SerializerService lastserializer = new SerializerService();

            lastserializer.RegisterType <SessionAuthChallengeEvent_Vanilla>();
            lastserializer.Compile();

            //act
            byte[] bytes = lastserializer.Serialize(new SessionAuthChallengeEvent_Vanilla(new SessionAuthChallengeEventData(55, new byte[32])));
            SessionAuthChallengeEvent_Vanilla payload = serializer.Deserialize <SessionAuthChallengeEvent_Vanilla>(bytes);

            //assert
            Assert.NotNull(bytes);
        }
        public void Test_Can_Deserialize_ReadToEnd_String_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <ReadToEndStringType>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new ReadToEndStringType(5, TestStrings));
            ReadToEndStringType deserializer = serializer.Deserialize <ReadToEndStringType>(bytes);

            Assert.NotNull(deserializer);
            Assert.IsNotEmpty(deserializer.Strings);
            Assert.AreEqual(5, deserializer.I);
            Assert.AreEqual(TestStrings.Length, deserializer.Strings.Length);

            //Check that there are null terminators
            Assert.AreEqual(TestStrings.Length, bytes.Skip(4).Count(b => b == 0));

            for (int i = 0; i < TestStrings.Length; i++)
            {
                Assert.AreEqual(TestStrings[i], deserializer.Strings[i]);
            }
        }
Exemple #6
0
        /// <summary>
        /// Gets the raw string (xml) from the broker db by URL
        /// </summary>
        /// <param name="Url">URL of the page</param>
        /// <returns>String with page xml or empty string if no page was found</returns>
        public string GetContentByUrl(string Url)
        {
            Page page = new Page();

            page.Title    = Randomizer.AnyString(15);
            page.Id       = Randomizer.AnyUri(64);
            page.Filename = Randomizer.AnySafeString(8) + ".html";

            PageTemplate pt = new PageTemplate();

            pt.Title = Randomizer.AnyString(20);
            Field ptfieldView = new Field();

            ptfieldView.Name = "view";
            ptfieldView.Values.Add("Standard");
            pt.MetadataFields = new FieldSet();
            pt.MetadataFields.Add(ptfieldView.Name, ptfieldView);

            page.PageTemplate = pt;

            page.ComponentPresentations = new List <ComponentPresentation>();

            string cpString = ComponentPresentationProvider.GetContent("");

            page.ComponentPresentations.Add(SerializerService.Deserialize <ComponentPresentation>(cpString));

            FieldSet metadataFields = new FieldSet();

            page.MetadataFields = metadataFields;

            return(SerializerService.Serialize <Page>(page));
        }
        public void Can_Serialize_DeserializedDTO_To_Same_Binary_Representation(PacketCaptureTestEntry entry)
        {
            //arrange
            Console.WriteLine($"Entry Size: {entry.BinaryData.Length} OpCode: {entry.OpCode}");
            SerializerService serializer = Serializer;
            GamePacketPayload payload    = serializer.Deserialize <GamePacketPayload>(entry.BinaryData);

            //act
            byte[] serializedBytes = serializer.Serialize(payload);

            //assert
            try
            {
                Assert.AreEqual(entry.BinaryData.Length, serializedBytes.Length, $"Mismatched length on OpCode: {entry.OpCode} Type: {payload.GetType().Name}");
            }
            catch (AssertionException e)
            {
                Assert.Fail($"Failed: {e.Message} {PrintFailureBytes(entry.BinaryData, serializedBytes)}");
            }


            for (int i = 0; i < entry.BinaryData.Length; i++)
            {
                Assert.AreEqual(entry.BinaryData[i], serializedBytes[i], $"Mismatched byte value at Index: {i} on OpCode: {entry.OpCode} Type: {payload.GetType().Name}");
            }
        }
Exemple #8
0
        public static void Test_Can_Deserialize_SeperatedCollection_Type()
        {
            Assert.Warn("TODO You must fix and reimplement seperated collection. It's not working fully as intended.");
            return;

            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestSeperatedCollection>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestSeperatedCollection("Hello meep56!", 123456, new[] { 55523, 90, 2445, 63432, 6969 }));
            TestSeperatedCollection deserialized = serializer.Deserialize <TestSeperatedCollection>(bytes);

            //assert
            Assert.NotNull(deserialized);
            Assert.NotNull(deserialized.IntsChars);

            Assert.AreEqual(5, deserialized.Size, "Expected the size to be the original collection size");
            Assert.AreEqual(5, deserialized.IntsChars.Length, $"Expected the length of the collection to be the original length");

            Assert.AreEqual("Hello meep56!", deserialized.TestString);
            Assert.AreEqual(123456, deserialized.AnotherValue);
        }
Exemple #9
0
        public void Test_Can_Serialize_Type_With_Complex_Array_Ignored_And_SendSize_Array_Succedding(int[] intArray)
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestComplexOptionalFieldWithDisable>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestComplexOptionalFieldWithDisable(intArray));
            TestComplexOptionalFieldWithDisable deserializerData = serializer.Deserialize <TestComplexOptionalFieldWithDisable>(bytes);

            //assert
            Assert.NotNull(bytes);
            Assert.True(bytes.Length != 0);

            //Check it's sizeof the element * length + the sendsize
            Assert.True(bytes.Length == intArray.Length * sizeof(int) + sizeof(int));

            Assert.NotNull(deserializerData);

            for (int i = 0; i < intArray.Length; i++)
            {
                Assert.AreEqual(intArray[i], deserializerData.TestInts[i]);
            }
        }
Exemple #10
0
        public static byte[] MemoryCompress(object obj, AcedCompressionLevel level)
        {
            byte[]       objs     = SerializerService.Serialize(obj);
            AcedDeflator instance = new AcedDeflator();

            byte[] bytes = instance.Compress(objs, 0, objs.Length, level, 0, 0);
            return(bytes);
        }
        public static void Test_Can_Deserialize_Complex_Compressed_Class()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestComplexTypeWithCompressedComplex>();
            serializer.RegisterType <TestComplexType>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestComplexTypeWithCompressedComplex(new TestComplexType(5, 50)));
            TestComplexTypeWithCompressedComplex obj = serializer.Deserialize <TestComplexTypeWithCompressedComplex>(bytes);

            byte[] justTestComplexBytes = serializer.Serialize(new TestComplexType(65, 50));

            //assert
            Assert.True(bytes.Length < 40 * sizeof(int));             //might be longer with header/footer
            Assert.AreEqual(50, obj.CompressedComplex.testValues.Length);
        }
Exemple #12
0
        public void RemoveKategori(Kategori Kategori)
        {
            var kategori          = Kategori;
            var serializerService = new SerializerService();
            var jsonFilename      = "kategori.json";
            var kategoriLista     = serializerService.Deserialize(jsonFilename);

            kategoriLista.Remove(kategori);
            serializerService.Serialize(jsonFilename, kategoriLista);
        }
Exemple #13
0
        public static void Save()
        {
            if (Instance.Current == null)
            {
                return;
            }

            string json = SerializerService.Serialize(Instance.Current);

            File.WriteAllText(filePath, json);
        }
        public static void Test_Can_Serialize_Readonly_Property()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestWithReadonlyProperty>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestWithReadonlyProperty(5));
        }
        async Task <SendResult> IPeerPayloadSendService <GameClientPacketPayload> .SendMessageImmediately <TPayloadType>(TPayloadType payload, DeliveryMethod method = DeliveryMethod.ReliableOrdered)
        {
            byte[] packet = SerializerService.Serialize(payload);

            ((short)packet.Length).Reinterpret(PacketBuffer, 0);

            await Client.socket.write(2, PacketBuffer);

            await Client.socket.write(packet.Length, packet);

            return(SendResult.Sent);
        }
Exemple #16
0
        public static void Test_String_Serializer_Serializes()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.Compile();

            //act
            string value = serializer.Deserialize <string>(serializer.Serialize("Hello!"));

            //assert
            Assert.AreEqual(value, "Hello!");
        }
Exemple #17
0
		public void Test_Can_Serializer_ReadToEnd_String_Type()
		{
			//arrange
			SerializerService serializer = new SerializerService();
			serializer.RegisterType<ReadToEndCustomClassType>();
			serializer.Compile();

			//act
			byte[] bytes = serializer.Serialize(new ReadToEndCustomClassType(5, TestStrings.Select(t => new TestReadToEndCustomClass(t, 5)).ToArray()));

			Assert.NotNull(bytes);
			Assert.IsNotEmpty(bytes);
			Assert.True(bytes.Length > 4);
		}
Exemple #18
0
        public static void Test_Can_Serializer_SeperatedCollectionThroughInternal_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestSeperatedCollectionThroughInternal>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestSeperatedCollectionThroughInternal("Hello meep!", 55, new[] { 55523, 90, 2445, 63432 }, 55));

            Assert.NotNull(bytes);
            Assert.IsNotEmpty(bytes);
        }
        public static void Test_Uf16_UsesNullTerminator_When_Not_Using_DontTerminate(string testString)
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <UTF8StringTestWithTerminator>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new UTF8StringTestWithTerminator(testString));

            Assert.AreEqual(8 + Encoding.UTF8.GetBytes(testString).Length + NULL_TERMINATOR_SIZE, bytes.Length);
            Assert.AreEqual(0, bytes.Last(), "Last byte was not null terminator");
        }
Exemple #20
0
        public static void Test_EnumStringUTF16_Produces_Expected_Byte_Size()
        {
            //arrange
            SerializerService service = new SerializerService();

            service.RegisterType <KnownSizeEnumStringTestUTF16>();
            service.Compile();

            //act
            byte[] bytes = service.Serialize(new KnownSizeEnumStringTestUTF16(TestStringEnum.Hello));

            //using KnownSize won't null terminate extend
            Assert.AreEqual(5 * 2, bytes.Length);
            Assert.AreEqual(TestStringEnum.Hello.ToString(), Encoding.Unicode.GetString(bytes));
        }
        public static void Test_Uf16_UsesNullTerminator_When_Not_Using_DontTerminate(string testString)
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <Utf16StringTestWithTerminator>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new Utf16StringTestWithTerminator(testString));

            Assert.AreEqual(8 + testString.Length * 2 + 2, bytes.Length);
            Assert.AreEqual(0, bytes.Last());
            Assert.AreEqual(0, bytes.Reverse().Skip(1).First());
        }
        public void Test_Can_Serialize_Subcommand60Payload()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <Sub60MovingFastPositionSetCommand>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new Sub60MovingFastPositionSetCommand(5, new Vector2 <float>(2, 5)));

            //assert
            Assert.NotNull(bytes);
            Assert.True(bytes.Length != 0);
        }
        public void Test_Can_Serializer_ReadToEnd_String_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <ReadToEndStringType>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new ReadToEndStringType(5, TestStrings));

            Assert.NotNull(bytes);
            Assert.IsNotEmpty(bytes);
            Assert.True(bytes.Length > 4);
        }
        public static void Test_DontWrite_Doesnt_Write_Values()
        {
            //arrange
            SerializerService service = new SerializerService();

            service.RegisterType <TestClassDontWriteField>();
            service.Compile();

            //act
            byte[] bytes = service.Serialize(new TestClassDontWriteField(5));


            //assert
            Assert.IsEmpty(bytes);
        }
        public static void Test_Can_Serialize_Compression_Marked_Class()
        {
            //arrange
            int[]             values     = new int[] { 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 };
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestInt32ArrayCompression>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestInt32ArrayCompression(values));

            //assert
            Assert.NotNull(bytes);
            Assert.IsTrue(bytes.Length < ((values.Length - 1) * sizeof(int)));
        }
Exemple #26
0
        public static void Test_Can_Serialize_To_String_With_Only_Null_Terminator()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestOnlyNullTerminatorString>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestOnlyNullTerminatorString(""));

            //assert
            Assert.NotNull(bytes, "bytes array was null.");
            Assert.True(bytes.Length == 1);
            Assert.True(bytes[0] == 0);
        }
Exemple #27
0
        public static void Test_Seperated_Collection_Size_Does_Not_Extend_TypeSize_For_Unwritten_Members()
        {
            Assert.Warn("TODO You must fix and reimplement seperated collection. It's not working fully as intended.");
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestSeperatedCollectionSerializedSizeShouldBeZero>();
            serializer.Compile();
            TestSeperatedCollectionSerializedSizeShouldBeZero testValue = new TestSeperatedCollectionSerializedSizeShouldBeZero();

            //act
            byte[] bytes = serializer.Serialize(testValue);

            //assert
            Assert.AreEqual(0, bytes.Length, "Should not serializer any data.");
        }
        public static void Test_Can_Deserialize_Readonly_Property()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestWithReadonlyProperty>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestWithReadonlyProperty(5));
            TestWithReadonlyProperty obj = serializer.Deserialize <TestWithReadonlyProperty>(bytes);

            //assert
            Assert.NotNull(obj);
            Assert.AreEqual(5, obj.i);
        }
Exemple #29
0
        public static void Test_EnumString_Produces_Expected_Byte_Size()
        {
            //arrange
            SerializerService service = new SerializerService();

            service.RegisterType <KnownSizeEnumStringTest>();
            service.Compile();

            //act
            byte[] bytes = service.Serialize(new KnownSizeEnumStringTest(TestStringEnum.Hello));

            //using KnownSize won't null terminate extend
            Assert.AreEqual(5, bytes.Length);
            Assert.True(bytes[bytes.Length - 1] != 0);
            Assert.True(bytes[bytes.Length - 2] != 0);
        }
Exemple #30
0
        public static void Test_String_Serializer_Can_Serialize_Empty_String()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.Compile();

            //act
            string value = serializer.Deserialize <string>(serializer.Serialize(""));

            //Change was made here that makes null strings empty strings
            //This seems preferable and easier to deal with. Nullrefs are bad
            //and also serializing null is harder than serializing empty
            //this is overall less error prone.
            //assert
            Assert.NotNull(value);
        }