コード例 #1
0
        /// <summary>
        /// Checks a message name and if it's an ACK, decides the outcome
        /// for the message it refers to
        /// </summary>
        /// <param name="msgName">The name of the message</param>
        /// <param name="outcome">The outcome if the message is an ACK</param>
        /// <returns>true if the message should be notified to the sender,
        /// false otherwise</returns>
        private bool HandleAcks(string msgName, ref NotificationArgs args)
        {
            bool notify = true;

            switch (msgName)
            {
            case Tags.AckError:
            {
                args.Outcome = RequestOutcome.MessageError;
                break;
            }

            case Tags.NackMsg:
            {
                args.Outcome = RequestOutcome.WrongMsgFormatNack;
                break;
            }

            case Tags.NackServer:
            {
                args.Outcome = RequestOutcome.ServerNackError;
                break;
            }

            case Tags.AckJammed:
            {
                args.Outcome = RequestOutcome.ServerBusy;
                break;
            }

            case Tags.AckOK:
            case Tags.AckDeferred:
            {
                notify = false;
                break;
            }
            }
            return(notify);
        }
コード例 #2
0
        /// <summary>
        /// Callback method that notifies handlers of the response event
        /// </summary>
        /// <param name="state">It is a NotificationArgs object</param>
        private void NotifyThreadProc(object state)
        {
            NotificationArgs args = (NotificationArgs)state;

            DoNotify(args);
        }
コード例 #3
0
        /// <summary>
        /// Handles notifications
        /// </summary>
        /// <param name="args">The notification data</param>
        private void DoNotify(NotificationArgs args)
        {
            if (args.Outcome == RequestOutcome.SendOK)
            {
                bool          notify    = true;
                MessageAccess msgAccess = new MessageAccess(args.Response.XmlData);
                string        msgId     = msgAccess.GetMessageId();
                if (msgId != null && msgId.Length > 0)
                {
                    if (_msgsIds.ContainsKey(Convert.ToDecimal(msgId)))
                    {
                        string msgName = msgAccess.GetMessageName();
                        notify = HandleAcks(msgName, ref args);
                        if (notify)
                        {
                            string str = string.Format("RequestAdapter - About to notify response: {0}, {1}",
                                                       args.Outcome, args.Response.XmlData);
                            Debug.WriteLine(str);
                            if (_responseHandler != null)
                            {
                                _responseHandler(args.Outcome, args.Response);
                            }

                            _messageCount--;
                            if (_messageCount == 0)
                            {
                                _waiting = false;
                            }
                        }
                        else
                        {
                            string str = string.Format("RequestChannelAdapter.NotifyThreadProc - ACK not notified: {0}",
                                                       args.Response.XmlData);
                            Debug.WriteLine(str);
                        }
                    }
                }
                else
                {
                    string str = string.Format("RequestChannelAdapter.NotifyThreadProc - Bad message: {0}",
                                               args.Response.XmlData);
                    Debug.WriteLine(str);
                }
            }
            else
            {
                string str = string.Format("RequestChannelAdapter.NotifyThreadProc - Notifying error: {0}",
                                           args.Outcome);
                Debug.WriteLine(str);
                if (_responseHandler != null)
                {
                    _responseHandler(args.Outcome, null);
                }

                UninitializeChannel(_channel);
                string uri = _channel.Uri;
                try
                {
                    str = string.Format("RequestChannelAdapter.NotifyThreadProc - Closing channel: {0}",
                                        uri);
                    Debug.WriteLine(str);
                    Parameterization.ChannelManager.CloseChannel(uri);

/*					str = string.Format("RequestChannelAdapter.NotifyThreadProc - Opening channel: {0}",
 *                                              uri);
 *                                      Debug.WriteLine(str);
 *                                      _channel = Parameterization.ChannelManager.OpenChannel(uri);
 *                                      InitializeChannel(_channel);
 *                                      str = string.Format("RequestChannelAdapter.NotifyThreadProc - Reattached to channel: {0}",
 *                                              uri);
 *                                      Debug.WriteLine(str);*/
                }
                catch (Exception ex)
                {
                    //str = string.Format("RequestChannelAdapter.NotifyThreadProc - Error reopening channnel: {0}", ex.Message);
                    //Debug.WriteLine(str);
                    CommMain.Logger.AddLog(ex);
                }
            }
        }