internal P4PendingChangelist(string Description, P4Connection p4) { _p4 = p4; P4ExceptionLevels oldEx = _p4.ExceptionLevel; try { // we want to throw an exception if there are any errors. _p4.ExceptionLevel = P4ExceptionLevels.NoExceptionOnWarnings; baseForm = _p4.Fetch_Form("change"); // clear the Jobs list baseForm.ArrayFields["Jobs"] = new string[0]; // clear the Files list baseForm.ArrayFields["Files"] = new string[0]; // save the description baseForm.Fields["Description"] = Description; P4UnParsedRecordSet r = _p4.Save_Form(baseForm); // convert to int to verify we're parsing correctly int changeNumber = int.Parse(r.Messages[0].Split(' ')[1]); baseForm.Fields["Change"] = changeNumber.ToString(); } // no catch... we want the exception bubled up. finally { p4.ExceptionLevel = oldEx; } }
/// <summary> /// Determines if the Perforce connection is valid. /// </summary> /// <param name="checkLogin">if set to <c>true</c> it will check if the user is logged in.</param> /// <param name="checkClient">if set to <c>true</c> it will verify the client exists.</param> /// <returns> /// <c>true</c> if the connection is valid; otherwise, <c>false</c>. /// </returns> /// <remarks> /// IsValidConnection performs the following 3 checks (depending on the arguments passed). /// <list type="numbered"> /// <li>Runs p4 info, and verifies the server is valid.</li> /// <li>If checkClient is true, verifies that p4 info returns a clientName that is not "*unknown*.</li> /// <li>If checkLogin is true, verifies that p4 login -s does not have errors.</li> /// </list> /// </remarks> public bool IsValidConnection(bool checkLogin, bool checkClient) { P4ExceptionLevels oldExLevel = this.ExceptionLevel; try { this.ExceptionLevel = P4ExceptionLevels.NoExceptionOnErrors; P4RecordSet r = Run("info"); if (r.HasErrors()) { return(false); } if (r.Records.Length != 1) { return(false); } if (checkClient) { if (!r.Records[0].Fields.ContainsKey("clientName")) { return(false); } if (r.Records[0].Fields["clientName"] == "*unknown*") { return(false); } } if (checkLogin) { P4UnParsedRecordSet ur = RunUnParsed("login", "-s"); if (ur.HasErrors()) { return(false); } } } catch { // something went way wrong return(false); } finally { // set the ExceptionLevel back this.ExceptionLevel = oldExLevel; } return(true); }
/// <summary> /// Login to the Perforce Server /// </summary> /// <param name="password">The password.</param> public void Login(string password) { if (password == null) { throw new ArgumentNullException(); } // if password is empty, then don't do anything if (password == string.Empty) { return; } P4ExceptionLevels oldLevel = _exceptionLevel; try { P4UnParsedRecordSet r = new P4UnParsedRecordSet(); P4RecordsetCallback cb = new P4RecordsetCallback(r); r.LoginPassword = password; string[] Args = { }; _exceptionLevel = P4ExceptionLevels.NoExceptionOnErrors; RunCallbackUnparsed(cb, "login", Args); //for good measure delete the password r.LoginPassword = null; if (r.HasErrors()) { throw new P4API.Exceptions.InvalidLogin(r.ErrorMessage); } } finally { _exceptionLevel = oldLevel; } }
/// <summary> /// Login to the Perforce Server /// </summary> /// <param name="password">The password.</param> public void Login(string password) { if (password == null) { throw new ArgumentNullException(); } // if password is empty, then don't do anything if (password == string.Empty) { return; } P4ExceptionLevels oldLevel = _exceptionLevel; try { P4UnParsedRecordSet r = new P4UnParsedRecordSet(); r.LoginPassword = password; EstablishConnection(false); string[] Args = { }; _exceptionLevel = P4ExceptionLevels.NoExceptionOnErrors; RunIt("login", Args, r.ResultClientUser); //for good measure delete the password r.LoginPassword = null; if (r.HasErrors()) { throw new P4API.Exceptions.InvalidLogin(r.ErrorMessage); } } finally { _exceptionLevel = oldLevel; } }
/// <summary> /// Login to the Perforce Server /// </summary> /// <param name="password">The password.</param> public void Login(string password) { if (password == null) throw new ArgumentNullException(); // if password is empty, then don't do anything if (password == string.Empty) return; P4ExceptionLevels oldLevel = _exceptionLevel; try { P4UnParsedRecordSet r = new P4UnParsedRecordSet(); P4RecordsetCallback cb = new P4RecordsetCallback(r); r.LoginPassword = password; string[] Args = { }; _exceptionLevel = P4ExceptionLevels.NoExceptionOnErrors; RunCallbackUnparsed(cb, "login", Args); //for good measure delete the password r.LoginPassword = null; if (r.HasErrors()) { throw new P4API.Exceptions.InvalidLogin(r.ErrorMessage); } } finally { _exceptionLevel = oldLevel; } }