Exemplo n.º 1
0
        private void BrowseWorkspaceBtn_Click(object sender, EventArgs e)
        {
            this.TopMost = false;

            RepoStorage repo = SetRepoFromDlg();

            if (repo != null && CheckConnection(repo) && CheckLogin(repo))
            {
                WorkspaceBrowserDlg dlg = new WorkspaceBrowserDlg(repo, null);
                dlg.TopMost = true;

                if (!dlg.dlgCancelled)
                {
                    if (DialogResult.Cancel != dlg.ShowDialog())
                    {
                        if ((dlg.SelectedWorkspace != null) && (dlg.SelectedWorkspace.Name != null))
                        {
                            WorkspaceTB.Text = dlg.SelectedWorkspace.Name.ToString();
                        }
                    }
                }
                //_scm.Dispose();
            }
            this.TopMost = true;
        }
Exemplo n.º 2
0
        public UsersBrowserDlg(RepoStorage repo, string sender)
        {
            PreferenceKey = "UsersBrowserDlg";

            Repo = repo;
            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 (Repo != null)
            {
                Options      opts  = new Options();
                IList <User> users = Repo.rep.GetUsers(opts, null);
                foreach (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;
        }
Exemplo n.º 3
0
 public Client Show(RepoStorage repo)
 {
     if (this.DialogResult == DialogResult.OK)
     {
         return(SelectedWorkspace);
     }
     return(null);
 }
Exemplo n.º 4
0
        public P4ToolWindowControlBase(RepoStorage repo)
        {
            Repo = repo;
            //Scm = scm;

            //newConection = new P4VsProvider.NewConnectionDelegate(NewConnection);
            //P4VsProvider.NewConnection += newConection;
        }
Exemplo n.º 5
0
 public User Show(RepoStorage repo)
 {
     if (this.DialogResult == DialogResult.OK)
     {
         return(SelectedUser);
     }
     return(null);
 }
Exemplo n.º 6
0
        public P4ToolWindowControlBase()
        {
            Repo = P4EXPProgram.getRepoStorage("");

            //Scm = P4VsProvider.CurrentScm;

            //newConection = new P4VsProvider.NewConnectionDelegate(NewConnection);
            //P4VsProvider.NewConnection += newConection;
        }
Exemplo n.º 7
0
        //public ConnectionData ConnectionInfo { get; private set; }

        private void OkBtn_Click(object sender, EventArgs e)
        {
            RepoStorage repo = P4EXPProgram.getRepoStorage("");

            repo.rep = new Repository(new Server(new ServerAddress(ServerTB.Text.Trim())));
            repo.rep.Connection.UserName = UserTB.Text.Trim();
            try
            {
                repo.rep.Connection.Connect(null);
            }
            catch (Exception ex)
            {
                string  message = ex.Message;
                Message dlg     = new Message(Properties.Resources.MessageDlg_ConnectionError, message);
                dlg.ShowDialog();
                this.DialogResult = DialogResult.None;
                return;
            }

            if (!P4EXPProgram.IsHAS(""))
            {
                if (repo.rep.Connection.LastResults != null &&
                    repo.rep.Connection.LastResults.ErrorList != null)
                {
                    string  message = repo.rep.Connection.LastResults.ErrorList[0].ErrorMessage;
                    Message dlg     = new Message(Properties.Resources.MessageDlg_ConnectionError, message);
                    dlg.ShowDialog();
                    this.DialogResult = DialogResult.None;
                    repo.rep.Connection.Disconnect();
                    return;
                }
            }
            repo.rep.Connection.Disconnect();
            this.DialogResult = DialogResult.OK;

            //ConnectionData cd = new ConnectionData();
            //cd.ServerPort = ServerTB.Text;
            //cd.UserName = UserTB.Text;
            //cd.Workspace = WorkspaceTB.Text;

            //ConnectionInfo = cd;

            // moved this to P4ScmProvider so we can decide whether to save the most
            // recent connection after we know it was successful.

            //if (_recentConnections == null)
            //{
            //    _recentConnections = new MRUList(5);
            //}
            //_recentConnections.Add(cd);

            //Preferences.LocalSettings["RecentConnections"] = _recentConnections;
        }
Exemplo n.º 8
0
        private void DoLogin()
        {
            string      path  = SelectedItemPaths.FirstOrDefault();
            RepoStorage store = P4EXPProgram.getRepoStorage(path);

            lock (store)
            {
                // force the login dialog
                store.ClearReconnect();
                P4EXPProgram.Connect(path, true);
            }
        }
Exemplo n.º 9
0
 private bool CheckConnection(RepoStorage repo)
 {
     if (repo.rep.Connection.Status == ConnectionStatus.Connected)
     {
         return(true);
     }
     else
     {
         string  message = Properties.Resources.OpenConnectionDlg_CheckConnectionError;
         Message dlg     = new Message(Properties.Resources.MessageDlg_UnableToCompleteAction, message);
         dlg.ShowDialog();
         return(false);
     }
 }
Exemplo n.º 10
0
        public static List <KeyValuePair <string, string> > GetClientSpec(RepoStorage repo)
        {
            P4Command       cmd     = repo.rep.Connection.CreateCommand("spec", true, "-o", "client");
            P4CommandResult results = cmd.Run();
            List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >();

            if (results.TaggedOutput != null)
            {
                foreach (KeyValuePair <string, string> kvp in results.TaggedOutput[0])
                {
                    list.Add(kvp);
                }
            }
            return(list);
        }
Exemplo n.º 11
0
        public void InitView(RepoStorage store, IList <string> files, IList <object> fields)
        {
            listItemMap = new Dictionary <string, P4ObjectTreeListViewItem>();

            IList <FileSpec> fs = FileSpec.LocalSpecList(files.ToArray());

            Files  = store.GetFileMetaData(fs.ToArray());
            Fields = fields;

            foreach (FileMetaData file in Files)
            {
                P4FileTreeListViewItem it = new P4FileTreeListViewItem(null, file, (IList <object>)Fields);
                listItemMap.Add(file.DepotPath.Path, it);
                this.Items.Add(it);
            }
        }
Exemplo n.º 12
0
        private RepoStorage SetRepoFromDlg()
        {
            RepoStorage repo = P4EXPProgram.getRepoStorage("");

            repo.rep = new Repository(new Server(new ServerAddress(ServerTB.Text.Trim())));
            repo.rep.Connection.UserName = UserTB.Text.Trim();
            try
            {
                repo.rep.Connection.Connect(null);
            }
            catch (Exception)
            {
                string  message = Properties.Resources.OpenConnectionDlg_SetRepoFromDlgError;
                Message dlg     = new Message(Properties.Resources.MessageDlg_UnableToCompleteAction, message);
                dlg.ShowDialog();
                return(null);
            }
            return(repo);
        }
Exemplo n.º 13
0
        private void NewUserBtn_Click(object sender, EventArgs e)
        {
            this.TopMost = false;

            RepoStorage repo = SetRepoFromDlg();

            if (repo != null && CheckConnection(repo))
            {
                NewUserDlg dlg     = new NewUserDlg(repo);
                User       newUser = dlg.Show(repo);
                dlg.TopMost = true;
                if (null != newUser)
                {
                    //_scm.NewUser(newUser);
                    UserTB.Text = newUser.Id;
                }
                //repo.Dispose();
            }
            this.TopMost = true;
        }
Exemplo n.º 14
0
        public static Client EditWorkspace(RepoStorage repo, Client workspace)
        {
            Client updatedClient = null;

            while (updatedClient == null)
            {
                Client editedWorkspace = DlgEditWorkspace.Show(repo, workspace);
                if (editedWorkspace != null)
                {
                    try
                    {
                        updatedClient = repo.rep.CreateClient(editedWorkspace, null);
                        // if the current client is being updated, update the connection with the changed client

                        if (updatedClient != null)
                        {
                            if ((repo != null) && (repo.rep != null) &&
                                (repo.connected))
                            {
                                if ((repo.rep.Connection.Client == null) ||
                                    (updatedClient.Name == repo.rep.Connection.Client.Name))
                                {
                                    repo.rep.Connection.Client = updatedClient;
                                }
                            }
                            return(updatedClient);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, Properties.Resources.P4EXP, MessageBoxButtons.OK);
                    }
                }
                else
                {
                    updatedClient = new Client();
                    return(null);
                }
            }
            return(updatedClient);
        }
Exemplo n.º 15
0
        private void BrowseUserBtn_Click(object sender, EventArgs e)
        {
            this.TopMost = false;

            RepoStorage repo = SetRepoFromDlg();

            if (repo != null && CheckConnection(repo))
            {
                UsersBrowserDlg dlg = new UsersBrowserDlg(repo, null);

                dlg.TopMost = true;;

                if ((DialogResult.Cancel != dlg.ShowDialog()) && (dlg.SelectedUser.Id != null))
                {
                    UserTB.Text = dlg.SelectedUser.Id;
                }
            }
            //_scm.Dispose();

            this.TopMost = true;;
        }
Exemplo n.º 16
0
 private bool CheckLogin(RepoStorage repo)
 {
     if (repo.rep.Connection.LastResults.ErrorList != null)
     {
         foreach (P4ClientError err in repo.rep.Connection.LastResults.ErrorList)
         {
             if (err.ErrorCode == 807672853)
             {
                 P4EXPProgram.Login(repo, true);
                 if (repo.loggedIn)
                 {
                     return(true);
                 }
                 string  message = Properties.Resources.OpenConnectionDlg_CheckLoginError;
                 Message dlg     = new Message(Properties.Resources.MessageDlg_UnableToCompleteAction, message);
                 dlg.ShowDialog();
                 return(false);
             }
         }
     }
     return(true);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Determines whether this instance can a shell context show menu, given the specified selected file list.
        /// </summary>
        /// <returns>
        ///   <c>true</c> if this instance should show a shell context menu for the specified file list; otherwise, <c>false</c>.
        /// </returns>
        protected override bool CanShowMenu()
        {
            string[] TargetFiles = SelectedItemPaths.ToArray();

            // start a connection here.
            P4EXPProgram.Connect(TargetFiles[0]);

            RepoStorage store = null;

            try
            {
                store = P4EXPProgram.getRepoStorage(TargetFiles[0]);
            }
            catch (Exception e)
            {
                FileLogger.LogException(Properties.Resources.FileLogger_MenuExtension, e);
                return(true);
            }

            lock (store)
            {
                try
                {
                    loginVisible = !store.connected || !store.loggedIn;

                    if (!store.connected)
                    {
                        // notify of disconnected in top menu item
                        setConnection              = Properties.Resources.ContextMenus_SetConnectionNotConnectedMenuItem;
                        setConnectionImage         = Properties.Resources.disconnected;
                        outsideRootMenuitemVisible = false;
                        startP4VMenuitemVisible    = true;
                        return(true);
                    }

                    if (store.rep.Connection.Client == null ||
                        (store.rep.Connection.Client.Root == null &&
                         store.roots.Count < 1))
                    {
                        // notify of missing P4CLIENT in top menu item
                        setConnection              = Properties.Resources.ContextMenus_SetConnectionConnectedMenuItem;
                        setConnectionImage         = Properties.Resources.connected_with_issues;
                        outside                    = Properties.Resources.ContextMenus_NoWorkspaceSet;
                        outsideRootMenuitemVisible = true;
                        startP4VMenuitemVisible    = true;
                        return(true);
                    }

                    if (!store.IsUnderClientRoot(TargetFiles[0]))
                    {
                        // notify of outside root in top menu item
                        setConnection              = Properties.Resources.ContextMenus_SetConnectionConnectedMenuItem;
                        setConnectionImage         = Properties.Resources.connected_with_issues;
                        outside                    = Properties.Resources.ContextMenus_OutsideRoot;
                        outsideRootMenuitemVisible = true;
                        startP4VMenuitemVisible    = true;
                        return(true);
                    }



                    Repository rep = store.rep;
                    // checking here for connected and directory change

                    bool stale        = false;
                    bool checkedout   = false;
                    bool indepot      = false;
                    bool notindepot   = false;
                    bool haverev      = false;
                    bool cancheckout  = false;
                    bool folderselect = false;

                    //check if each target file is a directory and if so, convert
                    // convert to =+/...

                    List <string> selectedItems = new List <string>();
                    commandFiles = new List <FileMetaData>();

                    foreach (string path in TargetFiles)
                    {
                        string         pathToAdd = path;
                        FileAttributes attr      = System.IO.File.GetAttributes(path);
                        if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            pathToAdd   += @"\...";
                            notindepot   = true;
                            folderselect = true;
                            FileMetaData folder = new FileMetaData();
                            folder.LocalPath = new LocalPath(pathToAdd);
                            commandFiles.Add(folder);
                            pathToAdd = pathToAdd.Replace(@"\...", @"\*");
                            selectedItems.Add(pathToAdd);
                        }
                        else
                        {
                            selectedItems.Add(pathToAdd);
                            FileMetaData file = new FileMetaData();
                            file.LocalPath = new LocalPath(pathToAdd);
                            commandFiles.Add(file);
                        }
                    }

                    FileSpec[] fs = new FileSpec[TargetFiles.Length];
                    fs = FileSpec.LocalSpecArray(selectedItems.ToArray());

                    // TODO might need to set an fstat -m limit here
                    if (store.loggedIn)
                    {
                        IList <FileMetaData> fmd = P4EXPProgram.GetFileMetaData(fs);

                        // if no P4Exception is caught by attempting to get
                        // FileMetaData, remove the initial menu items and
                        // add the rest of the menu items and seperators
                        if (fmd != null)
                        {
                            moreMenuitemVisible = true;

                            foreach (FileMetaData d in fmd)
                            {
                                if (stale && checkedout && indepot && notindepot && haverev && cancheckout)
                                {
                                    break;
                                }
                                if (d == null || (d.HaveRev == -1 && d.Action != FileAction.Add))
                                {
                                    notindepot = true;
                                    break;
                                }
                                if (d.HaveRev < d.HeadRev)
                                {
                                    stale = true;
                                }
                                if (d.Action != FileAction.None)
                                {
                                    checkedout = true;
                                }
                                if (d.IsInDepot)
                                {
                                    indepot = true;
                                }
                                if (d.IsInClient)
                                {
                                    haverev = true;
                                }
                                if ((d.Action == FileAction.None) && d.IsInClient && d.IsInDepot)
                                {
                                    cancheckout = true;
                                }
                            }
                        }
                        else
                        {
                            outsideRootMenuitemVisible = true;
                            startP4VMenuitemVisible    = true;
                        }

                        if (stale || folderselect)
                        {
                            getLatestMenuitemVisible = true;
                            subSeperator1Visible     = true;
                        }
                        if (checkedout || folderselect)
                        {
                            submitMenuitemVisible = true;
                        }
                        if (cancheckout || folderselect)
                        {
                            checkoutMenuitemVisible = true;
                            subSeperator2Visible    = true;
                        }
                        if (notindepot || folderselect)
                        {
                            addMenuitemVisible = true;
                        }
                        if (cancheckout)
                        {
                            deleteMenuitemVisible = true;
                            subSeperator2Visible  = true;
                        }
                        if (checkedout || folderselect || notindepot)
                        {
                            subSeperator2Visible = true;
                            if (!notindepot)
                            {
                                if (!folderselect)
                                {
                                    revertMenuitemVisible = true;
                                }
                                revertUnchangedMenuitemVisible = true;
                                subSeperator3Visible           = true;
                            }
                        }

                        // only on single selection of file
                        if (TargetFiles.Length == 1)
                        {
                            if (!folderselect && haverev)
                            {
                                diffAgainstHaveMenuitemVisible = true;
                                diffAgainstMenuitemVisible     = true;
                                fileHistoryMenuitemVisible     = true;
                                timeLapseViewMenuitemVisible   = true;
                                propertiesMenuitemVisible      = true;
                                showInP4VMenuitemVisible       = true;
                                subSeperator4Visible           = true;
                            }
                            else
                            {
                                if (!folderselect)
                                {
                                    diffAgainstMenuitemVisible = true;
                                }
                                // don't allow folder history on the
                                // workspace root
                                if (TargetFiles[0] != store.rep.Connection.Client.Root)
                                {
                                    fileHistoryMenuitemVisible = true;
                                }
                                subSeperator4Visible = true;
                            }
                        }

                        if ((haverev && !(checkedout)) || folderselect)
                        {
                            removeFromWorkspaceMenuitemVisible = true;
                        }
                        if (fmd != null || folderselect || notindepot)
                        {
                            refreshFileStateMenuitemVisible = true;
                            subSeperator5Visible            = true;
                            pendingChangesMenuitemVisible   = true;
                            moreMenuitemVisible             = true;
                        }
                    }
                }
                catch (P4Exception ex)
                {
                    // Leaving this for now. It looks like it is a possible redundant check
                    // of more efficient if (ex.ErrorCode == P4ClientError.MsgDb_NotUnderRoot)
                    // below. It also looks like it would never be hit based on the string
                    // "outside root". Adding a message dialog for the case that this ever gets
                    // hit.
                    if (ex.ErrorLevel == ErrorSeverity.E_FATAL && ex.Message == "outside root")
                    {
                        Message message = new Message("CanShowMenu() P4Exception", ex.Message);
                        message.ShowDialog();
                        setConnection              = Properties.Resources.ContextMenus_SetConnectionConnectedMenuItem;
                        setConnectionImage         = Properties.Resources.connected_with_issues;
                        outside                    = Properties.Resources.ContextMenus_OutsideRoot;
                        outsideRootMenuitemVisible = true;
                        startP4VMenuitemVisible    = true;
                    }

                    if (P4EXPProgram.IsLoginException(ex.ErrorCode))
                    {
                        P4EXPProgram.Login(TargetFiles[0]);
                        if (store.rep.Connection.Status == ConnectionStatus.Disconnected)
                        {
                            // notify of disconnected in top menu item
                            setConnection              = Properties.Resources.ContextMenus_SetConnectionNotConnectedMenuItem;
                            setConnectionImage         = Properties.Resources.disconnected;
                            outsideRootMenuitemVisible = false;
                            startP4VMenuitemVisible    = true;
                        }
                    }
                    else if (ex.ErrorCode == P4ClientError.MsgServer_PasswordExpired)
                    {
                        store.loggedIn = false;
                        loginVisible   = true;
                        string  message = ex.Message;
                        Message dlg     = new Message(Properties.Resources.MessageDlg_PasswordExpired, message);
                        dlg.ShowDialog();
                    }
                    else if (ex.ErrorCode == P4ClientError.MsgDm_NeedClient)
                    {
                        // second happens when P4CLIENT is not set 841226339
                        setConnection              = Properties.Resources.ContextMenus_SetConnectionConnectedMenuItem;
                        setConnectionImage         = Properties.Resources.connected_with_issues;
                        outside                    = Properties.Resources.ContextMenus_NoWorkspaceSet;
                        outsideRootMenuitemVisible = true;
                        startP4VMenuitemVisible    = true;
                    }
                    else if (ex.ErrorCode == P4ClientError.MsgDb_NotUnderRoot)
                    {
                        // do nothing, this is a file not under workspace root.
                        // just return, the context menu is already set to show this.
                        outsideRootMenuitemVisible = true;
                        startP4VMenuitemVisible    = true;
                    }
                    if (P4EXPProgram.showP4Exception())
                    {
                        string message = ex.Message + "\n" +
                                         ex.StackTrace + "\n" +
                                         ex.TargetSite.Name;
                        Message dlg = new Message(Properties.Resources.MessageDlg_P4Exception, message);
                        dlg.ShowDialog();
                    }
                    FileLogger.LogException(Properties.Resources.FileLogger_BuildContextMenu, ex);
                    return(true);
                }
                catch (Exception ex)
                {
                    // TODO: is this catching a login request?
                    // this does not appear to be something that will be
                    // part of a P4ClientError. Leaving it in for now. Unsure if it
                    // would ever be hit. Adding a message dialog for the case that
                    // this ever gets hit.
                    if (ex.Message.Contains("requires"))
                    {
                        Message message = new Message("CanShowMenu()  Exception", ex.Message);
                        message.ShowDialog();

                        P4EXPProgram.Connect(TargetFiles[0]);
                    }

                    if (store.rep != null && store.rep.Connection.Status == ConnectionStatus.Disconnected)
                    {
                        // notify of disconnected in top menu item
                        setConnection              = Properties.Resources.ContextMenus_SetConnectionNotConnectedMenuItem;
                        setConnectionImage         = Properties.Resources.disconnected;
                        outsideRootMenuitemVisible = false;
                        startP4VMenuitemVisible    = true;
                    }
                    if (P4EXPProgram.showException())
                    {
                        string message = ex.Message + "\n" +
                                         ex.StackTrace + "\n" +
                                         ex.TargetSite.Name;
                        Message dlg = new Message(Properties.Resources.MessageDlg_Exception, message);
                        dlg.ShowDialog();
                    }
                    FileLogger.LogException(Properties.Resources.FileLogger_BuildContextMenu, ex);
                    return(true);
                }
            }
            //  We always show the menu for now. This will still return true,
            // but individual menu items may be made invisible
            return(true);
        }
Exemplo n.º 18
0
 public NewUserDlg(RepoStorage repo)
 {
     Repo = repo;
     InitializeComponent();
     this.FormBorderStyle = FormBorderStyle.FixedDialog;
 }
Exemplo n.º 19
0
        public static Client EditWorkspace(RepoStorage repo, string workspaceName, Options options)
        {
            Client workspace = repo.rep.GetClient(workspaceName, null);

            return(EditWorkspace(repo, workspace));
        }
Exemplo n.º 20
0
        public static Client Show(RepoStorage repo, Client workspace)
        {
            if (workspace == null)
            {
                return(null);
            }
            DlgEditWorkspace dlg = new DlgEditWorkspace();

            if (dlg.DialogResult == DialogResult.Cancel)
            {
                return(null);
            }

            dlg.Text = string.Format(Properties.Resources.DlgEditWorkspace_Title, workspace.Name,
                                     repo.rep.Connection.Server.Address.Uri, repo.rep.Connection.UserName);


            dlg.workspaceFormNameTB.Text = workspace.Name;

            //if (Preferences.LocalSettings.GetBool("P4Date_format", true))
            //{
            //	dlg.workspaceUpdatedFormTB.Text = workspace.Updated.ToString("yyyy/MM/dd HH:mm:ss");
            //	dlg.workspaceLastAccessedFormTB.Text = workspace.Accessed.ToString("yyyy/MM/dd HH:mm:ss");
            //}
            //else
            //{
            //	dlg.workspaceUpdatedFormTB.Text = workspace.Updated.ToString();
            //	dlg.workspaceLastAccessedFormTB.Text = workspace.Accessed.ToString();
            //}
            if (workspace.Updated == DateTime.MinValue)
            {
                dlg.workspaceUpdatedFormTB.Text = string.Empty;
            }
            if (workspace.Accessed == DateTime.MinValue)
            {
                dlg.workspaceLastAccessedFormTB.Text = string.Empty;
            }
            dlg.workspaceOwnerNameFormTB.Text = workspace.OwnerName;
            if (workspace.Description != null)
            {
                dlg.workspaceDescriptionFormRTB.Text = workspace.Description;
            }
            dlg.workspaceRootFormTB.Text = workspace.Root;
            if (workspace.AltRoots != null)
            {
                foreach (string altRoot in workspace.AltRoots)
                {
                    dlg.workspaceAltRootsFormRTB.AppendText(altRoot + "\r\n");
                }
            }
            if (workspace.Host != null)
            {
                dlg.hostFormTB.Text = workspace.Host;
            }

            string selectedOpts = workspace.SubmitOptions;

            dlg.submitOptionsFormCB.Text = selectedOpts;
            string selectedLineEnd = workspace.LineEnd.ToString();

            dlg.lineEndingsFormCB.Text = selectedLineEnd;

            dlg.workspaceStreamRootFormTB.Enabled      = false;
            dlg.workspacesStreamAtChangeFormTB.Enabled = false;
            dlg.workspacesServerIDFormTB.Enabled       = false;

            // try to populate the spec with existing entries

            if (workspace.Stream != null)
            {
                dlg.workspaceStreamRootFormTB.Text    = workspace.Stream;
                dlg.workspaceStreamRootFormTB.Enabled = true;
            }

            if (workspace.StreamAtChange != null)
            {
                dlg.workspacesStreamAtChangeFormTB.Text    = workspace.StreamAtChange;
                dlg.workspacesStreamAtChangeFormTB.Enabled = true;
            }

            if (workspace.ServerID != null)
            {
                dlg.workspacesServerIDFormTB.Text    = workspace.ServerID;
                dlg.workspacesServerIDFormTB.Enabled = true;
            }


            List <KeyValuePair <string, string> > clientSpec = GetClientSpec(repo);

            if (clientSpec != null)
            {
                foreach (var pair in clientSpec)
                {
                    if (pair.Key.Contains("Values2"))
                    {
                        dlg.lineEndingsFormCB.Items.Clear();
                        string lineEnds = pair.Value;
                        lineEnds = lineEnds.Remove(0, lineEnds.LastIndexOf(" ") + 1);
                        string[] lineEndsArray = lineEnds.Split('/');
                        foreach (string lineEnd in lineEndsArray)
                        {
                            dlg.lineEndingsFormCB.Items.Add(lineEnd);
                        }
                        selectedLineEnd            = workspace.LineEnd.ToString();
                        dlg.lineEndingsFormCB.Text = selectedLineEnd;
                    }
                    if (pair.Value.Contains("Stream line 64 optional"))
                    {
                        dlg.workspaceStreamRootFormTB.Text    = workspace.Stream;
                        dlg.workspaceStreamRootFormTB.Enabled = true;
                    }

                    if (pair.Value.Contains("StreamAtChange line 64 optional"))
                    {
                        dlg.workspacesStreamAtChangeFormTB.Text    = workspace.StreamAtChange;
                        dlg.workspacesStreamAtChangeFormTB.Enabled = true;
                    }

                    if (pair.Value.Contains("ServerID line 64 always"))
                    {
                        dlg.workspacesServerIDFormTB.Text    = workspace.ServerID;
                        dlg.workspacesServerIDFormTB.Enabled = true;
                    }
                }
            }


            if (workspace.ViewMap != null)
            {
                dlg.workspaceViewMapFormRTB.Text = workspace.ViewMap.ToString();
            }
            dlg.allwriteFormChk.Checked = ((workspace.Options & ClientOption.AllWrite) != 0);
            dlg.clobberFormChk.Checked  = ((workspace.Options & ClientOption.Clobber) != 0);
            dlg.compressFormChk.Checked = ((workspace.Options & ClientOption.Compress) != 0);
            dlg.lockedFormChk.Checked   = ((workspace.Options & ClientOption.Locked) != 0);
            dlg.modtimeFormChk.Checked  = ((workspace.Options & ClientOption.ModTime) != 0);
            dlg.rmdirFormChk.Checked    = ((workspace.Options & ClientOption.RmDir) != 0);

            if (dlg.ShowDialog() != DialogResult.Cancel)
            {
                if (dlg.DialogResult == DialogResult.OK)
                {
                    workspace.Name = dlg.workspaceFormNameTB.Text;
                    //workspace.Updated.ToShortDateString() = dlg.workspaceUpdatedFormTB.Text;
                    //workspace.Accessed.ToShortDateString() = dlg.workspaceLastAccessedFormTB.Text;
                    workspace.OwnerName = dlg.workspaceOwnerNameFormTB.Text;

                    workspace.Description = dlg.workspaceDescriptionFormRTB.Text;

                    workspace.Root = dlg.workspaceRootFormTB.Text;

                    string[] alt = Regex.Split(dlg.workspaceAltRootsFormRTB.Text, "\r\n");

                    workspace.AltRoots = alt.ToList();

                    workspace.Host = dlg.hostFormTB.Text;

                    workspace.SubmitOptions = dlg.submitOptionsFormCB.Text;

                    workspace.LineEnd = (LineEnd)Enum.Parse(typeof(LineEnd), dlg.lineEndingsFormCB.Text, true);

                    string mapLines = dlg.workspaceViewMapFormRTB.Text.Trim();

                    List <string> map = new List <string>(mapLines.Split('\n'));

                    if (clientSpec != null)
                    {
                        foreach (var pair in clientSpec)
                        {
                            if (pair.Value.Contains("Stream line 64 optional"))
                            {
                                workspace.Stream = dlg.workspaceStreamRootFormTB.Text;
                            }

                            if (pair.Value.Contains("StreamAtChange line 64 optional"))
                            {
                                workspace.StreamAtChange = dlg.workspacesStreamAtChangeFormTB.Text;
                            }

                            if (pair.Value.Contains("ServerID line 64 always"))
                            {
                                workspace.ServerID = dlg.workspacesServerIDFormTB.Text;
                            }
                        }
                    }

                    ViewMap vm = new ViewMap(map);

                    workspace.ViewMap = vm;

                    workspace.Options = ClientOption.None;

                    if (dlg.allwriteFormChk.Checked)
                    {
                        workspace.Options |= ClientOption.AllWrite;
                    }

                    if (dlg.clobberFormChk.Checked)
                    {
                        workspace.Options |= ClientOption.Clobber;
                    }

                    if (dlg.compressFormChk.Checked)
                    {
                        workspace.Options |= ClientOption.Compress;
                    }

                    if (dlg.lockedFormChk.Checked)
                    {
                        workspace.Options |= ClientOption.Locked;
                    }

                    if (dlg.modtimeFormChk.Checked)
                    {
                        workspace.Options |= ClientOption.ModTime;
                    }

                    if (dlg.rmdirFormChk.Checked)
                    {
                        workspace.Options |= ClientOption.RmDir;
                    }

                    return(workspace);
                }

                if (dlg.DialogResult == DialogResult.OK)
                {
                    return(workspace);
                }
            }
            return(null);
        }
Exemplo n.º 21
0
        private void NewWorkspaceBtn_Click(object sender, EventArgs e)
        {
            this.TopMost = false;

            RepoStorage repo = SetRepoFromDlg();

            if (repo != null && CheckConnection(repo) && CheckLogin(repo))
            {
                Client workspace  = null;
                Client clientInfo = new Client();
                string newName    = GetStringDlg.Show(Properties.Resources.OpenConnectionDlg_NewWorkspaceDlgTitle,
                                                      Properties.Resources.OpenConnectionDlg_NewWorkspaceDlgPrompt, null);
                if ((newName != null) && (newName != string.Empty))
                {
                    if (newName.Contains(" "))
                    {
                        MessageBox.Show(Properties.Resources.OpenConnectionDlg_NameContainsSpacesWarning, Properties.Resources.P4EXP,
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    ClientsCmdOptions opts = new ClientsCmdOptions(ClientsCmdFlags.None, null, newName, 1, null);
                    //IList<Client> checkExisting = _scm.getClients(ClientsCmdFlags.None, null, newName, 1, null);
                    IList <Client> checkExisting = repo.rep.GetClients(opts);

                    if (checkExisting == null)
                    {
                        clientInfo = repo.rep.GetClient(newName);
                        if (clientInfo != null)
                        {
                            // adjust root here based on users dir
                            string root = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                            int    idx  = root.LastIndexOf(@"\");
                            root            = root.Remove(idx + 1);
                            root           += newName;
                            clientInfo.Root = root;
                            workspace       = DlgEditWorkspace.EditWorkspace(repo, clientInfo);
                        }
                    }
                    else
                    {
                        MessageBox.Show(string.Format(Properties.Resources.OpenConnectionDlg_WorkspaceExistsWarning, newName),
                                        Properties.Resources.P4EXP, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NewWorkspaceBtn_Click(null, null);
                    }
                }
                else
                {
                    if (newName == string.Empty)
                    {
                        MessageBox.Show(Properties.Resources.OpenConnectionDlg_EmptyWorkspaceNameWarning,
                                        Properties.Resources.P4EXP, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NewWorkspaceBtn_Click(null, null);
                    }
                }
                if (workspace != null)
                {
                    WorkspaceTB.Text = workspace.Name;
                }
            }
            this.TopMost = true;
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
0
        public WorkspaceBrowserDlg(RepoStorage repo, string sender)
        {
            PreferenceKey = "WorkspaceBrowserDlg";

            Repo = repo;
            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("workspace_icon.png", Images.workspace_icon);

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

            if (Repo != null)
            {
                ClientsCmdOptions opts = new ClientsCmdOptions(ClientsCmdFlags.None, null,
                                                               null, 0, null);
                try
                {
                    IList <Client> workspaces = Repo.rep.GetClients(opts);
                    foreach (Client workspace in workspaces)
                    {
                        string id = workspace.Name;

                        DateTime localAccess = workspace.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        = workspace.OwnerName;
                        string name         = workspace.Description;

                        string[]     theUser = new string[] { id, email, lastAccessed, name };
                        ListViewItem lvi     = new ListViewItem(theUser);
                        lvi.Tag        = workspace;
                        lvi.ImageIndex = 0;
                        listView1.Items.Add(lvi);
                    }
                }
                catch (Exception ex)
                {
                    Message dlg = new Message(Properties.Resources.MessageDlg_Exception, ex.Message);
                    dlgCancelled = true;
                    dlg.ShowDialog();
                }
            }
            ClosedByDoubleClick = false;
        }