自定义签入策略:从变更文件访问filecontent [英] Custom Checkin Policy: Access to filecontent from changeset files
问题描述
我想whrite我自己签的政策。
我想回顾如有cs文件中包含一些代码。所以我的问题是,如果可能从重写初始化-了Methode的变更让每一个文件的内容和/或评估-了Methode(从PolicyBase)。
I'm trying to whrite my own checkin policy. I want to review if any .cs file contains some code. So my question is, if its possible to get the content of every file from the changeset in the overriden Initialize-Methode and/or Evaluate-Methode (from PolicyBase).
在先进的感谢!
推荐答案
您不能从文件直接获得内容,你需要打开它们自己。对于每个检查在你的评估
方法,你应该看看 PendingCheckin.PendingChanges.CheckedPendingChanges
(以确保只有你限制自己将在检查挂起更改。)每个 PendingChange
有一个 LocalItem
,您可以打开并扫描
You can't get the contents from the files directly, you'll need to open them yourselves. For each checked In your Evaluate
method, you should look at the PendingCheckin.PendingChanges.CheckedPendingChanges
(to ensure that you only limit yourself to the pending changes that will be checked in.) Each PendingChange
has a LocalItem
that you can open and scan.
例如:
public override PolicyFailure[] Evaluate()
{
List<PolicyFailure> failures = new List<PolicyFailure>();
foreach(PendingChange pc in PendingCheckin.PendingChanges.CheckedPendingChanges)
{
if(pc.LocalItem == null)
{
continue;
}
/* Open the file */
using(FileStream fs = new FileStream(pc.LocalItem, ...))
{
if(/* File contains your prohibited code */)
{
failures.Add(new PolicyFailure(/* Explain the problem */));
}
fs.Close();
}
}
return failures.ToArray();
}
这篇关于自定义签入策略:从变更文件访问filecontent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!