Exemple #1
0
        public UsersBrowserDlg(P4ScmProvider scm, string sender)
        {
            PreferenceKey = "UsersBrowserDlg";

            Scm = scm;
            InitializeComponent();

            if (components == null)
            {
                components = new Container();
            }
            this.Icon = Images.icon_p4vs_16px;

            imageList1 = new System.Windows.Forms.ImageList(components);

            //
            // imageList1
            //
            imageList1.TransparentColor = System.Drawing.Color.Transparent;
            imageList1.Images.Add("users_icon.png", Images.users_icon);

            this.listView1.LargeImageList = this.imageList1;
            this.listView1.SmallImageList = this.imageList1;

            if (Scm != null)
            {
                IList <P4.User> users = Scm.GetUsers(null, null);
                foreach (P4.User user in users)
                {
                    string id = user.Id;

                    DateTime localAccess = user.Accessed;

                    // we need a pref for local time, until then, don't do this:
                    //DateTime localAccess = TimeZone.CurrentTimeZone.ToLocalTime(user.Accessed);
                    string access = "";
                    if (Preferences.LocalSettings.GetBool("P4Date_format", true))
                    {
                        access = localAccess.ToString("yyyy/MM/dd HH:mm:ss");
                    }
                    else
                    {
                        access = string.Format("{0} {1}", localAccess.ToShortDateString(),
                                               localAccess.ToShortTimeString());
                    }

                    string       lastAccessed = access;
                    string       email        = user.EmailAddress;
                    string       name         = user.FullName;
                    string[]     theUser      = new string[] { id, email, lastAccessed, name };
                    ListViewItem lvi          = new ListViewItem(theUser);
                    lvi.Tag        = user;
                    lvi.ImageIndex = 0;
                    listView1.Items.Add(lvi);
                }
            }
            ClosedByDoubleClick = false;
        }
Exemple #2
0
        public P4.User Show(P4ScmProvider scm)
        {
            SetPasswordOnly = false;
            Scm             = scm;
            string oldPasswd = null;

            P4.User newUser = new P4.User();

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

                        // Set connection options
                        P4.Options options = new P4.Options();
                        options["ProgramName"]    = "P4VS";
                        options["ProgramVersion"] = Versions.product();

                        newUser.Id           = name;
                        newUser.FullName     = fullNameTB.Text;
                        newUser.EmailAddress = emailTB.Text;
                        scm.Connection.Repository.Connection.UserName = newUser.Id;
                        scm.Connection.Repository.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;
                            scm.Connection.Repository.Connection.SetPassword(null, password1TB.Text);
                        }
                        else
                        {
                            SetPasswordOnly = false;
                            newUser         = scm.NewUser(newUser);
                        }
                        return(newUser);
                    }
                    catch (P4.P4Exception p4ex)
                    {
                        // if from Connection.SetPassword(), error has not been shown
                        if (P4.P4ClientError.IsBadPasswdError(p4ex.ErrorCode))
                        {
                            SetPasswordOnly = true;
                        }
                        if ((p4ex.ErrorCode == P4.P4ClientError.MsgServer_PasswordTooShort) ||
                            (p4ex.ErrorCode == P4.P4ClientError.MsgServer_PasswordTooSimple))
                        {
                            MessageBox.Show(Resources.NewUserDlg_PasswordTooShortOrSimple, Resources.P4VS,
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            scm.ShowException(p4ex);
                        }
                    }

                    P4.P4CommandResult results = scm.Connection.Repository.Connection.LastResults;
                    oldPasswd = password1TB.Text;
                }
                else
                {
                    return(null);
                }
            } while (true);
        }