public static bool AddNode(IConnectionManager connectionManager, IPeerBanning peerBanning, string endpointStr, string command) { IPEndPoint endpoint = endpointStr.ToIPEndPoint(connectionManager.Network.DefaultPort); switch (command) { case "add": if (peerBanning.IsBanned(endpoint)) { throw new InvalidOperationException("Can't perform 'add' for a banned peer."); } connectionManager.AddNodeAddress(endpoint); break; case "remove": connectionManager.RemoveNodeAddress(endpoint); break; case "onetry": if (peerBanning.IsBanned(endpoint)) { throw new InvalidOperationException("Can't connect to a banned peer."); } connectionManager.ConnectAsync(endpoint).GetAwaiter().GetResult(); break; default: throw new ArgumentException("command"); } return(true); }
public async Task ConnectAsync(IConnectionViewModel connection) { _shell.AssertIsOnMainThread(); await _connectionManager.ConnectAsync(SelectedConnection.Name, SelectedConnection.Path, SelectedConnection.RCommandLineArguments); UpdateConnections(); }
protected override void Handle() { var rClientPath = MicrosoftRClient.GetRClientPath(); if (string.IsNullOrEmpty(rClientPath)) { if (_shell.ShowMessage(Resources.Prompt_RClientNotInstalled, MessageButtons.YesNo) == MessageButtons.Yes) { var installer = _shell.ExportProvider.GetExportedValue <IMicrosoftRClientInstaller>(); installer.LaunchRClientSetup(_shell); return; } } var connection = _connectionManager.ActiveConnection; if (!connection.IsRemote && !string.IsNullOrEmpty(connection.Path) && connection.Path.EqualsIgnoreCase(rClientPath)) { _shell.ShowMessage(Resources.Message_RClientIsAlreadySet, MessageButtons.OK); return; } connection = _connectionManager.GetOrAddConnection("Microsoft R Client", rClientPath, string.Empty); _connectionManager.ConnectAsync(connection).DoNotWait(); }
public static void Connect(IConnectionManager connectionManager, IUIService ui, IRSettings settings, IConnection connection) { var activeConnection = connectionManager.ActiveConnection; if (activeConnection != null && connection.BrokerConnectionInfo == activeConnection.BrokerConnectionInfo) { var text = Resources.ConnectionManager_ConnectionsAreIdentical.FormatCurrent(activeConnection.Name, connection.Name); ui.ShowMessage(text, MessageButtons.OK); } else { if (activeConnection != null && settings.ShowWorkspaceSwitchConfirmationDialog == YesNo.Yes) { var message = Resources.ConnectionManager_SwitchConfirmation.FormatCurrent(activeConnection.Name, connection.Name); if (ui.ShowMessage(message, MessageButtons.YesNo) == MessageButtons.No) { return; } } var progressBarMessage = activeConnection != null ? Resources.ConnectionManager_SwitchConnectionProgressBarMessage.FormatCurrent(activeConnection.Name, connection.Name) : Resources.ConnectionManager_ConnectionToProgressBarMessage.FormatCurrent(connection.Name); ui.ProgressDialog.Show(ct => connectionManager.ConnectAsync(connection, ct), progressBarMessage); } }
public async Task <CommandResult> InvokeAsync() { var connection = _connectionsManager.ActiveConnection; if (connection != null) { await _connectionsManager.ConnectAsync(connection); } return(CommandResult.Executed); }
public async Task Invoke(HttpContext httpContext, IConnectionManager manager, IStreamCompressor compressor, ILoggerFactory loggerFactory) { if (httpContext.WebSockets.IsWebSocketRequest) { string connectionId = string.Empty; string connectorName = string.Empty; StringValues headerValue = ""; if (httpContext.Request.Headers.TryGetValue(NCSConstants.ConnectorName, out headerValue)) { connectorName = headerValue.ToString(); } if (httpContext.Request.Headers.TryGetValue(NCSConstants.ConnectionId, out headerValue)) { connectionId = headerValue.ToString(); } if (string.IsNullOrEmpty(connectorName)) { if (httpContext.Request.Query.ContainsKey(NCSConstants.ConnectorName)) { connectorName = httpContext.Request.Query[NCSConstants.ConnectorName]; } } if (string.IsNullOrEmpty(connectionId)) { if (httpContext.Request.Query.ContainsKey(NCSConstants.ConnectionId)) { connectionId = httpContext.Request.Query[NCSConstants.ConnectionId]; Guid connectionIdGuid = Guid.Empty; if (!Guid.TryParse(connectionId, out connectionIdGuid)) { connectionId = string.Empty; } } } var webSocket = await httpContext.WebSockets.AcceptWebSocketAsync(); if (string.IsNullOrEmpty(connectionId)) { connectionId = Guid.NewGuid().ToString("N"); } await manager.ConnectAsync(webSocket, connectionId : connectionId, connectorName : connectorName, cancellationToken : _cancellationToken); } else { await _next(httpContext); } }
public async Task <CommandResult> InvokeAsync(int index) { if (_recentConnections == null) { _recentConnections = _connnectionManager.RecentConnections; } if (index < _recentConnections.Count) { var connection = _recentConnections[index]; await _connnectionManager.ConnectAsync(connection); } return(CommandResult.Executed); }
public void Connect(IConnectionViewModel connection) { _shell.AssertIsOnMainThread(); if (connection.IsActive && !IsConnected) { _shell.ProgressDialog.Show(_connectionManager.ReconnectAsync, Resources.ConnectionManager_ReconnectionToProgressBarMessage.FormatInvariant(connection.Name)); } else { var progressBarMessage = _connectionManager.ActiveConnection != null ? Resources.ConnectionManager_SwitchConnectionProgressBarMessage.FormatInvariant(_connectionManager.ActiveConnection.Name, connection.Name) : Resources.ConnectionManager_ConnectionToProgressBarMessage.FormatInvariant(connection.Name); _shell.ProgressDialog.Show(ct => _connectionManager.ConnectAsync(connection, ct), progressBarMessage); } UpdateConnections(); }
public Task <CommandResult> InvokeAsync(int index) { if (_recentConnections == null) { _recentConnections = _connectionManager.RecentConnections; } if (index < _recentConnections.Count) { var connection = _recentConnections[index]; var progressBarMessage = _connectionManager.ActiveConnection != null ? Resources.ConnectionManager_SwitchConnectionProgressBarMessage.FormatInvariant(_connectionManager.ActiveConnection.Name, connection.Name) : Resources.ConnectionManager_ConnectionToProgressBarMessage.FormatInvariant(connection.Name); _shell.ProgressDialog.Show(ct => _connectionManager.ConnectAsync(connection, ct), progressBarMessage); } return(Task.FromResult(CommandResult.Executed)); }
public Task InvokeAsync(int index) { if (_recentConnections == null) { _recentConnections = _connectionManager.RecentConnections; } if (index < _recentConnections.Count) { var connection = _recentConnections[index]; var activeConnection = _connectionManager.ActiveConnection; if (activeConnection != null && connection.BrokerConnectionInfo == activeConnection.BrokerConnectionInfo) { var text = Resources.ConnectionManager_ConnectionsAreIdentical.FormatCurrent(activeConnection.Name, connection.Name); _ui.ShowMessage(text, MessageButtons.OK); } else { if (activeConnection != null && _settings.ShowWorkspaceSwitchConfirmationDialog == YesNo.Yes) { var message = Resources.ConnectionManager_SwitchConfirmation.FormatCurrent(activeConnection.Name, connection.Name); if (_ui.ShowMessage(message, MessageButtons.YesNo) == MessageButtons.No) { return(Task.CompletedTask); } } var progressBarMessage = activeConnection != null ? Resources.ConnectionManager_SwitchConnectionProgressBarMessage.FormatCurrent(activeConnection.Name, connection.Name) : Resources.ConnectionManager_ConnectionToProgressBarMessage.FormatCurrent(connection.Name); _ui.ProgressDialog.Show(ct => _connectionManager.ConnectAsync(connection, ct), progressBarMessage); } } return(Task.CompletedTask); }