Пример #1
0
		public EntryLinkTransformer(IEntryLinkFactory linkFactory) {

			ParamIs.NotNull(() => linkFactory);

			this.linkFactory = linkFactory;

		}
Пример #2
0
		public void CheckComment(Comment comment, IEntryLinkFactory entryLinkFactory, IRepositoryContext<User> ctx) {

			var userMatches = Regex.Match(comment.Message, @"@(\w+)");

			if (!userMatches.Success)
				return;

			var userNames = userMatches.Groups.Cast<Group>().Skip(1).Select(g => g.Value).ToArray();

			var users = ctx.Query().Where(u => u.Active && userNames.Contains(u.Name)).ToArray();

			if (!users.Any())
				return;

			var commentMsg = comment.Message.Truncate(200);
			var msg = string.Format("{0} mentioned you in a comment for {1}\n\n{2}", comment.AuthorName, MarkdownHelper.CreateMarkdownLink(entryLinkFactory.GetFullEntryUrl(comment.Entry), comment.Entry.DefaultName), commentMsg);

			foreach (var user in users) {

				var notification = new UserMessage(user, "Mentioned in a comment", msg, false);
				ctx.OfType<UserMessage>().Save(notification);

			}

		}
Пример #3
0
		private string CreateMessageBody(Artist[] followedArtists, User user, IEntryWithNames entry, IEntryLinkFactory entryLinkFactory, bool markdown) {
			
			var entryTypeName = entry.EntryType.ToString().ToLowerInvariant();
			var entryName = entry.Names.SortNames[user.DefaultLanguageSelection];
			var url = entryLinkFactory.GetFullEntryUrl(entry);

			string entryLink;
			if (markdown) {
				entryLink = MarkdownHelper.CreateMarkdownLink(url, entryName);
			} else {
				entryLink = string.Format("{0} ( {1} )", entryName, url);
			}

			string msg;

			if (followedArtists.Length == 1) {

				var artistName = followedArtists.First().TranslatedName[user.DefaultLanguageSelection];
				msg = string.Format("A new {0}, '{1}', by {2} was just added.",
					entryTypeName, entryLink, artistName);

			} else {

				msg = string.Format("A new {0}, '{1}', by multiple artists you're following was just added.",
					entryTypeName, entryLink);

			}

			msg += "\nYou're receiving this notification because you're following the artist(s).";
			return msg;

		}
Пример #4
0
        public UserQueries(IUserRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory, IStopForumSpamClient sfsClient,
                           IUserMessageMailer mailer, IUserIconFactory userIconFactory, ObjectCache cache)
            : base(repository, permissionContext)
        {
            ParamIs.NotNull(() => repository);
            ParamIs.NotNull(() => permissionContext);
            ParamIs.NotNull(() => entryLinkFactory);
            ParamIs.NotNull(() => sfsClient);
            ParamIs.NotNull(() => mailer);

            this.entryLinkFactory = entryLinkFactory;
            this.sfsClient        = sfsClient;
            this.mailer           = mailer;
            this.userIconFactory  = userIconFactory;
            this.cache            = cache;
        }
Пример #5
0
        public void SendReportNotification(IDatabaseContext <UserMessage> ctx,
                                           ArchivedObjectVersion reportedVersion,
                                           string notes,
                                           IEntryLinkFactory entryLinkFactory,
                                           string reportName)
        {
            if (reportedVersion == null)
            {
                return;
            }

            var receiver = reportedVersion.Author;

            if (receiver == null)
            {
                return;
            }

            var entry = reportedVersion.EntryBase;

            string body, title;

            using (new ImpersonateUICulture(CultureHelper.GetCultureOrDefault(receiver.LanguageOrLastLoginCulture))) {
                body  = EntryReportStrings.EntryVersionReportBody;
                title = EntryReportStrings.EntryVersionReportTitle;
            }

            // Report type name + notes
            string notesAndName = notes;

            if (!string.IsNullOrEmpty(reportName) && !string.IsNullOrEmpty(notes))
            {
                notesAndName = string.Format("{0} ({1})", reportName, notes);
            }
            else if (string.IsNullOrEmpty(notes))
            {
                notesAndName = reportName;
            }

            var message = string.Format(body,
                                        MarkdownHelper.CreateMarkdownLink(entryLinkFactory.GetFullEntryUrl(entry), entry.DefaultName),
                                        notesAndName);

            var notification = new UserMessage(receiver, string.Format(title, entry.DefaultName), message, false);

            ctx.Save(notification);
        }
Пример #6
0
 public AlbumQueries(IAlbumRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory,
                     IEntryThumbPersister imagePersister, IEntryPictureFilePersister pictureFilePersister, IUserMessageMailer mailer,
                     IUserIconFactory userIconFactory, IEnumTranslations enumTranslations, IPVParser pvParser,
                     IFollowedArtistNotifier followedArtistNotifier, IAggregatedEntryImageUrlFactory entryThumbPersister, ObjectCache cache)
     : base(repository, permissionContext)
 {
     this.entryLinkFactory     = entryLinkFactory;
     this.imagePersister       = imagePersister;
     this.pictureFilePersister = pictureFilePersister;
     this.mailer                 = mailer;
     this.userIconFactory        = userIconFactory;
     this.enumTranslations       = enumTranslations;
     this.pvParser               = pvParser;
     this.followedArtistNotifier = followedArtistNotifier;
     this.imageUrlFactory        = entryThumbPersister;
     this.cache = cache;
 }
Пример #7
0
 public TagQueries(
     ITagRepository repository,
     IUserPermissionContext permissionContext,
     IEntryLinkFactory entryLinkFactory,
     IEntryThumbPersister imagePersister,
     IAggregatedEntryImageUrlFactory thumbStore,
     IUserIconFactory userIconFactory,
     IEnumTranslations enumTranslations,
     ObjectCache cache,
     IDiscordWebhookNotifier discordWebhookNotifier)
     : base(repository, permissionContext)
 {
     _entryLinkFactory       = entryLinkFactory;
     _imagePersister         = imagePersister;
     _thumbStore             = thumbStore;
     _userIconFactory        = userIconFactory;
     _enumTranslations       = enumTranslations;
     _cache                  = cache;
     _discordWebhookNotifier = discordWebhookNotifier;
 }
Пример #8
0
 public ArtistQueries(
     IArtistRepository repository,
     IUserPermissionContext permissionContext,
     IEntryLinkFactory entryLinkFactory,
     IEntryThumbPersister imagePersister,
     IEntryPictureFilePersister pictureFilePersister,
     ObjectCache cache,
     IUserIconFactory userIconFactory,
     IEnumTranslations enumTranslations,
     IAggregatedEntryImageUrlFactory imageUrlFactory,
     IDiscordWebhookNotifier discordWebhookNotifier)
     : base(repository, permissionContext)
 {
     _entryLinkFactory     = entryLinkFactory;
     _imagePersister       = imagePersister;
     _pictureFilePersister = pictureFilePersister;
     _cache                  = cache;
     _userIconFactory        = userIconFactory;
     _enumTranslations       = enumTranslations;
     _imageUrlFactory        = imageUrlFactory;
     _discordWebhookNotifier = discordWebhookNotifier;
 }
Пример #9
0
 public EventQueries(
     IEventRepository eventRepository,
     IEntryLinkFactory entryLinkFactory,
     IUserPermissionContext permissionContext,
     IEntryThumbPersister imagePersister,
     IUserIconFactory userIconFactory,
     IEnumTranslations enumTranslations,
     IUserMessageMailer mailer,
     IFollowedArtistNotifier followedArtistNotifier,
     IAggregatedEntryImageUrlFactory imageUrlFactory,
     IDiscordWebhookNotifier discordWebhookNotifier)
     : base(eventRepository, permissionContext)
 {
     _entryLinkFactory       = entryLinkFactory;
     _imagePersister         = imagePersister;
     _userIconFactory        = userIconFactory;
     _enumTranslations       = enumTranslations;
     _mailer                 = mailer;
     _followedArtistNotifier = followedArtistNotifier;
     _imageUrlFactory        = imageUrlFactory;
     _discordWebhookNotifier = discordWebhookNotifier;
 }
Пример #10
0
 public static string GetFullEntryUrl(this IEntryLinkFactory entryLinkFactory, GlobalEntryId globalId, string slug = null)
 {
     return(entryLinkFactory.GetFullEntryUrl(globalId.EntryType, globalId.Id, slug));
 }
Пример #11
0
 public ArtistService(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory, IEntryUrlParser entryUrlParser)
     : base(sessionFactory, permissionContext, entryLinkFactory)
 {
     this.entryUrlParser = entryUrlParser;
 }
Пример #12
0
 public CommentApiController(IRepository db, IUserPermissionContext userContext, IUserIconFactory userIconFactory, IEntryLinkFactory entryLinkFactory)
 {
     this.db               = db;
     this.userContext      = userContext;
     this.userIconFactory  = userIconFactory;
     this.entryLinkFactory = entryLinkFactory;
 }
Пример #13
0
		public ServiceModel(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory, BrandableStringsManager brandableStringsManager) {
			this.sessionFactory = sessionFactory;
			this.permissionContext = permissionContext;
			this.entryLinkFactory = entryLinkFactory;
			this.brandableStringsManager = brandableStringsManager;
		}
Пример #14
0
        protected ServiceBase(
            ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory)
        {
            ParamIs.NotNull(() => sessionFactory);

            this.sessionFactory    = sessionFactory;
            this.permissionContext = permissionContext;
            this.entryLinkFactory  = entryLinkFactory;
        }
Пример #15
0
 public EventController(EventQueries queries, ReleaseEventService service, IEnumTranslations enumTranslations, IEntryLinkFactory entryLinkFactory,
                        IAggregatedEntryImageUrlFactory thumbPersister)
 {
     this.queries          = queries;
     this.service          = service;
     this.enumTranslations = enumTranslations;
     this.entryLinkFactory = entryLinkFactory;
     this.thumbPersister   = thumbPersister;
 }
Пример #16
0
 public SongListQueries(ISongListRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory,
                        IEntryImagePersisterOld imagePersister, IAggregatedEntryImageUrlFactory thumbStore, IUserIconFactory userIconFactory)
     : base(repository, permissionContext)
 {
     this.entryLinkFactory = entryLinkFactory;
     this.imagePersister   = imagePersister;
     this.thumbStore       = thumbStore;
     this.userIconFactory  = userIconFactory;
 }
Пример #17
0
 public CommentQueries(IDatabaseContext ctx, IUserPermissionContext permissionContext, IUserIconFactory userIconFactory, IEntryLinkFactory entryLinkFactory,
                       Func <int, TEntry> entryLoaderFunc = null)
 {
     this.ctx = ctx;
     this.entryLinkFactory  = entryLinkFactory;
     this.permissionContext = permissionContext;
     this.userIconFactory   = userIconFactory;
     this.entryLoaderFunc   = entryLoaderFunc;
 }
Пример #18
0
 public SongListQueries(ISongListRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory, IEntryImagePersisterOld imagePersister)
 {
     this.repository        = repository;
     this.permissionContext = permissionContext;
     this.entryLinkFactory  = entryLinkFactory;
     this.imagePersister    = imagePersister;
 }
Пример #19
0
 public ServiceModel(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory)
 {
     this.sessionFactory = sessionFactory;
     this.permissionContext = permissionContext;
     this.entryLinkFactory = entryLinkFactory;
 }
Пример #20
0
 public MikuDbAlbumService(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory)
     : base(sessionFactory, permissionContext, entryLinkFactory)
 {
 }
Пример #21
0
 public SongService(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory, IEntryUrlParser entryUrlParser,
                    VdbConfigManager config)
     : base(sessionFactory, permissionContext, entryLinkFactory)
 {
     _entryUrlParser = entryUrlParser;
     _config         = config;
 }
Пример #22
0
		/// <summary>
		/// Sends notifications
		/// </summary>
		/// <param name="ctx">Repository context. Cannot be null.</param>
		/// <param name="entry">Entry that was created. Cannot be null.</param>
		/// <param name="artists">List of artists for the entry. Cannot be null.</param>
		/// <param name="creator">User who created the entry. The creator will be excluded from all notifications. Cannot be null.</param>
		/// <param name="entryLinkFactory">Factory for creating links to entries. Cannot be null.</param>
		/// <param name="mailer">Mailer for user email messages. Cannot be null.</param>
		public void SendNotifications(IRepositoryContext<UserMessage> ctx, IEntryWithNames entry, 
			IEnumerable<Artist> artists, IUser creator, IEntryLinkFactory entryLinkFactory,
			IUserMessageMailer mailer) {

			ParamIs.NotNull(() => ctx);
			ParamIs.NotNull(() => entry);
			ParamIs.NotNull(() => artists);
			ParamIs.NotNull(() => creator);
			ParamIs.NotNull(() => entryLinkFactory);
			ParamIs.NotNull(() => mailer);

			var coll = artists.ToArray();
			var artistIds = coll.Select(a => a.Id).ToArray();

			// Get users with 3 or less unread messages, following any of the artists
			var usersWithArtists = ctx.OfType<ArtistForUser>()
				.Query()
				.Where(afu => 
					artistIds.Contains(afu.Artist.Id) 
					&& afu.User.Id != creator.Id && afu.User.Active
					&& afu.SiteNotifications
					&& afu.User.ReceivedMessages.Count(m => !m.Read) <= 9)
				.Select(afu => new {
					UserId = afu.User.Id, 
					ArtistId = afu.Artist.Id
				})
				.ToArray()
				.GroupBy(afu => afu.UserId)
				.ToDictionary(afu => afu.Key, afu => afu.Select(a => a.ArtistId));

			var userIds = usersWithArtists.Keys;

			if (!userIds.Any())
				return;

			var users = ctx.OfType<User>().Query().Where(u => userIds.Contains(u.Id)).ToArray();

			foreach (var user in users) {

				var artistIdsForUser = new HashSet<int>(usersWithArtists[user.Id]);
				var followedArtists = coll.Where(a => artistIdsForUser.Contains(a.Id)).ToArray();

				if (followedArtists.Length == 0)
					continue;

				string title;

				var entryTypeName = entry.EntryType.ToString().ToLowerInvariant();
				var msg = CreateMessageBody(followedArtists, user, entry, entryLinkFactory, true);

				if (followedArtists.Length == 1) {

					var artistName = followedArtists.First().TranslatedName[user.DefaultLanguageSelection];
					title = string.Format("New {0} by {1}", entryTypeName, artistName);

				} else {

					title = string.Format("New {0}", entryTypeName);

				}

				var notification = new UserMessage(user, title, msg, false);
				ctx.Save(notification);

				if (user.EmailOptions != UserEmailOptions.NoEmail && !string.IsNullOrEmpty(user.Email) 
					&& followedArtists.Any(a => a.Users.Any(u => u.User.Equals(user) && u.EmailNotifications))) {
					
					mailer.SendEmail(user.Email, user.Name, title, CreateMessageBody(followedArtists, user, entry, entryLinkFactory, false));

				}

			}

		}
Пример #23
0
 public ArtistQueries(IArtistRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory,
                      IEntryThumbPersister imagePersister, IEntryPictureFilePersister pictureFilePersister,
                      ObjectCache cache, IUserIconFactory userIconFactory, IEnumTranslations enumTranslations, IAggregatedEntryImageUrlFactory imageUrlFactory)
     : base(repository, permissionContext)
 {
     this.entryLinkFactory     = entryLinkFactory;
     this.imagePersister       = imagePersister;
     this.pictureFilePersister = pictureFilePersister;
     this.cache            = cache;
     this.userIconFactory  = userIconFactory;
     this.enumTranslations = enumTranslations;
     this.imageUrlFactory  = imageUrlFactory;
 }
Пример #24
0
		public MikuDbAlbumService(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory, ServiceModel services) 
			: base(sessionFactory, permissionContext, entryLinkFactory) {
			
			this.Services = services;

		}
Пример #25
0
 public SongListFormatter(IEntryLinkFactory entryLinkFactory)
     : base(entryLinkFactory)
 {
 }
Пример #26
0
 public ActivityFeedService(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory)
     : base(sessionFactory, permissionContext, entryLinkFactory)
 {
 }
Пример #27
0
 public MikuDbAlbumService(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory,
                           AlbumService albumService, SongService songService)
     : base(sessionFactory, permissionContext, entryLinkFactory)
 {
     _albumService = albumService;
     _songService  = songService;
 }
Пример #28
0
 public static string GetFullEntryUrl(this IEntryLinkFactory entryLinkFactory, IEntryBase entryBase)
 {
     return(entryLinkFactory.GetFullEntryUrl(entryBase.EntryType, entryBase.Id));
 }
Пример #29
0
 public AlbumQueries(IAlbumRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory,
                     IEntryThumbPersister imagePersister, IEntryPictureFilePersister pictureFilePersister, IUserMessageMailer mailer,
                     IUserIconFactory userIconFactory, IEnumTranslations enumTranslations, IPVParser pvParser)
     : base(repository, permissionContext)
 {
     this.entryLinkFactory     = entryLinkFactory;
     this.imagePersister       = imagePersister;
     this.pictureFilePersister = pictureFilePersister;
     this.mailer           = mailer;
     this.userIconFactory  = userIconFactory;
     this.enumTranslations = enumTranslations;
     this.pvParser         = pvParser;
 }
Пример #30
0
 public VenueQueries(IVenueRepository venueRepository, IEntryLinkFactory entryLinkFactory, IUserPermissionContext permissionContext, IEnumTranslations enumTranslations)
     : base(venueRepository, permissionContext)
 {
     _entryLinkFactory = entryLinkFactory;
     _enumTranslations = enumTranslations;
 }
Пример #31
0
 public RankingService(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory)
     : base(sessionFactory, permissionContext, entryLinkFactory)
 {
 }
Пример #32
0
 public OtherService(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory,
                     IUserIconFactory userIconFactory, EntryForApiContractFactory entryForApiContractFactory, ObjectCache cache)
     : base(sessionFactory, permissionContext, entryLinkFactory)
 {
     this.userIconFactory            = userIconFactory;
     this.entryForApiContractFactory = entryForApiContractFactory;
     this.cache = cache;
 }
Пример #33
0
 public OtherService(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory, IEntryThumbPersister thumbPersister)
     : base(sessionFactory, permissionContext, entryLinkFactory)
 {
     this.thumbPersister = thumbPersister;
 }
Пример #34
0
        public bool CreateReport <TEntry, TReport, TReportType>(IDatabaseContext <TEntry> ctx,
                                                                IUserPermissionContext permissionContext,
                                                                IEntryLinkFactory entryLinkFactory,
                                                                Expression <Func <TReport, bool> > addExistingEntryFunc,
                                                                Func <TEntry, User, string, TReport> reportFunc,
                                                                Func <string> reportNameFunc,
                                                                int entryId, TReportType reportType, string hostname, string notes)
            where TEntry : IEntryWithVersions
            where TReport : EntryReport
        {
            ParamIs.NotNull(() => hostname);
            ParamIs.NotNull(() => notes);

            var msg = string.Format("creating report for {0} [{1}] as {2}", typeof(TEntry).Name, entryId, reportType);

            ctx.AuditLogger.SysLog(msg, hostname);

            var loggedUserId = permissionContext.LoggedUserId;
            var existing     = ctx.Query <TReport>()
                               .Where(addExistingEntryFunc)
                               .Where(r => (loggedUserId != 0 && r.User.Id == loggedUserId) || r.Hostname == hostname)
                               .FirstOrDefault();

            if (existing != null && !permissionContext.IsLoggedIn)
            {
                return(false);
            }

            var entry    = ctx.Load(entryId);
            var reporter = ctx.OfType <User>().GetLoggedUserOrNull(permissionContext);
            var report   = reportFunc(entry, reporter, notes.Truncate(EntryReport.MaxNotesLength));

            // Reported version. If a specific version was reported the author is already defined.
            var versionForReport = report.VersionBase;

            if (versionForReport == null)
            {
                // Get first version, check if all following edits were made by the same user OR the reporter
                var firstVersion = entry.ArchivedVersionsManager.VersionsBase.FirstOrDefault(
                    ver => ver.Author != null && !ver.Author.Equals(reporter));

                var oneEditor = firstVersion != null && firstVersion.Author != null &&
                                entry.ArchivedVersionsManager.VersionsBase.All(ver =>
                                                                               Equals(ver.Author, reporter) ||          // Editor is reporter
                                                                               firstVersion.Author.Equals(ver.Author)); // Editor is the creator

                if (oneEditor)
                {
                    versionForReport = firstVersion;                     // TODO: need to include report type in notification
                }
            }

            // Get translated report type name
            string reportName = null;

            if (versionForReport != null && versionForReport.Author != null)
            {
                using (new ImpersonateUICulture(CultureHelper.GetCultureOrDefault(versionForReport.Author.LanguageOrLastLoginCulture))) {
                    reportName = reportNameFunc();
                }
            }

            new EntryReportNotifier().SendReportNotification(ctx.OfType <UserMessage>(), versionForReport, notes, entryLinkFactory, reportName);

            if (existing != null)
            {
                return(false);
            }

            msg = string.Format("reported {0} as {1} ({2})", entryLinkFactory.CreateEntryLink(entry), reportType, HttpUtility.HtmlEncode(notes));
            ctx.AuditLogger.AuditLog(msg.Truncate(200), new AgentLoginData(reporter, hostname));

            ctx.Save(report);
            return(true);
        }
Пример #35
0
 public static string GetFullEntryUrl(this IEntryLinkFactory entryLinkFactory, IEntryBase entryBase, string slug = null)
 {
     return(entryLinkFactory.GetFullEntryUrl(entryBase.EntryType, entryBase.Id, slug));
 }
Пример #36
0
        public TagUsageForApiContract[] AddTags <TEntry, TTag>(int entryId, TagBaseContract[] tags,
                                                               bool onlyAdd,
                                                               IRepository <User> repository,
                                                               IEntryLinkFactory entryLinkFactory,
                                                               IEnumTranslations enumTranslations,
                                                               Func <TEntry, TagManager <TTag> > tagFunc,
                                                               Func <TEntry, IDatabaseContext <TTag>, ITagUsageFactory <TTag> > tagUsageFactoryFactory)
            where TEntry : IEntryWithNames, IEntryWithTags where TTag : TagUsage
        {
            ParamIs.NotNull(() => tags);

            permissionContext.VerifyManageDatabase();

            tags = tags.Where(IsValid).ToArray();

            if (onlyAdd && !tags.Any())
            {
                return(new TagUsageForApiContract[0]);
            }

            return(repository.HandleTransaction(ctx => {
                // Tags are primarily added by Id, secondarily by translated name.
                // First separate given tags for tag IDs and tag names
                var tagIds = tags.Where(HasId).Select(t => t.Id).ToArray();
                var translatedTagNames = tags.Where(t => !HasId(t) && !string.IsNullOrEmpty(t.Name)).Select(t => t.Name).ToArray();

                // Load existing tags by name and ID.
                var tagsFromIds = ctx.Query <Tag>().Where(t => tagIds.Contains(t.Id)).ToArray();

                var tagsFromNames = ctx.Query <Tag>().WhereHasName(translatedTagNames).ToArray();

                // Figure out tags that don't exist yet (no ID and no matching name).
                var newTagNames = translatedTagNames.Except(tagsFromNames.SelectMany(t => t.Names.AllValues), StringComparer.InvariantCultureIgnoreCase).ToArray();

                var user = ctx.OfType <User>().GetLoggedUser(permissionContext);
                var tagFactory = new TagFactoryRepository(ctx.OfType <Tag>(), new AgentLoginData(user));
                var newTags = newTagNames.Select(t => tagFactory.CreateTag(t)).ToArray();

                // Get the final list of tag names with translations
                var appliedTags = tagsFromNames.Concat(tagsFromIds).Concat(newTags).Distinct().ToArray();

                var entry = ctx.OfType <TEntry>().Load(entryId);
                var tagUsageFactory = tagUsageFactoryFactory(entry, ctx.OfType <TTag>());

                var tagNames = appliedTags.Select(t => t.DefaultName);
                ctx.AuditLogger.AuditLog(string.Format("tagging {0} with {1}",
                                                       entryLinkFactory.CreateEntryLink(entry), string.Join(", ", tagNames)), user);

                var addedTags = appliedTags.Except(entry.Tags.Tags).ToArray();
                new FollowedTagNotifier().SendNotifications(ctx, entry, addedTags, new[] { user.Id }, entryLinkFactory, enumTranslations);

                var updatedTags = tagFunc(entry).SyncVotes(user, appliedTags, tagUsageFactory, onlyAdd: onlyAdd);
                var tagCtx = ctx.OfType <Tag>();

                foreach (var tag in updatedTags)
                {
                    tagCtx.Update(tag);
                }

                RecomputeTagUsagesCounts(tagCtx, updatedTags);

                ctx.AuditLogger.SysLog("finished tagging");

                return tagFunc(entry).ActiveUsages.Select(t => new TagUsageForApiContract(t, permissionContext.LanguagePreference)).ToArray();
            }));
        }
Пример #37
0
 public SongQueries(ISongRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory, IPVParser pvParser, IUserMessageMailer mailer,
                    ILanguageDetector languageDetector, IUserIconFactory userIconFactory, IEnumTranslations enumTranslations, ObjectCache cache, VdbConfigManager config)
     : base(repository, permissionContext)
 {
     this.entryLinkFactory = entryLinkFactory;
     this.pvParser         = pvParser;
     this.mailer           = mailer;
     this.languageDetector = languageDetector;
     this.userIconFactory  = userIconFactory;
     this.enumTranslations = enumTranslations;
     this.cache            = cache;
     this.config           = config;
 }
Пример #38
0
 public static CommentQueries <T> Create <T>(IRepositoryContext <T> ctx, IUserPermissionContext permissionContext, IUserIconFactory userIconFactory, IEntryLinkFactory entryLinkFactory)
     where T : Comment
 {
     return(new CommentQueries <T>(ctx, permissionContext, userIconFactory, entryLinkFactory));
 }
Пример #39
0
 public OtherService(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory)
     : base(sessionFactory, permissionContext, entryLinkFactory)
 {
 }
Пример #40
0
 public SongListController(SongListQueries queries, IEntryLinkFactory entryLinkFactory)
 {
     this.queries          = queries;
     this.entryLinkFactory = entryLinkFactory;
 }