private void OpenConnectionBtn_Click(object sender, EventArgs e) { P4ScmProvider newConection = new P4ScmProvider(SccService); if (UseEnvConnect) { newConection.Connection.Connect(true, null); } else { // trigger the connection dialog newConection.Connection.Connect(); } // only replace ScmProvider if a connection has been made // through env vars or connection dlg if (newConection.Connected) { SccService.ScmProvider = newConection; } if (SccService.ScmProvider.Connection.Repository != null && !(string.IsNullOrEmpty(SccService.ScmProvider.Connection.Workspace))) { if (SccService.ScmProvider != null) { SccService.ScmProvider.LoadingSolution = !string.IsNullOrEmpty(SccService.LoadingControlledSolutionLocation); } Init(); P4VsProvider.BroadcastNewConnection(SccService.ScmProvider); ConnectionInfo = new ConnectionData(); ConnectionInfo.ServerPort = SccService.ScmProvider.Connection.Port; ConnectionInfo.UserName = SccService.ScmProvider.Connection.User; ConnectionInfo.Workspace = SccService.ScmProvider.Connection.Workspace; P4VsProvider.Instance.currentConnectionDropDownComboChoice = ConnectionInfo.ToString(); string key = "ActiveChangelist_" + SccService.ScmProvider.Connection.Repository.Connection.Server.Address.Uri.Replace(':', '_') + "_" + SccService.ScmProvider.Connection.User + "_" + SccService.ScmProvider.Connection.Workspace; P4VsProvider.Instance.ChangeLists = new ActiveChangeListCombo(SccService); string newActiveChangeListComboChoice = Preferences.LocalSettings.GetString(key, Resources.Changelist_Default); P4VsProvider.Instance.ChangeLists.SetActiveChangeList(newActiveChangeListComboChoice); } else { P4VsProvider.BroadcastNewConnection(null); } }
internal void ConnectToScm(string port, string user, string workspace) { if (SuppressConnection) { SuppressConnection = false; if ((SccService.ScmProvider.Connection.Disconnected) && (LastConnectionInfo != null)) { if (SccService.ScmProvider != null) { BroadcastNewConnection(null); SccService.ScmProvider.Dispose(); SccService.ScmProvider = null; } SccService.ScmProvider = new P4ScmProvider(SccService); SccService.ScmProvider.Connection.Connect(LastConnectionInfo); SccService.ScmProvider.LoadingSolution = !string.IsNullOrEmpty(SccService.LoadingControlledSolutionLocation); ChangeLists = new ActiveChangeListCombo(SccService); } if (SccService.ScmProvider.Connected) { return; } } bool showConnectDlg = false; ConnectionPreference pref = ConnectionPreference.ShowDialog; if (Preferences.LocalSettings.ContainsKey("ConnectPreference")) { pref = (ConnectionPreference)Preferences.LocalSettings["ConnectPreference"]; } string _port = null; string _user = null; string _workspace = null; switch (pref) { default: case ConnectionPreference.ShowDialog: showConnectDlg = true; break; case ConnectionPreference.UseRecent: if ((SccService.ScmProvider != null) && (SccService.ScmProvider.CheckConnection())) { //already connected return; } MRUList _recentConnections = (MRUList)Preferences.LocalSettings["RecentConnections"]; if (_recentConnections != null) { ConnectionData con = _recentConnections[0] as ConnectionData; if (con != null) { _port = con.ServerPort; _user = con.UserName; _workspace = con.Workspace; } } else { // no recent connections showConnectDlg = true; } break; case ConnectionPreference.UseSolution: if (string.IsNullOrEmpty(port) || string.IsNullOrEmpty(user) || string.IsNullOrEmpty(workspace)) { // didn't contain all the connection data, so show dialog showConnectDlg = true; } else { _port = port; _user = user; _workspace = workspace; } break; case ConnectionPreference.UseEnvironment: _port = null; _user = null; _workspace = null; break; } if (SccService.ScmProvider != null) { BroadcastNewConnection(null); SccService.ScmProvider.Dispose(); SccService.ScmProvider = null; } SccService.ScmProvider = new P4ScmProvider(SccService); SccService.ScmProvider.LoadingSolution = !string.IsNullOrEmpty(SccService.LoadingControlledSolutionLocation); ChangeLists = new ActiveChangeListCombo(SccService); if ((showConnectDlg == false) || (InCommandLineMode())) { SccService.ScmProvider.Connection.Connect(_port, _user, _workspace, true, Path.GetDirectoryName(GetSolutionFileName())); } else if ((showConnectDlg || SccService.ScmProvider.Connection.Disconnected) && (!InCommandLineMode())) { SccService.ScmProvider.Connection.Connect(); } if ((SolutionFileTagged == false) && (Preferences.LocalSettings.GetBool("TagSolutionProjectFiles", false))) { // Need to tag sln file if tagging is enabled, so mark dirty props so // it'll get tagged SolutionHasDirtyProps = true; } BroadcastNewConnection(SccService.ScmProvider); if (SccService.ScmProvider.Connected) { ConnectionData cd = new ConnectionData(); cd.ServerPort = SccService.ScmProvider.Connection.Port; cd.UserName = SccService.ScmProvider.Connection.User; cd.Workspace = SccService.ScmProvider.Connection.Workspace; MRUList recentConnections = (MRUList)Preferences.LocalSettings["RecentConnections"]; if (recentConnections == null) { recentConnections = new MRUList(5); } recentConnections.Add(cd); Preferences.LocalSettings["RecentConnections"] = recentConnections; currentConnectionDropDownComboChoice = cd.ToString(); string key = "ActiveChangelist_" + SccService.ScmProvider.Connection.Repository.Connection.Server.Address.Uri.Replace(':', '_') + "_" + SccService.ScmProvider.Connection.User + "_" + SccService.ScmProvider.Connection.Workspace; string newActiveChangeListComboChoice = Preferences.LocalSettings.GetString(key, Resources.Changelist_Default); ChangeLists.SetActiveChangeList(newActiveChangeListComboChoice); } if ((SccService.ScmProvider != null) && (SccService.ScmProvider.Connected)) { SccService.ScmProvider.SolutionFile = GetSolutionFileName(); } }