Beispiel #1
0
        public void T03_CyclicSelfReferences()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new C4();
                dIn.FC4 = dIn;

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (C4)s.Deserialize(ms);

                Aver.IsTrue(object.ReferenceEquals(dOut, dOut.FC4));
                Aver.IsTrue(object.ReferenceEquals(dOut.FC4, dOut.FC4.FC4));
            }
        }
Beispiel #2
0
        public void T3_Batch_CSUM_Mismatch()
        {
            using (var ms = new MemoryStream())
            {
                var s1 = new SlimSerializer(new Type[] { typeof(A1) });
                s1.TypeMode = TypeRegistryMode.Batch;
                var o1 = new A1 {
                    I1 = 12
                };

                s1.Serialize(ms, o1);
                ms.Seek(0, SeekOrigin.Begin);

                var s2 = new SlimSerializer(new Type[] { typeof(A2) });
                s2.TypeMode = TypeRegistryMode.Batch;
                var o2 = (A1)s2.Deserialize(ms);
            }
        }
Beispiel #3
0
        private void SerializeNFXSlim()
        {
            var s          = new MemoryStream();
            var serializer = new SlimSerializer(SlimFormat.Instance);

            serializer.Serialize(s, Value);
            var bytes = s.ToArray();

            RunTest("NFX Slim Serializer", () =>
            {
                var stream = new MemoryStream();
                serializer.Serialize(stream, Value);
            }, () =>
            {
                s.Position = 0;
                serializer.Deserialize(s);
            }, bytes.Length);
        }
Beispiel #4
0
        public void T04()
        {
          using(var ms = new MemoryStream())
          {           
            var s = new SlimSerializer(SlimFormat.Instance);
            
            var root = new ObjectA
            {
              AField = 2345,
              Another1 = new ObjectA{ AField = 7892},
              Another2 = new ObjectB{ AField = 5678, BField = -12}
            };
             
            s.Serialize(ms, root);

            ms.Position = 0;


            var deser = s.Deserialize(ms) as ObjectA;

            Assert.IsNotNull( deser );
            Assert.IsTrue( deser.GetType() == typeof(ObjectA));
            Assert.AreEqual(2345,  deser.AField );

            Assert.IsNotNull( deser.Another1 );
            Assert.AreEqual(7892,  deser.Another1.AField );
           
            Assert.IsNotNull( deser.Another2 );
            Assert.AreEqual(5678,  deser.Another2.AField );

            Assert.IsTrue( deser.Another2.GetType() == typeof(ObjectB));
            Assert.AreEqual(-12,  ((ObjectB)deser.Another2).BField );

            Assert.IsNull( deser.Another3 );
            Assert.IsNull( deser.Another4 );
            Assert.IsNull( deser.Another5 );
            Assert.IsNull( deser.Another6 );
            Assert.IsNull( deser.Another7 );
            Assert.IsNull( deser.Another8 );
            Assert.IsNull( deser.Another9 );
            Assert.IsNull( deser.Another10 );

          }
        }
Beispiel #5
0
        public void Circular2()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new[] {
                    new cA {
                        A = 1, B = 100
                    },
                    new cB {
                        A = 2, B = 200
                    },
                    new cB {
                        A = 3, B = 300
                    },
                };

                dIn[0].Child = dIn[2];
                dIn[1].Child = dIn[0];
                dIn[2].Child = dIn[1]; //circular reference


                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (cA[])s.Deserialize(ms);

                Aver.AreEqual(3, dOut.Length);
                Aver.IsTrue(dOut[0] is cA);
                Aver.IsTrue(dOut[1] is cB);
                Aver.IsTrue(dOut[2] is cB);

                Aver.AreEqual(1, dOut[0].A);
                Aver.AreEqual(100, dOut[0].B);

                Aver.AreEqual(2, dOut[1].A);
                Aver.AreEqual(200, dOut[1].B);

                Aver.AreEqual(3, dOut[2].A);
                Aver.AreEqual(300, dOut[2].B);
            }
        }
Beispiel #6
0
        private void Initialize()
        {
            if (!base.JustInitialized)
            {
                return;
            }
            var typeList = new List <Type> {
                _primaryType
            };

            if (_secondaryTypes != null)
            {
                typeList.AddRange(_secondaryTypes);
            }
            var treg = new TypeRegistry(typeList, TypeRegistry.BoxedCommonNullableTypes, TypeRegistry.BoxedCommonTypes);

            _serializer     = new SlimSerializer(treg);
            JustInitialized = false;
        }
Beispiel #7
0
        public void T13_Struct1_PilePointer()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var s1 = new NFX.ApplicationModel.Pile.PilePointer(10, 231, 223421);

                s.Serialize(ms, s1);
                ms.Seek(0, SeekOrigin.Begin);

                var s2 = (NFX.ApplicationModel.Pile.PilePointer)s.Deserialize(ms);

                Console.WriteLine(NFX.Serialization.JSON.JSONWriter.Write(s1));
                Console.WriteLine(NFX.Serialization.JSON.JSONWriter.Write(s2));

                Assert.IsTrue(s1 == s2);
            }
        }
Beispiel #8
0
        public void T13_Struct1_PilePointer()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var s1 = new Azos.Pile.PilePointer(10, 231, 223421);

                s.Serialize(ms, s1);
                ms.Seek(0, SeekOrigin.Begin);

                var s2 = (Azos.Pile.PilePointer)s.Deserialize(ms);

                Azos.Serialization.JSON.JsonWriter.Write(s1).See();
                Azos.Serialization.JSON.JsonWriter.Write(s2).See();

                Aver.IsTrue(s1 == s2);
            }
        }
Beispiel #9
0
        public void T6_BatchParcelMismatch_WriteMany()
        {
            using (var ms = new MemoryStream())
            {
                var s1 = new SlimSerializer
                {
                    TypeMode = TypeRegistryMode.Batch
                };
                var o1a = new A1 {
                    I1 = 12
                };
                var o1b = new A2 {
                    I2 = 13
                };
                var o1c = new A1 {
                    I1 = 14
                };
                var o1d = new A1 {
                    I1 = 15
                };
                var o1e = new A1 {
                    I1 = 16
                };

                s1.Serialize(ms, o1a); Aver.IsTrue(s1.BatchTypesAdded);
                s1.Serialize(ms, o1b); Aver.IsTrue(s1.BatchTypesAdded);
                s1.Serialize(ms, o1c); Aver.IsFalse(s1.BatchTypesAdded);
                s1.Serialize(ms, o1d); Aver.IsFalse(s1.BatchTypesAdded);
                s1.Serialize(ms, o1e); Aver.IsFalse(s1.BatchTypesAdded);
                ms.Seek(0, SeekOrigin.Begin);

                var buf = ms.GetBuffer();
                buf.ToDumpString(DumpFormat.Printable, 0, (int)ms.Length).See();

                var s2 = new SlimSerializer
                {
                    TypeMode = TypeRegistryMode.PerCall//MISMATCH!!!
                };
                var o2a = (A1)s2.Deserialize(ms);
                var o2b = (A2)s2.Deserialize(ms);//exception
            }
        }
Beispiel #10
0
        public void T07_CovariantArrays()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new C10()
                {
                    FIC9s = new IC9[] { new C9_1(), new C9() }
                };

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (C10)s.Deserialize(ms);

                Aver.IsTrue(dOut.FIC9s[0] is C9_1);
                Aver.IsTrue(dOut.FIC9s[1] is C9);
            }
        }
Beispiel #11
0
        public void T10_CovariantStructInterfaceArrays()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new C12()
                {
                    FIC12s = new IC12[] { new C12_2(), new C12_1() }
                };

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (C12)s.Deserialize(ms);

                Assert.IsInstanceOf <C12_2>(dOut.FIC12s[0]);
                Assert.IsInstanceOf <C12_1>(dOut.FIC12s[1]);
            }
        }
Beispiel #12
0
        public void T1000_CustomSerializableWithNesting()
        {
            using (var ms = new MemoryStream())
            {
                var s  = new SlimSerializer();
                var o1 = new CustomSer {
                    Data = new object[] { 1, 2, true, "ok" }
                };
                s.Serialize(ms, o1);

                ms.Position = 0;

                var o2 = s.Deserialize(ms) as CustomSer;

                Assert.IsNotNull(o2);

                Assert.AreEqual(4, ((object[])o2.Data).Length);
                Assert.AreEqual("ok", ((object[])o2.Data)[3]);
            }
        }
Beispiel #13
0
        public void T06_CovariantCyclicArrays()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new C8();
                dIn.FObjs = new object[] { null, (object)dIn, (IC8)dIn, (C8_1)dIn, dIn };

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (C8)s.Deserialize(ms);

                Assert.IsNull(dOut.FObjs[0]);
                Assert.AreSame(dOut, dOut.FObjs[1]);
                Assert.AreSame(dOut, dOut.FObjs[2]);
                Assert.AreSame(dOut, dOut.FObjs[3]);
            }
        }
Beispiel #14
0
        public void T14_Struct2()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var s1 = new MyStructFields {
                    X = 10, Y = 15, F = true
                };

                s.Serialize(ms, s1);
                ms.Seek(0, SeekOrigin.Begin);

                var s2 = (MyStructFields)s.Deserialize(ms);

                Aver.AreEqual(s1.X, s2.X);
                Aver.AreEqual(s1.Y, s2.Y);
                Aver.AreEqual(s1.F, s2.F);
            }
        }
Beispiel #15
0
        public void T07_CovariantArrays()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new C10()
                {
                    FIC9s = new IC9[] { new C9_1(), new C9() }
                };

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (C10)s.Deserialize(ms);

                Assert.IsInstanceOf <C9_1>(dOut.FIC9s[0]);
                Assert.IsInstanceOf <C9>(dOut.FIC9s[1]);
            }
        }
Beispiel #16
0
        public void T7_CountMismatchResetBatch_WriteMany()
        {
            using (var ms = new MemoryStream())
            {
                var s1 = new SlimSerializer();
                s1.TypeMode = TypeRegistryMode.Batch;
                var o1a = new A1 {
                    I1 = 12
                };
                var o1b = new A2 {
                    I2 = 13
                };
                var o1c = new A1 {
                    I1 = 14
                };
                var o1d = new A1 {
                    I1 = 15
                };
                var o1e = new A1 {
                    I1 = 16
                };

                s1.Serialize(ms, o1a);  Assert.IsTrue(s1.BatchTypesAdded);
                s1.Serialize(ms, o1b);  Assert.IsTrue(s1.BatchTypesAdded);
                s1.Serialize(ms, o1c);  Assert.IsFalse(s1.BatchTypesAdded);
                s1.Serialize(ms, o1d);  Assert.IsFalse(s1.BatchTypesAdded);
                s1.Serialize(ms, o1e);  Assert.IsFalse(s1.BatchTypesAdded);
                ms.Seek(0, SeekOrigin.Begin);

                var buf = ms.GetBuffer();
                Console.WriteLine(buf.ToDumpString(DumpFormat.Printable, 0, (int)ms.Length));

                var s2 = new SlimSerializer();
                s2.TypeMode = TypeRegistryMode.Batch;
                var o2a = (A1)s2.Deserialize(ms); Assert.IsTrue(s2.BatchTypesAdded);
                Assert.AreEqual(12, o2a.I1);

                s2.ResetCallBatch();
                var o2b = (A2)s2.Deserialize(ms); //Exception
            }
        }
Beispiel #17
0
        public void NLS_Root()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new NLSMap("eng{n='name' d='description'} rus{n='имя' d='описание'}".AsLaconicConfig());

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (NLSMap)s.Deserialize(ms);

                Aver.AreEqual(2, dOut.Count);
                Aver.AreEqual("name", dOut.Get(NLSMap.GetParts.Name, "eng"));
                Aver.AreEqual("имя", dOut.Get(NLSMap.GetParts.Name, "rus"));

                Aver.AreEqual("description", dOut.Get(NLSMap.GetParts.Description, "eng"));
                Aver.AreEqual("описание", dOut.Get(NLSMap.GetParts.Description, "rus"));
            }
        }
Beispiel #18
0
        public void T04_CyclicReference()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var c6  = new C6();
                var dIn = new C5()
                {
                    FC6 = c6
                };
                c6.FC5 = dIn;

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (C5)s.Deserialize(ms);

                Assert.AreSame(dOut, dOut.FC6.FC5);
            }
        }
Beispiel #19
0
        public void T15_Struct3()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var s1 = new MyStructWithReadonlyField(10, 15, true);

                s.Serialize(ms, s1);
                ms.Seek(0, SeekOrigin.Begin);

                var s2 = (MyStructWithReadonlyField)s.Deserialize(ms);

                Azos.Serialization.JSON.JsonWriter.Write(s1).See();
                Azos.Serialization.JSON.JsonWriter.Write(s2).See();

                Aver.AreEqual(s1.X, s2.X);
                Aver.AreEqual(s1.Y, s2.Y);
                Aver.AreEqual(s1.F, s2.F);
            }
        }
Beispiel #20
0
        public void T3100_Dictionary_TYPE_Int_Field()
        {
            using (var ms = new MemoryStream())
            {
                var s  = new SlimSerializer();
                var d1 = new dictTypeClass {
                    Data   = new Dictionary <Type, int>(0xff),
                    ADummy = new List <Type>(0xff)
                };

                d1.Data.Add(typeof(List <S3>), 1);
                d1.Data.Add(typeof(S3[]), 20);
                d1.Data.Add(typeof(Tuple <string, S3>), 90);

                d1.ADummy.Add(typeof(List <S3>));
                d1.ADummy.Add(typeof(S3[]));
                d1.ADummy.Add(typeof(Tuple <string, S3>));


                s.Serialize(ms, d1);

                ms.Position = 0;

                var d2 = s.Deserialize(ms) as dictTypeClass;

                Assert.IsNotNull(d2);
                Assert.IsNotNull(d2.Data);
                Assert.IsNotNull(d2.ADummy);

                Assert.AreEqual(3, d2.Data.Count);
                Assert.AreEqual(1, d2.Data[typeof(List <S3>)]);
                Assert.AreEqual(20, d2.Data[typeof(S3[])]);
                Assert.AreEqual(90, d2.Data[typeof(Tuple <string, S3>)]);

                Assert.AreEqual(3, d2.ADummy.Count);
                Assert.AreEqual(typeof(List <S3>), d2.ADummy[0]);
                Assert.AreEqual(typeof(S3[]), d2.ADummy[1]);
                Assert.AreEqual(typeof(Tuple <string, S3>), d2.ADummy[2]);
            }
        }
Beispiel #21
0
        public void SerializeRecordUsingSlim()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer(SlimFormat.Instance);

                var r1 = makeValidPostedPerson();

                s.Serialize(ms, r1);
                ms.Seek(0, SeekOrigin.Begin);

                var r2 = (PersonRecord)s.Deserialize(ms);


                Assert.AreEqual(r1.State, r2.State);
                Assert.AreEqual(r1.fldName, r2.fldName);
                Assert.AreEqual(r1.fldDOB, r2.fldDOB);
                Assert.AreEqual(r1.fldScore, r2.fldScore);
                Assert.AreEqual(r1.Validated, r2.Validated);
                Assert.AreEqual(r1.Valid, r2.Valid);
            }
        }
Beispiel #22
0
        public void TZ9999_StringInVariousLanguages()
        {
            using (var ms = new MemoryStream())
            {
                var s1 = new SlimSerializer();
                var o1 = new A3 {
                    Text = "Hello 久有归天愿,Աեցեհի, Не менее 100 советских самолетов поднялись в воздух, asağıda yağız yer yaratıldıkta. I Agree!"
                };

                Console.WriteLine(o1.Text);

                s1.Serialize(ms, o1);
                ms.Seek(0, SeekOrigin.Begin);

                var s2 = new SlimSerializer();
                var o2 = (A3)s2.Deserialize(ms);

                Console.WriteLine(o2.Text);

                Assert.AreEqual(o1.Text, o2.Text);
            }
        }
Beispiel #23
0
        public void ASCII8Nullable_Root()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                Atom?dIn = Atom.Encode("ABC123");

                s.Serialize(ms, (Atom?)null);
                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (Atom?)s.Deserialize(ms);

                Aver.IsFalse(dOut.HasValue);
                dOut = (Atom?)s.Deserialize(ms);

                Aver.IsTrue(dOut.HasValue);
                Aver.AreEqual(dOut, dIn);
                Aver.AreEqual("ABC123", dOut.Value.Value);
            }
        }
Beispiel #24
0
        //20140206 DKh
        private void clientThreadSpin(object c)   //executes in its own thread
        {
            var client   = (TcpClient)c;
            var remoteIP = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();  //DO NOT NEED POrt as it creates 1000s instrumentation messages

            if (Binding.InstrumentServerTransportStat)
            {
                Instrumentation.ClientConnectedEvent.Happened(remoteIP);
            }

            try
            {
                Interlocked.Increment(ref m_OpenChannels);
                try
                {
                    var serializer = new SlimSerializer(SyncBinding.KNOWN_SERIALIZER_TYPES);
                    serializer.TypeMode = TypeRegistryMode.Batch;
                    clientThreadSpinBody(client, serializer);
                }
                finally
                {
                    Interlocked.Decrement(ref m_OpenChannels);
                }
            }
            catch (Exception error)
            {
                Binding.WriteLog(
                    LogSrc.Server,
                    Log.MessageType.Error,
                    StringConsts.GLUE_CLIENT_THREAD_ERROR + error.ToMessageWithType(),
                    from: "SyncServerTransport.clientThreadSpin",
                    exception: error);
            }

            if (Binding.InstrumentServerTransportStat)
            {
                Instrumentation.ClientDisconnectedEvent.Happened(remoteIP);
            }
        }
Beispiel #25
0
        public void StringMap_WideCharsLong(int cnt)
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var original1 = new string('久', cnt);
                var original2 = "就是巴尼宝贝儿吧,俺说。有什么怪事儿或是好事儿吗? когда американские авианосцы 'Уинсон' и 'Мидуэй' приблизились 지구상의 3대 we have solved the problem";

                var dIn = new stringMapCls
                {
                    Map1 = new StringMap(false)
                    {
                        { "a", original1 },
                        { "b", original2 }
                    }
                };

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (stringMapCls)s.Deserialize(ms);

                Aver.IsNotNull(dOut);
                Aver.IsNotNull(dOut.Map1);
                Aver.IsNull(dOut.Map2);

                Aver.IsFalse(dOut.Map1.CaseSensitive);
                Aver.AreEqual(2, dOut.Map1.Count);


                Aver.AreEqual(original1, dOut.Map1["a"]);
                Aver.AreEqual(original1, dOut.Map1["A"]);

                Aver.AreEqual(original2, dOut.Map1["b"]);
                Aver.AreEqual(original2, dOut.Map1["B"]);
            }
        }
Beispiel #26
0
        public void FullLifecycle_NotWrapped()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };

            var parcel = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            Assert.AreEqual(ParcelState.Creating, parcel.State);
            Assert.AreEqual(true, parcel.PayloadUnwrapped);
            parcel.Seal(FakeNOPBank.Instance);

            var ser = new SlimSerializer(Parcel.STANDARD_KNOWN_SERIALIZER_TYPES);

            var ms = new MemoryStream();

            ser.Serialize(ms, parcel);
            ms.Position = 0;
            var parcel2 = ser.Deserialize(ms) as PeopleNamesParcel_NotWrapped;

            Assert.IsNotNull(parcel2);

            Assert.IsFalse(parcel2.HasWrappedPayload);      //mode unwrapped
            parcel2.Open();                                 // no effect
            Assert.IsFalse(parcel2.HasWrappedPayload);      //mode unwrapped

            parcel2.Payload[1] = "Boyarskiy";
            parcel2.Seal(FakeNOPBank.Instance);

            ms.Position = 0;
            ser.Serialize(ms, parcel2);
            ms.Position = 0;
            var parcel3 = ser.Deserialize(ms) as PeopleNamesParcel_NotWrapped;

            Assert.IsTrue(new List <string> {
                "Kozloff", "Boyarskiy", "Aroyan", "Gurevich"
            }.SequenceEqual(parcel3.Payload));
        }
Beispiel #27
0
        /// <summary>
        /// Called only if this parcel is ParcelPayloadWrappingMode.Wrapped.
        /// Override to perform custom content deserialization, i.e. when particular store may use special format for data marshalling.
        /// Base implementation understands  Parcel.STANDARD_SLIM_PAYLOAD_FORMAT and Parcel.STANDARD_PODSLIM_PAYLOAD_FORMAT formats
        /// </summary>
        protected virtual object DoUnwrapPayload()
        {
            var wrapped = m_PayloadData as byte[];

            if (wrapped == null)
            {
                return(null);
            }


            ISerializer serializer = null;

            if (m_WrappedPayloadFormat == STANDARD_SLIM_PAYLOAD_FORMAT)
            {
                serializer = new SlimSerializer(STANDARD_KNOWN_SERIALIZER_TYPES);
            }
            else if (m_WrappedPayloadFormat == STANDARD_PODSLIM_PAYLOAD_FORMAT)
            {
                serializer = new PODSlimSerializer();
            }
            else
            {
                throw new DistributedDataParcelSerializationException(
                          StringConsts.DISTRIBUTED_DATA_PARCEL_UNWRAP_FORMAT_ERROR.Args(GetType().FullName, m_WrappedPayloadFormat ?? StringConsts.NULL_STRING));
            }

            try
            {
                using (var ms = new System.IO.MemoryStream(wrapped))
                    return(serializer.Deserialize(ms));
            }
            catch (Exception error)
            {
                throw new DistributedDataParcelSerializationException(
                          StringConsts.DISTRIBUTED_DATA_PARCEL_UNWRAP_DESER_ERROR.Args(GetType().FullName, error.ToMessageWithType())
                          , error);
            }
        }
Beispiel #28
0
        public void NLS_Array()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new NLSMap[] {
                    new NLSMap("eng{n='name' d='description'} rus{n='имя' d='описание'}".AsLaconicConfig()),
                    new NLSMap("eng{n='color' d='of product'} rus{n='zvet' d='producta'}".AsLaconicConfig()),
                    new NLSMap("eng{n='size' d='of item'} rus{n='razmer' d='tovara'}".AsLaconicConfig())
                };


                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (NLSMap[])s.Deserialize(ms);

                Aver.IsNotNull(dOut);

                Aver.AreEqual(3, dOut.Length);

                Aver.AreEqual("name", dOut[0].Get(NLSMap.GetParts.Name, "eng"));
                Aver.AreEqual("имя", dOut[0].Get(NLSMap.GetParts.Name, "rus"));
                Aver.AreEqual("description", dOut[0].Get(NLSMap.GetParts.Description, "eng"));
                Aver.AreEqual("описание", dOut[0].Get(NLSMap.GetParts.Description, "rus"));

                Aver.AreEqual("color", dOut[1].Get(NLSMap.GetParts.Name, "eng"));
                Aver.AreEqual("zvet", dOut[1].Get(NLSMap.GetParts.Name, "rus"));
                Aver.AreEqual("of product", dOut[1].Get(NLSMap.GetParts.Description, "eng"));
                Aver.AreEqual("producta", dOut[1].Get(NLSMap.GetParts.Description, "rus"));

                Aver.AreEqual("size", dOut[2].Get(NLSMap.GetParts.Name, "eng"));
                Aver.AreEqual("razmer", dOut[2].Get(NLSMap.GetParts.Name, "rus"));
                Aver.AreEqual("of item", dOut[2].Get(NLSMap.GetParts.Description, "eng"));
                Aver.AreEqual("tovara", dOut[2].Get(NLSMap.GetParts.Description, "rus"));
            }
        }
Beispiel #29
0
        public void Create_Seal_SerializeDeserialize_Read_NotWrapped()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };

            var parcel = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            Assert.AreEqual(ParcelState.Creating, parcel.State);
            Assert.AreEqual(true, parcel.PayloadUnwrapped);
            parcel.Seal(FakeNOPBank.Instance);



            var ser = new SlimSerializer(Parcel.STANDARD_KNOWN_SERIALIZER_TYPES);

            var ms = new MemoryStream();

            ser.Serialize(ms, parcel);
            ms.Position = 0;
            var parcel2 = ser.Deserialize(ms) as PeopleNamesParcel_NotWrapped;

            Assert.IsNotNull(parcel2);
            Assert.IsFalse(parcel2.PayloadUnwrapped);
            Assert.IsFalse(parcel2.HasWrappedPayload);      //mode unwrapped
            var payload2 = parcel2.Payload;

            Assert.IsNotNull(payload2);
            Assert.IsTrue(parcel2.PayloadUnwrapped);

            Assert.IsFalse(parcel2.HasWrappedPayload); //mode unwrapped
            parcel2.ForgetWrappedPayloadCopy();        //no effect in wnwrapped mode
            Assert.IsFalse(parcel2.HasWrappedPayload);


            Assert.AreEqual(payload2.Count, names.Count);
            Assert.IsTrue(payload2.SequenceEqual(names));
        }
Beispiel #30
0
        public IActionResult BeginDB()
        {
            if (string.IsNullOrEmpty(ObjName))
            {
                return(StatusCode(404));
            }
            if (TryGetDB(out var olddb))
            {
                return(Ok("ok"));
            }
            var fname = $"{Program.DBFolder}/ZhiHuExtDB-{ObjName}.json";

            using (var reader = new JsonTextReader(new StreamReader(System.IO.File.OpenRead(fname))))
            {
                try
                {
                    var db = SlimSerializer.Deserialize <StandardDB>(reader);
                    LOG.LogInformation("json loaded");
                    var banusrcnt = db.users.Where(usr => usr.status_ != UserStatus.empty).Count();
                    LOG.LogInformation($"bans:{banusrcnt}\tspams:{db.spams.Count}\tusers:{db.users.Count}\tzans:{db.zans.Count}\tzanarts:{db.zanarts.Count}");
                    LOG.LogInformation($"questions:{db.questions.Count}\tanswers:{db.answers.Count}\tarticles:{db.articles.Count}\tdetails:{db.details.Count}");
                    db.Slim(1);
                    GC.Collect(2, GCCollectionMode.Optimized, false, true);
                    var cache = BuildCache(db);
                    if (!NewCache(cache) || !NewDB(db))
                    {
                        return(StatusCode(500));
                    }
                }
                catch (Exception e)
                {
                    LOG.LogError(e.Message, e.StackTrace);
                    return(StatusCode(500));
                }
            }
            GC.Collect(2, GCCollectionMode.Optimized, false, true);
            return(Ok("ok"));
        }