Exemplo n.º 1
0
        public void SerializeToBytes_WithByteArray()
        {
            byte[] data = new byte[1];
            data[0] = 10;

            byte[] serializedData = _formatter.Serialize(data);
            Assert.NotNull(serializedData);

            byte[] deserializedData = _formatter.Deserialize <byte[]>(serializedData);
            Assert.NotNull(deserializedData);
            Assert.Equal(deserializedData.Length, data.Length);
            Assert.Equal(data[0], deserializedData[0]);
        }
Exemplo n.º 2
0
        //public void Register(string metadata, IWebSocket webSocket)
        //{
        //    if (clientsByMetadata.ContainsKey(metadata))
        //    {
        //        clientsByMetadata[metadata].Add(webSocket);
        //    }
        //    else
        //    {
        //        clientsByMetadata.Add(metadata, new List<IWebSocket> { webSocket });
        //        messageQueuesByMetadata.Add(metadata, new FileQueue(metadata));
        //    }
        //}

        /// <summary>
        /// Sends reliable message
        /// </summary>
        /// <param name="message">Message to send</param>
        public void Send(IMessage message)
        {
            if (message == null)
            {
                return;
            }

            var serializedMessage = formatter.Serialize(message);

            messageQueue.Enqueue(serializedMessage);
            Send();
        }
Exemplo n.º 3
0
        public void Publish <T>(T msg) where T : Message.Message
        {
            if (_ignoreMe.Contains(msg.MsgId))
            {
                _ignoreMe.Remove(msg.MsgId);
                return;
            }
            var client = new NamedPipeClientStream(
                ".",
                _pipeName.Write,
                PipeDirection.InOut,
                PipeOptions.None,
                System.Security.Principal.TokenImpersonationLevel.None);

            client.Connect();
            _formatter.Serialize(client, msg);
            Debug.WriteLine($"[ => ] New message of type {msg.GetType().Name} sent to pipe {_pipeName.Write}");
            client.Dispose();
        }