Exemplo n.º 1
0
        private void ServerOnUserMessageReceived(object sender, MessageSenderEventArgs e)
        {
            var guid   = e.Sender;         //.Item1;
            var stream = e.Message.Stream; // tuple.Item2;

            stream.Seek(0, SeekOrigin.Begin);
            using (var reader = new StreamReader(stream, Encoding.ASCII))
            {
                stream.Seek(0, SeekOrigin.Begin);
                var msg = reader.ReadLine();
                _messages.Add(new Tuple <Guid, string>(guid, msg));
                UpdateText();

                using (var memStream = new MemoryStream())
                    using (var writer = new BinaryWriter(new NonClosingStream(memStream)))
                    {
                        writer.Write(guid.ToString());
                        writer.Write(msg);
                        var newMessage = new Message(NetCode.UserMessage, memStream);
                        _messageServer.WriteMessageRelay(guid, newMessage);
                    }
            }


            stream.Seek(0, SeekOrigin.Begin);
            _networkServer.WriteMessageRelay(guid, stream);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Captures data sent by HTTP sender and logs if verbose is enabled
        /// </summary>
        private static void OnSend(object sender, MessageSenderEventArgs e)
        {
            Console.WriteLine(@"Sending payload to MP:");
            Console.WriteLine(e.Message.Body.Payload);

            if (e.Message.Attachments.Count > 0)
            {
                if (e.Message is ConfigMgrFileCollectionMessage ||
                    e.Message is ConfigMgrUploadRequest)
                {
                    Console.WriteLine(@"Not writing attachments for {0} message to console", e.Message);
                    return;
                }

                for (int i = 0; i < e.Message.Attachments.Count; i++)
                {
                    Console.WriteLine(@"+======== ATTACHMENT #{0} (name: {1})========+", i + 1, e.Message.Attachments[i].Name);
                    Console.WriteLine(e.Message.Attachments[i].Body.Payload);
                }
            }
        }
Exemplo n.º 3
0
        private void ServerOnUpdateUserNameReceived(object sender, MessageSenderEventArgs e)
        {
            e.Message.Stream.Seek(0, SeekOrigin.Begin);
            using (var reader = new BinaryReader(e.Message.Stream))
            {
                var deserializer = new BinaryDeserializer(reader);
                var userName     = deserializer.ReadString();
                UpdateUsername(e.Sender, userName);
            }

            using (var memStream = new MemoryStream())
                using (var writer = new BinaryWriter(memStream))
                {
                    writer.Write(_userNames.Count);
                    foreach (var kvp in _userNames)
                    {
                        writer.Write(kvp.Key.ToString());
                        writer.Write(kvp.Value);
                    }
                    var msg = new Message(NetCode.UpdateUsername, memStream);
                    _messageServer.WriteMessageAll(msg);
                }
            UpdateText();
        }
Exemplo n.º 4
0
 private static void OnReceived(object sender, MessageSenderEventArgs e)
 {
     Console.WriteLine(@"Received payload from MP:");
     Console.WriteLine(e.Message.Body.Payload);
 }