Пример #1
0
        public static void Init(out XmlProtoSerializer xpsEvent, out XmlProtoSerializer xpsUpdate, out XmlProtoSerializer xpsCommand)
        {
            Serializer.PrepareSerializer <Event>();
            Serializer.PrepareSerializer <Update>();
            Serializer.PrepareSerializer <Command>();

            xpsEvent   = new XmlProtoSerializer(RuntimeTypeModel.Default, typeof(Event));
            xpsUpdate  = new XmlProtoSerializer(RuntimeTypeModel.Default, typeof(Update));
            xpsCommand = new XmlProtoSerializer(RuntimeTypeModel.Default, typeof(Command));
        }
        public void TestRoundTripNakedEnum()
        {
            var ser = new XmlProtoSerializer(RuntimeTypeModel.Default, typeof(Foo));
            var ms  = new MemoryStream();

            ser.WriteObject(ms, Foo.B);
            ms.Position = 0;
            var clone = (Foo)ser.ReadObject(ms);

            Assert.Equal(Foo.B, clone);
        }
Пример #3
0
        public Task QueueSendAsync <T>(T message)
        {
            // TODO: Serializer shouldn't be in here! (bad daniel, no scooby snacks for you).
            // TODO: ISerializer
            var xps = new XmlProtoSerializer(RuntimeTypeModel.Default, typeof(T));

            var bm = new BrokeredMessage(message, xps)
            {
                ContentType = typeof(T).FullName
            };

            return(_queueClient.SendAsync(bm));
        }
Пример #4
0
        public void TestRoundTripWrappedEnum()
        {
            var ser = new XmlProtoSerializer(RuntimeTypeModel.Default, typeof(FooWrapper));
            var ms  = new MemoryStream();

            ser.WriteObject(ms, new FooWrapper {
                Foo = Foo.B
            });
            ms.Position = 0;
            var clone = (FooWrapper)ser.ReadObject(ms);

            Assert.AreEqual(Foo.B, clone.Foo);
        }
Пример #5
0
        static object RoundTrip(object obj)
        {
            Assert.IsNotNull(obj, "obj");
            var model = RuntimeTypeModel.Create();
            var ser   = XmlProtoSerializer.TryCreate(model, obj.GetType());

            Assert.IsNotNull(ser, "ser");
            using (var ms = new MemoryStream())
            {
                ser.WriteObject(ms, obj);
                Debug.WriteLine(Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length));
                ms.Position = 0;
                object clone;
                using (var reader = XmlReader.Create(ms))
                {
                    Assert.IsTrue(ser.IsStartObject(reader));
                    clone = ser.ReadObject(reader);
                }
                Assert.IsNotNull(clone, "clone");
                Assert.AreNotSame(obj, clone);
                return(clone);
            }
        }