internal HandlerData(IMessageHandler handler, MessageAccess msg, string replyId, string srcId)
 {
     _handler = handler;
     _message = msg;
     _replyId = replyId;
     _srcId   = srcId;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 查看通告列表:返回所有的通告
 /// </summary>
 /// <returns></returns>
 public List <Message> ShowMessageList()
 {
     try
     {
         return(MessageAccess.SelectMessage());
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 ///删除通告
 /// </summary>
 /// <param name="diaryID"></param>
 /// <returns></returns>
 public Boolean DeleteAnnunciate(int msgID)
 {
     try
     {
         return(MessageAccess.DeleteMessage(msgID));
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 添加通告
 /// </summary>
 /// <param name="emp">实体类对象</param>
 /// <returns></returns>
 public Boolean AddMessage(Message msg)
 {
     // 判断数据的有效性
     try
     {
         return(MessageAccess.InsertMessage(msg));
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        /// <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
            });
        }
Ejemplo n.º 8
0
        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;
            }
        }
Ejemplo n.º 9
0
 /// <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);
     }
 }
Ejemplo n.º 10
0
 /// <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);
     }
 }
Ejemplo n.º 11
0
        /// <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);
     }
 }
Ejemplo n.º 13
0
 public List <Message> pullMsg(string name)
 {
     return(MessageAccess.GetUnreadMsg(name));
 }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 15
0
 public MessageManager(MessageAccess messageAccess, IEmailManager emailManager)
 {
     _messageAccess = messageAccess;
     _email         = emailManager;
 }
Ejemplo n.º 16
0
        /// <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);
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// 更新通告查阅次数
 /// </summary>
 /// <param name="id"></param>
 /// <param name="diary"></param>
 /// <returns></returns>
 public Boolean UpdateMessageTotal(int msgID)
 {
     MessageAccess.Update(msgID);
     return(true);
 }
Ejemplo n.º 18
0
 public MessageController(IConfiguration config)
 {
     _messageAccess = new MessageAccess(config);
 }
Ejemplo n.º 19
0
 public MessageController(DatabaseInterface db)
 {
     _db      = db;
     _Message = new MessageAccess(db);
 }
Ejemplo n.º 20
0
 public int getMsgCountBy(string where)
 {
     return(MessageAccess.GetCount(where));
 }