private void UpdateActiveConnection(IConnection candidateConnection = null) { lock (_syncObj) { var brokerConnectionInfo = _sessionProvider.Broker.ConnectionInfo; if (candidateConnection != null) { if (candidateConnection == ActiveConnection && candidateConnection.BrokerConnectionInfo == brokerConnectionInfo) { return; } } else if (brokerConnectionInfo == (ActiveConnection?.BrokerConnectionInfo ?? default(BrokerConnectionInfo))) { return; } var connection = candidateConnection ?? RecentConnections.FirstOrDefault(c => brokerConnectionInfo == c.BrokerConnectionInfo); if (connection != null) { connection.LastUsed = DateTime.Now; } ActiveConnection = connection; SaveActiveConnectionToSettings(); UpdateRecentConnections(); } }
private void SwitchBrokerToLastConnection() { var connectionInfo = _settings.LastActiveConnection; if (!string.IsNullOrEmpty(connectionInfo?.Path)) { SwitchBroker(connectionInfo.Name, connectionInfo.Path, connectionInfo.RCommandLineArguments); return; } var connection = RecentConnections.FirstOrDefault(); if (connectionInfo != null) { SwitchBroker(connection); return; } var localRPath = new RInstallation().GetRInstallPath(); if (localRPath != null) { SwitchBroker(CreateConnection("Local", localRPath, string.Empty)); } }
private void SaveConnectionsToSettings() { _settings.Connections = RecentConnections .Select(c => new ConnectionInfo(c)) .ToArray(); _settings.SaveSettingsAsync().DoNotWait(); }
private void SaveConnectionsToSettings() { _settings.Connections = RecentConnections .Select(c => new ConnectionInfo { Name = c.Name, Path = c.Path, RCommandLineArguments = c.RCommandLineArguments }) .ToArray(); }
private void UpdateActiveConnection() { if (ActiveConnection?.Id == _brokerConnector.BrokerUri) { return; } ActiveConnection = RecentConnections.FirstOrDefault(c => c.Id == _brokerConnector.BrokerUri); SaveActiveConnectionToSettings(); }
private void UpdateActiveConnection() { if (string.IsNullOrEmpty(_sessionProvider.Broker.Name) || ActiveConnection?.Id == _sessionProvider.Broker.Uri) { return; } ActiveConnection = RecentConnections.FirstOrDefault(c => c.Id == _sessionProvider.Broker.Uri); SaveActiveConnectionToSettings(); }
public static bool ConnectTo(Connection conData) { try { var data = _cl.DownloadString($"http://{conData.Address}:{conData.Port}"); if (data == null) { return(false); } else { RecentConnections.Add(conData); return(true); } } catch { return(false); } }
/// <summary> /// Sets up server/client connection information</summary> /// <returns>True iff information set up</returns> public bool ConfigureConnection() { bool result; var dlg = new Connections(this); if ((MainForm != null) && (MainForm.Icon != null)) { dlg.Icon = MainForm.Icon; } DialogResult dr = dlg.ShowDialog(MainForm); if (dr == DialogResult.OK) { string oldConnection = CurrentConnection; lock (m_lock) { if (m_repository != null) { m_repository.Dispose(); m_repository = null; } } m_connectionInitialized = false; m_configuring = true; // nullify InitializeConnection() string[] connectionConfig = ExtractConnectionParts(dlg.ConnectionSelected); if (connectionConfig != null && connectionConfig.Length == 3) { var server = new Server(new ServerAddress(connectionConfig[0])); lock (m_lock) { m_repository = new Repository(server); m_repository.Connection.UserName = connectionConfig[1]; m_repository.Connection.Client = new Client { Name = connectionConfig[2] }; } } if (ValidateConnection(true))// a valid connection { m_connectionInitialized = true; if (dlg.UseAsDefaultConnection) { DefaultConnection = CurrentConnection; } int index = RecentConnections.IndexOf(CurrentConnection); if (index != -1) { RecentConnections.RemoveAt(index); } RecentConnections.Insert(0, CurrentConnection); if (CurrentConnection != oldConnection) { OnConnectionChanged(EventArgs.Empty); } } result = true; } else //if (dr == DialogResult.Cancel) { result = false; } m_configuring = false; return(result); }