Beispiel #1
0
        public static P4.Client EditWorkspace(P4ScmProvider scm, P4.Client workspace)
        {
            P4.Client updatedClient = null;
            while (updatedClient == null)
            {
                P4.Client editedWorkspace = DlgEditWorkspace.Show(scm, workspace);
                if (editedWorkspace != null)
                {
                    try
                    {
                        updatedClient = scm.createClient(workspace, null);
                        // if the current client is being updated, update the connection with the changed client

                        if (updatedClient != null)
                        {
                            if ((scm != null) && (scm.Connection.Repository != null) &&
                                (scm.Connection.Repository.Connection != null))
                            {
                                if ((scm.Connection.Repository.Connection.Client == null) ||
                                    (updatedClient.Name == scm.Connection.Repository.Connection.Client.Name))
                                {
                                    scm.Connection.Repository.Connection.Client = updatedClient;
                                }
                            }
                            return(updatedClient);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, Resources.PerforceSCM, MessageBoxButtons.OK);
                    }
                }
                else
                {
                    updatedClient = new P4.Client();
                    return(null);
                }
            }
            return(updatedClient);
        }
Beispiel #2
0
        private void NewWorkspaceBtn_Click(object sender, EventArgs e)
        {
            this.TopMost = false;

            P4ScmProvider _scm = new P4ScmProvider(null);

            _scm.Connection.Port = ServerPort;
            _scm.Connection.User = UserName;

            _scm.Connection.Connect(true, null, true);
            if (_scm.Connected && _scm.Connection.isLoggedIn())
            {
                P4.Client workspace  = null;
                P4.Client clientInfo = new P4.Client();
                string    newName    = GetStringDlg.Show(Resources.OpenConnectionDlg_NewWorkspaceDlgTitle,
                                                         Resources.OpenConnectionDlg_NewWorkspaceDlgPrompt, null);
                if ((newName != null) && (newName != string.Empty))
                {
                    if (newName.Contains(" "))
                    {
                        MessageBox.Show(Resources.OpenConnectionDlg_NameContainsSpacesWarning, Resources.P4VS,
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    IList <P4.Client> checkExisting = _scm.getClients(P4.ClientsCmdFlags.None, null, newName, 1, null);
                    if (checkExisting == null)
                    {
                        clientInfo = _scm.getClient(newName, null);
                        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(_scm, clientInfo);
                        }
                    }
                    else
                    {
                        MessageBox.Show(string.Format(Resources.OpenConnectionDlg_WorkspaceExistsWarning, newName),
                                        Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NewWorkspaceBtn_Click(null, null);
                    }
                }
                else
                {
                    if (newName == string.Empty)
                    {
                        MessageBox.Show(Resources.OpenConnectionDlg_EmptyWorkspaceNameWarning,
                                        Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NewWorkspaceBtn_Click(null, null);
                    }
                }
                if (workspace != null)
                {
                    WorkspaceTB.Text = workspace.Name;
                }
            }
            this.TopMost = true;
        }
Beispiel #3
0
        public static P4.Client Show(P4ScmProvider scm, P4.Client workspace)
        {
            if (workspace == null)
            {
                return(null);
            }
            DlgEditWorkspace dlg = new DlgEditWorkspace();

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

            dlg.Text = string.Format(Resources.DlgEditWorkspace_Title, workspace.Name, scm.Connection.Port, scm.Connection.User);


            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 = scm.GetClientSpec();

            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 & P4.ClientOption.AllWrite) != 0);
            dlg.clobberFormChk.Checked  = ((workspace.Options & P4.ClientOption.Clobber) != 0);
            dlg.compressFormChk.Checked = ((workspace.Options & P4.ClientOption.Compress) != 0);
            dlg.lockedFormChk.Checked   = ((workspace.Options & P4.ClientOption.Locked) != 0);
            dlg.modtimeFormChk.Checked  = ((workspace.Options & P4.ClientOption.ModTime) != 0);
            dlg.rmdirFormChk.Checked    = ((workspace.Options & P4.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 = (P4.LineEnd)Enum.Parse(typeof(P4.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;
                            }
                        }
                    }

                    P4.ViewMap vm = new P4.ViewMap(map);

                    workspace.ViewMap = vm;

                    workspace.Options = P4.ClientOption.None;

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

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

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

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

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

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

                    return(workspace);
                }

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