// methods /// <inheritdoc/> public void Authenticate(IConnection connection, ConnectionDescription description, CancellationToken cancellationToken) { Ensure.IsNotNull(connection, nameof(connection)); Ensure.IsNotNull(description, nameof(description)); // If we don't have SaslSupportedMechs as part of the response, that means we didn't piggyback the initial // hello or legacy hello request and should query the server (provided that the server >= 4.0), merging results into // a new ConnectionDescription if (!description.IsMasterResult.HasSaslSupportedMechs && Feature.ScramSha256Authentication.IsSupported(description.ServerVersion)) { var command = CustomizeInitialIsMasterCommand(HelloHelper.CreateCommand()); var helloProtocol = HelloHelper.CreateProtocol(command, _serverApi); var helloResult = HelloHelper.GetResult(connection, helloProtocol, cancellationToken); var mergedHelloResult = new IsMasterResult(description.IsMasterResult.Wrapped.Merge(helloResult.Wrapped)); description = new ConnectionDescription( description.ConnectionId, mergedHelloResult, description.BuildInfoResult); } var authenticator = GetOrCreateAuthenticator(connection, description); authenticator.Authenticate(connection, description, cancellationToken); }
private HelloResult GetHelloResult( IConnection connection, CommandWireProtocol <BsonDocument> helloProtocol, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (_heartbeatStartedEventHandler != null) { _heartbeatStartedEventHandler(new ServerHeartbeatStartedEvent(connection.ConnectionId, connection.Description.HelloResult.TopologyVersion != null)); } try { var stopwatch = Stopwatch.StartNew(); var helloResult = HelloHelper.GetResult(connection, helloProtocol, cancellationToken); stopwatch.Stop(); if (_heartbeatSucceededEventHandler != null) { _heartbeatSucceededEventHandler(new ServerHeartbeatSucceededEvent(connection.ConnectionId, stopwatch.Elapsed, connection.Description.HelloResult.TopologyVersion != null)); } return(helloResult); } catch (Exception ex) { if (_heartbeatFailedEventHandler != null) { _heartbeatFailedEventHandler(new ServerHeartbeatFailedEvent(connection.ConnectionId, ex, connection.Description.HelloResult.TopologyVersion != null)); } throw; } }
private void btnShowHelllo_Click(object sender, EventArgs e) { MessageBox.Show( HelloHelper.SayHello(txbInput.Text), "Hello!", MessageBoxButtons.OK, MessageBoxIcon.None); }
protected void OnBtnShowHelloPressed(object sender, EventArgs e) { var dialog = new MessageDialog( this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, HelloHelper.SayHello(txbInput.Text) ); dialog.Run(); dialog.Destroy(); }
// private methods private CommandWireProtocol <BsonDocument> InitializeHelloProtocol(IConnection connection) { BsonDocument helloCommand; var commandResponseHandling = CommandResponseHandling.Return; if (connection.Description.IsMasterResult.TopologyVersion != null) { connection.SetReadTimeout(_serverMonitorSettings.ConnectTimeout + _serverMonitorSettings.HeartbeatInterval); commandResponseHandling = CommandResponseHandling.ExhaustAllowed; var veryLargeHeartbeatInterval = TimeSpan.FromDays(1); // the server doesn't support Infinite value, so we set just a big enough value var maxAwaitTime = _serverMonitorSettings.HeartbeatInterval == Timeout.InfiniteTimeSpan ? veryLargeHeartbeatInterval : _serverMonitorSettings.HeartbeatInterval; helloCommand = HelloHelper.CreateCommand(connection.Description.IsMasterResult.TopologyVersion, maxAwaitTime); } else { helloCommand = HelloHelper.CreateCommand(); } return(HelloHelper.CreateProtocol(helloCommand, _serverApi, commandResponseHandling)); }
public async Task RunAsync() { var helloOk = false; while (!_cancellationToken.IsCancellationRequested) { try { if (_roundTripTimeConnection == null) { await InitializeConnectionAsync().ConfigureAwait(false); // sets _roundTripTimeConnection } else { var helloCommand = HelloHelper.CreateCommand(_serverApi, helloOk); var helloProtocol = HelloHelper.CreateProtocol(helloCommand, _serverApi); var stopwatch = Stopwatch.StartNew(); var helloResult = await HelloHelper.GetResultAsync(_roundTripTimeConnection, helloProtocol, _cancellationToken).ConfigureAwait(false); stopwatch.Stop(); AddSample(stopwatch.Elapsed); helloOk = helloResult.HelloOk; } } catch (Exception) { IConnection toDispose; lock (_lock) { toDispose = _roundTripTimeConnection; _roundTripTimeConnection = null; } toDispose?.Dispose(); } await Task.Delay(_heartbeatInterval, _cancellationToken).ConfigureAwait(false); } }
// private methods private void MonitorServer() { var helloOk = false; while (!_cancellationToken.IsCancellationRequested) { try { if (_roundTripTimeConnection == null) { InitializeConnection(); // sets _roundTripTimeConnection } else { var helloCommand = HelloHelper.CreateCommand(_serverApi, helloOk); var helloProtocol = HelloHelper.CreateProtocol(helloCommand, _serverApi); var stopwatch = Stopwatch.StartNew(); var helloResult = HelloHelper.GetResult(_roundTripTimeConnection, helloProtocol, _cancellationToken); stopwatch.Stop(); AddSample(stopwatch.Elapsed); helloOk = helloResult.HelloOk; } } catch (Exception) { IConnection toDispose; lock (_lock) { toDispose = _roundTripTimeConnection; _roundTripTimeConnection = null; } toDispose?.Dispose(); } ThreadHelper.Sleep(_heartbeatInterval, _cancellationToken); } }
private void HelloButton_OnClicked(object sender, EventArgs e) { DisplayAlert("Hello!", HelloHelper.SayHello(TxbInput.Text), "OK"); }
private static void Main(string[] args) { var name = (args.Length > 0) ? args[0] : string.Empty; Console.WriteLine(HelloHelper.SayHello(name)); }