Beispiel #1
0
        public void ChatNewMessage(SendMessageData toserver)
        {
            var tosend = SendToMessage(toserver, MessageEvent.NewMessage);

            tosend.MessageId = -1;
            var xml = _serializer.Serialize(tosend);

            _communicator.Send(xml, _moduleIdentifier);
        }
Beispiel #2
0
        private MessageData SendToMessage(SendMessageData toconvert, MessageEvent ChatEvent)
        {
            var Converted = new MessageData();

            Converted.Event         = ChatEvent;
            Converted.Type          = toconvert.Type;
            Converted.Message       = toconvert.Message;
            Converted.FileData      = null;
            Converted.SenderId      = UserId;
            Converted.ReceiverIds   = toconvert.ReceiverIds;
            Converted.ReplyThreadId = toconvert.ReplyThreadId;
            Converted.Starred       = false;
            Converted.SentTime      = DateTime.Now;
            return(Converted);
        }
Beispiel #3
0
        /// <summary>
        ///     Send a file type message to the server
        /// </summary>
        /// <param name="message">SendMessageData object specifying the file message to send</param>
        public void Send(SendMessageData message)
        {
            Trace.WriteLine("[FileClient] Received file send request");
            if (message.Type != MessageType.File)
            {
                throw new ArgumentException("Message argument to FileClient::Send does not have MessageType File");
            }

            // check if file with given file path exists
            var filepath = message.Message;

            if (!File.Exists(filepath))
            {
                throw new FileNotFoundException("File {0} not found", filepath);
            }

            // initialize a MessageData object that will be sent to the server
            var toSend   = new MessageData();
            var filedata = new SendFileData(filepath);

            // set toSend's fields appropriately
            toSend.Event         = MessageEvent.NewMessage;
            toSend.Type          = MessageType.File;
            toSend.MessageId     = -1;
            toSend.Message       = filedata.fileName;
            toSend.SenderId      = UserId;
            toSend.ReceiverIds   = message.ReceiverIds;
            toSend.ReplyThreadId = -1;
            toSend.SentTime      = DateTime.Now;
            toSend.Starred       = false;

            toSend.FileData = filedata;

            // serialize the message
            Trace.WriteLine("[FileClient] Serializing the file data");
            var toSendSerialized = _serializer.Serialize(toSend);

            // send the message
            Trace.WriteLine("[FileClient] Sending the file to server");
            _communicator.Send(toSendSerialized, "Content");
        }