Esempio n. 1
0
        /// <summary>
        /// Executes a Perforce command in non-tagged mode.
        /// </summary>
        /// <param name="Command">The command.</param>
        /// <param name="Args">The args.</param>
        /// <returns></returns>
        public P4UnParsedRecordSet RunUnParsed(string Command, params string[] Args)
        {
            P4UnParsedRecordSet r = new P4UnParsedRecordSet();

            P4BaseRecordSet.OnPromptEventHandler handler = new P4BaseRecordSet.OnPromptEventHandler(this.HandleOnPrompt);
            r.OnPrompt += handler;
            EstablishConnection(false);
            RunIt(Command, Args, r.ResultClientUser);
            r.OnPrompt -= handler;

            if (((_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings ||
                  _exceptionLevel == P4ExceptionLevels.NoExceptionOnWarnings) &&
                 r.HasErrors())
                ||
                (_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings &&
                 r.HasWarnings())
                )
            {
                throw new RunUnParsedException(r);
            }

            // always throw a defered exception (means something went WAY wrong)
            if (r.ResultClientUser.DeferedException != null)
            {
                throw r.ResultClientUser.DeferedException;
            }

            return(r);
        }
Esempio n. 2
0
        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;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Saves the form to Perforce.
        /// </summary>
        /// <param name="formCommand">The form command to run.</param>
        /// <param name="formSpec">The formatted spec.</param>
        /// <param name="args">Arguments to the form command.</param>
        /// <returns>P4UnParsedRecordSet.  Output can be parsed to verify the form was processed correctly.</returns>
        public P4UnParsedRecordSet Save_Form(string formCommand, string formSpec, params string[] args)
        {
            if (formCommand == null)
            {
                throw new ArgumentNullException("formCommand");
            }
            if (formCommand == string.Empty)
            {
                throw new ArgumentException("Parameter 'formCommand' can not be empty");
            }
            if (formSpec == null)
            {
                throw new ArgumentNullException("formSpec");
            }
            if (formSpec == string.Empty)
            {
                throw new ArgumentException("Parameter 'formSpec' can not be empt");
            }

            P4UnParsedRecordSet r  = new P4UnParsedRecordSet();
            P4RecordsetCallback cb = new P4RecordsetCallback(r);

            r.InputData = formSpec;
            List <string> formargs = new List <string>();

            foreach (string arg in args)
            {
                if (arg == "-i" || arg == "-o")
                {
                    throw new InvalidFormArgument();
                }
                formargs.Add(arg);
            }
            formargs.Add("-i");

            RunCallbackUnparsed(cb, formCommand, formargs.ToArray());

            if (((_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings ||
                  _exceptionLevel == P4ExceptionLevels.NoExceptionOnWarnings) &&
                 r.HasErrors())
                ||
                (_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings &&
                 r.HasWarnings())
                )
            {
                throw new RunUnParsedException(r);
            }
            return(r);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        /// <summary>
        /// Saves the form to Perforce.
        /// </summary>
        /// <param name="formCommand">The form command to run.</param>
        /// <param name="formSpec">The formatted spec.</param>
        /// <param name="Force">True to pass the '-f' flag when saving.</param>
        /// <returns>P4UnParsedRecordSet.  Output can be parsed to verify the form was processed correctly.</returns>
        public P4UnParsedRecordSet Save_Form(string formCommand, string formSpec, bool Force)
        {
            if (formCommand == null)
            {
                throw new ArgumentNullException("formCommand");
            }
            if (formCommand == string.Empty)
            {
                throw new ArgumentException("Parameter 'formCommand' can not be empty");
            }
            if (formSpec == null)
            {
                throw new ArgumentNullException("formSpec");
            }
            if (formSpec == string.Empty)
            {
                throw new ArgumentException("Parameter 'formSpec' can not be empt");
            }

            P4UnParsedRecordSet r = new P4UnParsedRecordSet();

            r.InputData = formSpec;
            EstablishConnection(false);
            if (Force)
            {
                string[] Args = { "-i", "-f" };
                RunIt(formCommand, Args, r.ResultClientUser);
            }
            else
            {
                string[] Args = { "-i" };
                RunIt(formCommand, Args, r.ResultClientUser);
            }
            if (((_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings ||
                  _exceptionLevel == P4ExceptionLevels.NoExceptionOnWarnings) &&
                 r.HasErrors())
                ||
                (_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings &&
                 r.HasWarnings())
                )
            {
                throw new RunUnParsedException(r);
            }
            return(r);
        }
Esempio n. 6
0
        /// <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;
            }
        }
Esempio n. 7
0
        /// <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;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Executes a Perforce command in non-tagged mode.
        /// </summary>
        /// <param name="Command">The command.</param>
        /// <param name="Args">The args.</param>
        /// <returns></returns>
        public P4UnParsedRecordSet RunUnParsed(string Command, params string[] Args)
        {
            P4UnParsedRecordSet r  = new P4UnParsedRecordSet();
            P4RecordsetCallback cb = new P4RecordsetCallback(r);

            P4BaseRecordSet.OnPromptEventHandler handler = new P4BaseRecordSet.OnPromptEventHandler(this.HandleOnPrompt);
            r.OnPrompt += handler;
            RunCallbackUnparsed(cb, Command, Args);
            r.OnPrompt -= handler;

            if (((_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings ||
                  _exceptionLevel == P4ExceptionLevels.NoExceptionOnWarnings) &&
                 r.HasErrors())
                ||
                (_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings &&
                 r.HasWarnings())
                )
            {
                throw new RunUnParsedException(r);
            }

            return(r);
        }
Esempio n. 9
0
        /// <summary>
        /// Saves the form to Perforce.
        /// </summary>
        /// <param name="formCommand">The form command to run.</param>
        /// <param name="formSpec">The formatted spec.</param>
        /// <param name="args">Arguments to the form command.</param>
        /// <returns>P4UnParsedRecordSet.  Output can be parsed to verify the form was processed correctly.</returns>
        public P4UnParsedRecordSet Save_Form(string formCommand, string formSpec, params string[] args)
        {
            if (formCommand == null) throw new ArgumentNullException("formCommand");
            if (formCommand == string.Empty) throw new ArgumentException("Parameter 'formCommand' can not be empty");
            if (formSpec == null) throw new ArgumentNullException("formSpec");
            if (formSpec == string.Empty) throw new ArgumentException("Parameter 'formSpec' can not be empt");

            P4UnParsedRecordSet r = new P4UnParsedRecordSet();
            P4RecordsetCallback cb = new P4RecordsetCallback(r);
            r.InputData = formSpec;
            List<string> formargs = new List<string>();
            foreach (string arg in args)
            {
                if (arg == "-i" || arg == "-o")
                {
                    throw new InvalidFormArgument();
                }
                formargs.Add(arg);
            }
            formargs.Add("-i");

            RunCallbackUnparsed(cb, formCommand, formargs.ToArray());
        
            if (((_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings
                 || _exceptionLevel == P4ExceptionLevels.NoExceptionOnWarnings)
                 && r.HasErrors())
                ||
                  (_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings
                   && r.HasWarnings())
                )
            {
                throw new RunUnParsedException(r);
            }
            return r;
        }
Esempio n. 10
0
        /// <summary>
        /// Executes a Perforce command in non-tagged mode.
        /// </summary>
        /// <param name="Command">The command.</param>
        /// <param name="Args">The args.</param>
        /// <returns></returns>
        public P4UnParsedRecordSet RunUnParsed(string Command, params string[] Args)
        {
            P4UnParsedRecordSet r = new P4UnParsedRecordSet();
            P4RecordsetCallback cb = new P4RecordsetCallback(r);
            P4BaseRecordSet.OnPromptEventHandler handler = new P4BaseRecordSet.OnPromptEventHandler(this.HandleOnPrompt);
            r.OnPrompt += handler;
            RunCallbackUnparsed(cb, Command, Args);
            r.OnPrompt -= handler;

            if (((_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings
                 || _exceptionLevel == P4ExceptionLevels.NoExceptionOnWarnings)
                 && r.HasErrors())
                ||
                  (_exceptionLevel == P4ExceptionLevels.ExceptionOnBothErrorsAndWarnings
                   && r.HasWarnings())
                )
            {
                throw new RunUnParsedException(r);
            }

            return r;
        }
Esempio n. 11
0
        /// <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;
            }

        }