Ejemplo n.º 1
0
        internal void AddPostToUi(Message mess)
        {
            _oddLine = !_oddLine;

            var tb = new TextBlock();
            if (_oddLine) tb.Background = new SolidColorBrush(Colors.Aquamarine);

            tb.Inlines.Add(new Run("[" + mess.Time.ToLongTimeString() + "]")
            {
                FontWeight = FontWeights.Bold
            });

            tb.Inlines.Add(new Run(" " + mess.User)
            {
                FontWeight = FontWeights.Bold,
                Foreground = Brushes.Blue
            });

            tb.Inlines.Add(new Run(": "));

            tb.Inlines.Add(new Run(mess.Body));

            Wm.StackPanelMessages.Children.Add(tb);

            if (Wm.StackPanelMessages.Children.Count > Maxmesseges)
            {
                Wm.StackPanelMessages.Children.RemoveAt(0);
            }
        }
Ejemplo n.º 2
0
 private void btSendMessage_Click(object sender, EventArgs e)
 {
     if (selectedIndex != -1)
     {
         Chat.Message message;
         if (CurrentDialogId == chatDialogId)
         {
             message         = new Chat.Message();
             message.Content = tbMessageContent.Text;
             message.FilesID = new List <int>(loadedFiles.Keys.AsEnumerable());
         }
         else
         {
             message         = new Chat.Message(clientsList[selectedIndex].Key, tbMessageContent.Text);
             message.FilesID = new List <int>(loadedFiles.Keys.AsEnumerable());
             message.Name    = "Me";
             chatDialogsInfo[message.ReceiverID].Messages.Add(message);
         }
         if (cbIsConnected.Checked)
         {
             if (IsLoadingFiles)
             {
                 MessageBox.Show("Please wait for file loading", "Not ready",
                                 MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             else
             {
                 client.SendMessage(message);
                 loadedFiles.Clear();
                 UpdateView();
             }
         }
     }
 }
Ejemplo n.º 3
0
 Task Send(Message msg) {
   var s = state;
   var bc = chans.Broadcast;
   if (s == State.Connected && bc != null)
     return bc.SendAsync(msg);
   else
     //shouldn't get here...
     throw new InvalidOperationException("(inner:) disconnected or no broadcast-chan");
 }
Ejemplo n.º 4
0
 public void Send(Message message)
 {
     try
     {
         TcpWorks.SendObjectOnce(message, Client);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Ejemplo n.º 5
0
        bool CheckMessageForFiles(int index)
        {
            bool result = false;

            Chat.Message message = chatDialogsInfo[CurrentDialogId].Messages[index];
            if (message.FilesID != null && message.FilesID.Count > 0)
            {
                result = true;
            }
            return(result);
        }
Ejemplo n.º 6
0
 private void btGetHistory_Click(object sender, EventArgs e)
 {
     lbParticipants.SelectedIndex = 0;
     Chat.Message message = new Chat.Message()
     {
         messageType = MessageType.History,
         ReceiverID  = clientsList[selectedIndex].Key
     };
     client.SendMessage(message);
     UpdateView();
 }
Ejemplo n.º 7
0
        public int SendMessage(System.Net.Sockets.Socket sender)
        {
            Enum MessageType = Message.MessageType.Message; // the type of message where sending here is a text message.
            Message msg = new Message();

            string ChatMessage = "";
            ChatMessage = GetMessageFromStream();

            byte[] message = Encoding.ASCII.GetBytes(ChatMessage + "<EOF>");
            int sent = sender.Send(message);

            return sent;
        }
Ejemplo n.º 8
0
        string ShowMessageContent(Chat.Message message)
        {
            string visualMessage = (message.Name + ": " + message.Content);

            if (message.FilesID != null)
            {
                foreach (int fileName in message.FilesID)
                {
                    visualMessage += "\n[FILE] " + fileName.ToString();
                }
            }
            return(visualMessage);
        }
Ejemplo n.º 9
0
		nfloat CalculateHeightFor (Message msg, UITableView tableView)
		{
			var index = (int)msg.Type;
			BubbleCell cell = sizingCells [index];
			if (cell == null)
				cell = sizingCells [index] = (BubbleCell)tableView.DequeueReusableCell (GetReuseId (msg.Type));

			cell.Message = msg; 

			cell.SetNeedsLayout ();
			cell.LayoutIfNeeded ();
			CGSize size = cell.ContentView.SystemLayoutSizeFittingSize (UIView.UILayoutFittingCompressedSize);
			return NMath.Ceiling (size.Height) + 1;
		}
Ejemplo n.º 10
0
        private void TextBoxPostEdit_KeyDown(object sender, KeyEventArgs e)
        {
            if (
                !((Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) &&
                  Keyboard.IsKeyDown(Key.Enter))) return;

            var text = TextBoxPostEdit.Text;

            if (!ParseCommand(text) && IsConnected)
            {
                var mess = new Message(Username, DateTime.Now, Message.PackType.Post, text);
                Send(mess);
            }

            TextBoxPostEdit.Text = "";
        }
Ejemplo n.º 11
0
        public int SendIP(System.Net.Sockets.Socket sender)
        {
            Message msg = new Message();

            string HostIpAddress =
                Net.GetHostIpAddress();

            // the type of message where sending here is a Ip address.
            string type =
                "type:" + msg.GetMessageTypeByName(Message.MessageType.SentIP);

            byte[] message = Encoding.ASCII.GetBytes(HostIpAddress +
                                                " connected. " +
                                                 type +
                                                  Chat.EOF_FLAG);

            int sent = sender.Send(message);

            return sent;
        }
        private static void Work()
        {
            var id = Process.GetCurrentProcess().Id.ToString();
            string temp = String.Empty;

            while (temp != "exit")
            {
                temp = Console.ReadLine();
                var message = new Message
                {
                    Author = id,
                    CreationTicks = System.DateTime.Now.Ticks,
                    Text = @temp,
                    Picture = "test"//ImageToString(@"avatar.bmp")
                };
                Storage.ToSend.TryAdd(Storage.ToSend.Count, message);
                Console.WriteLine("Отправлено: " + temp);
            }
            Storage.ServerStream.Close();
            Storage.Client.Close();
        }
        void OnSendClicked(object sender, EventArgs e)
        {
            var text = TextView.Text;
            TextView.Text = string.Empty; // this will not generate change text event
            UpdateButtonState ();

            if (string.IsNullOrWhiteSpace (text))
                return;

            var msg = new Message {
                Type = MessageType.Outgoing,
                Text = text.Trim ()
            };

            messages.Add (msg);
            tableView.InsertRows (new NSIndexPath[] { NSIndexPath.FromRowSection (messages.Count - 1, 0) }, UITableViewRowAnimation.None);
            ScrollToBottom (true);
        }
Ejemplo n.º 14
0
 private void Send(Message mess)
 {
     if (IsConnected && mess != null)
     {
         _tcpClient.Send(mess);
     }
 }
Ejemplo n.º 15
0
        public void HandleReceivedMessages(Chat.Message message)
        {
            switch (message.messageType)
            {
            case MessageType.Regular:
                chatDialogsInfo[chatDialogId].AddMessage(message);
                break;

            case MessageType.Private:
                chatDialogsInfo[message.SenderID].AddMessage(message);
                break;

            case MessageType.ClientsList:
            {
                Action action = delegate
                {
                    clientsList.Clear();
                    clientsList.Add(new EndPointNamePair()
                        {
                            Key = chatDialogId, Value = "Chat"
                        });
                    foreach (EndPointNamePair nameClient in message.clientsNames)
                    {
                        clientsList.Add(nameClient);
                        if (!chatDialogsInfo.ContainsKey(nameClient.Key))
                        {
                            chatDialogsInfo.Add(nameClient.Key, new ChatDialogInfo(nameClient.Value));
                        }
                    }
                };
                if (InvokeRequired)
                {
                    Invoke(action);
                }
                else
                {
                    action();
                }
            }
            break;

            case MessageType.SearchResponse:
            {
                Action action = delegate
                {
                    tbIPAdress.Text = message.IPAdress;
                    tbPort.Text     = message.Port.ToString();
                };
                if (InvokeRequired)
                {
                    Invoke(action);
                }
                else
                {
                    action();
                }
            }
            break;

            case MessageType.History:
                chatDialogsInfo[message.ReceiverID].Messages = message.MessageHistory;
                break;

            default:
                return;
            }
            UpdateView();
        }
Ejemplo n.º 16
0
    //used from ChanEvent
    void ReceiveMessage(Message msg) {
      switch (msg.Type) {
        case Message.MessageType.Message:
          connector.RunOrDefault(Cmd.ReceivedMsg, msg.Data);
          return;
        case Message.MessageType.SysMessage:
          connector.RunNotifySystem(msg.Data);
          return;
        case Message.MessageType.Connected:
          //someone has conected: notify
          //POSSIBLY: improve (better msg; consider text...)
          connector.RunNotifySystem(msg.Data.Source.ArgSrc("connected"));
          return;
        case Message.MessageType.Disconnected:
          //someone has disconected: notify
          connector.RunNotifySystem(msg.Data.Source.ArgSrc("disconnected"));
          return;

      }
    }
Ejemplo n.º 17
0
 public void BroadcastMessage(Message msg, Action<Task> afterSent = null) {
   switch (state) {
     case State.Connected:
       var sentT = Send(msg);
       if (afterSent != null)
         sentT = sentT.ContinueWith(afterSent);
       connector.PipeEx("ChatClient.BcMsg", sentT);
       return;
     case State.Connecting:
       connector.RunNotifySystem("connecting...".ArgSrc(Cmd.Send));
       Action orig;
       Action merged;
       do {
         orig = afterConnected;
         merged = orig + (() => BroadcastMessage(msg, afterSent));
         if (state != State.Connecting) {
           BroadcastMessage(msg, afterSent);
           return;
         }
       } while (orig != Interlocked.CompareExchange(ref afterConnected, merged, orig));
       return;
     case State.ConnectingFailed:
       connector.RunError("ConnectingFailed; cannot send: " + msg);
       return;
     case State.Disconnected:
       connector.RunError("sending: not connected");
       return;
   }
 }
Ejemplo n.º 18
0
 private void AddMessageToQueue(Message mess)
 {
     _messages.Enqueue(mess);
     NewMessegeEvent.Set();
 }
Ejemplo n.º 19
0
 internal void AddTextToUi(string text)
 {
     var mess = new Message("System", DateTime.Now, Message.PackType.Post, text);
     AddPostToUi(mess);
 }
Ejemplo n.º 20
0
        public NewMessageViewController(string channel, Repository repo)
        {
            Title = "New Message";

            _text = new UITextView (View.Bounds) {
                Font = UIFont.SystemFontOfSize (24),
            };
            View.AddSubview (_text);

            NavigationItem.LeftBarButtonItem = new UIBarButtonItem (
                UIBarButtonSystemItem.Cancel,
                delegate {
                    DismissModalViewControllerAnimated (true);
            });

            NavigationItem.RightBarButtonItem = new UIBarButtonItem (
                "Send",
                UIBarButtonItemStyle.Done,
                delegate {
                    NavigationItem.RightBarButtonItem.Enabled = false;
                    var message = new Message {
                        ChannelName = channel,
                        PostTime = DateTime.UtcNow,
                        Username = "******",
                        Text = _text.Text,
                    };
                    repo.Save (message).ContinueWith ((task) => {
                        if (task.IsFaulted) AppDelegate.ShowError ("Send", task.Exception);
                        DismissModalViewControllerAnimated (true);
                    }, new DispatchQueueScheduler ());
                });
        }