Exemple #1
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);
     }
 }
        /// <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
            });
        }
Exemple #3
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;
            }
        }
Exemple #4
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);
            }
        }