Exemplo n.º 1
0
 public void Test_CreateTable_WithFilter()
 {
     var table = new TypeAliasTable(new[] { GetAssembly() },
                                    t => t.Name.StartsWith("Alice") == false);
     Assert.AreEqual(null, table.GetType(1));
     Assert.AreEqual(typeof(BobClass), table.GetType(2));
 }
Exemplo n.º 2
0
        public void Test_CreateTable_WithFilter()
        {
            var table = new TypeAliasTable(new[] { GetAssembly() },
                                           t => t.Name.StartsWith("Alice") == false);

            Assert.AreEqual(null, table.GetType(1));
            Assert.AreEqual(typeof(BobClass), table.GetType(2));
        }
Exemplo n.º 3
0
 public void Test_CreateTable_WithCustomResolveAutoAlias()
 {
     var table = new TypeAliasTable(new[] { GetAssembly() },
                                    null,
                                    t => t.Name.Length);
     Assert.AreEqual(typeof(AliceClass), table.GetType(1));
     Assert.AreEqual(typeof(EveClass), table.GetType(8));
     Assert.AreEqual(null, table.GetType(483686294));
 }
Exemplo n.º 4
0
        public void Test_CreateTable_WithCustomResolveAutoAlias()
        {
            var table = new TypeAliasTable(new[] { GetAssembly() },
                                           null,
                                           t => t.Name.Length);

            Assert.AreEqual(typeof(AliceClass), table.GetType(1));
            Assert.AreEqual(typeof(EveClass), table.GetType(8));
            Assert.AreEqual(null, table.GetType(483686294));
        }
Exemplo n.º 5
0
        public TestZoneSet(TypeAliasTable typeTable, TypeModel typeModel)
        {
            ServerZone = new TestServerZone(EntityFactory.Default);
            ((EntityTimerProvider)ServerZone.TimerProvider).ActionScheduled = OnActionSchedule;

            ClientZones   = new TestClientZone[0];
            ClientZoneMap = new Dictionary <int, TestClientZone>();

            _typeTable = typeTable;
            _typeModel = typeModel;
        }
Exemplo n.º 6
0
        public static object ReadObject(BinaryReader reader, TypeAliasTable typeTable, TypeModel typeModel)
        {
            var length = reader.ReadInt32();

            if (length > 0)
            {
                var typeAlias = reader.ReadInt32();
                var type      = typeTable.GetType(typeAlias);
                var obj       = typeModel.Deserialize(reader.BaseStream, null, type, length - 4);
                return(obj);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 7
0
        public static TestZoneSet Build(int clientZoneCount)
        {
            var typeTable = new TypeAliasTable();

            var typeModel = TypeModel.Create();

            typeModel.Add(typeof(TrackablePocoTracker <ISpaceShipData>), false)
            .SetSurrogate(typeof(TrackableSpaceShipDataTrackerSurrogate));

            var zoneSet = new TestZoneSet(typeTable, typeModel);

            for (var i = 0; i < clientZoneCount; i++)
            {
                zoneSet.AddClient();
            }
            return(zoneSet);
        }
Exemplo n.º 8
0
        private static void Main(string[] args)
        {
            s_typeModel      = TypeModel.Create();
            s_typeAliasTable = new TypeAliasTable();

            // Serialize
            var writeStream = new MemoryStream();
            var obj1        = new AliceClass {
                Name = "Wonderland", Value = 100
            };

            Console.WriteLine("Before Serialize: {0}", obj1);
            Serialize(writeStream, obj1);
            var data = writeStream.ToArray();

            Console.WriteLine("DataSize: {0}", data.Length);

            // Deserialize
            var readStream = new MemoryStream(data);
            var obj2       = Deserialize(readStream, (int)readStream.Length);

            Console.WriteLine("After Serialize: {0}", obj2);
        }
Exemplo n.º 9
0
 public static void WriteObject(BinaryWriter writer, object obj, TypeAliasTable typeTable, TypeModel typeModel)
 {
     if (obj != null)
     {
         var pos = (int)writer.BaseStream.Position;
         writer.BaseStream.Seek(4, SeekOrigin.Current);
         var typeAlias = typeTable.GetAlias(obj.GetType());
         if (typeAlias == 0)
         {
             throw new ArgumentException("Type of object doesn't have alias. Type: " + obj.GetType().FullName);
         }
         writer.Write(typeAlias);
         typeModel.Serialize(writer.BaseStream, obj);
         var posEnd = (int)writer.BaseStream.Position;
         writer.Seek(pos, SeekOrigin.Begin);
         writer.Write((posEnd - pos) - 4);
         writer.Seek(posEnd, SeekOrigin.Begin);
     }
     else
     {
         writer.Write(0);
     }
 }
Exemplo n.º 10
0
 public void Test_CreateTable_WithCustomAssemblies()
 {
     var table = new TypeAliasTable(new[] { GetAssembly() });
     Assert.AreEqual(typeof(AliceClass), table.GetType(1));
 }
Exemplo n.º 11
0
 public Data(IMessageSerializer serializer, TypeAliasTable typeTable)
 {
     MessageSerializer = serializer;
     TypeTable         = typeTable;
 }
 public override TypeAliasTable GetTypeAliasTable()
 {
     return(_typeAliasTable ?? (_typeAliasTable = new TypeAliasTable()));
 }
Exemplo n.º 13
0
        private static void Main(string[] args)
        {
            var typeTable = new TypeAliasTable();

            var typeModel = TypeModel.Create();

            typeModel.Add(typeof(TrackablePocoTracker <ISpaceShipData>), false)
            .SetSurrogate(typeof(TrackableSpaceShipDataTrackerSurrogate));

            var serverZone = new ServerZone(EntityFactory.Default);

            var clientZones = Enumerable.Range(0, 2).Select(i =>
            {
                var channelUp = new ProtobufChannelToServerZoneOutbound
                {
                    TypeTable       = typeTable,
                    TypeModel       = typeModel,
                    OutboundChannel = new DummyChannelToServerZoneInbound
                    {
                        Channel = new ProtobufChannelToServerZoneInbound
                        {
                            TypeTable         = typeTable,
                            TypeModel         = typeModel,
                            ClientId          = i + 1,
                            InboundServerZone = serverZone,
                        }
                    }
                };
                var clientZone = new ClientZone(EntityFactory.Default, channelUp);
                var channel    = new ProtobufChannelToClientZoneOutbound
                {
                    TypeTable       = typeTable,
                    TypeModel       = typeModel,
                    OutboundChannel = new ProtobufChannelToClientZoneInbound()
                    {
                        TypeTable         = typeTable,
                        TypeModel         = typeModel,
                        InboundClientZone = clientZone,
                    }
                };
                serverZone.AddClient(i + 1, channel);
                return(clientZone);
            }).ToArray();

            serverZone.RunAction(zone =>
            {
                zone.Spawn(typeof(ISpaceShip), 0, EntityFlags.AnyoneCanControl);
            });

            var cship1A = (ClientSpaceShip)clientZones[0].GetEntity(1);
            var cship1B = (ClientSpaceShip)clientZones[1].GetEntity(1);

            Console.WriteLine($"cship1A.Score = {cship1A.Data.Score}");
            clientZones[0].RunAction(_ => cship1A.Say("Hello"));
            Console.WriteLine($"cship1A.Score = {cship1A.Data.Score}");
            clientZones[0].RunAction(_ => cship1A.Stop(1, 2));
            clientZones[1].RunAction(_ =>
            {
                cship1B.Say("World");
                cship1B.Shoot(1, 2, 3, 4);
            });
        }
 public ProtobufSerializer(ExtendedActorSystem system)
     : base(system)
 {
     _typeModel = CreateTypeModel();
     _typeTable = new TypeAliasTable();
 }
Exemplo n.º 15
0
        public void Test_CreateTable_WithCustomAssemblies()
        {
            var table = new TypeAliasTable(new[] { GetAssembly() });

            Assert.AreEqual(typeof(AliceClass), table.GetType(1));
        }