Exemplo n.º 1
0
        private void StartReceive(object sender, DoWorkEventArgs e)
        {
            while (_socket.Connected)
            {
                // Read the command object.
                var bytes = new byte[8192];
                try
                {
                    var readBytes = _socket.Receive(bytes);
                    if (readBytes == 0)
                    {
                        break;
                    }
                    CommandContainer command = (CommandContainer)SerializerManager.Deserialize(bytes);

                    if ((command.CommandType == CommandType.ClientSignUp) || (command.CommandType == CommandType.ClientLogIn))
                    {
                        ProfileContainer profile = (ProfileContainer)command.Data;
                        _clientName = profile.UserName;
                    }

                    OnCommandReceived(new CommandEventArgs(command));
                }
                catch (Exception)
                {
                }
            }
            OnDisconnected(new ClientEventArgs(_socket));
            Disconnect();
        }
Exemplo n.º 2
0
        private void StartReceive(object sender, DoWorkEventArgs e)
        {
            while (_clientSocket.Connected)
            {
                // Read the command object.
                var bytes = new byte[8192];
                try
                {
                    var readBytes = _clientSocket.Receive(bytes);
                    if (readBytes == 0)
                    {
                        break;
                    }
                    CommandContainer cmd = (CommandContainer)SerializerManager.Deserialize(bytes);

                    OnCommandReceived(new CommandEventArgs(cmd));
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
            OnServerDisconnected(new ServerEventArgs(_clientSocket));
            Disconnect();
        }
Exemplo n.º 3
0
        public override void OnLoadData()
        {
            base.OnLoadData();

            DebugLog.Message("OnLoadData: Data Ids: {0}", string.Join(", ", this.serializableDataManager.EnumerateData()));

            //TODO: erase data after usage?

            SerializerManager.Deserialize(serializableDataManager);
        }
Exemplo n.º 4
0
        public void Should_Allow_Custom_Udt_Serializers()
        {
            var typeSerializer = new UdtSerializerWrapper();
            var serializer     = new SerializerManager(ProtocolVersion.MaxSupported, new ITypeSerializer[] { typeSerializer })
                                 .GetCurrentSerializer();
            var buffer = serializer.Serialize(new object());

            CollectionAssert.AreEqual(Encoding.UTF8.GetBytes("DUMMY UDT SERIALIZED"), buffer);
            CollectionAssert.AreEqual(buffer, (IEnumerable)serializer.Deserialize(buffer, ColumnTypeCode.Udt, new UdtColumnInfo("ks1.udt1")));
            //Check that other serializers are still working
            CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 10 }, serializer.Serialize(10));
            CollectionAssert.AreEqual(new byte[] { 0x61, 0x62 }, serializer.Serialize("ab"));
            Assert.AreEqual(1, typeSerializer.DeserializationCounter);
            Assert.AreEqual(1, typeSerializer.SerializationCounter);
        }
Exemplo n.º 5
0
        private void LoadLevel(ISerializableData serializeData)
        {
            // Is called even for new maps
            // Is called before LoadGame
            // serializeData == Managers.serializableData

            try
            {
                SerializerManager.Deserialize(serializeData);
            }
            catch (Exception e)
            {
                Log.Error($"Error while loading data: {e.Message}");
            }
        }
Exemplo n.º 6
0
        public void Should_Allow_Custom_Cql_Type_Serializers()
        {
            var typeSerializer = new DummyCustomTypeSerializer();
            var serializer     = new SerializerManager(ProtocolVersion.MaxSupported, new ITypeSerializer[] { typeSerializer })
                                 .GetCurrentSerializer();
            var value  = new DummyCustomType(new byte[] { 1, 2 });
            var buffer = serializer.Serialize(value);

            CollectionAssert.AreEqual(new byte[] { 1, 2 }, buffer);
            var deserializedValue = serializer.Deserialize(buffer, ColumnTypeCode.Custom, typeSerializer.TypeInfo);

            Assert.IsInstanceOf <DummyCustomType>(deserializedValue);
            var deserializedCustom = (DummyCustomType)deserializedValue;

            CollectionAssert.AreEqual(value.Buffer, deserializedCustom.Buffer);
            //Check that other serializers are still working
            CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 10 }, serializer.Serialize(10));
            CollectionAssert.AreEqual(new byte[] { 0x61 }, serializer.Serialize("a"));
        }
Exemplo n.º 7
0
        public void Should_Allow_Custom_Primitive_Serializers()
        {
            var serializer = new SerializerManager(ProtocolVersion.MaxSupported, new[] { new BigDecimalSerializer() })
                             .GetCurrentSerializer();
            var value  = new BigDecimal(5, 1);
            var buffer = serializer.Serialize(value);

            CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 5, 1 }, buffer);
            var deserializedValue = serializer.Deserialize(buffer, ColumnTypeCode.Decimal, null);

            Assert.IsInstanceOf <BigDecimal>(deserializedValue);
            var deserializedDecimal = (BigDecimal)deserializedValue;

            Assert.AreEqual("0.00001", deserializedDecimal.ToString());
            Assert.AreEqual(value.Scale, deserializedDecimal.Scale);
            Assert.AreEqual(value.UnscaledValue, deserializedDecimal.UnscaledValue);
            //Check that other serializers are still working
            CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 10 }, serializer.Serialize(10));
            CollectionAssert.AreEqual(new byte[] { 0x61 }, serializer.Serialize("a"));
        }