public RaptoRConApiControllerBase(IConnectionHost connectionHost) { this.ConnectionHost = connectionHost; var hubConnection = new HubConnection("http://localhost:10505/"); this.MessageHubProxy = hubConnection.CreateHubProxy("MessageHub"); hubConnection.Start().Wait(); }
private async Task <IChannelHost> CreateChannelAsync(ulong channelId, bool ackable) { IChannelHost chanHost = null; IConnectionHost connHost = null; while (true) { _logger.LogDebug(LogMessages.ChannelPool.CreateChannel, channelId); var sleep = false; try { connHost = await _connectionPool .GetConnectionAsync() .ConfigureAwait(false); if (!await connHost.HealthyAsync().ConfigureAwait(false)) { _logger.LogDebug(LogMessages.ChannelPool.CreateChannelFailedConnection, channelId); sleep = true; } } catch { _logger.LogDebug(LogMessages.ChannelPool.CreateChannelFailedConnection, channelId); sleep = true; } if (!sleep) { try { chanHost = new ChannelHost(channelId, connHost, ackable); } catch { _logger.LogDebug(LogMessages.ChannelPool.CreateChannelFailedConstruction, channelId); sleep = true; } } if (sleep) { _logger.LogDebug(LogMessages.ChannelPool.CreateChannelSleep, channelId); await Task .Delay(Config.PoolSettings.SleepOnErrorInterval) .ConfigureAwait(false); continue; // Continue here forever (till reconnection is established). } break; } _flaggedChannels[chanHost.ChannelId] = false; _logger.LogDebug(LogMessages.ChannelPool.CreateChannelSuccess, channelId); return(chanHost); }
private async Task <IChannelHost> CreateChannelAsync(ulong channelId, bool ackable) { IChannelHost chanHost; IConnectionHost connHost = null; while (true) { _logger.LogTrace(LogMessages.ChannelPools.CreateChannel, channelId); var sleep = false; // Get ConnectionHost try { connHost = await _connectionPool.GetConnectionAsync().ConfigureAwait(false); } catch { _logger.LogTrace(LogMessages.ChannelPools.CreateChannelFailedConnection, channelId); sleep = true; } // Create a Channel Host if (!sleep) { try { chanHost = new ChannelHost(channelId, connHost, ackable); await _connectionPool.ReturnConnectionAsync(connHost); // Return Connection (or lose them.) _flaggedChannels[chanHost.ChannelId] = false; _logger.LogDebug(LogMessages.ChannelPools.CreateChannelSuccess, channelId); return(chanHost); } catch { _logger.LogTrace(LogMessages.ChannelPools.CreateChannelFailedConstruction, channelId); sleep = true; } } // Sleep on failure. if (sleep) { if (connHost != null) { await _connectionPool.ReturnConnectionAsync(connHost); } // Return Connection (or lose them.) _logger.LogDebug(LogMessages.ChannelPools.CreateChannelSleep, channelId); await Task .Delay(Options.PoolOptions.SleepOnErrorInterval) .ConfigureAwait(false); } } }
public ChannelHost(ulong channelId, IConnectionHost connHost, bool ackable) { _logger = LogHelper.GetLogger <ChannelHost>(); ChannelId = channelId; _connHost = connHost; Ackable = ackable; MakeChannelAsync().GetAwaiter().GetResult(); }
public async ValueTask ReturnConnectionAsync(IConnectionHost connHost) { if (!await _connections .Writer .WaitToWriteAsync() .ConfigureAwait(false)) { throw new InvalidOperationException(ExceptionMessages.GetConnectionErrorMessage); } await _connections .Writer .WriteAsync(connHost); }
private async Task ReturnConnectionWithOptionalSleep(IConnectionHost connHost, ulong channelId, int sleep) { if (connHost != null) { await _connectionPool.ReturnConnectionAsync(connHost); } // Return Connection (or lose them.) if (sleep > 0) { _logger.LogDebug(LogMessages.ChannelPools.CreateChannelSleep, channelId); await Task .Delay(sleep) .ConfigureAwait(false); } }
public ChannelHost(ulong channelId, IConnectionHost connHost, bool ackable) { ChannelId = channelId; Channel = connHost .Connection .CreateModel(); if (ackable) { Ackable = ackable; Channel.ConfirmSelect(); } Channel.ModelShutdown += ChannelClose; ConnectionHealthy = connHost.HealthyAsync; }
public ConnectionOld(IConnectionHost pConnectionHost = null) { _connectionState = ConnectionState.DISCONNECTED; _tcpClient = null; __bIsReceivingHeader = true; __bInWriting = false; _networkStream = null; _sessionKey = null; _encryptedSessionKey = null; __receiveBuffer = new byte[RECEIVE_BUFFER_SIZE]; __nBytesReceived = 0; __sendMsgQueue = new Queue <MsgBase>(); __receiveMsgQueue = new QuickList <MsgBase>(); __lock = new object(); _pAESMgr = new RijndaelManaged(); _heartBeatTimer = TimerMgr.AddTimer(); _heartBeatTimer.LoopCount(MathEx.INFINITE).Interval(HEART_BEAT_INTERVAL).Handler(_onHeartBeat); _bInUpdateSessionKey = false; _nLastSvrTime = 0; _nLastLocalTime = 0; __nMsgLength = 0; if (pConnectionHost != null) { _pConnectionHost = pConnectionHost; } else { _pConnectionHost = new _DefaultConnectionHost(); } }
private async Task <IChannelHost> CreateChannelAsync(ulong channelId, bool ackable) { IChannelHost chanHost = null; IConnectionHost connHost = null; while (true) { _logger.LogTrace(LogMessages.ChannelPools.CreateChannel, channelId); // Get ConnectionHost try { connHost = await _connectionPool.GetConnectionAsync().ConfigureAwait(false); } catch { _logger.LogTrace(LogMessages.ChannelPools.CreateChannelFailedConnection, channelId); await ReturnConnectionWithOptionalSleep(connHost, channelId, Options.PoolOptions.SleepOnErrorInterval).ConfigureAwait(false); continue; } // Create a Channel Host try { chanHost = new ChannelHost(channelId, connHost, ackable); await ReturnConnectionWithOptionalSleep(connHost, channelId, 0).ConfigureAwait(false); _flaggedChannels[chanHost.ChannelId] = false; _logger.LogDebug(LogMessages.ChannelPools.CreateChannelSuccess, channelId); return(chanHost); } catch { _logger.LogTrace(LogMessages.ChannelPools.CreateChannelFailedConstruction, channelId); await ReturnConnectionWithOptionalSleep(connHost, channelId, Options.PoolOptions.SleepOnErrorInterval).ConfigureAwait(false); } } }
public CommandController(IConnectionHost connectionHost ) : base(connectionHost) { }
public void SetConnectionHost(IConnectionHost host) { _pConnectionHost = host; }