public string M59(string sMessage)
        {
            string strRdo = "";

            try
            {
                if (Session["MessagesSession"] == null)
                {
                    MessagesSession msgSession = new MessagesSession();
                    Session["MessagesSession"] = msgSession;
                }

                IRecvMessage msg = null;
                msg         = MessageFactory.GetReceivedMessage(sMessage);
                msg.Session = ((MessagesSession)Session["MessagesSession"]);


                StringCollection sc = msg.Process();

                System.Collections.Specialized.StringEnumerator myEnumerator = sc.GetEnumerator();
                while (myEnumerator.MoveNext())
                {
                    strRdo += myEnumerator.Current + "\n";
                }
            }
            catch (Exception e)
            {
                strRdo = e.ToString();
            }

            return(strRdo);
        }
        public string M3(string sMessage)
        {
            string strRdo = "";

            try
            {
                IRecvMessage msg = null;
                msg = MessageFactory.GetReceivedMessage(sMessage);
                StringCollection sc = msg.Process();

                System.Collections.Specialized.StringEnumerator myEnumerator = sc.GetEnumerator();
                while (myEnumerator.MoveNext())
                {
                    strRdo += myEnumerator.Current + "\n";
                }
            }
            catch (Exception e)
            {
                strRdo = e.ToString();
            }

            return(strRdo);
        }
        public string Message(string sMessage)
        {
            string strRdo = "";

            try
            {
                if (_logger == null)
                {
                    System.Configuration.AppSettingsReader appSettings = new System.Configuration.AppSettingsReader();

                    // *** TODO
                    _logger = new Logger(MethodBase.GetCurrentMethod().DeclaringType);
                    //               _logger = new FileLogger(LoggerSeverities.Debug, (string)appSettings.GetValue("ServiceLog", typeof(string)));
                    //OPS.Comm.Messaging.CommMain.Logger.AddLogMessage += new AddLogMessageHandler(Logger_AddLogMessage);
                    //OPS.Comm.Messaging.CommMain.Logger.AddLogException += new AddLogExceptionHandler(Logger_AddLogException);
                    DatabaseFactory.Logger = _logger;
                }

                Logger_AddLogMessage(string.Format("Message.LogMsgDB: Empty unit. xml={0}", "Hello"), LoggerSeverities.Error);

                if (Session["MessagesSession"] == null)
                {
                    MessagesSession msgSession = new MessagesSession();
                    Session["MessagesSession"] = msgSession;
                }

                IRecvMessage msg = null;
                msg = MessageFactory.GetReceivedMessage(sMessage);

                msg.Session = ((MessagesSession)Session["MessagesSession"]);

                StringCollection sc = msg.Process();

                System.Collections.Specialized.StringEnumerator myEnumerator = sc.GetEnumerator();
                while (myEnumerator.MoveNext())
                {
                    strRdo += myEnumerator.Current + "\n";
                }

                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(sMessage);
                    int iUnitId = GetUnitIdForLogging(doc);

                    if (iUnitId != -1)
                    {
                        System.Configuration.AppSettingsReader appSettings = new System.Configuration.AppSettingsReader();
                        string CCunitId = (string)appSettings.GetValue("UnitID", typeof(string));
                        LogMsgDB(iUnitId, int.Parse(CCunitId), doc.DocumentElement.Name, sMessage, strRdo.Replace("\n", ""));
                    }
                    else
                    {
                        Logger_AddLogMessage(string.Format("Message.LogMsgDB: Empty unit. xml={0}", sMessage), LoggerSeverities.Error);
                    }
                }
                catch (Exception e)
                {
                    Logger_AddLogException(e);
                }
            }
            catch (Exception e)
            {
                strRdo = e.ToString();
            }

            return(strRdo);
        }
예제 #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);
            }
        }
예제 #5
0
        public bool Message(byte [] msgIn, out byte [] msgOut)
        {
            bool bRdo = false;

            msgOut = null;

            try
            {
                if (_logger == null)
                {
                    System.Configuration.AppSettingsReader appSettings = new System.Configuration.AppSettingsReader();
                    _logger = new Logger(MethodBase.GetCurrentMethod().DeclaringType);
                    DatabaseFactory.Logger = _logger;

                    // *** TODO
                    //               _logger = new FileLogger(LoggerSeverities.Debug, ((string)appSettings.GetValue("ServiceLog", typeof(string))).Replace(".log","BB.log"));
                    //OPS.Comm.Messaging.CommMain.Logger.AddLogMessage += new AddLogMessageHandler(Logger_AddLogMessage);
                    //OPS.Comm.Messaging.CommMain.Logger.AddLogException += new AddLogExceptionHandler(Logger_AddLogException);
                    //DatabaseFactory.Logger=_logger;
                }

                if (Session["MessagesSession"] == null)
                {
                    MessagesSession msgSession = new MessagesSession();
                    Session["MessagesSession"] = msgSession;
                }

                string  strMsgIn  = DecryptMsg(msgIn);
                char [] charsTrim = new char[1];
                charsTrim[0] = '\0';
                strMsgIn     = strMsgIn.Trim(charsTrim);
                string       strMsgOut = "";
                IRecvMessage msg       = null;
                Logger_AddLogMessage("Msg In: " + strMsgIn.Replace("\n", ""), LoggerSeverities.Info);

                msg = MessageFactory.GetReceivedMessage(strMsgIn);

                msg.Session = ((MessagesSession)Session["MessagesSession"]);

                StringCollection sc = msg.Process();



                System.Collections.Specialized.StringEnumerator myEnumerator = sc.GetEnumerator();
                while (myEnumerator.MoveNext())
                {
                    strMsgOut += myEnumerator.Current;
                }

                if (strMsgOut != "")
                {
                    msgOut = EncryptMsg(strMsgOut);
                    Logger_AddLogMessage("Msg Out: " + strMsgOut, LoggerSeverities.Info);
                    string strIP = Context.Request.UserHostAddress;
                    LogMsgDB(strMsgIn, strMsgOut, strIP);
                    bRdo = true;
                }
            }
            catch (Exception e)
            {
                bRdo = false;
            }

            return(bRdo);
        }