コード例 #1
0
        private void ShowConnectionStatus(ConnectionEvent connEv)
        {
            // Category to string
            var msg = connEv.Description;

            // 1) Update connection expander header
            ConnectionExpander.Header = connEv.EventTypeString;

            // 2) Update the status label
            SetConnectionStatusText(text: msg, isProblem: connEv.IsError);

            // 3) In status log, show the message with a timestamp and the numeric status ID
            var fullMsg = string.Format("{0} {1}{2}",
                                        DateTime.Now.ToString("d.M. H.mm.ss"),
                                        msg,
                                        Environment.NewLine
                                        );

            ConnectionLogTextBox.AppendText(fullMsg);

            // Scrolling the status log to the bottom
            ConnectionLogTextBox.ScrollToEnd();
        }
コード例 #2
0
        /// <summary>
        /// Sends a connection event. Use this for errors.
        /// </summary>
        /// <param name="connMaint">Whether connection is still being maintained or at least tried to reconnect.</param>
        /// <param name="evType">Event type.</param>
        /// <param name="exc">Related exception.</param>
        protected void SendConnectionEvent(bool connMaint, ConnectionEventType evType, Exception exc)
        {
            bool disposedTemp;

            lock (m_lockObject)
            {
                disposedTemp = m_disposed;
            }

            // No callbacks after dispose except termination.
            // If dispose is called right after the condition, the callback can
            // occur after it, but this is unlikely and unimportant.
            if (disposedTemp &&
                evType != ConnectionEventType.TerminatingConnectionByUser &&
                evType != ConnectionEventType.ConnectionTerminatedByUser)
            {
                return;
            }

            // Event related to an error?
            if (exc != null)
            {
                var errorReason = AmqpErrorHandler.GetErrorReason(exc);
                var description = GenerateDescription(evType, errorReason.ToString());

                var connEvent = new ConnectionEvent(connMaint: connMaint, evType: evType,
                                                    desc: description, errReason: errorReason, excep: exc);
                b_connectionEventCallback(connEvent);
            }
            else
            {
                var description = GenerateDescription(evType, "");

                var connEvent = new ConnectionEvent(connMaint: connMaint, evType: evType, desc: description);
                b_connectionEventCallback(connEvent);
            }
        }