public static CheckinNotificationModel ToCheckinNotificationModel(this CheckinNotification checkinNotification, IVssRequestContext requestContext)
 {
     return(new CheckinNotificationModel
     {
         AuthorName = checkinNotification.ChangesetOwner.DisplayName,
         ChangesetId = checkinNotification.Changeset,
         Comment = checkinNotification.Comment
     });
 }
        private bool ShouldMergeItemsIfNecessary(
            TeamFoundationRequestContext requestContext,
            CheckinNotification checkinNotification)
        {
            if (checkinNotification.Comment != null &&
                checkinNotification.Comment.IndexOf("***NO_PBI***", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                return(false);
            }

            return(true);
        }
        protected override IEnumerable <INotification> CreateNotifications(TeamFoundationRequestContext requestContext, TFVC.CheckinNotification checkin, int maxLines)
        {
            var locationService = requestContext.GetService <TeamFoundationLocationService>();


            string baseUrl = String.Format("{0}/{1}/",
                                           locationService.GetAccessMapping(requestContext, "PublicAccessMapping").AccessPoint,
                                           requestContext.ServiceHost.Name);

            var teamNames = new HashSet <string>();
            var projects  = new Dictionary <string, string>();

            var submittedItems = checkin.GetSubmittedItems(requestContext).ToList();

            const string pattern = @"^\$\/([^\/]*)\/";

            foreach (string item in submittedItems)
            {
                Match match = Regex.Match(item, pattern);
                if (match.Success)
                {
                    string projectName = match.Groups[1].Value;
                    if (projects.ContainsKey(projectName))
                    {
                        continue;
                    }

                    string projectUrl = baseUrl + projectName;
                    projects.Add(projectName, projectUrl);

                    foreach (var team in GetUserTeamsByProjectName(requestContext, projectName, checkin.ChangesetOwner.Descriptor))
                    {
                        teamNames.Add(team);
                    }
                }
            }

            var notification = new CheckinNotification()
            {
                TeamProjectCollection = requestContext.ServiceHost.Name,
                UniqueName            = checkin.ChangesetOwner.UniqueName,
                DisplayName           = checkin.ChangesetOwner.DisplayName,
                ChangesetUrl          = $"{baseUrl}_versionControl/changeset/{checkin.Changeset}",
                ChangesetId           = checkin.Changeset,
                Projects       = projects,
                Comment        = TextHelper.Truncate(checkin.Comment, Settings.CommentMaxLength, true),
                TeamNames      = teamNames,
                SubmittedItems = submittedItems
            };

            yield return(notification);
        }
        protected override IEnumerable <INotification> CreateNotifications(TeamFoundationRequestContext requestContext, TFVC.CheckinNotification checkin, int maxLines)
        {
            var locationService = requestContext.GetService <TeamFoundationLocationService>();


            string baseUrl = String.Format("{0}/{1}/",
                                           locationService.GetAccessMapping(requestContext, "PublicAccessMapping").AccessPoint,
                                           requestContext.ServiceHost.Name);

            var notification = new CheckinNotification()
            {
                TeamProjectCollection = requestContext.ServiceHost.Name,
                UniqueName            = checkin.ChangesetOwner.UniqueName,
                DisplayName           = checkin.ChangesetOwner.DisplayName,
                ChangesetUrl          = String.Format("{0}_versionControl/changeset/{1}", baseUrl, checkin.Changeset),
                ChangesetId           = checkin.Changeset,
                Projects = new Dictionary <string, string>(),
                Comment  = checkin.Comment,
                Teams    = new Dictionary <string, string>()
            };
            string pattern = @"^\$\/([^\/]*)\/";

            foreach (string item in checkin.GetSubmittedItems(requestContext))
            {
                Match match = Regex.Match(item, pattern);
                if (match.Success)
                {
                    string projectName = match.Groups[1].Value;
                    if (notification.Projects.ContainsKey(projectName))
                    {
                        continue;
                    }
                    string projectUrl = baseUrl + projectName;
                    notification.Projects.Add(projectName, projectUrl);

                    // Add the teams to the notification
                    foreach (var team in this.GetTeamsByUser(requestContext, projectName, notification.DisplayName))
                    {
                        if (notification.Teams.ContainsKey(team.Key))
                        {
                            continue;
                        }
                        notification.Teams.Add(team.Key, team.Value);
                    }
                }
            }

            yield return(notification);
        }
Beispiel #5
0
        public EventNotificationStatus ProcessEvent(TeamFoundationRequestContext requestContext, NotificationType notificationType, object notificationEventArgs,
                                                    out int statusCode, out string statusMessage, out ExceptionPropertyCollection properties)
        {
            statusCode    = 0;
            properties    = null;
            statusMessage = String.Empty;

            try
            {
                if (notificationType == NotificationType.DecisionPoint && notificationEventArgs is CheckinNotification)
                {
                    CheckinNotification ev = notificationEventArgs as CheckinNotification;
                    if (ev != null && ev.PolicyOverrideInfo != null)
                    {
                        if (ev.PolicyOverrideInfo.PolicyFailures != null)
                        {
                            // One or more of the checkin policies have been overridden
                            // If all the files being checked in are in the published folder, then allow overridding the policies since those are installation packages
                            foreach (string file in ev.GetSubmittedItems(null))
                            {
                                if (!Regex.IsMatch(file, @"/published", RegexOptions.IgnoreCase) &&
                                    !Regex.IsMatch(Path.GetDirectoryName(file), @"/published", RegexOptions.IgnoreCase))
                                {
                                    statusCode = -1;
                                    break;
                                }
                            }
                            if (statusCode != 0)
                            {
                                // One or more of the checkin policies have been overridden and not all files are installation files (in the published folder)
                                statusMessage = Resource.CheckinCancelledStatusMessage;
                                foreach (PolicyFailureInfo policy in ev.PolicyOverrideInfo.PolicyFailures)
                                {
                                    statusMessage = String.Concat(statusMessage, "\n    > ", policy.PolicyName, ": ", policy.Message);
                                }
                                return(EventNotificationStatus.ActionDenied);
                            }
                        }
                    }
                    return(EventNotificationStatus.ActionPermitted);
                }
            }
            catch (Exception exception)
            {
                // decide what you want to do, if exception occurs
            }
            return(EventNotificationStatus.ActionPermitted);
        }
        private bool ShouldMergeItemsIfNecessary(
			TeamFoundationRequestContext requestContext, 
			CheckinNotification checkinNotification)
        {
            if (checkinNotification.Comment != null &&
                checkinNotification.Comment.IndexOf("***NO_PBI***", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                return false;
            }

            return true;
        }