public void Run(ServerCommandArgs args)
        {
            var receivedContent = Serializer.Deserialize <MessageContent>(args.Message);

            if (receivedContent.Key == null)
            {
                throw new ArgumentNullException("Key");
            }

            if (receivedContent.Message == null)
            {
                throw new ArgumentNullException("Message");
            }

            if (string.IsNullOrEmpty(receivedContent.Receiver))
            {
                throw new ArgumentException("Receiver");
            }

            if (!ServerModel.Server.ContainsConnection(receivedContent.Receiver))
            {
                ServerModel.API.SendSystemMessage(receivedContent.Receiver, "Данного пользователя нет в сети.");
                return;
            }

            var sendingContent = new ClientOutPrivateMessageCommand.MessageContent
            {
                Key     = receivedContent.Key,
                Message = receivedContent.Message,
                Sender  = args.ConnectionId
            };

            ServerModel.Server.SendMessage(receivedContent.Receiver, ClientOutPrivateMessageCommand.Id, sendingContent);
        }
Example #2
0
        public void SendPrivateMessage(string receiver, string message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (string.IsNullOrEmpty(receiver))
            {
                throw new ArgumentException("receiver");
            }

            var sendingContent = new ClientOutPrivateMessageCommand.MessageContent {
                Message = message
            };

            ClientModel.Peer.SendMessage(receiver, ClientOutPrivateMessageCommand.CommandId, sendingContent);
        }