public void AddToTrayMsgQueue(NtfMsgInfo msgInfo) { if (MsgQueue.Count == MaxMsgForm) { MsgQueue.Dequeue(); } MsgQueue.Enqueue(msgInfo); }
public void OnNotifyMsgNtf(String strNotifyMsg) { if (this.InvokeRequired) { this.BeginInvoke(new DlgtVoidInputString(OnNotifyMsgNtf), strNotifyMsg); } else { string[] msgs = strNotifyMsg.Split(new Char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string msg in msgs) { string jsonMsg = GlobalMgr.TrimStartString(msg, "#", ""); if (jsonMsg.ToLower() == "{ping}") { //if(HeartBeatLostTime >= MAX_HEARTBEAT_LOST) //SetStatus("服务器已连接"); // We get feedback, reset the heart beat lost count to 0. HeartBeatLostTime = 0; continue; } try { JObject jo = JObject.Parse(jsonMsg); if (jo == null) { return; } NtfMsgInfo ntfMsgInfo = new NtfMsgInfo(); ntfMsgInfo.TitleInfo = jo["title"].ToString(); ntfMsgInfo.LinkInfo = jo["link"].ToString(); ntfMsgInfo.TimeInfo = DateTime.Now.ToString(TimeConverter.Format, TimeConverter.CultureInfo); InsertNewMsg(ntfMsgInfo); TrayMsgControl.AddToTrayMsgQueue(ntfMsgInfo); // notifyIcon1.ShowBalloonTip(5000, ntfMsgInfo.TimeInfo, ntfMsgInfo.TitleInfo, ToolTipIcon.Info); if (this.WindowState == FormWindowState.Minimized) { // Enable icon flash on Tray. TrayIconFlash(true); } } catch { continue; } } } }
public void MarkMsgAsRead(NtfMsgInfo msg) { foreach (ListViewItem item in listViewMsgs.Items) { if (item.SubItems[COLUMN_TIME].Text == msg.TimeInfo) { item.ImageIndex = MSG_ICON_READ; return; } } }
//public TrayMsgForm() //{ // InitializeComponent(); //} public TrayMsgForm(int maxDuration, NtfMsgInfo msgInfo, TrayMsgController controller) { InitializeComponent(); MaxDisplayTime = maxDuration; Msg = msgInfo; CurrentDisplayTime = 0; MsgController = controller; }
private void NotifyIcon1_BalloonTipClicked(object sender, EventArgs e) { NtfMsgInfo msg = LatestMsg; if (msg != null) { System.Diagnostics.Process.Start(msg.LinkInfo); TrayIconFlash(false); // Mark it as read MarkMsgAsRead(msg); } }
private void InsertNewMsg(NtfMsgInfo ntfMsgInfo) { if (listViewMsgs.Items.Count + 1 > MAX_MSGS) { listViewMsgs.Items.RemoveAt(listViewMsgs.Items.Count - 1); } ListViewItem listItem = new ListViewItem(ntfMsgInfo.TitleInfo, MSG_ICON_UNREAD); listItem.SubItems.Add(ntfMsgInfo.TimeInfo); listItem.SubItems.Add(ntfMsgInfo.LinkInfo); // Later msg always shows in the first. listViewMsgs.Items.Insert(0, listItem); // Update latest msg which will be opened when click on the ballontip. LatestMsg = ntfMsgInfo; }
public void ShowTrayMsg() { if (MsgQueue.Count == 0) { return; } NtfMsgInfo msgInfo = MsgQueue.Dequeue(); if (TrayMsgFormList.Count == MaxMsgForm) { TrayMsgForm formToRemove = TrayMsgFormList.First(); formToRemove.CloseForm(); } TrayMsgForm newForm = new TrayMsgForm(Host.MAX_MSG_DISPLAY_TIME, msgInfo, this); TrayMsgFormList.Insert(0, newForm); UpdateFormsPosition(); newForm.Show(); PlaySound(); }
public void MarkMsgAsRead(NtfMsgInfo msg) { Host.MarkMsgAsRead(msg); }