public RESTStatus GetPendingChatMessages(SQLLib sql, object dummy, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ComputerLogin) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } string MachineID = ni.Username; ChatList2 = new PushChatMessageList(); ChatList2.List = new List <PushChatMessage>(); lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("select * from Chats where [Read]=0 AND MachineID=@m AND ToClient=1 ORDER BY DT ASC", new SQLParam("@m", MachineID)); while (dr.Read()) { PushChatMessage pch = new PushChatMessage(); pch.ID = Convert.ToInt64(dr["ID"]); pch.DT = SQLLib.GetDTUTC(dr["DT"]); pch.Name = Convert.ToString(dr["Name"]); pch.Text = Convert.ToString(dr["Text"]); ChatList2.List.Add(pch); } dr.Close(); } return(RESTStatus.Success); }
public frmChat(PushChatMessage initialchat) { #if ENABLECHAT this.initialchat = initialchat; #endif InitializeComponent(); }
void AppendText(PushChatMessage chat) { txtRecvText.Text += chat.DT.ToLocalTime().ToLongDateString() + " " + chat.DT.ToLocalTime().ToLongTimeString() + " - " + chat.Name + ":\r\n" + chat.Text + "\r\n"; txtRecvText.SelectionStart = txtRecvText.Text.Length; txtRecvText.SelectionLength = 0; txtRecvText.ScrollToCaret(); }
private void timPull_Tick(object sender, EventArgs e) { #if ENABLECHAT PushChatMessage msg = Status.PopChatMessage(); if (msg == null) { return; } AppendText(msg); Status.ConfirmChatMessage(msg.ID); GetNotice(); #endif }
static void PushMessage(PushChatMessage msg) { lock (ChatQueueLock) { foreach (PushChatMessage q in ChatQueue) { if (q.ID == msg.ID) { return; } } ChatQueue.Add(msg); ChatQueue = ChatQueue.OrderBy(c => c.DT).ToList(); } }
private void cmdSend_Click(object sender, EventArgs e) { if (txtSendText.Text.Trim() == "") { return; } Program.net.PushSendChat(MID, "", txtSendText.Text.Trim()); PushChatMessage c = new PushChatMessage(); c.DT = DateTime.UtcNow; c.Name = "You"; c.Text = txtSendText.Text.Trim(); c.ID = 0; AppendText(c); txtSendText.Text = ""; }
private void cmdSend_Click(object sender, EventArgs e) { #if ENABLECHAT if (txtSendText.Text.Trim() == "") { return; } Status.SendChatMessage(txtSendText.Text.Trim()); PushChatMessage c = new PushChatMessage(); c.DT = DateTime.UtcNow; c.Name = "You"; c.Text = txtSendText.Text.Trim(); c.ID = 0; AppendText(c); txtSendText.Text = ""; #endif }
public static PushChatMessage PopMessage() { lock (ChatQueueLock) { if (ChatQueue.Count == 0) { return(null); } PushChatMessage q = ChatQueue[0]; ChatQueue.RemoveAt(0); if (q.ID != 0) { ChatPickedUp.Add(q.ID); } return(q); } }
public RESTStatus GetPendingChatData(SQLLib sql, object dummy, NetworkConnectionInfo ni, string MachineID) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } ChatList = new PushChatMessageList(); ChatList.List = new List <PushChatMessage>(); List <Int64> IDs = new List <long>(); lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("select * from Chats where [Read]=0 AND MachineID=@m AND ToClient=0 ORDER BY DT ASC", new SQLParam("@m", MachineID)); while (dr.Read()) { IDs.Add(Convert.ToInt64(dr["ID"])); PushChatMessage pch = new PushChatMessage(); pch.ID = Convert.ToInt64(dr["ID"]); pch.DT = SQLLib.GetDTUTC(dr["DT"]); pch.Name = Convert.ToString(dr["Name"]); pch.Text = Convert.ToString(dr["Text"]); ChatList.List.Add(pch); } dr.Close(); } foreach (Int64 id in IDs) { lock (ni.sqllock) { sql.ExecSQL("UPDATE Chats SET [Read]=1 WHERE ID=@id", new SQLParam("@id", id)); } } return(RESTStatus.Success); }
private void Timer_Tick(object sender, EventArgs e) { TimerCounter++; #if !DEBUG if (TimerCounter > 60) #else if (TimerCounter > 5) #endif { TimerCounter = 0; if (Program.Chat == null) { PushChatMessage chat = Status.PopChatMessage(); if (chat == null) { return; } Program.Chat = new frmChat(chat); Program.Chat.Show(); } } }
static void PushThreadActionRunner(object o) { if (!(o is PushDataForThreadRunner)) { return; } PushDataForThreadRunner t = (PushDataForThreadRunner)o; try { switch (t.p.Action) { case "ping": t.net.ResponsePushData10("ok", t.p.Action, 10, t.p.ReplyID); break; case "chatmessage": try { PushChatMessage m = JsonConvert.DeserializeObject <PushChatMessage>(t.p.AdditionalData1); PushMessage(m); } catch { } t.net.ResponsePushData10(new NetBool() { Data = true }, t.p.Action, 10, t.p.ReplyID); break; } } catch (Exception ee) { Debug.WriteLine(ee.ToString()); FoxEventLog.VerboseWriteEventLog("Push10: PushThreadActionRunner thread crashed", System.Diagnostics.EventLogEntryType.Information); } }
public RESTStatus SendChatMessageToServer(SQLLib sql, PushChatMessage ChatMessage, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ComputerLogin) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } string MachineID = ni.Username; lock (ni.sqllock) { Int64?ID = sql.InsertMultiDataID("Chats", new SQLData("MachineID", MachineID), new SQLData("DT", DateTime.UtcNow), new SQLData("Read", 0), new SQLData("ToClient", 0), new SQLData("Name", ni.Name), new SQLData("Text", ChatMessage.Text)); } return(RESTStatus.Success); }
public RESTStatus SendChatmessageToClient(SQLLib sql, PushChatMessage ChatMessage, NetworkConnectionInfo ni, string MachineID) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } string guid = Guid.NewGuid().ToString(); Int64?ID = null; lock (ni.sqllock) { ID = sql.InsertMultiDataID("Chats", new SQLData("MachineID", MachineID), new SQLData("DT", DateTime.UtcNow), new SQLData("Read", 0), new SQLData("ToClient", 1), new SQLData("Name", ni.Name), new SQLData("Text", ChatMessage.Text)); } if (ID != null) { ChatMessage.ID = ID.Value; } else { ChatMessage.ID = 0; } ChatMessage.DT = DateTime.UtcNow; ChatMessage.Name = ni.Name; PushData p = new PushData(); p.Action = "chatmessage"; p.ReplyID = guid; p.AdditionalData1 = JsonConvert.SerializeObject(ChatMessage); PushServiceHelper.SendPushService(MachineID, p, 10); PushDataResponse resp = PushServiceHelper.PopResponse(MachineID, 10, guid); if (resp == null) { ni.Error = "No response"; ni.ErrorID = ErrorFlags.NoData; return(RESTStatus.NoContent); } try { Res = JsonConvert.DeserializeObject <NetBool>(resp.Data.ToString()); } catch { ni.Error = "Faulty data"; ni.ErrorID = ErrorFlags.NoData; return(RESTStatus.NoContent); } return(RESTStatus.Success); }