コード例 #1
0
 protected override void TestFixtureSetUp()
 {
     base.TestFixtureSetUp();
     AbstractSerializer.RegisterKnownType(typeof(MyIdentity));
     AbstractSerializer.RegisterKnownType(typeof(MySerializationMessage <MyIdentity>));
     Xyperico.Agres.ProtoBuf.SerializerSetup.RegisterInheritance <Identity <TId>, MyIdentity>();
 }
コード例 #2
0
        public void WhenSerializingUnknownTypeItThrowsInvalidOperation()
        {
            AbstractSerializer.RegisterKnownType(typeof(object));

            AbstractSerializer s = new MySerializer();

            AssertThrows <InvalidOperationException>(() => s.Serialize(new { }));
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            AbstractSerializer.RegisterKnownType(typeof(UserCreatedEvent));

            // Create serializers after registering known types
            ISerializer[] Serializers =
            {
                new DataContractSerializer(),
                new ProtoBufSerializer(),
                new BsonNetSerializer(),
                new JsonNetSerializer()
            };

            foreach (Func <IAppendOnlyStore> aStoreBuilder in AppendOnlyStores)
            {
                foreach (ISerializer serializer in Serializers)
                {
                    UserId        id     = new UserId(1);
                    List <IEvent> events = new List <IEvent>()
                    {
                        new UserCreatedEvent(id, "John")
                    };

                    IAppendOnlyStore aStore = aStoreBuilder();
                    try
                    {
                        EventStoreDB eStore = new EventStoreDB(aStore, serializer);
                        eStore.Append(id, 0, events);

                        // Warm up various caches
                        for (int i = 0; i < 10; ++i)
                        {
                            EventStream s = eStore.Load(id);
                            eStore.Append(id, s.Version, events);
                        }

                        int      count = 0;
                        DateTime t1    = DateTime.Now;
                        do
                        {
                            id = new UserId(100 + count);
                            //EventStream s = eStore.Load(id);
                            eStore.Append(id, 0, new IEvent[] { new UserCreatedEvent(id, "John") });
                            ++count;
                        }while ((DateTime.Now - t1) < TimeSpan.FromMilliseconds(1000));

                        Console.WriteLine("{0} + {1}: {2}", aStore, serializer, count);
                    }
                    finally
                    {
                        aStore.Dispose();
                    }
                }
            }
        }
コード例 #4
0
        public static void Initialize()
        {
            Xyperico.Agres.ProtoBuf.SerializerSetup.RegisterInheritance <Identity <Guid>, UserAccountId>();

            var serializerTypes =
                typeof(UserAccountId).Assembly.GetTypes()
                .Where(t => typeof(Identity <>).IsAssignableFrom(t) || typeof(IMessage).IsAssignableFrom(t))
                .Where(t => !t.IsAbstract);

            AbstractSerializer.RegisterKnownTypes(serializerTypes);

            AbstractSerializer.RegisterKnownType(typeof(EMail));
            AbstractSerializer.RegisterKnownType(typeof(UserAccountId));
            AbstractSerializer.RegisterKnownType(typeof(UserAccountCreatedEvent));
            AbstractSerializer.RegisterKnownType(typeof(PasswordChangedEvent));
        }