private void IncReceiveMessageCount(int id, int size) { MessageCountInfo ctInfo; if (m_ReceiveMessageCounts.TryGetValue(id, out ctInfo)) { ++ctInfo.m_MsgCount; ctInfo.m_TotalMsgSize += size; } else { ctInfo = new MessageCountInfo(); ctInfo.m_MsgCount = 1; ctInfo.m_TotalMsgSize = size; m_ReceiveMessageCounts.Add(id, ctInfo); } }
public void ProcessRequest(HttpContext context) { MessageCountInfo mci = new MessageCountInfo(); if (context.User.Identity.IsAuthenticated) { try { m_userName = context.User.Identity.Name; m_context = context; string action = context.Request["action"]; if (!string.IsNullOrEmpty(action)) { switch (action) { case "getunread": int total = m_messageService.CountMessage(m_userName, "all", 0); int managecount = m_messageService.CountABSManagementUnreadMessages(m_userName); int ticketCount = m_messageService.CountTicketUnreadMseeages(m_userName); mci.OK = true; mci.managecount = managecount; mci.total = total; mci.ticketCount = ticketCount; mci.abscount = total - managecount - ticketCount; break; case "mark": int state = 0; if (int.TryParse(context.Request["state"], out state) && Math.Abs(state) == 1) { if (ChangeStateMultiple(context.Request["contentids"].Trim(), state)) { mci.OK = true; } } break; default: break; } } } catch (Exception /* ex*/) { mci.OK = false; } } else { mci.OK = false; } context.Response.ContentType = "application/json"; List <string> trustedHosts = new List <string>(); //Add new hosts below if need cors (notice that cors header allow only one domain name) trustedHosts.Add("absmanager.cn-abs.com"); trustedHosts.Add("deallab.cn-abs.com"); string sender = context.Request.UrlReferrer == null ? "" : context.Request.UrlReferrer.Host; if (trustedHosts.Contains(sender)) { context.Response.AddHeader("Access-Control-Allow-Origin", "https://" + sender); } context.Response.AddHeader("Access-Control-Allow-Credentials", "true"); context.Response.Write(JsonConvert.SerializeObject(mci)); }