public void RemoveNotification(ChatMessage notification) { if (Notifications.Contains(notification)) { Notifications.Remove(notification); } if (Notifications.Count < 1) { Close(); _isActive = false; } }
public void AddNotification(ChatMessage notification) { if (Notifications.Count >= MaxNotifications) { RemoveNotification(Notifications.First()); } Notifications.Insert(0, notification); if (!((Notifications.Count <= 0) || _isActive)) { Show(); _isActive = true; } }
public void AppendConversation(string user, string text, string bare) { try { var item = new ChatMessage(user) { Text = text, From = bare }; Messages.Add(item); Helper.SaveToFile(item); } catch (Exception exception) { _log.Error(exception); } }
private void ShowMessageNotification(ChatMessage message) { try { new MessageNotifications().AddNotification(message); } catch (Exception exception) { _log.Error(exception); } }
private void ReadFromFile() { try { var path = Path.Combine(Directory.GetCurrentDirectory(), "History"); if (Directory.Exists(path)) { var str3 = Path.Combine(path, string.Format("{0}.csv", User.Bare)); if (File.Exists(str3)) { var list = new List<ChatMessage>(); var num = 0; using (var reader = new StreamReader(File.Open(str3, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))) { while (!reader.EndOfStream) { var str4 = reader.ReadLine(); if ((str4 != null) && (num != 0)) { var strArray = str4.Split(new[] { ';' }); var item = new ChatMessage(strArray[0]) { Date = DateTime.Parse(strArray[1]), From = strArray[2], Text = strArray[3].Replace("☺n☺", "\r") }; list.Add(item); } num++; } } list.Reverse(); foreach (var message3 in list) { Messages.Insert(0, message3); } } } } catch (Exception exception) { _log.Error(exception); } }
private void JabberClientOnMessage(object sender, Message msg) { try { Application.Current.Dispatcher.Invoke(() => { if (!(from t in _users select t.Bare).Contains<string>(msg.From.Bare)) { var user = new ChatUser { Bare = msg.From.Bare, Name = msg.From.User }; _currentUser = user; _users.Add(_currentUser); } else { _currentUser = _users.First(t => t.Bare.Equals(msg.From.Bare)); } notifyIcon.Tag = _currentUser; var viewChatUser = GetViewChatUser(_currentUser); CreateChatWindow(); var item = new ChatMessage(_currentUser.Name) { Text = msg.Body, From = _currentUser.Bare }; viewChatUser.Messages.Add(item); if (((_chatWindow == null) || !_chatWindow.IsActive) || (_chatWindow.IsActive && !_chatWindow.SelectedViewChatUser.Equals(viewChatUser))) { _currentUser.Image = _messageImage; ShowGifForMessage(true); ShowMessageNotification(item); PlaySound(); } Helper.SaveToFile(item); }); } catch (Exception exception) { _log.Error(exception); } }
private void JabberClientOnError(object sender, Exception ex) { Application.Current.Dispatcher.Invoke(() => { try { _log.Error(ex); _dispatcherTimer.Start(); statusListView.SelectedIndex = 1; var message = new ChatMessage(ChatSettingsControl.Instance.Login) { Text = @"Связь прервана. \тПроверьте настройки подключения!" }; ShowMessageNotification(message); } catch (Exception exception) { _log.Error(exception); } }); }
private void JabberClientOnAuthError(object sender, XmlElement rp) { try { if (rp.Name == "failure") { Application.Current.Dispatcher.Invoke(() => { _log.ErrorFormat("Неправильный логин или пароль!", new object[0]); var itemsSource = usersListView.ItemsSource as ObservableCollection<ChatUser>; if (itemsSource != null) { itemsSource.Clear(); } statusListView.SelectedIndex = 1; var message = new ChatMessage(ChatSettingsControl.Instance.Login) { Text = "Неправильный логин или пароль!" }; ShowMessageNotification(message); }); } } catch (Exception exception) { _log.Error(exception); } }
public void TryToConnect() { try { if (string.IsNullOrEmpty(ChatSettingsControl.Instance.Login)) { var message = new ChatMessage("Онлайн-консультант") { Text = "Логин не может быть пустым!" }; ShowMessageNotification(message); } else { if (_jabberClient == null) { InitializeJabberClient(); } if (!((_jid == null) || _jid.User.Equals(ChatSettingsControl.Instance.Login))) { _users.Clear(); } _jid = new JID(ChatSettingsControl.Instance.Login.Trim()); _jabberClient.User = _jid.User; _jabberClient.Server = _jid.Server; _jabberClient.Password = ChatSettingsControl.Instance.Password; _jabberClient.Connect(); } } catch (Exception exception) { _log.Error(exception); } }
private void AppendMessage(ChatMessage message) { try { var inline = new Run(message.FullName) { Foreground = HeaderForeground, FontSize = HeaderTextSize, FontFamily = new FontFamily(TextFontFamily) }; richTextBox.Document.Blocks.Add(new Paragraph(inline)); var run2 = new Run(message.Text) { FontFamily = new FontFamily(TextFontFamily) }; richTextBox.Document.Blocks.Add(new Paragraph(run2)); richTextBox.ScrollToEnd(); } catch (Exception exception) { _log.Error(exception); } }