コード例 #1
0
        private bool CanProcess(MultiPartMessage msg)
        {
            VocollectSession session = SessionManager.Instance[msg.Properties.ReadAsString("SerialNumber")];

            /* Safe guard to ensure reset of session after new logon */
            if ((session != null) && (msg.Properties.ReadAsString("MessageType") == "PrTaskLUTCoreConfiguration"))
            {
                SessionManager.Instance.DestroySession(msg.Properties.ReadAsString("SerialNumber"));
                session.Dispose();
                session = null;
            }

            TcpAdapterEndPoint endPoint = MessageEngine.Instance.AdapterProxy.ResolveUriToEndPoint((Uri)msg.Metadata.Read("ReceiveUri")) as TcpAdapterEndPoint;

            if ((session != null) && (endPoint != null))
            {
                try
                {
                    if (!session.AcquireLock(Configuration.ReadAsInt("PendingOperationsTimeout")))
                    {
                        /* Thread timed out or aborted due to a newer request */
                        if ((MessageEngine.Instance.Tracing.Switch.Level & SourceLevels.Warning) == SourceLevels.Warning)
                        {
                            MessageEngine.Instance.Tracing.TraceEvent(TraceEventType.Warning, 0, "Thread timed out waiting for a pending operation to complete.");
                        }

                        return(false);
                    }
                }
                catch (ObjectDisposedException)
                {
                    return(false);
                }

                lock (endPointDictionary)
                {
                    endPointDictionary.Add(endPoint, session);
                }

                if (IsDuplicate(msg, session, endPoint))
                {
                    /* Message is duplicate, retransmit last response */
                    if ((MessageEngine.Instance.Tracing.Switch.Level & SourceLevels.Warning) == SourceLevels.Warning)
                    {
                        MessageEngine.Instance.Tracing.TraceEvent(TraceEventType.Warning, 0, "Message timeout detected, retransmitting last response.");
                    }

                    MultiPartMessage retransmitMsg = session.LastResponseMessage;
                    retransmitMsg.Metadata.Write("Loopback", false);
                    retransmitMsg.Metadata.Write("SendUri", msg.Metadata.Read("ReceiveUri"));

                    MessageEngine.Instance.TransmitMessage(retransmitMsg);

                    return(false);
                }
                else
                {
                    /* Message is valid, continue processing */
                    session.LastRequestMessage  = msg;
                    session.LastResponseMessage = null;
                }
            }

            return(true);
        }