TFS 中的自定义签入策略?

发布于 2024-11-10 08:15:55 字数 241 浏览 0 评论 0原文

我们的项目中有一些 xml 文件,每当我们将这些 xml 文件签入 TFS 时,我们都会在签入之前确保已将这些 xml 文件添加到专有应用程序中。

现在,新员工经常忘记在签入之前将文件添加到专有应用程序中,而且这种情况越来越严重......

我们想要一个确认对话框(提醒),询问开发人员是否已将 xml 文件添加到应用程序中。如果是,则签入,否则保持签出...

请建议此类事情是否可能,并且任何相关代码或链接将不胜感激。

We have some xml files in the our project and whenever we check-in these xml files into TFS, We have make sure before checking-in that we have added those xml files to proprietary application.

Now the new employees more often forget to add files into proprietary application before check-in and this is getting serious...

We want kinda confirmation dialog (a reminder) asking the developers if they have added the xml files into the app. If yes then check-in otherwise keep it checkedout...

Please suggest if such thing is possible and any relevant code or links will be really appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

放低过去 2024-11-17 08:15:55

在自定义签入策略中引发 UI 是不合适的 - 签入策略的生命周期非常短,并且它们将被频繁评估,并且不一定在 UI 上下文或 UI 线程上。

您能否以编程方式确定是否签入了适当的 XML 文件?如果是这样,您可以创建一个自定义签入策略,如果未挂起添加 XML 文件,该策略就会失败。

门控签入可能是此问题的最佳解决方案:如果这些 XML 文件不存在,构建会失败吗?或者如果这些文件丢失,单元测试会失败吗?如果是这样,那么这是门控签到的完美候选者,这将阻止这些签到的发生。

It's not appropriate to raise UI in a custom check-in policy - the lifecycle of a check-in policy is very short, and they will be evaluated frequently and not necessarily in a UI context or on the UI thread.

Can you determine programmatically whether the appropriate XML files are being checked in? If so, you could create a custom check-in policy that fails if the XML files are not pended for add.

Gated Check-in may be the best solution to this problem: does the build fail if these XML files do not exist - or would unit tests fail if these files are missing? If so, this is a perfect candidate for Gated Check-in, which will prevent these check-ins from occurring.

等你爱我 2024-11-17 08:15:55

我将创建一个自定义构建模板来检查这些 xml 文件。让它成为一个封闭的签入,你就得到了你的解决方案。

I would create a custom build template that checks for these xml files. Make it a gated check-in and you've got your solution.

醉态萌生 2024-11-17 08:15:55

Evaluate 方法应该是快速的并且不应该显示 UI,但是当用户与称为 Activate 的策略交互时,策略上会触发一个事件,这是这是展示 UI 并与策略沟通的好时机。你可以这样做:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JesseHouwing.CheckinPolicies
{
    using System.Windows.Forms;

    using Microsoft.TeamFoundation.Client.Reporting;
    using Microsoft.TeamFoundation.VersionControl.Client;

    [Serializable]
    public class ConfirmPolicy :PolicyBase
    {
        private AffectedTeamProjectsEventHandler _affectedTeamProjectsEventHandler;
        private EventHandler _checkedPendingChangesEventHandler;

        public ConfirmPolicy()
        {
        }

        public void StatusChanged()
        {
            _userconfirmed = false;
            OnPolicyStateChanged(Evaluate());
        }

        public override void Initialize(IPendingCheckin pendingCheckin)
        {
            _affectedTeamProjectsEventHandler = (sender, e) => StatusChanged();
            _checkedPendingChangesEventHandler = (sender, e) => StatusChanged();

            base.Initialize(pendingCheckin);
            _userconfirmed = false;                
            pendingCheckin.PendingChanges.AffectedTeamProjectsChanged += _affectedTeamProjectsEventHandler;
            pendingCheckin.PendingChanges.CheckedPendingChangesChanged += _checkedPendingChangesEventHandler;
        }

        protected override void OnPolicyStateChanged(PolicyFailure[] failures)
        {
            _userconfirmed = false;
            base.OnPolicyStateChanged(Evaluate());
        }

        public override void Activate(PolicyFailure failure)
        {
            if (MessageBox.Show("Confirm the policy?", "Policy Check", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                _userconfirmed = true;
                base.OnPolicyStateChanged(Evaluate());
            }
        }

        public override PolicyFailure[] Evaluate()
        {
            if (_userconfirmed == true)
            {
                return new PolicyFailure[0];
            }
            else
            {
                return new PolicyFailure[]{new PolicyFailure("User must confirm", this)};
            }
        }

        public override string Description
        {
            get { throw new NotImplementedException(); }
        }

        public override bool Edit(IPolicyEditArgs policyEditArgs)
        {
            return true;
        }

        public override string Type
        {
            get
            {
                return "User Confirm";
            }
        }

        public override string TypeDescription
        {
            get
            {
                return "User Confirm";
            }
        }

        public override void Dispose()
        {
            this.PendingCheckin.PendingChanges.AffectedTeamProjectsChanged -= _affectedTeamProjectsEventHandler;
            this.PendingCheckin.PendingChanges.CheckedPendingChangesChanged -= _checkedPendingChangesEventHandler;

            base.Dispose();
        }
    }
}

我还没有测试过这个确切的代码,它可能需要一些调整,但这是一般要做的事情。现在,它会在签入的文件发生更改时触发,但您也可以订阅任何其他事件(工作项更改)或在每次调用 Evaluate 时触发您自己的项目评估。

或者您可以在每个签入周期触发一次确认。这一切都取决于你。您甚至可以执行“单击关闭”并完全跳过 Messagebox。只需设置 _userConfirmed=true 并触发 PolicyStateChanged 事件。

The Evaluate method is supposed to be quick and should not show UI, but there is an event on the policy that triggers when the user interacts with the policy called Activate, this is a good moment to show UI and communicate with the policy. You could do something like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JesseHouwing.CheckinPolicies
{
    using System.Windows.Forms;

    using Microsoft.TeamFoundation.Client.Reporting;
    using Microsoft.TeamFoundation.VersionControl.Client;

    [Serializable]
    public class ConfirmPolicy :PolicyBase
    {
        private AffectedTeamProjectsEventHandler _affectedTeamProjectsEventHandler;
        private EventHandler _checkedPendingChangesEventHandler;

        public ConfirmPolicy()
        {
        }

        public void StatusChanged()
        {
            _userconfirmed = false;
            OnPolicyStateChanged(Evaluate());
        }

        public override void Initialize(IPendingCheckin pendingCheckin)
        {
            _affectedTeamProjectsEventHandler = (sender, e) => StatusChanged();
            _checkedPendingChangesEventHandler = (sender, e) => StatusChanged();

            base.Initialize(pendingCheckin);
            _userconfirmed = false;                
            pendingCheckin.PendingChanges.AffectedTeamProjectsChanged += _affectedTeamProjectsEventHandler;
            pendingCheckin.PendingChanges.CheckedPendingChangesChanged += _checkedPendingChangesEventHandler;
        }

        protected override void OnPolicyStateChanged(PolicyFailure[] failures)
        {
            _userconfirmed = false;
            base.OnPolicyStateChanged(Evaluate());
        }

        public override void Activate(PolicyFailure failure)
        {
            if (MessageBox.Show("Confirm the policy?", "Policy Check", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                _userconfirmed = true;
                base.OnPolicyStateChanged(Evaluate());
            }
        }

        public override PolicyFailure[] Evaluate()
        {
            if (_userconfirmed == true)
            {
                return new PolicyFailure[0];
            }
            else
            {
                return new PolicyFailure[]{new PolicyFailure("User must confirm", this)};
            }
        }

        public override string Description
        {
            get { throw new NotImplementedException(); }
        }

        public override bool Edit(IPolicyEditArgs policyEditArgs)
        {
            return true;
        }

        public override string Type
        {
            get
            {
                return "User Confirm";
            }
        }

        public override string TypeDescription
        {
            get
            {
                return "User Confirm";
            }
        }

        public override void Dispose()
        {
            this.PendingCheckin.PendingChanges.AffectedTeamProjectsChanged -= _affectedTeamProjectsEventHandler;
            this.PendingCheckin.PendingChanges.CheckedPendingChangesChanged -= _checkedPendingChangesEventHandler;

            base.Dispose();
        }
    }
}

I haven't tested this exact code yet, it might need some tweaking, but this is the general thing to do. Right now it triggers on a change in the files being checked in, but you can subscribe to any of the other events as well (work item changes) or trigger your own evaluation of the project each time Evaluate is called.

Or you can just trigger the confirm once per checkin cycle. it's all up to you. You could even do a "Click to Dismiss" and skip the Messagebox altogether. Just set _userConfirmed=true and fire the PolicyStateChanged event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文