Exemple #1
0
        /// <summary>
        /// Read the fields from the tagged output of a diff2 command
        /// </summary>
        /// <param name="objectInfo">Tagged output from the 'diff2' command</param>
        /// <param name="connection"></param>
        /// <param name="options"></param>
        public void FromGetDepotFileDiffsCmdTaggedOutput(TaggedObject objectInfo, Connection connection, Options options)
        {
            DepotFileDiff ParsedDepotFileDiff = new DepotFileDiff();
            string        ldepotfile          = string.Empty;
            string        rdepotfile          = string.Empty;
            int           lrev = -1;
            int           rrev = -1;

            if (objectInfo.ContainsKey("status"))
            {
                _type = objectInfo["status"];
            }

            if (objectInfo.ContainsKey("depotFile"))
            {
                ldepotfile = objectInfo["depotFile"];
            }

            if (objectInfo.ContainsKey("rev"))
            {
                int.TryParse(objectInfo["rev"], out lrev);
            }

            if (objectInfo.ContainsKey("depotFile2"))
            {
                rdepotfile = objectInfo["depotFile2"];
            }

            if (objectInfo.ContainsKey("rev2"))
            {
                int.TryParse(objectInfo["rev2"], out rrev);
            }

            LeftFile = new FileSpec(new DepotPath(ldepotfile), new Revision(lrev));

            RightFile = new FileSpec(new DepotPath(rdepotfile), new Revision(rrev));

            if (objectInfo["status"] == "content")
            {
                string       filepathl   = ldepotfile + "#" + lrev;
                string       filepathr   = rdepotfile + "#" + rrev;
                P4.P4Command getDiffData = new P4Command(connection, "diff2", false, filepathl, filepathr);

                P4.P4CommandResult r = getDiffData.Run(options);
                if (r.Success != true)
                {
                    P4Exception.Throw(r.ErrorList);
                }
                if (r.TextOutput != null)
                {
                    Diff = r.TextOutput.ToString();
                }
                else if (r.InfoOutput != null)
                {
                    Diff = r.InfoOutput.ToString();
                }
            }

            ParsedDepotFileDiff = new DepotFileDiff(Type, LeftFile, RightFile, Diff);
        }
Exemple #2
0
        private P4ErrorDlg(P4.P4CommandResult results, bool showCancel)
        {
            PreferenceKey = "P4ErrorDlg";

            InitializeComponent();

            _defCancelBtnLocation = CancelBtn.Location;
            _defOKBtnLocation     = OkBtn.Location;

            this.Icon     = Images.icon_p4vs_16px;
            Results       = results;
            ShowCancelBtn = showCancel;
        }
Exemple #3
0
        public static DialogResult Show(P4.P4CommandResult results, bool showCancel)
        {
            if ((results == null) || (results.ErrorList == null) || (results.ErrorList.Count <= 0))
            {
                return(DialogResult.Ignore);
            }
            int           numWarnings = 0;
            List <string> WarningMsgs = new List <string>();

            foreach (P4.P4ClientError error in results.ErrorList)
            {
                if (error.SeverityLevel <= P4.ErrorSeverity.E_WARN)
                {
                    numWarnings++;
                }
                WarningMsgs.Add(string.Format("{0}: {1}", error.SeverityLevel, error.ErrorMessage));
            }
            if ((results.ErrorList.Count - numWarnings) <= 0)
            {
                if (WarningMsgs.Count > 0)
                {
                    // error dlialog will not display, so list any warning in the output pane
                    foreach (string msg in WarningMsgs)
                    {
                        P4VsOutputWindow.AppendMessage(msg);
                    }
                }
                return(DialogResult.Ignore);
            }

            P4ErrorDlg dlg = new P4ErrorDlg(results, showCancel);

            dlg.PromptLbl.Text = Resources.P4ErrorDlg_PromptLabel;
            dlg.TopMost        = true;
            return(dlg.ShowDialog());
        }
Exemple #4
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 #5
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 #6
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 #7
0
        private void InitFileListView()
                #region single pass initialization of the list
        {
            this.FileList.Items.Clear();
//			itemMap = null;

            if (_files == null)
            {
                return;
            }
//			itemMap = new Dictionary<string, FileListViewItem>();
            resolveCallback = new P4.Client.ResolveFileDelegate(ResolveCallBackHandler);

            P4.Options options = new P4.ResolveCmdOptions(
                P4.ResolveFilesCmdFlags.ForceTextualMerge | P4.ResolveFilesCmdFlags.DisplayBaseFile, -1);

            int itemCnt = 0;

            IList <P4.P4Exception> errors = null;

            IList <string> filesNotListed = new List <string>();

            foreach (string file in _files)
            {
                IList <P4.FileResolveRecord> records = null;
                try
                {
                    records = _scm.Connection.Repository.Connection.Client.ResolveFiles(
                        resolveCallback, options, P4.FileSpec.LocalSpec(file));
                }
                catch (P4.P4Exception ex)
                {
                    if (errors == null)
                    {
                        errors = new List <P4.P4Exception>();
                    }
                    errors.Add(ex);
                }
                P4.P4CommandResult results = _scm.Connection.Repository.Connection.LastResults;

                int subItemIdx = 0;

                FileListViewItem firstItem = null;

                if ((records != null) && (records.Count > 0))
                {
                    foreach (P4.FileResolveRecord record in records)
                    {
                        string path = null;
                        if (record.LocalFilePath != null)
                        {
                            path = record.LocalFilePath.Path;
                        }
                        else if ((record.FromFileSpec != null) && (record.FromFileSpec.LocalPath != null))
                        {
                            path = record.FromFileSpec.LocalPath.Path;
                        }
                        else
                        {
                            continue;
                        }

                        CurrentItem = new FileListViewItem(path, subItemIdx);

                        if (subItemIdx == 0)
                        {
                            firstItem = CurrentItem;
                        }
                        else
                        {
                            CurrentItem.FirstItem = firstItem;
                        }
                        subItemIdx++;

                        // string key = string.Format("<{0}>{1}", record.ResolveType, path.ToLower());
                        //				itemMap.Add(key, CurrentItem);

                        this.FileList.Items.Add(CurrentItem);

                        CurrentItem.ResolveRecord = record;
                        CurrentItem.Source        = record.FromFileSpec;
                        if (record.ResolveType != P4.ResolveType.None)
                        {
                            CurrentItem.ResolveType = record.ResolveType;
                        }
                        else if ((record.Analysis != null) && (record.Analysis.ResolveType != P4.ResolveType.None))
                        {
                            CurrentItem.ResolveType = record.Analysis.ResolveType;
                        }
                        CurrentItem.ResolveAnalysis = record.Analysis;


                        CurrentItem = null;
                    }
                }
                else
                {
                    filesNotListed.Add(file);
                }
            }
            if (errors != null)
            {
                P4ErrorDlg.Show(errors, false);
            }
            // clean out files that do not need to be resolved
            foreach (string file in filesNotListed)
            {
                _files.Remove(file);
            }

            if (RefreshUICallback != null)
            {
                RefreshUICallback();
            }
            if ((_files == null) || (_files.Count <= 0))
            {
                // no files to resolve
                if (bFirstInit)
                {
                    MessageBox.Show(Resources.ResolveFileDlg_NoFileToResolveWarning, Resources.P4VS,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    this.DialogResult = DialogResult.OK;
                    Close();
                    return;
                }
            }
            bFirstInit = false;

            SelectionCountLbl.Text = string.Format(SelectionCountLblTxt, 0, itemCnt);

            resolveCallback = null;

            AutoResolveRB_CheckedChanged(null, null);
        }
        private void AutoResolveBtn_Click(object sender, EventArgs e)
        {
            if (SelectedItems == null)
            {
                return;
            }

            AutoResolveMethod method = SelectedMethod;

            P4.ResolveFilesCmdFlags flags = P4.ResolveFilesCmdFlags.None;
            if (MergeBinaryAsText)
            {
                flags |= P4.ResolveFilesCmdFlags.ForceTextualMerge;
            }
            switch (method)
            {
            default:
            case AutoResolveMethod.Safe:
                flags |= P4.ResolveFilesCmdFlags.AutomaticSafeMode;
                break;

            case AutoResolveMethod.SafeMerge:
                flags |= P4.ResolveFilesCmdFlags.AutomaticMergeMode;
                break;

            case AutoResolveMethod.Source:
                flags |= P4.ResolveFilesCmdFlags.AutomaticTheirsMode;
                break;

            case AutoResolveMethod.Target:
                flags |= P4.ResolveFilesCmdFlags.AutomaticYoursMode;
                break;

            case AutoResolveMethod.MergeWithConflicts:
                flags |= P4.ResolveFilesCmdFlags.AutomaticForceMergeMode;
                break;
            }
            P4.Options options = new P4.ResolveCmdOptions(flags, -1);

            //Dictionary<string, ResolveFileDlg.FileListViewItem> itemMap = new Dictionary<string, ResolveFileDlg.FileListViewItem>();

            int failedResolves = 0;

            foreach (ResolveFileDlg.FileListViewItem item in SelectedItems)
            {
                try
                {
                    IList <P4.FileResolveRecord> records =
                        Scm.Connection.Repository.Connection.Client.ResolveFiles(
                            null, options, item.ResolveRecord.LocalFilePath);

                    //bool resolveFailed = true;
                    //if (records != null)
                    //{
                    //    foreach (P4.FileResolveRecord r in records)
                    //    {
                    //        if (r.Action != P4.FileAction.None)
                    //        {
                    //            resolveFailed = false;
                    //            break;
                    //        }
                    //    }
                    //}
                    //if (resolveFailed)
                    //{
                    //    failedResolves++;
                    //}
                    P4.P4CommandResult results = null;
                    P4.FileMetaData    newMd   = Scm.GetFileMetaData(null, item.ResolveRecord.LocalFilePath.Path, out results);
                    if (newMd.Unresolved)
                    {
                        failedResolves++;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Resources.PerforceSCM, MessageBoxButtons.OK);
                    return;
                }
            }
            if (UpdateListView != null)
            {
                UpdateListView();
            }
            if (failedResolves > 0)
            {
                string msg = string.Format(Resources.ResolveFileAutoControl_FilesNotResolvedWarning, failedResolves);
                MessageBox.Show(msg, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #9
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);
                }
            }
        }
Exemple #10
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;
        }