Ejemplo n.º 1
0
        public virtual void AppendMessage(string message, string label, bool showTime)
        {
            ControlUtils.AsyncSafeInvoke(this, () =>
            {
                string text = (MessageList.Lines?.Length ?? 0) > 0 ? "\r\n" : string.Empty;

                if (showTime)
                {
                    text += string.Format("[{0:T}]", DateTime.Now);
                }

                if (string.IsNullOrWhiteSpace(label) == false)
                {
                    text += string.Format("[{0}]", label ?? string.Empty);
                }

                if (string.IsNullOrWhiteSpace(text) == false)
                {
                    text += " " + message ?? string.Empty;
                }
                else
                {
                    text = message ?? string.Empty;
                }

                MessageList.AppendText(text);
                ControlUtils.ScrollToBottom(MessageList);
                this.Invalidate();
            });
        }
Ejemplo n.º 2
0
        private async void Connect()
        {
            connection.On <string, string, string>("ReceiveMessage", (emailAddress, displayname, message) =>
            {
                this.Dispatcher.Invoke(() => ReceiveMessage(emailAddress, message));
            });

            connection.On <FileMessage>("FileMessage", (file) =>
            {
                this.Dispatcher.Invoke(() => ReceiveFileMessage(file));
            });

            try
            {
                await connection.StartAsync();

                MessageList.ScrollToEnd();
            }
            catch (Exception exception)
            {
                MessageList.AppendText(exception.Message);
            }

            await connection.InvokeAsync("JoinGroup", _groupId);
        }
Ejemplo n.º 3
0
        private async void SendFileBtnEvent(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                string      fullPath = openFileDialog.FileName;
                string      fileName = System.IO.Path.GetFileName(fullPath);
                FileMessage file     = new FileMessage()
                {
                    FileBinary  = File.ReadAllBytes(fullPath),
                    FileHeaders = fileName
                };
                try
                {
                    await connection.InvokeAsync("FileMessage", _emailAddress, _groupId, file);

                    await connection.InvokeAsync("SendMessage", _emailAddress, _groupId, "Sent file \"" + fileName + "\"");
                }
                catch (Exception exception)
                {
                    MessageList.AppendText(exception.Message);
                }
            }
        }
Ejemplo n.º 4
0
        private void ReceiveFileMessage(FileMessage file)
        {
            MessageList.AppendText("File received\n");

            Directory.CreateDirectory(storageDir);
            File.WriteAllBytes(System.IO.Path.Combine(storageDir, file.FileHeaders), file.FileBinary);
            MessageList.AppendText((file.FileHeaders));
        }
Ejemplo n.º 5
0
        private async Task SendMessage()
        {
            try
            {
                //Calls method in hub - with the three arguments: email, groupid and message
                await connection.InvokeAsync("SendMessage", _emailAddress, _groupId, MessageTextBox.Text);

                MessageTextBox.Clear();
                MessageTextBox.Focus();
            }
            catch (Exception exception)
            {
                MessageList.AppendText(exception.Message);
            }
        }