protected override IEnumerable<Notifications.INotification> CreateNotifications(IVssRequestContext requestContext, object notificationEventArgs, int maxLines)
        {
            var repositoryService = requestContext.GetService<ITeamFoundationGitRepositoryService>();
            var identityService = requestContext.GetService<ITeamFoundationIdentityService>();
            var commonService = requestContext.GetService<CommonStructureService>();
            var locationService = requestContext.GetService<ILocationService>();

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

            var gitNotification = notificationEventArgs as GitNotification;

            Notifications.RepositoryNotification notification = null;

            if (gitNotification is RepositoryCreatedNotification)
            {
                var ev = notificationEventArgs as RepositoryCreatedNotification;
                var identity = identityService.ReadIdentity(requestContext, IdentitySearchFactor.Identifier, ev.Creator.Identifier);

                notification = new Notifications.RepositoryCreatedNotification();
                notification.UniqueName = identity.UniqueName;
                notification.DisplayName = identity.DisplayName;
                notification.TeamNames = GetUserTeamsByProjectUri(requestContext, gitNotification.TeamProjectUri, identity.Descriptor);
                using (ITfsGitRepository repository = repositoryService.FindRepositoryById(requestContext, gitNotification.RepositoryId))
                {
                    notification.RepoUri = repository.GetRepositoryUri();
                    notification.RepoName = repository.Name;
                }
            }
            else if (gitNotification is RepositoryRenamedNotification)
            {
                notification = new Notifications.RepositoryRenamedNotification();
                notification.RepoName = gitNotification.RepositoryName;
                using (ITfsGitRepository repository = repositoryService.FindRepositoryById(requestContext, gitNotification.RepositoryId))
                {
                    notification.RepoUri = repository.GetRepositoryUri();
                    notification.RepoName = repository.Name;
                }
                notification.TeamNames = Enumerable.Empty<string>();
            }
            else if (gitNotification is RepositoryDeletedNotification)
            {
                var repoInfo = repositoryService
                    .QueryDeletedRepositories(requestContext, gitNotification.TeamProjectUri)
                    .Single(r => r.RepositoryId == gitNotification.RepositoryId);
                var identity = identityService.ReadIdentities(requestContext, new[] { repoInfo.DeletedBy }).First();
                notification = new Notifications.RepositoryDeletedNotification();
                notification.UniqueName = identity.UniqueName;
                notification.DisplayName = identity.DisplayName;
                notification.TeamNames = GetUserTeamsByProjectUri(requestContext, gitNotification.TeamProjectUri, identity.Descriptor);
                notification.RepoName = repoInfo.Name;
            }

            notification.TeamProjectCollection = requestContext.ServiceHost.Name;
            notification.ProjectName = commonService.GetProject(requestContext, gitNotification.TeamProjectUri).Name;
            notification.ProjectUrl = baseUrl + notification.ProjectName;

            yield return notification;
        }
Exemple #2
0
        protected override IEnumerable <Notifications.INotification> CreateNotifications(IVssRequestContext requestContext, object notificationEventArgs, int maxLines)
        {
            var repositoryService = requestContext.GetService <ITeamFoundationGitRepositoryService>();
            var identityService   = requestContext.GetService <ITeamFoundationIdentityService>();
            var commonService     = requestContext.GetService <CommonStructureService>();
            var locationService   = requestContext.GetService <ILocationService>();

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

            var gitNotification = notificationEventArgs as GitNotification;

            Notifications.RepositoryNotification notification = null;

            if (gitNotification is RepositoryCreatedNotification)
            {
                var ev       = notificationEventArgs as RepositoryCreatedNotification;
                var identity = identityService.ReadIdentity(requestContext, IdentitySearchFactor.Identifier, ev.Creator.Identifier);

                notification             = new Notifications.RepositoryCreatedNotification();
                notification.UniqueName  = identity.UniqueName;
                notification.DisplayName = identity.DisplayName;
                notification.TeamNames   = GetUserTeamsByProjectUri(requestContext, gitNotification.TeamProjectUri, identity.Descriptor);
                using (ITfsGitRepository repository = repositoryService.FindRepositoryById(requestContext, gitNotification.RepositoryId))
                {
                    notification.RepoUri  = repository.GetRepositoryUri();
                    notification.RepoName = repository.Name;
                }
            }
            else if (gitNotification is RepositoryRenamedNotification)
            {
                notification          = new Notifications.RepositoryRenamedNotification();
                notification.RepoName = gitNotification.RepositoryName;
                using (ITfsGitRepository repository = repositoryService.FindRepositoryById(requestContext, gitNotification.RepositoryId))
                {
                    notification.RepoUri  = repository.GetRepositoryUri();
                    notification.RepoName = repository.Name;
                }
                notification.TeamNames = Enumerable.Empty <string>();
            }
            else if (gitNotification is RepositoryDeletedNotification)
            {
                var repoInfo = repositoryService
                               .QueryDeletedRepositories(requestContext, gitNotification.TeamProjectUri)
                               .Single(r => r.RepositoryId == gitNotification.RepositoryId);
                var identity = identityService.ReadIdentities(requestContext, new[] { repoInfo.DeletedBy }).First();
                notification             = new Notifications.RepositoryDeletedNotification();
                notification.UniqueName  = identity.UniqueName;
                notification.DisplayName = identity.DisplayName;
                notification.TeamNames   = GetUserTeamsByProjectUri(requestContext, gitNotification.TeamProjectUri, identity.Descriptor);
                notification.RepoName    = repoInfo.Name;
            }

            notification.TeamProjectCollection = requestContext.ServiceHost.Name;
            notification.ProjectName           = commonService.GetProject(requestContext, gitNotification.TeamProjectUri).Name;
            notification.ProjectUrl            = baseUrl + notification.ProjectName;

            yield return(notification);
        }