public void SelectChannel(string channelName, MessageReceiver channelType) { Channel newSelected; if (channelType == MessageReceiver.Channel) { newSelected = ChatData.GetInstance().Channels.Where(channel => channel.Name == channelName).First(); } else if (channelType == MessageReceiver.User) { newSelected = ChatData.GetInstance().Users.Where(channel => channel.Name == channelName).First(); } else { throw new Exception($"Unknown MessageType: {channelType}"); } SetSelectedChannel(newSelected); ChannelType.Text = newSelected.ChannelType.ToString(); TargetChannel.Text = newSelected.Name; bool isTargetChannelFrozen = newSelected.ChannelType == MessageReceiver.User; TargetChannel.IsReadOnly = isTargetChannelFrozen; selected = newSelected; }
public void Refresh() { _ = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { ChatData data = ChatData.GetInstance(); SetChannels(data); UpdateSelectedChannelMessages(); }); }
private void Loop() { NetworkStream stream = client.GetStream(); Message newMessage; DateTime lastHeartbeat = SendHeartbeat(); while (client.Connected && keepListening) { if (client.Connected && stream.DataAvailable && stream.CanRead) { newMessage = TcpIO.ReadStream(stream); ChatData.GetInstance().AddMessage(newMessage); UIController.GetInstance().Refresh(); } if (DateTime.Now.Subtract(lastHeartbeat).TotalSeconds >= 2) { lastHeartbeat = SendHeartbeat(); } Thread.Yield(); } }