internal HandlerData(IMessageHandler handler, MessageAccess msg, string replyId, string srcId) { _handler = handler; _message = msg; _replyId = replyId; _srcId = srcId; }
/// <summary> /// 查看通告列表:返回所有的通告 /// </summary> /// <returns></returns> public List <Message> ShowMessageList() { try { return(MessageAccess.SelectMessage()); } catch (Exception ex) { return(null); } }
/// <summary> ///删除通告 /// </summary> /// <param name="diaryID"></param> /// <returns></returns> public Boolean DeleteAnnunciate(int msgID) { try { return(MessageAccess.DeleteMessage(msgID)); } catch (Exception ex) { return(false); } }
public void HandleMessage(MessageAccess msg, string replyToId, string srcId) { if (msg.ToString().Substring(0, 2).Equals("<s")) { ProcessSystemMessage(msg, replyToId); } else { ProcessUserMessage(msg, replyToId, srcId); } }
/// <summary> /// 添加通告 /// </summary> /// <param name="emp">实体类对象</param> /// <returns></returns> public Boolean AddMessage(Message msg) { // 判断数据的有效性 try { return(MessageAccess.InsertMessage(msg)); } catch (Exception ex) { return(false); } }
public bool pushMsg(string from, string to, string msg, string time, byte msgType) { Message model = new Message() { FromId = from, ToId = to, Text = msg, SendTime = DateTime.Parse(time), msgType = msgType }; return(MessageAccess.AddMessage(model)); }
/// <summary> /// Adds a row to a message dataset using a row from the configuration /// dataset and the specific information for the new message /// </summary> /// <param name="cfgRow">A row from the message configuration dataset</param> /// <param name="msgId">The message identifier</param> /// <param name="msgBody">The text of the message</param> /// <param name="msgsDs">The dataset where the new row has to be added</param> private static void AddMessageRow(DataRow cfgRow, decimal msgId, string msgBody, decimal relatedId, DataSet msgsDs) { /// TODO: Obtain these values decimal version = decimal.One; decimal valid = decimal.One; decimal deleted = decimal.Zero; AppSettingsReader appSettings = new System.Configuration.AppSettingsReader(); double nDifHour = 0; try { nDifHour = (double)appSettings.GetValue("HOUR_DIFFERENCE", typeof(double)); } catch { nDifHour = 0; } MessageAccess msg = new MessageAccess(msgBody); msg.UpdateMessageHeader(msgId.ToString(), cfgRow[MessageConfiguration.DestUnitId].ToString(), cfgRow[MessageConfiguration.Priority].ToString()); string xml = msg.ToString(); msgsDs.Tables[0].Rows.Add(new object[] { msgId, cfgRow[MessageConfiguration.MsgId], cfgRow[MessageConfiguration.MediaId], DateTime.Now.AddHours(nDifHour), cfgRow[MessageConfiguration.Priority], cfgRow[MessageConfiguration.Mandatory], (relatedId != 0) ? (object)relatedId : (object)DBNull.Value, (relatedId != 0) ? (object)cfgRow[MessageConfiguration.Order] : (object)DBNull.Value, xml, cfgRow[MessageConfiguration.DestUnitId], cfgRow[MessageConfiguration.IPAdapter], (DBNull.Value.Equals(cfgRow[MessageConfiguration.IPAdapter])) ? cfgRow[MessageConfiguration.DestUnitPort] : cfgRow[MessageConfiguration.PortAdapter], decimal.Zero, DBNull.Value, DBNull.Value, cfgRow[MessageConfiguration.TotalRetries], cfgRow[MessageConfiguration.PartialRetries], cfgRow[MessageConfiguration.TotalInterval], cfgRow[MessageConfiguration.PartialInterval], cfgRow[MessageConfiguration.TotalTime], cfgRow[MessageConfiguration.HisMandatory], DBNull.Value, version, valid, deleted }); }
public void ProcessSystemMessage(MessageAccess msgAccess, string replyToId) { string body = msgAccess.ToString(); BecsMain.Logger.AddLog("[BecsMessageHandler]:Received system message (body): " + body, LoggerSeverities.Debug); try { SystemMessages sysmsgs = new SystemMessages(); sysmsgs.Process(body); } catch (Exception) { return; } }
/// <summary> /// 查看单个通告(根据ID) /// </summary> /// <returns></returns> public Message ShowSingleMessage(int msgID) { try { string sqlWhere = string.Format(" and msgId= {0}", msgID); List <Message> list = MessageAccess.SelectSingleMessage(sqlWhere); if (list != null && list.Count > 0) { return(list[0]); } return(null); } catch (Exception ex) { return(null); } }
/// <summary> /// 查看单个通告(根据标题) /// </summary> /// <returns></returns> public List <Message> LookSingleMessage(string msgTitle) { try { string sqlWhere = string.Format(" and msgTitle= '{0}'", msgTitle); List <Message> list = MessageAccess.SelectSingleMessage(sqlWhere); if (list != null && list.Count > 0) { return(list); } return(null); } catch (Exception ex) { return(null); } }
/// <summary> /// 分页显示 /// </summary> /// <param name="pageIndex">几页</param> /// <param name="pageSize">每页的数量</param> /// <returns></returns> public Pager <Message> ShowPagerMessageList(int pageIndex, int pageSize) { List <Message> rows = new List <Message>(); rows = MessageAccess.SelectMessage(); for (int i = 0; i < pageSize; i++) { if (pageIndex * pageSize + i < rows.Count) { rows.Add(rows[pageIndex * pageSize + i]); } } try { return(MessageAccess.Select("", pageIndex, pageSize, "msgID asc")); } catch (Exception ex) { return(null); } }
/// <summary> /// Dispatchs a single message /// </summary> /// <param name="xmlData">The body of the message</param> /// <param name="replyToId">The identifier of the object to respond to /// Might be null if the message is already a response</param> /// <param name="srcId">Source unit id</param> public void DispatchMessage(string xmlData, string replyToId, string srcId) { try { MessageAccess msg = new MessageAccess(xmlData); String msgName = msg.GetMessageName(); Type handlerType = (Type)_msgHandlers[msgName]; if (handlerType != null) { object o = Activator.CreateInstance(handlerType); IMessageHandler handler = (IMessageHandler)o; HandlerData p = new HandlerData(handler, msg, replyToId, srcId); ThreadPool.QueueUserWorkItem(new WaitCallback(FireMessageHandler), p); } } catch (Exception ex) { Debug.WriteLine("BecsMsgDispatcher.DispatchMessage error - " + ex.Message); BecsMain.Logger.AddLog(ex); } }
public List <Message> pullMsg(string name) { return(MessageAccess.GetUnreadMsg(name)); }
public List <Message> getMsgByPage(string where, int pageIndex, int pageSize) { int startIndex = (pageIndex - 1) * pageSize, endIndex = pageIndex * pageSize + 1; return(MessageAccess.GetDataByPage(where, startIndex, endIndex)); }
public MessageManager(MessageAccess messageAccess, IEmailManager emailManager) { _messageAccess = messageAccess; _email = emailManager; }
/// <summary> /// Just processes the message, delegating the real work on the corresponding class /// To do so, just creates the message class and calls it's Process method /// </summary> /// <param name="msgAccess">An accessor to the received message</param> /// <param name="replyToId">The identifier of the object to reply to</param> /// <param name="srcId">Source Unit Id</param> public void ProcessUserMessage(MessageAccess msgAccess, string replyToId, string srcId) { // Delegate message processing to the subclass that // really handles the process, and sends back the // response to MSMQ. TODO: Save response in MSGS string body = msgAccess.ToString(); BecsMain.Logger.AddLog("[BecsMessageHandler]:Received message(body): " + body, LoggerSeverities.Debug); BecsMain.Logger.AddLog("[BecsMessageHandler]:# Starting message processing ", LoggerSeverities.Debug); IRecvMessage msg = null; try { // Gets an instance of the class that processes the message msg = MessageFactory.GetReceivedMessage(body); msg.Session = BecsEngine.Session.MessagesSession; } catch (Exception) { // This exception means that message has not been created // This is probably because parameters are incorrect StringCollection nack = new StringCollection(); nack.Add(new NackMessage(MessageFactory.GetIdFromMessage(body), NackMessage.NackTypes.NACK_SEMANTIC).ToString()); SendResponsesBack(nack, replyToId, srcId); LogMsgDB(srcId, msgAccess.GetMessageName(), body, nack, replyToId); return; } try { BecsMain.Logger.AddLog("[BecsMessageHandler]:# Process Message", LoggerSeverities.Debug); BecsMain.Logger.AddLog("[BecsMessageHandler]ProcessUserMessage " + msg.MsgId.ToString(), LoggerSeverities.Debug); BecsMain.Logger.AddLog("[BecsMessageHandler]From UnitId: " + srcId, LoggerSeverities.Debug); // Execute the real processing of the message System.Collections.Specialized.StringCollection sc = msg.Process(); // Send back all responses SendResponsesBack(sc, replyToId, srcId); LogMsgDB(srcId, msgAccess.GetMessageName(), body, sc, replyToId); } catch (System.Threading.ThreadAbortException) { // Thread was cancelled by user (stopping service, etc) // Must send a nack to the client with code "FE" BecsMain.Logger.AddLog("[BecsMessageHandler]:Thread " + System.Threading.Thread.CurrentThread.GetHashCode() + " aborted.", LoggerSeverities.Info); StringCollection nack = new StringCollection(); nack.Add(new NackMessage(msg.MsgId, NackMessage.NackTypes.NACK_ERROR_BECS, 0xFE).ToString()); SendResponsesBack(nack, replyToId, srcId); LogMsgDB(srcId, msgAccess.GetMessageName(), body, nack, replyToId); } catch (System.Exception ex) { // An unknown exception has happened // Must send a nack with code "FF" BecsMain.Logger.AddLog(ex); StringCollection nack = new StringCollection(); nack.Add(new NackMessage(msg.MsgId, NackMessage.NackTypes.NACK_ERROR_BECS, 0xFF).ToString()); SendResponsesBack(nack, replyToId, srcId); LogMsgDB(srcId, msgAccess.GetMessageName(), body, nack, replyToId); } }
/// <summary> /// 更新通告查阅次数 /// </summary> /// <param name="id"></param> /// <param name="diary"></param> /// <returns></returns> public Boolean UpdateMessageTotal(int msgID) { MessageAccess.Update(msgID); return(true); }
public MessageController(IConfiguration config) { _messageAccess = new MessageAccess(config); }
public MessageController(DatabaseInterface db) { _db = db; _Message = new MessageAccess(db); }
public int getMsgCountBy(string where) { return(MessageAccess.GetCount(where)); }