Example #1
0
        /// <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);
        }
Example #2
0
        /// <summary>
        /// Executes a Perforce command in tagged mode.
        /// </summary>
        /// <param name="Command">The command.</param>
        /// <param name="Args">The arguments to the Perforce command.  Remember to use a dash (-) in front of all switches</param>
        /// <returns>A P4Recordset containing the results of the command.</returns>
        public P4RecordSet Run(string Command, params string[] Args)
        {
            EstablishConnection(true);
            P4RecordSet         r  = new P4RecordSet();
            P4RecordsetCallback cb = new P4RecordsetCallback(r);

            RunCallback(cb, Command, Args);
            if (((_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings ||
                  _exceptionLevel == P4ExceptionLevels.NoExceptionOnWarnings) &&
                 r.HasErrors())
                ||
                (_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings &&
                 r.HasWarnings())
                )
            {
                throw new RunException(r);
            }


            return(r);
        }
Example #3
0
        /// <summary>
        /// Executes a Perforce command in tagged mode.
        /// </summary>
        /// <param name="Command">The command.</param>
        /// <param name="Args">The arguments to the Perforce command.  Remember to use a dash (-) in front of all switches</param>
        /// <returns>A P4Recordset containing the results of the command.</returns>
        public P4RecordSet Run(string Command, params string[] Args)
        {
            P4RecordSet r = new P4RecordSet();

            EstablishConnection(true);
            RunIt(Command, Args, r.ResultClientUser);
            if (((_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings ||
                  _exceptionLevel == P4ExceptionLevels.NoExceptionOnWarnings) &&
                 r.HasErrors())
                ||
                (_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings &&
                 r.HasWarnings())
                )
            {
                throw new RunException(r);
            }

            if (r.ResultClientUser.DeferedException != null)
            {
                throw r.ResultClientUser.DeferedException;
            }

            return(r);
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="P4RecordsetCallback"/> class.
 /// </summary>
 public P4RecordsetCallback()
 {
     _P4ResultRecordset = new P4RecordSet();
     _P4Result = _P4ResultRecordset;
 }
Example #5
0
 internal P4RecordsetCallback(P4BaseRecordSet p4Result)
 {
     _P4Result = p4Result;
     _P4ResultRecordset = null;
 }
Example #6
0
        /// <summary>
        /// Executes a Perforce command in tagged mode.
        /// </summary>
        /// <param name="Command">The command.</param>
        /// <param name="Args">The arguments to the Perforce command.  Remember to use a dash (-) in front of all switches</param>
        /// <returns>A P4Recordset containing the results of the command.</returns>
        public P4RecordSet Run(string Command, params string[] Args)
        {
            EstablishConnection(true);
            P4RecordSet r = new P4RecordSet();
            P4RecordsetCallback cb = new P4RecordsetCallback(r);

            RunCallback(cb, Command, Args);
            if (((_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings
                 || _exceptionLevel == P4ExceptionLevels.NoExceptionOnWarnings)
                 && r.HasErrors())
                ||
                  (_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings
                   && r.HasWarnings())
                )
            {
                throw new RunException(r);
            }


            return r;
        }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="P4RecordsetCallback"/> class.
 /// </summary>
 public P4RecordsetCallback()
 {
     _P4ResultRecordset = new P4RecordSet();
     _P4Result          = _P4ResultRecordset;
 }
Example #8
0
 internal P4RecordsetCallback(P4BaseRecordSet p4Result)
 {
     _P4Result          = p4Result;
     _P4ResultRecordset = null;
 }