Ejemplo n.º 1
0
        /// <summary>
        /// Converts event type to string.
        /// </summary>
        /// <param name="evType">Event type.</param>
        /// <returns>String.</returns>
        public static string EventTypeToString(ConnectionEventType evType)
        {
            switch (evType)
            {
            case ConnectionEventType.ConnectingFailed:
                return("Connecting failed");

            case ConnectionEventType.ConnectionLost:
                return("Connection lost");

            case ConnectionEventType.ConnectionRestored:
                return("Connection restored");

            case ConnectionEventType.ConnectionRestoreFailed:
                return("Connection restore failed");

            case ConnectionEventType.ConnectionTerminatedByUser:
                return("Connection terminated by user");

            case ConnectionEventType.RestoringConnection:
                return("Restoring connection");

            case ConnectionEventType.TerminatingConnectionByUser:
                return("User asked to terminate connection");

            default:
                // Connecting
                // Connected
                return(evType.ToString());
            }
        }
 //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
 //ORIGINAL LINE: private void onEvent(final Connection conn, final String remoteAddress, final ConnectionEventType type)
 private void onEvent(Connection conn, string remoteAddress, ConnectionEventType type)
 {
     if (eventListener != null)
     {
         eventExecutor.onEvent(new TempRunnable(eventListener, type, remoteAddress, conn));
     }
 }
 public TempRunnable(ConnectionEventListener eventListener, ConnectionEventType type, string remoteAddress, Connection conn)
 {
     this.eventListener = eventListener;
     this.type          = type;
     this.remoteAddress = remoteAddress;
     this.conn          = conn;
 }
Ejemplo n.º 4
0
        private void TelnetBufferWrite()
        {
            if (WriteBuffer == null)
            {
                return;
            }

            ConnectionEventType type = ConnectionEventType.Error;

            if (MyTelnetConnection.WriteLine(WriteBuffer))
            {
                if ((Input == CommandState.AcceptSLID) && (_slid == null))
                {
                    // wrote a slid manually set via the console
                    _slid = WriteBuffer;
                }

                type = ConnectionEventType.Write;
            }
            else
            {
                Input = CommandState.RejectAll;
            }

            OnCommunicationEvent(this, new ONTEventArgs(type, WriteBuffer));

            WriteBuffer = null;
        }
Ejemplo n.º 5
0
        private string GenerateDescription(ConnectionEventType eventType, string errorReason)
        {
            string description = ConnectionEvent.EventTypeToString(eventType);

            // Add more information to the description?
            switch (eventType)
            {
            case ConnectionEventType.Connecting:
                description += " to " + FormatConnectionInfo();
                break;

            case ConnectionEventType.ConnectingFailed:
                description += string.Format(". Suspected reason: {0}. Check parameters and retry.", errorReason);
                break;

            case ConnectionEventType.ConnectionRestoreFailed:
                description += string.Format(". Suspected reason: {0}. Retrying in {1} s.",
                                             errorReason, RetryIntervalSeconds);
                break;

            default:
                break;
            }

            return(description);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Constructor. Use this when the state is related to an error.
 /// </summary>
 /// <param name="connMaint">Whether the connection is being maintained or at least attempted.</param>
 /// <param name="evType">Current state of connection.</param>
 /// <param name="desc">Event description.</param>
 /// <param name="errReason">Error reason.</param>
 /// <param name="excep">Exception related to the error.</param>
 public ConnectionEvent(bool connMaint, ConnectionEventType evType, string desc, ErrorReasonType errReason, Exception excep)
 {
     IsConnectionMaintained = connMaint;
     EventType        = evType;
     Description      = desc;
     ErrorReason      = errReason;
     RelatedException = excep;
 }
Ejemplo n.º 7
0
            private bool CloseConnection(ConnectionEventType eventType)
            {
                if (this.OnConnectionEvent == null)
                {
                    return(false);
                }
                ConnectionEventArgs args = new ConnectionEventArgs(eventType);

                this.OnConnectionEvent(this, args);
                return(args.Close);
            }
        /// <summary>
        /// Construct a new <b>ConnectionEventArgs</b>.
        /// </summary>
        /// <param name="connection">
        /// The <see cref="IConnection"/> for which the event applies.
        /// </param>
        /// <param name="eventType">
        /// The event's type, one of <see cref="ConnectionEventType"/>
        /// enumeration values.
        /// </param>
        /// <param name="exc">
        /// An optional <b>Exception</b> associated with the event.
        /// </param>
        public ConnectionEventArgs(IConnection connection, ConnectionEventType eventType, Exception exc)
        {
            m_connection = connection;

            if (eventType < ConnectionEventType.Opened || eventType > ConnectionEventType.Error)
            {
                throw new ArgumentException();
            }

            m_eventType = eventType;
            m_exception = exc;
        }
        /// <summary>
        /// Dispatch events.
        /// </summary>
        /// <param name="type"> ConnectionEventType </param>
        /// <param name="remoteAddress"> remoting address </param>
        /// <param name="connection"> Connection </param>
        public virtual void onEvent(ConnectionEventType type, string remoteAddress, Connection connection)
        {
            var isGetValue = processors.TryGetValue(type, out var processorList);

            if (isGetValue)
            {
                foreach (ConnectionEventProcessor processor in processorList)
                {
                    processor.onEvent(remoteAddress, connection);
                }
            }
        }
        /// <summary>
        /// Add event processor.
        /// </summary>
        /// <param name="type"> ConnectionEventType </param>
        /// <param name="processor"> ConnectionEventProcessor </param>
        public virtual void addConnectionEventProcessor(ConnectionEventType type, ConnectionEventProcessor processor)
        {
            var isGetValue = processors.TryGetValue(type, out var processorList);

            if (!isGetValue)
            {
                if (!processors.ContainsKey(type))
                {
                    processors.AddOrUpdate(type, new List <ConnectionEventProcessor>(1), (key, oldValue) => new List <ConnectionEventProcessor>(1));
                }
                processors.TryGetValue(type, out processorList);
            }
            processorList.Add(processor);
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
0
 public ONTEventArgs(ConnectionEventType t, String s)
 {
     Type    = t;
     Message = s;
 }
 /// <summary>
 /// Construct a new <b>ConnectionEventArgs</b>.
 /// </summary>
 /// <param name="connection">
 /// The <see cref="IConnection"/> for which the event applies.
 /// </param>
 /// <param name="eventType">
 /// The event's type, one of <see cref="ConnectionEventType"/>
 /// enumeration values.
 /// </param>
 public ConnectionEventArgs(IConnection connection, ConnectionEventType eventType)
     : this(connection, eventType, null)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Add processor to process connection event.
 /// </summary>
 /// <param name="type"> connection event type </param>
 /// <param name="processor"> connection event processor </param>
 public virtual void addConnectionEventProcessor(ConnectionEventType type, ConnectionEventProcessor processor)
 {
     connectionEventListener.addConnectionEventProcessor(type, processor);
 }
 public abstract void addConnectionEventProcessor(ConnectionEventType type, ConnectionEventProcessor processor);
Ejemplo n.º 16
0
 public virtual void addConnectionEventProcessor(ConnectionEventType type, ConnectionEventProcessor processor)
 {
     this.server.addConnectionEventProcessor(type, processor);
 }
Ejemplo n.º 17
0
 public ConnectionEvent(ClientContract source, ConnectionEventType type, DateTime eventTime)
 {
     Source = source;
     Type = type;
     EventTime = eventTime;
 }
Ejemplo n.º 18
0
 private void InvokeConnectionEvent(ConnectionEventType evCtg, bool connectionMaintained)
 {
     SendConnectionEvent(connMaint: connectionMaintained, evType: evCtg);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Constructor. Use this when the event is *not* related to an error.
 /// </summary>
 /// <param name="connMaint">Whether the connection is being maintained or at least attempted.</param>
 /// <param name="evType">Current state of connection.</param>
 /// <param name="desc">Event description.</param>
 public ConnectionEvent(bool connMaint, ConnectionEventType evType, string desc)
     : this(connMaint : connMaint, evType : evType, desc : desc, errReason : ErrorReasonType.Other, excep : null)
 {
     // Empty ctor body
 }
Ejemplo n.º 20
0
 public AppConnectionEvent(AppConnectionDescriptor connection, ConnectionEventType type)
 {
     Connection = connection;
     Type       = type;
 }
Ejemplo n.º 21
0
 public override void addConnectionEventProcessor(ConnectionEventType type, ConnectionEventProcessor processor)
 {
     connectionEventListener.addConnectionEventProcessor(type, processor);
 }
Ejemplo n.º 22
0
 internal SimConnectEventArgs(ConnectionEventType connectionEventType, string message)
 {
     Message   = message;
     EventType = connectionEventType;
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Sends a connection event. Use this when there is no error.
 /// </summary>
 /// <param name="connMaint">Whether connection is still being maintained or at least tried to reconnect.</param>
 /// <param name="evType">Event type.</param>
 protected void SendConnectionEvent(bool connMaint, ConnectionEventType evType)
 {
     SendConnectionEvent(connMaint, evType, null); // No relevant exception in this overload
 }
Ejemplo n.º 24
0
 public ConnectionEventArgs(ConnectionEventType t)
 {
     EventType = t;
     Close     = false;
 }