private void EstablishConnection(bool tagged) { // If we're switching contexts from tagged to un-tagged, // then we need to reset the connection if ((m_ClientApi != null) && tagged != _tagged) { CloseConnection(); } if (m_ClientApi == null) { m_ClientApi = new ClientApi(); } if (m_ClientApi.Dropped() != 0) { // I can't figure out how to force this artificially, so currently untested :-( CloseConnection(); } if (!_Initialized) { Error err = null; try { _tagged = tagged; err = m_ClientApi.CreateError(); if (tagged) { m_ClientApi.SetProtocol("tag", ""); } if (tagged) { m_ClientApi.SetProtocol("specstring", ""); } //May have lost our settings... reset here if (_Client != null) { m_ClientApi.SetClient(_Client); } if (_User != null) { m_ClientApi.SetUser(_User); } if (_CWD != null) { m_ClientApi.SetCwd(_CWD); } if (_Charset != null) { m_ClientApi.SetCharset(_Charset); } if (_Host != null) { m_ClientApi.SetHost(_Host); } if (_Port != null) { m_ClientApi.SetPort(_Port); } if (_maxResults != 0) { m_ClientApi.SetMaxResults(_maxResults); } if (_maxScanRows != 0) { m_ClientApi.SetMaxScanRows(_maxResults); } if (_maxLockTime != 0) { m_ClientApi.SetMaxLockTime(_maxLockTime); } if (_ApiLevel != 0) { m_ClientApi.SetProtocol("api", _ApiLevel.ToString()); } m_ClientApi.Init(err); if (err.Severity == Error.ErrorSeverity.Failed || err.Severity == Error.ErrorSeverity.Fatal) { //Trace.WriteLine(err.Fmt()); //Trace.WriteLine("Unable to connect to Perforce!"); throw new Exception("Unable to connect to Perforce!"); } if (_CallingProgram != null) { m_ClientApi.SetProg(_CallingProgram); } if (_CallingProgramVersion != null) { m_ClientApi.SetVersion(_CallingProgramVersion); } _Initialized = true; err.Dispose(); } catch (Exception e) { //Trace.WriteLine(e.Message); m_ClientApi.Final(err); err.Dispose(); m_ClientApi.Dispose(); m_ClientApi = null; throw new PerforceInitializationError(e.Message); } } }
private void EstablishConnection(bool tagged, KeepAlive keepAlive) { if (m_ClientApi != null && m_ClientApi.Dropped() != 0) { // I can't figure out how to force this artificially, so currently untested :-( CloseConnection(); } if (m_ClientApi == null) { m_ClientApi = new ClientApi(); } if (!_Initialized) { Error err = null; try { _tagged = tagged; err = m_ClientApi.CreateError(); // Always use the specstring protocol. We'll controll form output via SetTag // before each run m_ClientApi.SetProtocol("specstring", ""); //May have lost our settings... reset here if (_Client != null) { m_ClientApi.SetClient(_Client); } if (_User != null) { m_ClientApi.SetUser(_User); } if (_CWD != null) { m_ClientApi.SetCwd(_CWD); } if (_Charset != null) { m_ClientApi.SetCharset(_Charset); } if (_Host != null) { m_ClientApi.SetHost(_Host); } if (_Port != null) { m_ClientApi.SetPort(_Port); } if (_Password != null) { m_ClientApi.SetPassword(_Password); } if (_TicketFile != null) { m_ClientApi.SetTicketFile(_TicketFile); } if (_maxResults != 0) { m_ClientApi.SetMaxResults(_maxResults); } if (_maxScanRows != 0) { m_ClientApi.SetMaxScanRows(_maxResults); } if (_maxLockTime != 0) { m_ClientApi.SetMaxLockTime(_maxLockTime); } if (_ApiLevel != 0) { m_ClientApi.SetProtocol("api", _ApiLevel.ToString()); } m_ClientApi.Init(err); if (err.Severity == Error.ErrorSeverity.Failed || err.Severity == Error.ErrorSeverity.Fatal) { throw new Exception("Unable to connect to Perforce!"); } _Initialized = true; err.Dispose(); } catch (Exception e) { string message = "Perforce connection error."; try { m_ClientApi.Final(err); message = e.Message; err.Dispose(); m_ClientApi.Dispose(); m_ClientApi = null; } catch { } throw new PerforceInitializationError(message); } } if (tagged) { m_ClientApi.SetTag(); } if (_CallingProgram != null) { m_ClientApi.SetProg(_CallingProgram); } if (_CallingProgramVersion != null) { m_ClientApi.SetVersion(_CallingProgramVersion); } m_ClientApi.SetBreak(keepAlive); }