private void Client_ConnectionClosed(object sender, ConnectionClosedEventArgs e) { if (AutoReconnect) { Connect(); } }
/// <summary> /// Rasied when Gateway Connection is closed /// </summary> private void OnConnectionClosed(object sender, ConnectionClosedEventArgs eventArgs) { try { if (LogoutArrived != null) { LogonArrived(_marketDataProviderName); } if (Logger.IsInfoEnabled) { Logger.Info("Connection closed", _type.FullName, "OnConnectionClosed"); } // Unhook Gateway Events UnregisterGatewayEvents(); // Attempt Logon if the Logout was not requested by the user if (!_logoutRequest) { // Send Logon request Start(); } } catch (Exception exception) { Logger.Error(exception, _type.FullName, "OnConnectionClosed"); } }
internal override void OnConnectionClosedInternalSynchronized(ConnectionClosedEventArgs args) { base.OnConnectionClosedInternalSynchronized(args); args.Connection.Dispose(); this.Connection = null; }
protected virtual async Task HandleRemotePeerAsync(RemoteTcpPeer remoteTcpPeer, CancellationToken cancellationToken) { try { await this.ReceiveFromRemotePeerAsync(remoteTcpPeer, cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { if (!cancellationToken.IsCancellationRequested) { remoteTcpPeer.ConnectionCloseReason = ConnectionCloseReason.Timeout; return; } else { remoteTcpPeer.ConnectionCloseReason = ConnectionCloseReason.LocalShutdown; return; } } catch (Exception ex) { var unhandledErrorEventArgs = new UnhandledErrorEventArgs(new ErrorData(ex)); this.OnUnhandledError(unhandledErrorEventArgs); } var connectionClosedEventArgs = new ConnectionClosedEventArgs(new ConnectionClosedData(remoteTcpPeer, remoteTcpPeer.ConnectionCloseReason)); this.OnConnectionClosed(remoteTcpPeer, connectionClosedEventArgs); }
/// <summary> /// Raises the Close event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="ConnectionClosedEventArgs"/> instance containing the event data.</param> public override void OnClose(IWebSocketConnection sender, ConnectionClosedEventArgs args) { Logger.Info($"{sender.ClientIdentifier}/{sender.UniqueIdentifier} disconnected"); UnregisterInExtensions(sender); base.OnClose(sender, args); }
private static async Task OnClientClosed(object?sender, ConnectionClosedEventArgs args, CancellationToken cancellationToken) { if (_client != null) { await _client.CloseAsync(); } Console.WriteLine($"Closed: {args.Description}"); }
/// <summary> /// Handles a closed connection. /// </summary> /// <param name="connection">The connection.</param> /// <param name="wasLast">Whether the connection was the last one.</param> public ValueTask OnConnectionClosed(MemberConnection connection, bool wasLast) { var args = new ConnectionClosedEventArgs(wasLast); // trigger ConnectionRemoved event return(ForEachHandler <ConnectionClosedEventHandler, ConnectionClosedEventArgs>( (handler, sender, a) => handler.HandleAsync(sender, a), args)); }
private void HandleConnectionClosed(object sender, ConnectionClosedEventArgs e) { Console.WriteLine($"Purging {sender}"); var connection = sender as IConnection; SopronMessageProcessor.Remove(connection); Modules.Remove(Connections[connection]); Connections.Remove(connection); }
protected override void OnConnectionClosed(ConnectionClosedEventArgs args) { if (this.session != null) { this.session?.Close(); rpcPeer.OnSessionClosed(new SessionClosedEventArgs(this.session, this)); } base.OnConnectionClosed(args); }
private void ConnectionClosed(object sender, ConnectionClosedEventArgs e) { log.Info("TpsService: Connection is Closed."); TpsConnectionClosed?.Invoke(); peer?.Dispose(); peer = null; awaitaiblePeer?.Dispose(); awaitaiblePeer = null; }
private void OnConnectionClosed(object sender, ConnectionClosedEventArgs args) { if (args.ClosedByPeer) { Log.ConnectionClosed(_logger, args.Error); _writer.TryWrite(ConnectCommand.Instance); } ConnectionClosed?.Invoke(sender, args); }
private static void OnConnectionClosed(object sender, ConnectionClosedEventArgs e) { LogUtility.LogMessage("Connection closed"); SetState(ConnectionState.Disconnected); if (ReconnectIsAllowed()) { ReconnectProcess.Begin(); } }
void CloseInternal(DisconnectReason reason, UdpRawMessage payload) { if (Status == UdpConnectionStatus.Disconnected) { return; } ChangeStatus(UdpConnectionStatus.Disconnected); logger.Trace($"{this} closing with ({reason})"); var disconnectReq_ = disconnectReq; if (disconnectReq_ != null) { disconnectReq_.Dispose(); disconnectReq = null; } var args = new ConnectionClosedEventArgs(this, reason, payload); logger.Trace($"{this} closing pre event syncronization"); peer.Configuration.SynchronizeSafe(() => { logger.Trace($"{this} firing event connection OnConnectionClosed"); try { OnConnectionClosed(args); } catch (Exception ex) { logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnConnectionClosed)}: {ex}"); } logger.Trace($"{this} firing event peer OnConnectionClosed"); peer.OnConnectionClosedInternalSynchronized(args); logger.Trace($"{this} events fired"); }, logger); logger.Trace($"{this} closing post event syncronization"); var connectTcs_ = this.connectTcs; if (connectTcs_ != null) { connectTcs_.TrySetException(new ConnectionFailed(reason)); } var disconnectTcs_ = this.disconnectTcs; if (disconnectTcs_ != null) { disconnectTcs_.TrySetResult(null); } logger.Info($"{this} closed ({reason})"); }
protected virtual void OnConnectionClosed(RemoteTcpPeer remoteTcpPeer, ConnectionClosedEventArgs e) { try { remoteTcpPeer.OnConnectionClosed(e); this.ConnectionClosed?.Invoke(this, e); } catch (Exception ex) { var unhandledErrorEventArgs = new UnhandledErrorEventArgs(new ErrorData(ex)); this.OnUnhandledError(unhandledErrorEventArgs); } }
private void OnConnectionClosedEvent(object sender, ConnectionClosedEventArgs e) { if (Player == null) { return; } if (Player.Level != null) { Player.Level.RemovePlayer(Player); } Player.Level = null; }
internal virtual void OnConnectionClosedInternalSynchronized(ConnectionClosedEventArgs args) { try { OnConnectionClosed(args); } catch (Exception ex) { Logger.Error($"Unhandled exception on {args.Connection.GetType().Name}.{nameof(OnConnectionClosed)}: {ex}"); } try { OnConnectionClosedEvent?.Invoke(args); } catch (Exception ex) { Logger.Error($"Unhandled exception on {args.Connection.GetType().Name}.{nameof(OnConnectionClosedEvent)}: {ex}"); } }
private void OnWebsocketClosed(object sender, EventArgs eventArgs) { Log.Debug("OnWebsocketClosed called"); ConnectionClosedEventArgs connectionClosedEventArg; try { Log.Error("OnWebsocketClosed called from: " + sender.ToString() + ", Reason:" + JsonConvert.SerializeObject(eventArgs)); ClosedEventArgs closedArgs = (ClosedEventArgs)eventArgs; connectionClosedEventArg = new ConnectionClosedEventArgs(closedArgs.Code, closedArgs.Reason); } catch (System.InvalidCastException ex) { Log.Trace($"Can't cast ClosedEventArgs: '{ex}'"); connectionClosedEventArg = ConnectionClosedEventArgs.Empty; } this.receivedIOConnected = false; this.ConnectionClosed?.Invoke(this, connectionClosedEventArg); }
protected virtual async Task HandleRemotePeerAsync(RemoteTcpPeer remoteTcpPeer, CancellationToken cancellationToken) { try { await this.ReceiveFromRemotePeerAsync(remoteTcpPeer, cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException ex) { if (!cancellationToken.IsCancellationRequested) { remoteTcpPeer.ConnectionCloseReason = ConnectionCloseReason.Timeout; } else { remoteTcpPeer.ConnectionCloseReason = ConnectionCloseReason.LocalShutdown; } remoteTcpPeer.ConnectionCloseException = ex; } catch (Exception ex) { remoteTcpPeer.ConnectionCloseReason = ConnectionCloseReason.ExceptionOccured; remoteTcpPeer.ConnectionCloseException = ex; var ue = new ExceptionEventArgs(ex); this.OnUnhandledException(ue); } this.RemoveRemoteTcpPeerFromConnectedList(remoteTcpPeer.IPEndPoint); var connectionClosedEventArgs = new ConnectionClosedEventArgs(remoteTcpPeer) { ConnectionCloseException = remoteTcpPeer.ConnectionCloseException, ConnectionCloseReason = remoteTcpPeer.ConnectionCloseReason }; this.OnConnectionClosed(remoteTcpPeer, connectionClosedEventArgs); }
protected virtual void OnConnectionClosed(RemoteTcpPeer remoteTcpPeer, ConnectionClosedEventArgs e) { try { remoteTcpPeer.OnConnectionClosed(e); } catch (Exception ex) { var ue = new ExceptionEventArgs(ex); this.OnUnhandledException(ue); } try { this.ConnectionClosed?.Invoke(this, e); } catch (Exception ex) { var ue = new ExceptionEventArgs(ex); this.OnUnhandledException(ue); } }
private void OnWebsocketClosed(object sender, EventArgs eventArgs) { ConnectionClosedEventArgs connectionClosedEventArg; try { WebSocket4Net.ClosedEventArgs closedArgs = (WebSocket4Net.ClosedEventArgs)eventArgs; connectionClosedEventArg = new ConnectionClosedEventArgs(closedArgs.Code, closedArgs.Reason); Log.Debug("WebSocket_Closed: Code: " + closedArgs.Code + ", Reason: " + closedArgs.Reason); } catch (System.InvalidCastException ex) { Log.Trace($"Can't cast ClosedEventArgs: '{ex}'"); connectionClosedEventArg = ConnectionClosedEventArgs.Empty; } this.receivedIOConnected = false; this.ConnectionClosed?.Invoke(this, connectionClosedEventArg); if (this.AutoReconnect && !this.reconnectInProgress) { this.reconnectInProgress = true; CancellationTokenSource tokenSource = new CancellationTokenSource(); this.reconnectTaskCancellationToken = tokenSource.Token; this.reconnectTask = Task.Run( () => { CancellationTokenSource source = new CancellationTokenSource(); while (!this.IsConnected() && !source.IsCancellationRequested) { Log.Info($"Trying to reconnect to '{this.MsbUrl}'"); bool connected = this.ConnectAsync().Result; Thread.Sleep(this.AutoReconnectIntervalInMilliseconds); } }, this.reconnectTaskCancellationToken); } }
private void HandleConnectionClosed(object sender, ConnectionClosedEventArgs e) { Connected.Reset(); new Thread((ThreadStart)async delegate { // attempt to reconnect while (!Connected.WaitOne(0)) { try { Connection.Close(); } catch { } //Thread.Sleep(5000); try { await Connect(ConnectionUri); await Handshake(); } catch (Exception ex) { } } Console.WriteLine("Reconnected"); }).Start(); }
internal void OnConnectionClosedInternal(ConnectionClosedEventArgs args) { }
//This event is raised when the connection to TWS client closed. private void _client_ConnectionClosed(object sender, ConnectionClosedEventArgs e) { RaiseEvent(Disconnected, this, new DataSourceDisconnectEventArgs(Name, "")); }
protected async Task InvokeConnectionClosed() { var handler = ConnectionClosed; var eventArgs = new ConnectionClosedEventArgs(); if (handler != null) { await Task.Factory.FromAsync<object, ConnectionClosedEventArgs>(handler.BeginInvoke, handler.EndInvoke, this, eventArgs, null); } }
private void _client_ConnectionClosed(object sender, ConnectionClosedEventArgs e) { Dispatcher.Invoke(() => _logger.Log(NLog.LogLevel.Error, string.Format("Instrument Adder connection closed."))); }
private void GesturesService_ConnectionClosed(object sender, ConnectionClosedEventArgs e) { WriteLogMessage($"ConnectionClosed", Colors.Red); }
private void OnClosed() { var connectionClosedEvent = new ConnectionClosedEventArgs(); ConnectionClosed?.Invoke(this, connectionClosedEvent); }
private void OnConnectionClosed(object sender, ConnectionClosedEventArgs e) { NetworkConnection connection = e.Connection; Console.WriteLine("#{0}: {1} disconnected to service", connection.BelongListener.Name, connection.Id); }
void _server_ConnectionClosed(object sender, ConnectionClosedEventArgs args) { App.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => StatusMessages.Add("Client disconnected."))); }
internal void OnConnectionClosedInternal(ConnectionClosedEventArgs args) { tcsSessionOpened?.TrySetException(new InvalidOperationException("Connection closed prematurely")); }
protected override void OnConnectionClosed(ConnectionClosedEventArgs args) { parent.OnConnectionClosedInternal(args); base.OnConnectionClosed(args); }
private void GameClient_ConnectionClosed(object sender, ConnectionClosedEventArgs e) { MessageBox.Show("Связь с сервером потеряна. Вы можете сохранить игру."); }
void ibclient_ConnectionClosed(object sender, ConnectionClosedEventArgs e) { tStart("ibclient_ConnectionClosed()"); //Console.WriteLine("Stingray: Connection to TWS closed"); logger.AddLog(LoggerLevel.Error, "ConnectionClosed()"); bool callDisconnect = false; lock (private_lock) { _twsConnected = false; if (ibclient != null && ibclient.Connected) callDisconnect = true; Accounts.Disconnect(); } // if(callDisconnect) //try //{ // if(callDisconnect) ibclient.Disconnect(); //} //catch (Exception /*ex*/) //{ // // MessageBox.Show("ibclient_ConnectionClosed: Disconnect: " + ex.Message); // ibclient = null; //} ibclient = null; ordersValid = false; positionsValid = false; _isConnected = false; EmitDisconnected(); tEnd("ibclient_ConnectionClosed()"); }