首页 > 解决方案 > TFS 2017 插件问题 - 捕获异常TF30063:您无权访问“https://tfs.com//TeamProject

问题描述

我正在尝试在 TFS 2017 中创建一个插件,该插件在签入前检查关联的工作项,如果不满足少数条件则拒绝签入。这适用于 One Collection 和 One TeamProject。现在我正在尝试在多个集合和团队项目中实现这一点,它会引发以下错误“TF30063:您无权访问” https://tfs.com//TeamProject “我正在粘贴下面的代码,请让我知道可能的问题是什么。

            {
                // Logic Goes here ...

                bool isNullComment = false;
                bool isDevBranchChange = false;
                bool isCodeReviewRequest = false;
                bool isCodeReviewResponse = false;
                bool isTaskAssociated = false;

                //Read all submitted items
                var changes = notification.GetSubmittedItems(requestContext);
                //Check if the changes have any DEV branch changes
                isDevBranchChange = changes.Any(change => change.ToUpper().Contains("/DEV/"));
                if (isDevBranchChange)
                {
                    isNullComment = string.IsNullOrEmpty(notification.Comment.ToString());
                    var assoWorkItems = notification.NotificationInfo.WorkItemInfo.Select(x => x.Id);  //Read all associated workitem id's                       
                    TfsTeamProjectCollection connection = new TfsTeamProjectCollection(GetTfsUri(requestContext));
                    WorkItemStore wiStore = connection.GetService<WorkItemStore>();

                    //check if any of associated workitem has code review
                    foreach (int id in assoWorkItems)
                    {
                        WorkItem wi = wiStore.GetWorkItem(id);
                        // Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem wi = witClient.GetWorkItemAsync(id).Result;

                        if (wi.Type.Name.ToUpper().Equals("CODE REVIEW REQUEST"))
                        {
                            isCodeReviewRequest = true;
                        }
                        if (wi.Type.Name.ToUpper().Equals("TASK"))
                        {
                            isTaskAssociated = true;
                        }
                        if (wi.Type.Name.ToUpper().Equals("CODE REVIEW RESPONSE"))
                        {
                            isCodeReviewResponse = true;
                        }
                    }

                    if (!isCodeReviewRequest || isNullComment || !isCodeReviewResponse || !isTaskAssociated)
                    {
                        statusMessage = "Check-in Rejected. Check-in Comment, Task, Code Review Request and Code Review Response workitems are Required. \nFor more information, please contact TFS Administrators: vsalm@abc.com";
                        return EventNotificationStatus.ActionDenied;
                    }

                }
            }
            catch (Exception exception)
            {

                statusMessage = "Caught an Exception" + exception.Message;
                return EventNotificationStatus.ActionDenied;
                // Any exception, TFS will disable it. So, Log it and eat it.
                TeamFoundationApplicationCore.LogException("DecisionPoint plugin encountered the following error while processing events", exception);
            }

        }

        return EventNotificationStatus.ActionPermitted;
    }

    private Uri GetTfsUri(IVssRequestContext _requestContext)
    {

        var locationService = _requestContext.GetService<ILocationService>();
        return new Uri(locationService.GetServerAccessMapping(_requestContext).AccessPoint + "/" + _requestContext.ServiceHost.Name);
    }
}

}

标签: tfstfvc

解决方案


推荐阅读