Example #1
0
        public void ThrowTest1()
        {
            P4ClientError error = new P4ClientError(ErrorSeverity.E_FAILED, "This is a test");

            P4Exception.MinThrowLevel = ErrorSeverity.E_FATAL;
            bool passed = true;

            try
            {
                P4Exception.Throw(error);
            }
            catch
            {
                passed = false;  // should not have thrown
            }
            Assert.IsTrue(passed, "Threw an exception < MinThrowLevel");

            P4Exception.MinThrowLevel = ErrorSeverity.E_FAILED;
            passed = false;
            try
            {
                P4Exception.Throw(error);
            }
            catch
            {
                passed = true;  // should have thrown
            }
            Assert.IsTrue(passed, "Did not throw an exception >= MinThrowLevel");
        }
Example #2
0
        /// <summary>Simple login check using `p4 login -s`</summary>
        /// <para>Return 'true' if logged in (with or without a password).</para>
        public bool isLoggedIn()
        {
            try
            {
                string[]        loginOptions = new string[] { "-s" };
                P4.P4Command    LoginCmd     = new P4Command(Repository, "login", true, loginOptions);
                P4CommandResult LoginResults = LoginCmd.Run();

                if ((LoginResults == null) || (LoginResults.TaggedOutput == null))
                {
                    return(false);
                }

                string validated;
                LoginResults.TaggedOutput[0].TryGetValue("2FA", out validated);
                if (validated == "required")
                {
                    P4ClientError err = new P4ClientError(ErrorSeverity.E_FAILED,
                                                          "Second factor authentication required! Run 'p4 login2'.");
                    err.ErrorCode = 807673723;
                    P4Exception ex = new P4Exception(err);
                    throw ex;
                }

                // logged in. May not have a ticket if no password was required.
                return(true);
            }
            catch (P4.P4Exception ex)
            {
                if (ex.ErrorCode == P4.P4ClientError.MsgServer_Login2Required)
                {
                    throw ex;
                }
                return(false);
            }
        }
Example #3
0
        public User Show(RepoStorage repo)
        {
            SetPasswordOnly = false;
            Repo            = repo;
            string oldPasswd = null;

            User newUser = new User();

            do
            {
                if (this.ShowDialog() == DialogResult.OK)
                {
                    if (!SetPasswordOnly)
                    {
                        string name = userNameTB.Text;
                        if (name.Contains(" "))
                        {
                            name = Regex.Replace(name, " ", "_");
                        }
                        Options        opts  = new Options();
                        IList <string> users = new List <string>();
                        users.Add(userNameTB.Text);
                        if (Repo.rep.GetUsers(users, opts) != null)
                        {
                            string msg = string.Format(Properties.Resources.NewUserDlg_UserExistsWarning, userNameTB.Text);
                            MessageBox.Show(msg, Properties.Resources.P4EXP, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            continue;
                        }

                        // Set connection options
                        Options options = new Options();
                        options["ProgramName"]    = Properties.Resources.P4EXP;
                        options["ProgramVersion"] = P4EXPProgram.ProductVersion;

                        newUser.Id                   = name;
                        newUser.FullName             = fullNameTB.Text;
                        newUser.EmailAddress         = emailTB.Text;
                        Repo.rep.Connection.UserName = newUser.Id;
                        Repo.rep.Connection.Connect(options);

                        //scm.Connection.User = newUser.Id;//.Repository.Connection.UserName = newUser.Id;
                        //scm.Connection.Connect(null);//.Repository.Connection.Connect(null);
                    }
                    if (!string.IsNullOrEmpty(fullNameTB.Text))
                    {
                        newUser.Password = password1TB.Text;
                    }
                    try
                    {
                        if (SetPasswordOnly)
                        {
                            SetPasswordOnly = false;
                            Repo.rep.Connection.SetPassword(null, password1TB.Text);
                        }
                        else
                        {
                            SetPasswordOnly = false;
                            newUser         = Repo.rep.CreateUser(newUser);
                        }
                        return(newUser);
                    }
                    catch (P4Exception p4ex)
                    {
                        // if from Connection.SetPassword(), error has not been shown
                        if (P4ClientError.IsBadPasswdError(p4ex.ErrorCode))
                        {
                            SetPasswordOnly = true;
                        }
                        if ((p4ex.ErrorCode == P4ClientError.MsgServer_PasswordTooShort) ||
                            (p4ex.ErrorCode == P4ClientError.MsgServer_PasswordTooSimple))
                        {
                            MessageBox.Show(Properties.Resources.NewUserDlg_PasswordTooShortOrSimple, Properties.Resources.P4EXP,
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show(p4ex.Message);
                            //scm.ShowException(p4ex);
                        }
                    }

                    P4CommandResult results = Repo.rep.Connection.LastResults;
                    oldPasswd = password1TB.Text;
                }
                else
                {
                    return(null);
                }
            } while (true);
        }