示例#1
0
        internal void SetChannelState(ChannelState state, ErrorInfo error = null, ProtocolMessage protocolMessage = null)
        {
            if (Logger.IsDebug)
            {
                var errorMessage = error != null ? "Error: " + error : "";
                Logger.Debug($"#{Name}: Changing state to: '{state}'. {errorMessage}");
            }

            OnError(error);
            var previousState = State;

            HandleStateChange(state, error, protocolMessage);

            //Notify internal clients on the Managed thread
            InternalStateChanged.Invoke(this, new ChannelStateChange(state, previousState, error));

            //Notify external client using the thread they subscribe on
            RealtimeClient.NotifyExternalClients(() =>
            {
                var args = new ChannelStateChange(state, previousState, error);
                try
                {
                    StateChanged.Invoke(this, args);
                }
                catch (Exception ex)
                {
                    Logger.Error($"Error notifying event handlers for state change: {state}", ex);
                }

                Emit(state, args);
            });
        }
示例#2
0
        private void ClearAllDelegatesOfStateChangeEventHandler()
        {
            foreach (var d in InternalStateChanged.GetInvocationList())
            {
                InternalStateChanged -= (EventHandler <ConnectionStateChange>)d;
            }

            foreach (var handler in ConnectionStateChanged.GetInvocationList())
            {
                ConnectionStateChanged -= (EventHandler <ConnectionStateChange>)handler;
            }
        }
示例#3
0
        /// <summary>
        /// Handle internal Pool state changed events.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        private void OnStateChanged(object source, RunspacePoolStateChangedEventArgs args)
        {
            if (ConnectionInfo is NewProcessConnectionInfo)
            {
                NewProcessConnectionInfo connectionInfo = ConnectionInfo as NewProcessConnectionInfo;
                if (connectionInfo.Process != null &&
                    (args.RunspacePoolStateInfo.State == RunspacePoolState.Opened ||
                     args.RunspacePoolStateInfo.State == RunspacePoolState.Broken))
                {
                    connectionInfo.Process.RunspacePool = this;
                }
            }

            // call any event handlers on this, replacing the
            // internalPool sender with 'this' since receivers
            // are expecting a RunspacePool
            InternalStateChanged.SafeInvoke(this, args);
        }