TFS 2015警报API:为团队或TFS组创建警报 [英] TFS 2015 Alert API: Create an alert for Team or TFS Group
问题描述
是否可以使用TFS 2015 API或Power Shell脚本以编程方式设置团队警报/TFS组警报?我们要求创建TFS Alert的时间应大于15,然后寻找使用api/脚本而不是手动创建警报的选项.
Is it possible to setup a Team Alert / TFS Group Alert Programmatically using TFS 2015 APIs or Power Shell script? We have a requirement to create TFS Alert more then ~15 and looking for an option to create alert using api / script instead of manually.
推荐答案
据我所知,警报用于团队项目和团队项目集合级别,因此您在团队中创建的警报将列在团队项目的警报列表.对于团队项目收集级别,警报将列在所有团队项目和团队的警报列表中.
As far as I know, the alerts are used for team project and team project collection level, so the alerts that you created in a team will be listed in the team project’s alerts list. For team project collection level, the alerts will be listed in all team project and team’s alerts list.
创建警报的简单代码:
NetworkCredential cred = new NetworkCredential("[user name]", "[password]", "[domain]");
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("[collection url]"), cred);
tpc.EnsureAuthenticated();
IIdentityManagementService2 ims = tpc.GetService<IIdentityManagementService2>();
TeamFoundationIdentity identity = ims.ReadIdentity(IdentitySearchFactor.AccountName,"[user name]", MembershipQuery.None,ReadIdentityOptions.None);
if(identity!=null)
{
string s = identity.Descriptor.Identifier;
}
IEventService es = tpc.GetService<IEventService>();
List<Subscription> allSubScrip = es.GetAllEventSubscriptions().ToList();
DeliveryPreference deliverPreference = new DeliveryPreference();
deliverPreference.Address = "[email address]";
deliverPreference.Schedule = DeliverySchedule.Immediate;
deliverPreference.Type = DeliveryType.EmailHtml;
string filter = string.Format("\"CoreFields/IntegerFields/Field[Name='ID']/NewValue\"='10'");
string eventName = string.Format("<PT N=\"A specific work item is changed API team\" />");
es.SubscribeEvent(identity.Descriptor.Identifier, "WorkItemChangedEvent", filter, deliverPreference, eventName,projectName: "[team project name]");
注意:如果您不知道如何指定过滤器,则可以在Web访问中创建示例警报,然后检查集合数据库的dbo.tbl_EventSubscription表中的记录.
Note: If you don't know how to specify filter, you could create the sample alerts in web access, then check record in dbo.tbl_EventSubscription table of the collection database.
这篇关于TFS 2015警报API:为团队或TFS组创建警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!