Example #1
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);
        }
Example #2
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;
        }
Example #3
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);
        }