Exemple #1
0
        private void removeFixToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // remove the selected changelist from the job

            P4.Changelist selected = fixesLV.SelectedItems[0].Tag as P4.Changelist;
            try
            {
                P4.Options     opts        = new P4.Options(P4.FixJobsCmdFlags.Delete, -1, null);
                IList <P4.Fix> fixToRemove = selected.FixJobs(opts, currentJob);
            }
            catch (Exception ex)
            {
                scm.ShowException(ex);
                return;
            }
            attachedFixes.Remove(selected);
            P4FileTreeListViewItem itemToRemove = fixesLV.SelectedItems[0] as P4FileTreeListViewItem;

            foreach (TreeListViewItem child in itemToRemove.ChildNodes)
            {
                fixesLV.Items.Remove(child);
            }

            fixesLV.Nodes.Remove(itemToRemove);
            fixesLV.Items.Remove(itemToRemove);
            fixesLV.BuildTreeList();
        }
Exemple #2
0
        private void saveBtn_Click(object sender, EventArgs e)
        {
            if (userNameTB.Text.Contains(" "))
            {
                MessageBox.Show(Resources.NewUserDlg_NameContainsSpacesWarning, Resources.P4VS,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            if (!(string.IsNullOrEmpty(password1TB.Text)) || !(string.IsNullOrEmpty(password2TB.Text)))
            {
                if (password1TB.Text != password2TB.Text)
                {
                    MessageBox.Show(Resources.NewUserDlg_PasswordsDontMatchWarning, Resources.P4VS,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }


            P4.Options     opts  = new P4.Options();
            IList <string> users = new List <string>();

            users.Add(userNameTB.Text);

            if ((SetPasswordOnly == true) || (Scm.GetUsers(users, opts) == null))
            {
                DialogResult = DialogResult.OK;
                Close();
            }
            else
            {
                string msg = string.Format(Resources.NewUserDlg_UserExistsWarning, userNameTB.Text);
                MessageBox.Show(msg, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #3
0
        public void AddFile(string LocalPath)
        {
            lock (cache)
            {
                if (Preferences.LocalSettings.GetBool("TreatProjectsAsFolders", true))
                {
                    string directoryPath = Path.GetDirectoryName(LocalPath);
                    if (directoryPath != null && ((CachedDirectories != null) &&
                                                  (CachedDirectories.ContainsKey(GetKey(directoryPath))) &&
                                                  (CachedDirectories[GetKey(directoryPath)] != DateTime.MinValue)))
                    {
                        cache[GetKey(LocalPath)] = null;
                        logger.Trace("AddFile: {0}", LocalPath);
                        return;
                    }
                    else if (directoryPath != null && ((CachedDirectories == null) ||
                                                       !CachedDirectories.ContainsKey(GetKey(directoryPath))))
                    {
                        AddDirectoryFilesToCache(directoryPath, false);
                        logger.Trace("AddDir: {0}", directoryPath);
                        return;
                    }
                }
                P4.Options opts = new P4.Options();
                opts["-Olhp"] = null;
                IList <P4.FileMetaData> files = _repository.GetFileMetaData(opts, P4.FileSpec.LocalSpec(LocalPath));

                if ((files != null) && (files.Count > 0))
                {
                    cache[GetKey(LocalPath)] = new CachedFile(files[0]);
                    logger.Trace("AddDirMeta: {0}", LocalPath);
                }
            }
        }
Exemple #4
0
        public static P4.Repository get(String Port, String User, String Workspace)
        {
            // Verify Paramiters
            if (string.IsNullOrEmpty(Port))
            {
                throw new P4.P4Exception(P4.ErrorSeverity.E_FATAL, "P4PORT is invalid or not set");
            }

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

            // Get Server connection
            P4.Server server = new P4.Server(new P4.ServerAddress(Port));

            // Create new Repository
            Repository = new P4.Repository(server);

            // set User
            if (!string.IsNullOrEmpty(User))
            {
                Repository.Connection.UserName = User;
            }

            // set Client
            if (!string.IsNullOrEmpty(Workspace))
            {
                P4.Client client = new P4.Client();
                client.Name = Workspace;
                Repository.Connection.Client = client;
            }

            // Connect...
            try
            {
                logger.Debug("AsyncConnectToRepository - Connect");
                bool connectResults = Repository.Connection.Connect(options);
                logger.Debug("AsyncConnectToRepository, result {0}", connectResults);
            }
            catch (P4.P4Exception ex)
            {
                // Look for trust errors
                checkTrust(ex);
            }

            // Set Command Timeout limits
            TimeSpan defCmdTimeout = TimeSpan.FromSeconds(30);
            TimeSpan cmdTimeout    = Preferences.LocalSettings.GetTimeSpan("CommandTimeOut", defCmdTimeout);

            Repository.Connection.CommandTimeout = cmdTimeout;

            return(Repository);
        }
Exemple #5
0
        public P4ChangeTreeListViewItem(TreeListViewItem parentItem, P4.Changelist changeData,
                                        P4ScmProvider scm, IList <object> fields)
            : base()
        {
            ParentItem = parentItem;
            Fields     = fields;
            NodeType   = nodeType.Pending;           // default
            Scm        = scm;
            Tag        = changeData;

            Ours = (changeData.ClientId == Scm.Connection.Workspace);

            if (Ours)
            {
                P4.Options opts = new P4.Options();

                if (changeData.Id > 0)
                {
                    opts["-e"] = changeData.Id.ToString();
                }
                else
                {
                    opts["-e"] = "default";
                    NodeType.Set(nodeType.Default);
                }
                opts["-Ru"] = null;
                opts["-m"]  = "1";
                P4.FileSpec        fs  = new P4.FileSpec(new P4.ClientPath(@"//" + Scm.Connection.Workspace + @"/..."), null);
                List <P4.FileSpec> lfs = new List <P4.FileSpec>();
                lfs.Add(fs);
                IList <P4.FileMetaData> unresolved = Scm.GetFileMetaData(lfs, opts);

                if ((unresolved != null) && (unresolved.Count > 0))
                {
                    NeedsResolve = true;
                }
            }

            _changeData = changeData;             // don't call InitSubitems() or SelectImagesFromMetaData() yet

            if (changeData.Id > 0)
            {
                _reviewData = Scm.Connection.Swarm.IsChangelistAttachedToReview(changeData.Id);
            }
            InitSubitems();
            SelectImagesFromMetaData();
        }
Exemple #6
0
        private void AddFiles(IList <string> LocalPaths)
        {
            lock (cache)
            {
                P4.Options opts = new P4.Options();
                opts["-Olhp"] = null;
                IList <P4.FileMetaData> files = _repository.GetFileMetaData(P4.FileSpec.LocalSpecList(LocalPaths.ToArray()), opts);

                if ((files != null) && (files.Count > 0))
                {
                    foreach (P4.FileMetaData file in files)
                    {
                        cache[GetKey(file.LocalPath.Path)] = new CachedFile(file);
                        logger.Trace("AddFiles: {0}", file.LocalPath.Path);
                    }
                }
            }
        }
Exemple #7
0
        private IList <string> UpdateFiles(IList <string> LocalPaths)
        {
            IList <string> updatedFiles = new List <string>();

            lock (cache)
            {
                P4.Options opts = new P4.Options();
                opts["-Olhp"] = null;
                IList <P4.FileMetaData> files = _repository.GetFileMetaData(P4.FileSpec.LocalSpecList(LocalPaths.ToArray()), opts);

                if ((files != null) && (files.Count > 0))
                {
                    foreach (P4.FileMetaData file in files)
                    {
                        var key = GetKey(file.LocalPath.Path);
                        if (cache.ContainsKey(key))
                        {
                            SourceControlStatus oldStat = cache[key].ScmStatus;
                            SourceControlStatus newStat = new SourceControlStatus(file);
                            if (oldStat.Flags != newStat.Flags)
                            {
                                cache[key] = new CachedFile(file);
                                updatedFiles.Add(file.LocalPath.Path);
                                logger.Trace("UpdateFiles: {0}", file.LocalPath.Path);
                            }
                        }
                        else
                        {
                            cache[key] = new CachedFile(file);
                            updatedFiles.Add(file.LocalPath.Path);
                            logger.Trace("UpdateFiles: {0}", file.LocalPath.Path);
                        }
                    }
                }
            }
            return(updatedFiles);
        }
Exemple #8
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);
        }
Exemple #9
0
        private void actionBtn_Click(object sender, EventArgs e)
        {
            previewTB.Clear();
            string sourceSelection = string.Empty;

            if (sourceCB.Enabled)
            {
                sourceSelection = this.sourceCB.SelectedItem.ToString();
            }
            else if (sourceTB.Enabled)
            {
                sourceSelection = this.sourceTB.Text;
            }

            P4.Stream effectiveTarget = _scm.GetStream(_target, null, null);
            P4.Stream effectiveSource = _scm.GetStream(sourceSelection, null, null);

            if (effectiveSource == null || effectiveTarget == null)
            {
                return;
            }

            if (effectiveTarget.Type == P4.StreamType.Virtual)
            {
                if (effectiveTarget.BaseParent != null)
                {
                    effectiveTarget = _scm.GetStream(effectiveTarget.BaseParent.Path, null, null);
                }
                else if (effectiveTarget.Parent != null)
                {
                    effectiveTarget = _scm.GetStream(effectiveTarget.Parent.Path, null, null);
                }
            }

            if (effectiveSource.Type == P4.StreamType.Virtual)
            {
                if (effectiveSource.BaseParent != null)
                {
                    effectiveSource = _scm.GetStream(effectiveSource.BaseParent.Path, null, null);
                }
                else if (effectiveSource.Parent != null)
                {
                    effectiveSource = _scm.GetStream(effectiveSource.Parent.Path, null, null);
                }
            }

            P4.Options          opts  = new P4.Options();
            IList <P4.FileSpec> files = new List <P4.FileSpec>();

            if ((effectiveSource.Parent != null && effectiveSource.Parent.Path == effectiveTarget.Id) || (effectiveSource.BaseParent != null && effectiveSource.BaseParent.Path == effectiveTarget.Id))
            {
                opts["-S"] = effectiveSource.Id;
            }
            else if ((effectiveTarget.Parent != null && effectiveTarget.Parent.Path == effectiveSource.Id) || (effectiveTarget.BaseParent != null && effectiveTarget.BaseParent.Path == effectiveSource.Id))
            {
                opts["-S"] = effectiveTarget.Id;
                opts["-r"] = null;
            }

            if (_action == "merge")
            {
                files = _scm.MergeFiles(opts);
            }
            else if (_action == "copy")
            {
                files = _scm.CopyFiles(opts);
            }

            P4.P4CommandResult results = _scm.Connection.Repository.Connection.LastResults;
            string             preview = null;

            if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
            {
                previewTB.Text = preview;
                foreach (P4.P4ClientError error in _scm.Connection.Repository.Connection.LastResults.ErrorList)
                {
                    previewTB.AppendText(error.ErrorMessage);
                }
                DialogResult = DialogResult.None;
                return;
            }
            if (files != null)
            {
                // if there are files to merge or copy, offer
                // changelist selection and submit or save
                int                   count   = files.Count();
                string                target  = targetTB.Text;
                string                action  = null;
                string                summary = string.Empty;
                P4.Changelist         getDesc = _scm.GetChangelist(-1);
                string                newChangeDescription = getDesc.Description;
                IList <P4.Changelist> changes = _scm.GetAvailibleChangelists(-1);

                if (count > 1)
                {
                    if (_action == "merge")
                    {
                        summary = string.Format(Resources.P4VsProviderService_MergeSummary, count);
                        if (newChangeDescription == null ||
                            newChangeDescription == Resources.DefaultChangeListDescription)
                        {
                            newChangeDescription = string.Format(
                                Resources.P4VsProviderService_MergeChangeDescription, target);
                        }
                    }
                    else if (_action == "copy")
                    {
                        summary = string.Format(Resources.P4VsProviderService_CopySummary, count);
                        if (newChangeDescription == null ||
                            newChangeDescription == Resources.DefaultChangeListDescription)
                        {
                            newChangeDescription = string.Format(
                                Resources.P4VsProviderService_CopyChangeDescription, target);
                        }
                        if (submitCopiedRB.Checked)
                        {
                            string[] fileStringArray = new string[count];
                            for (int idx = 0; idx < count; idx++)
                            {
                                fileStringArray[idx] = files[idx].LocalPath.Path;
                            }
                            _scm.SubmitFiles(newChangeDescription, null, false, fileStringArray);
                            return;
                        }
                    }
                }
                else
                {
                    if (_action == "merge")
                    {
                        summary = Resources.P4VsProviderService_Merge1Summary;
                        if (newChangeDescription == null ||
                            newChangeDescription == Resources.DefaultChangeListDescription)
                        {
                            newChangeDescription = string.Format(
                                Resources.P4VsProviderService_Merge1ChangeDescription, target);
                        }
                    }
                    else if (_action == "copy")
                    {
                        summary = Resources.P4VsProviderService_Copy1Summary;
                        if (newChangeDescription == null ||
                            newChangeDescription == Resources.DefaultChangeListDescription)
                        {
                            newChangeDescription = string.Format(
                                Resources.P4VsProviderService_Copy1ChangeDescription, target);
                        }
                        if (submitCopiedRB.Checked)
                        {
                            _scm.SubmitFiles(newChangeDescription, null, false, files[0].LocalPath.Path);
                            return;
                        }
                    }
                }

                int           changeListId = -1;
                P4.Changelist changelist   = SelectChangelistDlg.ShowChooseChangelistSubmit(
                    summary,
                    changes, ref newChangeDescription, out action, true, true, _scm);
                changeListId = changelist.Id;

                if (changeListId == -2)
                {
                    // user hit 'No'
                    return;
                }
                opts = new P4.Options();

                if (changeListId > 0)
                {
                    opts["-c"] = changeListId.ToString();
                }

                P4.Changelist changeToSubmit = _scm.Connection.Repository.NewChangelist();
                if (changeListId == -1)
                {
                    // Overwrite new changelist files. If default has files in it, a new
                    // changelist will automatically get those files.
                    changeToSubmit.Files       = files as IList <P4.FileMetaData>;
                    changeToSubmit.Description = changelist.Description;
                    changeToSubmit             = _scm.SaveChangelist(changeToSubmit, null);
                    opts["-c"]   = changeToSubmit.Id.ToString();
                    changeListId = changeToSubmit.Id;
                }

                if (opts.ContainsKey("-c"))
                {
                    Int32 c = Convert.ToInt32(opts["-c"]);
                    changeToSubmit = _scm.GetChangelist(c);
                    _scm.MoveFilesToChangeList(c, changelist.Description, files);
                    changeListId = changeToSubmit.Id;
                }

                // done, unless submit was hit
                if (action == "submit")
                {
                    changeToSubmit.Description = changelist.Description;

                    if (changeListId > 0)
                    {
                        SubmitDlg.SubmitPendingChanglist(changeToSubmit, changeToSubmit.Files, _scm);
                    }
                    else
                    {
                        IList <string> list = new List <string>();
                        foreach (P4.FileSpec fs in files)
                        {
                            list.Add(fs.LocalPath.Path.ToString());
                        }
                        SubmitDlg.SubmitFiles(list, _scm, false, changeToSubmit.Description);
                    }
                }
            }
            returnedFiles = files;
            DialogResult  = DialogResult.OK;
            return;
        }
Exemple #10
0
        private void previewBtn_Click(object sender, EventArgs e)
        {
            this.previewTB.Clear();
            string sourceSelection = string.Empty;

            if (sourceCB.Enabled)
            {
                sourceSelection = this.sourceCB.SelectedItem.ToString();
            }
            else if (sourceTB.Enabled)
            {
                sourceSelection = this.sourceTB.Text;
            }


            P4.Stream effectiveTarget = _scm.GetStream(_target, null, null);
            P4.Stream effectiveSource = _scm.GetStream(sourceSelection, null, null);

            if (effectiveTarget.Type == P4.StreamType.Virtual)
            {
                if (effectiveTarget.BaseParent != null)
                {
                    effectiveTarget = _scm.GetStream(effectiveTarget.BaseParent.Path, null, null);
                }
                else if (effectiveTarget.Parent != null)
                {
                    effectiveTarget = _scm.GetStream(effectiveTarget.Parent.Path, null, null);
                }
            }

            if (effectiveSource.Type == P4.StreamType.Virtual)
            {
                if (effectiveSource.BaseParent != null)
                {
                    effectiveSource = _scm.GetStream(effectiveSource.BaseParent.Path, null, null);
                }
                else if (effectiveSource.Parent != null)
                {
                    effectiveSource = _scm.GetStream(effectiveSource.Parent.Path, null, null);
                }
            }

            P4.Options          opts  = new P4.Options();
            IList <P4.FileSpec> files = new List <P4.FileSpec>();

            opts["-n"] = null;

            if ((effectiveSource.Parent != null && effectiveSource.Parent.Path == effectiveTarget.Id) || (effectiveSource.BaseParent != null && effectiveSource.BaseParent.Path == effectiveTarget.Id))
            {
                opts["-S"] = effectiveSource.Id;
            }
            else if ((effectiveTarget.Parent != null && effectiveTarget.Parent.Path == effectiveSource.Id) || (effectiveTarget.BaseParent != null && effectiveTarget.BaseParent.Path == effectiveSource.Id))
            {
                opts["-S"] = effectiveTarget.Id;
                opts["-r"] = null;
            }

            if (_action == "merge")
            {
                files = _scm.MergeFiles(opts);
            }
            else if (_action == "copy")
            {
                files = _scm.CopyFiles(opts);
            }

            P4.P4CommandResult results = _scm.Connection.Repository.Connection.LastResults;
            string             preview = string.Empty;

            this.previewTB.Text = preview;

            if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
            {
                foreach (P4.P4ClientError error in _scm.Connection.Repository.Connection.LastResults.ErrorList)
                {
                    this.previewTB.AppendText(error.ErrorMessage + "\r\n");
                }
            }

            if (files != null)
            {
                foreach (P4.FileSpec file in files)
                {
                    this.previewTB.AppendText(file.DepotPath.ToString() + "\r\n");
                }

                if (results.TaggedOutput != null)
                {
                    int count = files.Count;
                    if (_action == "merge")
                    {
                        if (count > 1)
                        {
                            this.previewTB.AppendText(string.Format(Resources.IntegrateDlg_FilesToBeMerged, count));
                        }
                        else
                        {
                            this.previewTB.AppendText(string.Format(Resources.IntegrateDlg_FileToBeMerged, count));
                        }
                    }
                    else if (_action == "copy")
                    {
                        if (count > 1)
                        {
                            this.previewTB.AppendText(string.Format(Resources.IntegrateDlg_FilesToBeCopied, count));
                        }
                        else
                        {
                            this.previewTB.AppendText(string.Format(Resources.IntegrateDlg_FileToBeCopied, count));
                        }
                    }
                }
            }

            this.previewTB.Enabled = true;
            this.previewTB.Visible = true;
        }
Exemple #11
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            int changeId = -1;

            if (ItemsCB.SelectedIndex >= 2)
            {
                string[] parts = ItemsCB.Text.Split(' ');

                if (parts.Length > 0)
                {
                    int.TryParse(parts[0], out changeId);
                }
            }
            else if (ItemsCB.SelectedIndex == 0)
            {
                // new changelist
                P4.Changelist change = SccService.ScmProvider.Connection.Repository.NewChangelist();
                change.Description = "Reconciled offline work";
                // Make sure files is empty. If default has files in it, a new changelist
                // will automatically get those files.
                change.Files = new List <P4.FileMetaData>();
                change       = SccService.ScmProvider.SaveChangelist(change, null);

                changeId = change.Id;
            }
            // otherwise it's the default
            else if (ItemsCB.SelectedIndex == 1)
            {
                changeId = 0;
            }

            IList <P4.FileSpec> dlgList = new List <P4.FileSpec>();

            foreach (ListViewItem item in listView1.Items)
            {
                if (item.Checked)
                {
                    P4.FileSpec fs = new P4.FileSpec();
                    fs.LocalPath = new P4.LocalPath(item.Tag.ToString());
                    dlgList.Add(fs);
                }
            }

            foreach (ListViewItem item in listView2.Items)
            {
                if (item.Checked)
                {
                    P4.FileSpec fs = new P4.FileSpec();
                    fs.LocalPath = new P4.LocalPath(item.Tag.ToString());
                    dlgList.Add(fs);
                }
            }

            foreach (ListViewItem item in listView3.Items)
            {
                if (item.Checked)
                {
                    P4.FileSpec fs = new P4.FileSpec();
                    fs.LocalPath = new P4.LocalPath(item.Tag.ToString());
                    dlgList.Add(fs);
                }
            }

            // do nothing if there are no files selected on click of Reconcile
            if (dlgList.Count > 0)
            {
                P4.Options sFlags = new P4.Options(P4.ReconcileFilesCmdFlags.NotOpened,
                                                   changeId);
                IList <P4.FileSpec> recList =
                    SccService.ScmProvider.ReconcileStatus(dlgList, sFlags);

                SccService.ScmProvider.BroadcastChangelistUpdate(this, new P4ScmProvider.ChangelistUpdateArgs(changeId,
                                                                                                              P4ScmProvider.ChangelistUpdateArgs.UpdateType.ContentUpdate));
            }

            this.Close();
        }
Exemple #12
0
 public static P4.Client EditWorkspace(P4ScmProvider scm, string workspaceName, P4.Options options)
 {
     P4.Client workspace = scm.getClient(workspaceName, options);
     return(EditWorkspace(scm, workspace));
 }
Exemple #13
0
        // Get Revision button click
        private void newOKBtn_Click(object sender, EventArgs e)
        {
            bool        updateSolution = false;
            IVsSolution solution       = null;
            string      path           = _scm.SolutionFile;

            IList <IVsHierarchy> projectsUpdating    = new List <IVsHierarchy>();
            IList <string>       projectsClosed      = new List <string>();
            IList <Guid>         projectsGuidsClosed = new List <Guid>();

            if (_isSolutionIncluded)
            {
                // Figure out a better test

                //updateSolution = _scm.SyncFile(
                //    new P4.SyncFilesCmdOptions(P4.SyncFilesCmdFlags.Preview, 1),
                //    path);

                updateSolution = true;
            }
            if (updateSolution)
            {
                if (DialogResult.Cancel == MessageBox.Show(
                        Resources.GetRevisionDlg_UpdatingSlnWarninig,
                        Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                {
                    return;
                }
                solution = (IVsSolution)P4VsProvider.Instance.GetService(typeof(SVsSolution));

                P4VsProvider.Instance.SuppressConnection = true;

                if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, null, 0))
                {
                    MessageBox.Show(Resources.Error_ClosingSolution, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else if (P4VsProvider.Instance.SccService.SelectedNodes != null)
            {
                bool needToAsk = true;
                foreach (VSITEMSELECTION pItem in P4VsProvider.Instance.SccService.SelectedNodes)
                {
                    if ((pItem.itemid == VSConstants.VSITEMID_ROOT) && (P4VsProvider.Instance.SccService.IsProjectControlled(pItem.pHier)))
                    {
#if VS2008
                        if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_UpdatingProjWarninig,
                                                                   Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                        {
                            return;
                        }
                        updateSolution = true;

                        solution = (IVsSolution)GetService(typeof(SVsSolution));

                        P4VsProvider.Instance.SuppressConnection = true;

                        if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, null, 0))
                        {
                            MessageBox.Show(Resources.Error_ClosingSolution, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
#else
                        IVsProject3 pProj = pItem.pHier as IVsProject3;
                        if (pProj != null)
                        {
                            if (needToAsk == true)
                            {
                                if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_UpdatingProjWarninig,
                                                                           Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                                {
                                    return;
                                }
                                needToAsk = false;
                            }
                            projectsUpdating.Add(pItem.pHier);

                            if (solution == null)
                            {
                                solution = (IVsSolution)P4VsProvider.Instance.GetService(typeof(SVsSolution));
                            }
                            Guid projGuid;
                            solution.GetGuidOfProject(pItem.pHier, out projGuid);
                            projectsGuidsClosed.Add(projGuid);

                            if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, pItem.pHier, 0))
                            {
                                MessageBox.Show(Resources.Error_ClosingProject, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
#endif
                    }
                }
            }
            List <string> refreshItems = new List <string>();

            try
            {
                //change this to a better global validator
                int  test = 0;
                bool num  = int.TryParse(ValueTB.Text, out test);
                if (specifierRB.Checked == true &&
                    num == false &&
                    specifierCB.SelectedIndex == 0 &&
                    ValueTB.Text != "head" &&
                    ValueTB.Text != "have" &&
                    ValueTB.Text != "none"
                    )
                {
                    MessageBox.Show(string.Format(Resources.GetRevisionDlg_InvalidRevisionSpecifierWarninig, ValueTB.Text));
                    ValueTB.Text = string.Empty;
                    return;
                }
                ////////
                _files = new List <P4.FileSpec>();

                foreach (ListViewItem item in filesListView.Items)
                {
                    P4.FileSpec     file = new P4.FileSpec();
                    P4.FileMetaData fmd  = new P4.FileMetaData();
                    if (item.Text.EndsWith("/..."))
                    {
                        fmd.DepotPath = new P4.DepotPath(item.Text);
                    }
                    else
                    {
                        fmd = _scm.GetFileMetaData(item.Text);
                    }

                    if (fmd.LocalPath != null)
                    {
                        file.LocalPath = fmd.LocalPath;
                    }
                    if (fmd.ClientPath != null)
                    {
                        file.ClientPath = fmd.ClientPath;
                    }
                    if (fmd.DepotPath != null)
                    {
                        file.DepotPath = fmd.DepotPath;
                    }
                    _files.Add(file);
                    refreshItems.Add(item.Text.ToString());
                }

                P4.SyncFilesCmdFlags flags = new P4.SyncFilesCmdFlags();
                flags = P4.SyncFilesCmdFlags.None;
                if (forceChk.Checked == true)
                {
                    flags = P4.SyncFilesCmdFlags.Force;
                }

                P4.Options options = new P4.Options(flags, -1);

                // set up the list of paths with specifiers that we will sync to
                IList <P4.FileSpec> files = new List <P4.FileSpec>();
                //int idx = 0;

                if (specifierRB.Checked == true)
                {
                    // #revision
                    if (specifierCB.SelectedIndex == 0)
                    {
                        bool disconnectAfterSync = false;
                        int  number = 0;
                        bool isnum  = int.TryParse(Value, out number);
                        if (isnum == true)
                        {
                            if (number == 0)
                            {
                                if (_isSolutionIncluded)
                                {
                                    if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_RemovingSlnWarninig,
                                                                               Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                                    {
                                        this.DialogResult = DialogResult.Cancel;
                                        return;
                                    }
                                    disconnectAfterSync = true;
                                }
                                else
                                {
                                    if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_RemovingProjWarninig,
                                                                               Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                                    {
                                        this.DialogResult = DialogResult.Cancel;
                                        return;
                                    }
                                }
                            }
                        }
                        foreach (P4.FileSpec file in _files)
                        {
                            if (isnum == true)
                            {
                                // skip meta data check for rev 0 there is none, but we dtill want to allow
                                // this as a way to remove the local copy of the file, but still keep checking
                                // to make sure other bad revisions are not fetched such as file that was moved
                                if (number != 0)
                                {
                                    IList <P4.FileSpec> fs = new List <FileSpec>();
                                    file.Version = new P4.Revision(number);
                                    fs.Add(file);
                                    IList <P4.FileMetaData> fmd = _scm.GetFileMetaData(fs, null);
                                    if (fmd == null)
                                    {
                                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                                        {
                                            if (_files.Count == 1)
                                            {
                                                P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                            }
                                            P4VsOutputWindow.AppendMessage(_scm.Connection.Repository.Connection.LastResults.ErrorList[0].ToString());
                                        }
                                        continue;
                                    }
                                }
                                file.Version = new P4.Revision(number);
                            }
                            else if (Value == "head")
                            {
                                file.Version = new P4.HeadRevision();
                            }
                            else if (Value == "have")
                            {
                                file.Version = new P4.HaveRevision();
                            }
                            else if (Value == "none")
                            {
                                file.Version = new P4.NoneRevision();
                            }
                            files.Add(file);
                        }
                        if (files.Count > 0)
                        {
                            _scm.SyncFiles(options, files);
                        }
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            if (_scm.SccService == null)
                            {
                                return;
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            if (_scm.SccService == null)
                            {
                                return;
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        if (disconnectAfterSync)
                        {
                            P4VsProvider.Instance.SccService.Dispose();
                        }
                    }

                    // @workspace
                    if (specifierCB.SelectedIndex == 4)
                    {
                        foreach (P4.FileSpec file in _files)
                        {
                            file.Version = new P4.ClientNameVersion(Value.ToString());
                            files.Add(file);
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @date/time
                    if (specifierCB.SelectedIndex == 2)
                    {
                        DateTime value = dateTimePicker.Value;

                        string timestamp = value.Date.ToShortDateString() + ":" + value.TimeOfDay.ToString();

                        foreach (P4.FileSpec file in _files)
                        {
                            file.Version = new P4.DateTimeVersion(value);
                            files.Add(file);
                        }
                        _scm.SyncFiles(options, _files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @changelist
                    if (specifierCB.SelectedIndex == 1)
                    {
                        if (changelistFilesChk.Checked == true)
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.VersionRange(new P4.ChangelistIdVersion(Convert.ToInt16(Value)),
                                                                   new P4.ChangelistIdVersion(Convert.ToInt32(Value)));
                                files.Add(file);
                            }
                        }
                        else
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.ChangelistIdVersion(Convert.ToInt32(Value));
                                files.Add(file);
                            }
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @label
                    if (specifierCB.SelectedIndex == 3)
                    {
                        if (removeChk.Checked == true)
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.LabelNameVersion(Value.ToString());
                                files.Add(file);
                            }
                        }
                        else
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.VersionRange(new P4.LabelNameVersion(Value.ToString()),
                                                                   new P4.LabelNameVersion(Value.ToString()));
                                files.Add(file);
                            }
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                }

                else if (getLatestRB.Checked == true)
                {
                    files = _files;
                    _scm.SyncFiles(options, files);
                    if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                    {
                        IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                        foreach (P4.P4ClientError error in errors)
                        {
                            if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                            {
                                P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                return;
                            }
                        }
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                }
            }
            finally
            {
                if (updateSolution)
                {
                    if (path != null)
                    {
                        solution.OpenSolutionFile(0, path);
                    }
                    if (_scm.SccService != null)
                    {
                        _scm.SccService.ResetSelection();
                    }
                }
#if !VS2008
                else if (projectsUpdating.Count > 0)
                {
                    foreach (Guid projGuid in projectsGuidsClosed)
                    {
                        Guid rProjGuid = projGuid;

                        var vsSolution4 = (IVsSolution4)solution;
                        if (vsSolution4 != null)
                        {
                            int res = vsSolution4.ReloadProject(ref rProjGuid);
                        }
                    }
                }
#endif
                // now refresh the selected nodes' glyphs
                if (_scm.SccService != null)
                {
                    _scm.SccService.UpdateProjectGlyphs(refreshItems, true);
                }
            }
        }
Exemple #14
0
        public void CheckForSwarm()
        {
            SwarmUrl = null;

            if ((repository == null) || (repository.Connection == null) ||
                repository.Connection.Status == ConnectionStatus.Disconnected || checkedForSwarm)
            {
                return;
            }
            P4.P4Command propertyCmd = repository.Connection.CreateCommand("property", true);
            P4.Options   opts        = new P4.Options();
            opts["-l"] = null;
            opts["-n"] = P4SwarmPropertyName;

            P4.P4CommandResult results = null;
            try
            {
                results = propertyCmd.Run(opts);
            }
            catch (P4Exception ex)
            {
                if (ex.ErrorCode == P4.P4ClientError.MsgServer_Login2Required)
                {
                    throw ex;
                }
                // error getting property, likely not logged in
                return;
            }
            catch
            {
                // error getting property, likely not logged in
                return;
            }
            //command ran, so if no property than not attached to swarm
            checkedForSwarm = true;

            if (results.TaggedOutput != null)
            {
                foreach (TaggedObject tag in results.TaggedOutput)
                {
                    if (tag.ContainsKey("name") && tag["name"].StartsWith(P4SwarmPropertyName) && tag.ContainsKey("value"))
                    {
                        SwarmUrl = tag["value"].TrimEnd('/');

                        SwarmApi.SwarmServer sw = new SwarmApi.SwarmServer(SwarmUrl, user, SwarmPassword);

                        if (certHandler == null)
                        {
                            certHandler = new ScmSSLCertificateHandler();
                            certHandler.Init(SwarmUrl);
                        }
                        SwarmVersion = sw.GetVersion;

                        if (SwarmVersion == null)
                        {
                            SwarmUrl = null;
                            return;
                        }

                        string msg = String.Format(Resources.P4ScmProvider_ConnectedToSwarmServer,
                                                   SwarmUrl, SwarmVersion.version);
                        P4VsOutputWindow.AppendMessage(msg);

                        FileLogger.LogMessage(3, "P4API.NET", msg);
                        return;
                    }
                }
            }
            return;
        }
Exemple #15
0
        public static P4.Job Show(P4ScmProvider Scm, P4.Job job)
        {
            if (Scm != null)
            {
                scm = Scm;
            }
            if (job == null)
            {
                return(null);
            }
            if (dlgRetry == false)
            {
                attachedFixes = new List <Changelist>();
            }
            dlgRetry   = false;
            currentJob = job;

            P4.Options opts = new P4.Options();
            opts["-o"] = null;
            jobspec    = Scm.Connection.Repository.GetFormSpec(opts, "job");

            DlgEditJob dlg = new DlgEditJob();

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

            string jobName = job.Id;

            if (job.Id == "new")
            {
                jobName = "New";
            }
            dlg.Text = dlg.Text + " " + jobName + " (" +
                       Scm.Connection.Repository.Server.Address.ToString() + ", " +
                       Scm.Connection.User + ")";

            dlg.addBtn.Enabled  = false;
            dlg.messageLbl.Text = "";

            P4.Job jobInfo = job;

            Dictionary <string, string> fields   = jobspec.FieldMap;
            Dictionary <string, string> valueMap = jobspec.Values;

            //string[] fields = Regex.Split(spec, ";;");

            int singleline = 0;

            // determine how many single line fields
            // exist in the job
            foreach (P4.SpecField field in jobspec.Fields)
            {
                if (field.DataType == SpecFieldDataType.Bulk ||
                    field.DataType == SpecFieldDataType.Text)
                {
                    continue;
                }
                singleline++;
            }

            int leftCol            = (singleline + 1) / 2;
            int leftcount          = 0; //job is there
            int rightcount         = 0;
            int bottomcount        = 0;
            int idx                = 0;
            int lidx               = 0; // Job: is 0
            int ridx               = 0;
            int bidx               = 0;
            int longestLeftLabel   = 0;
            int longestRightLabel  = 0;
            int longestBottomLabel = 0;

            Label[]       leftLabels       = new Label[jobspec.Fields.Count];
            TextBox[]     leftTextboxes    = new TextBox[jobspec.Fields.Count];
            ComboBox[]    leftComboboxes   = new ComboBox[jobspec.Fields.Count];
            Label[]       rightLabels      = new Label[jobspec.Fields.Count];
            TextBox[]     rightTextboxes   = new TextBox[jobspec.Fields.Count];
            ComboBox[]    rightComboboxes  = new ComboBox[jobspec.Fields.Count];
            Label[]       bottomLabels     = new Label[jobspec.Fields.Count];
            RichTextBox[] bottomTextboxes  = new RichTextBox[jobspec.Fields.Count];
            ComboBox[]    bottomComboboxes = new ComboBox[jobspec.Fields.Count];


            foreach (P4.SpecField field in jobspec.Fields)
            {
                string fieldname = field.Name;
                if (field.DataType == SpecFieldDataType.Bulk ||
                    field.DataType == SpecFieldDataType.Text)
                {
                    bottomLabels[bidx]          = new Label();
                    bottomLabels[bidx].AutoSize = true;

                    // set name and location for large text box labels
                    bottomLabels[bidx].Text = fieldname + ":";
                    Point location = dlg.jobLbl.Location;
                    location.Y = location.Y + (25 * leftCol) + (125 * bottomcount);
                    bottomLabels[bidx].Location = location;
                    bottomLabels[bidx].Name     = fieldname + "Lbl";
                    bottomLabels[bidx].Width    = bottomLabels[bidx].PreferredWidth;

                    // determine size of label and check to determine if
                    // the current label is the widest

                    if (bottomLabels[bidx] != null && bottomLabels[longestBottomLabel] != null)
                    {
                        if (bidx > 0 && bottomLabels[bidx].Width > bottomLabels[longestBottomLabel].Width)
                        {
                            longestBottomLabel = bidx;
                        }
                    }

                    // anchoring
                    bottomLabels[bidx].Anchor = AnchorStyles.Left | AnchorStyles.Top;

                    bottomTextboxes[bidx]                  = new RichTextBox();
                    location.X                            += (bottomLabels[bidx].Width + 5);
                    bottomTextboxes[bidx].Name             = fieldname + "TB";
                    bottomTextboxes[bidx].Location         = location;
                    bottomTextboxes[bidx].Height           = 120;
                    bottomTextboxes[bidx].Width            = 350;
                    bottomTextboxes[bidx].Multiline        = true;
                    bottomTextboxes[bidx].ScrollBars       = RichTextBoxScrollBars.Vertical;
                    bottomTextboxes[bidx].WordWrap         = true;
                    bottomTextboxes[bidx].ShortcutsEnabled = true;
                    if (job.ContainsKey(field.Name))
                    {
                        if (job[field.Name].ToString() == "<enter description here>\n")
                        {
                            bottomTextboxes[bidx].Text = job[field.Name].ToString();
                        }
                        else
                        {
                            bottomTextboxes[bidx].Text = job[field.Name].ToString().Replace("\n", "\r\n");
                        }
                    }

                    // anchoring
                    bottomTextboxes[bidx].Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left;

                    bottomcount++;
                    bidx++;
                }

                else
                {
                    Point location = new Point();


                    if (leftcount < leftCol)
                    {
                        leftLabels[lidx]      = new Label();
                        leftLabels[lidx].Text = fieldname + ":";
                        location    = dlg.jobLbl.Location;
                        location.Y += (25 * leftcount);

                        // anchoring
                        leftLabels[lidx].Anchor = AnchorStyles.Left | AnchorStyles.Top;

                        leftLabels[lidx].Location = location;
                        leftLabels[lidx].Name     = fieldname + "Lbl";
                        leftLabels[lidx].Width    = leftLabels[lidx].PreferredWidth;

                        // determine size of label and check to determine if
                        // the current label is the widest

                        if (leftLabels[lidx] != null && leftLabels[longestLeftLabel] != null)
                        {
                            if (lidx > 0 && leftLabels[lidx].Width > leftLabels[longestLeftLabel].Width)
                            {
                                longestLeftLabel = lidx;
                            }
                        }
                    }
                    else
                    {
                        rightLabels[ridx] = new Label();
                        //string fieldname = field.Name;
                        rightLabels[ridx].Text = fieldname + ":";
                        location    = dlg.jobLbl.Location;
                        location.Y += (25 * rightcount);
                        //int indent = (dlg.jobLbl.Width + 160);
                        //location.X = location.X + indent;

                        location.X = dlg.splitContainer.Panel1.Width / 2;


                        // anchoring
                        rightLabels[ridx].Anchor = AnchorStyles.Top | AnchorStyles.Left;

                        rightLabels[ridx].Location = location;
                        rightLabels[ridx].Name     = fieldname + "Lbl";
                        rightLabels[ridx].Width    = rightLabels[ridx].PreferredWidth;

                        // determine size of label and check to determine if
                        // the current label is the widest

                        if (rightLabels[ridx] != null && rightLabels[longestRightLabel] != null)
                        {
                            if (ridx > 0 && rightLabels[ridx].Width > rightLabels[longestRightLabel].Width)
                            {
                                longestRightLabel = ridx;
                            }
                        }
                    }



                    if (field.DataType == SpecFieldDataType.Select)
                    {
                        // anchoring
                        if (leftcount < leftCol)
                        {
                            leftComboboxes[lidx] = new ComboBox();
                            leftComboboxes[lidx].DropDownStyle = ComboBoxStyle.DropDownList;
                            leftComboboxes[lidx].Width         = 100;
                            leftComboboxes[lidx].Height        = 20;
                            int tab = leftLabels[lidx].Width + 5;
                            location.X = leftLabels[lidx].Location.X + tab;
                            leftComboboxes[lidx].Name     = fieldname + "TB";
                            leftComboboxes[lidx].Location = location;
                            string   values = valueMap[field.Name];
                            string[] val    = values.Split('/');
                            leftComboboxes[lidx].Items.AddRange(val);
                            if (job.ContainsKey(fieldname))
                            {
                                object sel = null;
                                job.TryGetValue(fieldname, out sel);
                                string selected = sel.ToString();
                                if (selected != null && selected != "\"\"")
                                {
                                    leftComboboxes[lidx].SelectedItem = selected;
                                }
                                else
                                {
                                    leftComboboxes[lidx].SelectedItem = val[0];
                                }
                            }
                            leftComboboxes[lidx].Anchor = AnchorStyles.Left | AnchorStyles.Top;
                            lidx++;
                            leftcount++;
                        }
                        else
                        {
                            rightComboboxes[ridx] = new ComboBox();
                            rightComboboxes[ridx].DropDownStyle = ComboBoxStyle.DropDownList;
                            rightComboboxes[ridx].Width         = 100;
                            rightComboboxes[ridx].Height        = 20;
                            int tab = rightLabels[ridx].Width + 5;
                            location.X = rightLabels[ridx].Location.X + tab;
                            rightComboboxes[ridx].Name     = fieldname + "TB";
                            rightComboboxes[ridx].Location = location;
                            string   values = valueMap[field.Name];
                            string[] val    = values.Split('/');
                            rightComboboxes[ridx].Items.AddRange(val);
                            if (job.ContainsKey(fieldname))
                            {
                                object sel = null;
                                job.TryGetValue(fieldname, out sel);
                                string selected = sel.ToString();
                                if (selected != null && selected != "\"\"")
                                {
                                    rightComboboxes[ridx].SelectedItem = selected;
                                }
                                else
                                {
                                    rightComboboxes[ridx].SelectedItem = val[0];
                                }
                            }
                            rightComboboxes[ridx].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                            ridx++;
                            rightcount++;
                        }
                    }

                    else
                    {
                        // anchoring
                        if (leftcount < leftCol)
                        {
                            leftTextboxes[lidx] = new TextBox();

                            //leftTextboxes[lidx].AutoSize = true;
                            int tab = leftLabels[lidx].Width + 5;
                            location.X = leftLabels[lidx].Location.X + tab;
                            leftTextboxes[lidx].Name             = fieldname + "TB";
                            leftTextboxes[lidx].Location         = location;
                            leftTextboxes[lidx].Height           = 15;
                            leftTextboxes[lidx].Width            = 100;
                            leftTextboxes[lidx].ShortcutsEnabled = true;
                            if (field.FieldType == SpecFieldFieldType.Always ||
                                field.FieldType == SpecFieldFieldType.Once ||
                                field.Code == 101)
                            {
                                leftTextboxes[lidx].ReadOnly = true;
                            }
                            if (job.ContainsKey(field.Name))
                            {
                                if ((field.DataType == P4.SpecFieldDataType.Date) &&
                                    p4Date() == false)
                                {
                                    DateTime d;
                                    DateTime.TryParse(job[field.Name].ToString(), out d);
                                    leftTextboxes[lidx].Text = d.ToString("MM/d/yyyy h:mm:ss tt");
                                }
                                else
                                {
                                    leftTextboxes[lidx].Text = job[field.Name].ToString();
                                }
                            }
                            leftTextboxes[lidx].Anchor = AnchorStyles.Left | AnchorStyles.Top;
                            lidx++;
                            leftcount++;
                        }
                        else
                        {
                            rightTextboxes[ridx] = new TextBox();
                            int tab = rightLabels[ridx].Width + 8;
                            location.X = rightLabels[ridx].Location.X + tab;
                            rightTextboxes[ridx].Name             = fieldname + "TB";
                            rightTextboxes[ridx].Location         = location;
                            rightTextboxes[ridx].Height           = 15;
                            rightTextboxes[ridx].Width            = 100;
                            rightTextboxes[ridx].ShortcutsEnabled = true;
                            if (field.FieldType == SpecFieldFieldType.Always ||
                                field.FieldType == SpecFieldFieldType.Once ||
                                field.Code == 101)
                            {
                                rightTextboxes[ridx].ReadOnly = true;
                            }
                            if (job.ContainsKey(field.Name))
                            {
                                if ((field.DataType == P4.SpecFieldDataType.Date) &&
                                    p4Date() == false)
                                {
                                    DateTime d;
                                    DateTime.TryParse(job[field.Name].ToString(), out d);
                                    rightTextboxes[ridx].Text = d.ToString("MM/d/yyyy h:mm:ss tt");
                                }
                                else
                                {
                                    rightTextboxes[ridx].Text = job[field.Name].ToString();
                                }
                            }
                            rightTextboxes[ridx].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                            ridx++;
                            rightcount++;
                        }
                    }
                }
            }

            // adjust all the placements based on largest label size
            // and dialog real estate remaining

            int fieldX     = 0;
            int fieldWidth = 0;

            // bottom labels and textboxes


            if (leftLabels[longestLeftLabel].Width >= bottomLabels[longestBottomLabel].Width)
            {
                fieldX = leftLabels[longestLeftLabel].Width + 5 +
                         leftLabels[longestLeftLabel].Location.X;
                fieldWidth = dlg.splitContainer.Panel1.Width - (fieldX + 10);
            }
            else
            {
                fieldX = bottomLabels[longestBottomLabel].Width + 5 +
                         leftLabels[longestBottomLabel].Location.X;
                fieldWidth = dlg.splitContainer.Panel1.Width - (fieldX + 10);
            }
            foreach (RichTextBox bottomTextbox in bottomTextboxes)
            {
                if (bottomTextbox != null)
                {
                    bottomTextbox.SetBounds(fieldX, bottomTextbox.Location.Y,
                                            fieldWidth, bottomTextbox.Size.Height);
                }
            }


            // left labels and textboxes / comboboxes
            if (leftLabels[longestLeftLabel].Width >= bottomLabels[longestBottomLabel].Width)
            {
                fieldX = leftLabels[longestLeftLabel].Width + 5 +
                         leftLabels[longestLeftLabel].Location.X;
                fieldWidth = (dlg.splitContainer.Panel1.Width / 2) - fieldX;
            }
            else
            {
                fieldX = bottomLabels[longestBottomLabel].Width + 5 +
                         leftLabels[longestBottomLabel].Location.X;
                fieldWidth = (dlg.splitContainer.Panel1.Width / 2) - fieldX;
            }
            foreach (ComboBox leftCombobox in leftComboboxes)
            {
                if (leftCombobox != null)
                {
                    leftCombobox.SetBounds(fieldX, leftCombobox.Location.Y,
                                           fieldWidth, leftCombobox.Size.Height);
                }
            }
            foreach (TextBox leftTextbox in leftTextboxes)
            {
                if (leftTextbox != null)
                {
                    leftTextbox.SetBounds(fieldX, leftTextbox.Location.Y,
                                          fieldWidth, leftTextbox.Size.Height);
                }
            }

            // right labels and textboxes / comboboxes
            fieldX = dlg.splitContainer.Panel1.Width / 2 + 5 +
                     rightLabels[longestRightLabel].Width;
            fieldWidth = (dlg.splitContainer.Panel1.Width / 2) -
                         (rightLabels[longestRightLabel].Width + 10);
            foreach (ComboBox rightCombobox in rightComboboxes)
            {
                if (rightCombobox != null)
                {
                    rightCombobox.SetBounds(fieldX, rightCombobox.Location.Y,
                                            fieldWidth, rightCombobox.Size.Height);
                }
            }
            foreach (TextBox rightTextbox in rightTextboxes)
            {
                if (rightTextbox != null)
                {
                    rightTextbox.SetBounds(fieldX, rightTextbox.Location.Y,
                                           fieldWidth, rightTextbox.Size.Height);
                }
            }


            dlg.splitContainer.Panel1.Controls.AddRange(leftLabels);
            dlg.splitContainer.Panel1.Controls.AddRange(leftTextboxes);
            dlg.splitContainer.Panel1.Controls.AddRange(leftComboboxes);
            dlg.splitContainer.Panel1.Controls.AddRange(rightLabels);
            dlg.splitContainer.Panel1.Controls.AddRange(rightTextboxes);
            dlg.splitContainer.Panel1.Controls.AddRange(rightComboboxes);
            dlg.splitContainer.Panel1.Controls.AddRange(bottomLabels);
            dlg.splitContainer.Panel1.Controls.AddRange(bottomTextboxes);
            dlg.splitContainer.Panel1.Controls.AddRange(bottomComboboxes);

            dlg.splitContainer.Panel1.Refresh();

            // add fixes here
            Options     fixOpts = new Options(GetFixesCmdFlags.IncludeIntegrations, -1, job.Id, -1);
            IList <Fix> fixes   = Scm.Connection.Repository.GetFixes(null, fixOpts);

            if (fixes != null)
            {
                foreach (Fix fix in fixes)
                {
                    Changelist change = Scm.GetChangelist(fix.ChangeId);

                    if (change != null)
                    {
                        dlg.addChangeToFixesLV(change);
                        attachedFixes.Add(change);
                    }
                }
            }

            if (attachedFixes.Count > 0)
            {
                foreach (Changelist fix in attachedFixes)
                {
                    if (fix != null)
                    {
                        dlg.addChangeToFixesLV(fix);
                    }
                }
            }


            if (dlg.ShowDialog() != DialogResult.Cancel)
            {
                idx = 0;
                if (dlg.DialogResult == DialogResult.OK)
                {
                    foreach (P4.SpecField field in jobspec.Fields)
                    {
                        string fieldname = field.Name;

                        Control[] control = dlg.splitContainer.Panel1.Controls.Find(fieldname + "TB", false);
                        if (control != null && control.Length > 0 && control[0] != null)
                        {
                            if ((field.DataType == SpecFieldDataType.Bulk ||
                                 field.DataType == SpecFieldDataType.Text) &&
                                control[0].Text != "<enter description here>\n")
                            {
                                job.IsFieldMultiLine[fieldname] = true;
                            }
                            if (field.DataType == SpecFieldDataType.Date)
                            {
                                job[fieldname] = "";
                            }
                            else
                            {
                                job[fieldname] = control[0].Text;
                            }
                        }
                        idx++;
                    }

                    P4.Job savedJob = scm.saveJob(job);
                    if (savedJob == null)
                    {
                        dlgRetry = true;
                        //dlg.Show();
                        Show(Scm, job);
                        return(job);
                    }
                    if (dlg.SelectedChangelistList != null)
                    {
                        foreach (P4.Changelist change in dlg.SelectedChangelistList)
                        {
                            try
                            {
                                opts = new P4.Options(P4.FixJobsCmdFlags.None, -1, null);
                                IList <P4.Fix> fixToAttach = change.FixJobs(opts, savedJob);
                            }
                            catch (Exception ex)
                            {
                                Scm.ShowException(ex);
                            }
                        }
                    }

                    if (dlg.UnselectedChangelistList != null)
                    {
                        foreach (P4.Changelist change in dlg.UnselectedChangelistList)
                        {
                            if (change != null && (change.Jobs != null && change.Jobs.ContainsKey(currentJob.Id)))
                            {
                                try
                                {
                                    opts = new P4.Options(P4.FixJobsCmdFlags.Delete, -1, null);
                                    IList <P4.Fix> fixToRemove = change.FixJobs(opts, savedJob);
                                }
                                catch (Exception ex)
                                {
                                    Scm.ShowException(ex);
                                }
                            }
                        }
                    }

                    return(savedJob);
                }
            }

            return(null);
        }
Exemple #16
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            try
            {
                DepotPathDlg dlg = new DepotPathDlg(_scm.SccService, Resources.GetRevisionDlg_AddFilesFoldersPrompt, false);


                if (DialogResult.OK == dlg.ShowDialog())
                {
                    string depotPath = null;
                    if (dlg.SelectedFile != null)
                    {
                        depotPath = dlg.SelectedFile;
                    }

                    P4.FileMetaData f = new P4.FileMetaData();
                    f.DepotPath = new P4.DepotPath(depotPath);
                    IList <P4.FileMetaData> fmd    = null;
                    IList <object>          fields = new List <object>();
                    fields.Add(P4FileTreeListViewItem.SubItemFlag.DepotFullPath);
                    P4FileTreeListViewItem lvi = new P4FileTreeListViewItem(null, f, fields);

                    if (depotPath != null && depotPath.EndsWith("/..."))
                    {
                        try
                        {
                            P4.Options options = new P4.Options();
                            //options["Op"] = null;
                            options["-m"] = "1";

                            fmd = _scm.GetFileMetaData(options, depotPath);
                        }
                        catch (P4Exception ex)
                        {
                            if (!(ex.ErrorCode == P4ClientError.MsgDb_NotUnderRoot))
                            {
                                MessageBox.Show(ex.Message, Resources.P4VS);
                                return;
                            }
                        }



                        //lvi.Text = depotPath;


                        foreach (ListViewItem item in filesListView.Items)
                        {
                            if (item.Text.Equals(lvi.Text))
                            {
                                return;
                            }
                        }

                        filesListView.Items.Add(lvi);
                    }

                    else
                    {
                        P4.FileMetaData file = null;
                        {
                            try
                            {
                                file = _scm.GetFileMetaData(depotPath);
                            }
                            catch (P4.P4Exception ex)
                            {
                                if ((ex.ErrorCode == P4.P4ClientError.MsgDb_NotUnderRoot) ||
                                    (ex.ErrorCode == P4.P4ClientError.MsgDb_NotUnderClient))
                                {
                                }
                                else
                                {
                                    MessageBox.Show(ex.Message, Resources.P4VS);
                                    //LogExeption(ex);

                                    return;
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, Resources.P4VS);
                                return;
                            }

                            if (file != null && file.LocalPath != null)
                            {
                                lvi.Text = file.LocalPath.Path;
                            }
                            else
                            {
                                if (file != null && file.DepotPath != null)
                                {
                                    lvi.Text = file.DepotPath.Path;
                                }
                            }


                            foreach (ListViewItem item in filesListView.Items)
                            {
                                if (item.Text.Equals(lvi.Text))
                                {
                                    return;
                                }
                            }

                            filesListView.Items.Add(lvi);
                        }
                    }
                    filesListView.Refresh();

                    newOKBtn.Enabled = filesListView.Items.Count > 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Resources.P4VS);
                this.DialogResult = DialogResult.Cancel;
            }
        }
Exemple #17
0
        public static void ChangeFileType(P4ScmProvider scm, IList <string> paths)
        {
            FileAttributesDlg dlg = new FileAttributesDlg(scm);

            int changelistId = 0;

            IList <string> CheckedinFiles  = new List <string>();
            IList <string> CheckedoutFiles = new List <string>();

            IList <P4.FileMetaData> fmd = scm.GetFileMetaData(paths, null);

            P4.FileType ft = null;
            if (fmd != null)
            {
                foreach (P4.FileMetaData md in fmd)
                {
                    if (ft == null)
                    {
                        ft = md.Type;
                        if (md.Change > 0)
                        {
                            changelistId = md.Change;
                        }
                    }
                    else
                    {
                        // only keep the base type if all the same
                        if (ft.BaseType != md.Type.BaseType)
                        {
                            ft.BaseType = P4.BaseFileType.Unspecified;
                        }
                        // only keep fags that are the same
                        ft.Modifiers &= md.Type.Modifiers;
                        if (changelistId != md.Change)
                        {
                            changelistId = 0;
                        }
                    }
                    if (md.Action == P4.FileAction.None)
                    {
                        CheckedinFiles.Add(md.LocalPath.Path);
                    }
                    else
                    {
                        CheckedoutFiles.Add(md.LocalPath.Path);
                    }
                }
            }

            dlg.FileType           = ft;
            dlg.TargetChangelistId = changelistId;

            if (dlg.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            int targetChangelist = dlg.TargetChangelistId;

            P4.Options options = null;

            if (targetChangelist < 0)
            {
                // if selected, create a new numbered changelist with the files.

                P4.Changelist change = scm.Connection.Repository.NewChangelist();
                change.Description = "<P4VS Change FileType>";
                change.ClientId    = scm.Connection.Repository.Connection.Client.Name;
                change.OwnerName   = scm.Connection.Repository.Connection.UserName;
                change.Files       = null;           // new List<P4.FileMetaData>();

                P4.Changelist newChange = scm.Connection.Repository.CreateChangelist(change);

                targetChangelist = newChange.Id;
            }

            if (CheckedoutFiles.Count > 0)
            {
                options = new P4.ReopenCmdOptions(targetChangelist, dlg.FileType);
                if ((options.ContainsKey("-t")) && (string.IsNullOrEmpty(options["-t"]) == false))
                {
                    scm.ReopenFiles(P4.FileSpec.LocalSpecList(CheckedoutFiles), options);
                }
            }

            if (CheckedinFiles.Count > 0)
            {
                options = new P4.EditCmdOptions(P4.EditFilesCmdFlags.None, targetChangelist, dlg.FileType);

                if ((options.ContainsKey("-t")) && (string.IsNullOrEmpty(options["-t"]) == false))
                {
                    scm.EditFiles(P4.FileSpec.LocalSpecList(CheckedinFiles), options);
                }
            }
            scm.BroadcastChangelistUpdate(null, new P4ScmProvider.ChangelistUpdateArgs(targetChangelist,
                                                                                       P4ScmProvider.ChangelistUpdateArgs.UpdateType.Edit));
        }
Exemple #18
0
        public IList <string> AddDirectoryFilesToCache(String directoryPath, bool recursive)
        {
            lock (cache)
            {
                try
                {
                    String fileSpec;
                    if (recursive)
                    {
                        fileSpec = String.Format("{0}/...", directoryPath);
                    }
                    else
                    {
                        fileSpec = String.Format("{0}/*", directoryPath);
                    }

                    var key = GetKey(directoryPath);

                    if (CachedDirectories == null)
                    {
                        CachedDirectories = new Dictionary <CacheKey, CachedDirectory>();
                    }
                    else if ((CachedDirectories.ContainsKey(key)) &&
                             (CachedDirectories[key] > DateTime.Now - TimeSpan.FromSeconds(25)))
                    {
                        return(null);
                    }
                    //make sure the added path is under the client's root directory
                    if (_scm != null && !string.IsNullOrEmpty(_scm.Connection.WorkspaceRoot))
                    {
                        var wsRoot = GetKey(_scm.Connection.WorkspaceRoot);
                        logger.Trace("wsRoot: {0}", wsRoot);
                        if (!key.ToString().StartsWith(wsRoot.ToString(), StringComparison.OrdinalIgnoreCase))
                        {
                            CachedDirectories[key] = new CachedDirectory(directoryPath);
                            logger.Trace("AddDir: {0}", key);
                            return(null);
                        }
                    }

                    // add/update cache folder to the hash of folders that have been cached
                    CachedDirectories[key] = new CachedDirectory(directoryPath);
                    if (recursive)
                    {
                        // non recursive directory walk to add/update all the subdirectories
                        // to the hash table of directories that have been cached
                        Queue <string> subdirs = new Queue <string>();
                        subdirs.Enqueue(directoryPath);

                        while (subdirs.Count > 0)
                        {
                            string subdir = subdirs.Dequeue();
                            foreach (string sd in System.IO.Directory.GetDirectories(subdir))
                            {
                                // add to queue for so it'll be walked for subdirectories
                                subdirs.Enqueue(sd);
                                // add/update this subdirectory to the hash of cached directories
                                CachedDirectories[GetKey(sd)] = new CachedDirectory(sd);
                            }
                        }
                    }

                    P4.Options opts = new P4.Options();
                    opts["-Olhp"] = null;
                    opts["-m"]    = "100000";
                    logger.Trace("WorkspaceRoot: {0}", _scm.Connection.WorkspaceRoot);

                    IList <P4.FileMetaData> files =
                        _repository.GetFileMetaData(opts, P4.FileSpec.LocalSpec(fileSpec));

                    IList <string> updated = null;
                    if (files != null)
                    {
                        updated = UpdateFileMetaData(files);
                    }
                    else
                    {
                        P4.P4CommandResult results = _repository.Connection.LastResults;

                        if ((results != null) && (results.ErrorList != null) && (results.ErrorList.Count > 0) &&
                            ((results.ErrorList[0].ErrorCode == P4.P4ClientError.MsgDb_NotUnderRoot) ||
                             (results.ErrorList[0].ErrorCode == P4.P4ClientError.MsgDb_NotUnderClient) ||
                             (results.ErrorList[0].ErrorCode == P4.P4ClientError.MsgDm_IntegMovedUnmapped) ||
                             (results.ErrorList[0].ErrorCode == P4.P4ClientError.MsgDm_ExVIEW) ||
                             (results.ErrorList[0].ErrorCode == P4.P4ClientError.MsgDm_ExVIEW2)))
                        {
                            if (CachedDirectories == null)
                            {
                                CachedDirectories = new Dictionary <CacheKey, CachedDirectory>();
                            }
                            CachedDirectories[key] = new CachedDirectory(directoryPath);
                        }
                    }
                    return(updated);
                }
                catch (Exception ex)
                {
                    // If the error is because the repository is now null, it means
                    // the connection was closed in the middle of a command, so ignore it.
                    if (_repository != null)
                    {
                        _scm.ShowException(ex, false, true, (Preferences.LocalSettings.GetBool("Log_reporting", false) == true));
                    }
                    if (CachedDirectories == null)
                    {
                        CachedDirectories = new Dictionary <CacheKey, CachedDirectory>();
                    }
                    CachedDirectories[GetKey(directoryPath)] = new CachedDirectory(directoryPath, DateTime.MinValue);
                    return(null);
                }
            }
        }