public void Archive(ISession session, Song song, SongDiff diff, SongArchiveReason reason, string notes = "") { var agentLoginData = SessionHelper.CreateAgentLoginData(session, PermissionContext); var archived = ArchivedSongVersion.Create(song, diff, agentLoginData, reason, notes); session.Save(archived); }
public static ArchivedSongContract GetAllProperties(ArchivedSongVersion version) { var data = new ArchivedSongContract(); var xmlCache = new XmlCache <ArchivedSongContract>(); var thisVersion = xmlCache.Deserialize(version.Version, version.Data); data.Id = thisVersion.Id; data.LengthSeconds = thisVersion.LengthSeconds; data.NicoId = thisVersion.NicoId; data.Notes = thisVersion.Notes; data.NotesEng = thisVersion.NotesEng; data.OriginalVersion = thisVersion.OriginalVersion; data.PublishDate = thisVersion.PublishDate; data.ReleaseEvent = thisVersion.ReleaseEvent; data.SongType = thisVersion.SongType; data.TranslatedName = thisVersion.TranslatedName; DoIfExists(version, SongEditableFields.Albums, xmlCache, v => data.Albums = v.Albums); DoIfExists(version, SongEditableFields.Artists, xmlCache, (v, doc) => SetArtists(data, v, doc)); DoIfExists(version, SongEditableFields.Lyrics, xmlCache, v => data.Lyrics = v.Lyrics); DoIfExists(version, SongEditableFields.Names, xmlCache, v => data.Names = v.Names); DoIfExists(version, SongEditableFields.PVs, xmlCache, v => data.PVs = v.PVs); DoIfExists(version, SongEditableFields.WebLinks, xmlCache, v => data.WebLinks = v.WebLinks); return(data); }
private ArchivedSongVersion CreateVersion(int versionNumber) { var version = new ArchivedSongVersion(_entry, new System.Xml.Linq.XDocument(), new SongDiff(), new AgentLoginData("Miku"), versionNumber, _entry.Status, SongArchiveReason.Unknown, string.Empty); _archivedVersionManager.Add(version); return(version); }
private void ArchiveSong(IRepositoryContext <Song> ctx, Song song, SongDiff diff, SongArchiveReason reason, string notes = "") { var agentLoginData = ctx.CreateAgentLoginData(PermissionContext); var archived = ArchivedSongVersion.Create(song, diff, agentLoginData, reason, notes); ctx.OfType <ArchivedSongVersion>().Save(archived); }
public ArchivedSongVersion Archive(IDatabaseContext <Song> ctx, Song song, SongDiff diff, SongArchiveReason reason, string notes = "") { var agentLoginData = ctx.CreateAgentLoginData(PermissionContext); var archived = ArchivedSongVersion.Create(song, diff, agentLoginData, reason, notes); ctx.OfType <ArchivedSongVersion>().Save(archived); return(archived); }
private async Task <ArchivedSongVersion> ArchiveSongAsync(IDatabaseContext <Song> ctx, Song song, SongDiff diff, SongArchiveReason reason, string notes = "") { var agentLoginData = await ctx.CreateAgentLoginDataAsync(PermissionContext); var archived = ArchivedSongVersion.Create(song, diff, agentLoginData, reason, notes); await ctx.OfType <ArchivedSongVersion>().SaveAsync(archived); return(archived); }
private static void DoIfExists(ArchivedSongVersion version, SongEditableFields field, XmlCache<ArchivedSongContract> xmlCache, Action<ArchivedSongContract, XDocument> func) { var versionWithField = version.GetLatestVersionWithField(field); if (versionWithField != null && versionWithField.Data != null) { var data = xmlCache.Deserialize(versionWithField.Version, versionWithField.Data); func(data, versionWithField.Data); } }
private static void DoIfExists(ArchivedSongVersion version, SongEditableFields field, XmlCache <ArchivedSongContract> xmlCache, Action <ArchivedSongContract, XDocument> func) { var versionWithField = version.GetLatestVersionWithField(field); if (versionWithField != null && versionWithField.Data != null) { var data = xmlCache.Deserialize(versionWithField.Version, versionWithField.Data); func(data, versionWithField.Data); } }
public void CreateReport_DoNotNotifyIfAmbiguous() { repository.Save(ArchivedSongVersion.Create(song, new SongDiff(), new AgentLoginData(user2), SongArchiveReason.PropertiesUpdated, String.Empty)); repository.Save(ArchivedSongVersion.Create(song, new SongDiff(), new AgentLoginData(user3), SongArchiveReason.PropertiesUpdated, String.Empty)); queries.CreateReport(song.Id, SongReportType.Other, "39.39.39.39", "It's Miku, not Rin", null); var report = repository.List <SongReport>().First(); Assert.AreEqual(song, report.Entry, "Report was created for song"); Assert.IsNull(report.Version, "Version"); var notification = repository.List <UserMessage>().FirstOrDefault(); Assert.IsNull(notification, "notification was not created"); }
public void CreateReport_Notify_ReportTypeNameAndNotes() { var editor = user2; repository.Save(ArchivedSongVersion.Create(song, new SongDiff(), new AgentLoginData(editor), SongArchiveReason.PropertiesUpdated, String.Empty)); queries.CreateReport(song.Id, SongReportType.BrokenPV, "39.39.39.39", "It's Miku, not Rin", null); var entryLink = MarkdownHelper.CreateMarkdownLink(entryLinkFactory.GetFullEntryUrl(song), song.DefaultName); var notification = repository.List <UserMessage>().FirstOrDefault(); Assert.IsNotNull(notification, "notification was created"); Assert.AreEqual(string.Format(EntryReportStrings.EntryVersionReportTitle, song.DefaultName), notification.Subject, "Notification subject"); Assert.AreEqual(string.Format(EntryReportStrings.EntryVersionReportBody, entryLink, "Broken PV (It's Miku, not Rin)"), notification.Message, "Notification body"); }
public void CreateReport_DoNotNotifyIfAmbiguous() { _repository.Save(ArchivedSongVersion.Create(_song, new SongDiff(), new AgentLoginData(_user2), SongArchiveReason.PropertiesUpdated, String.Empty)); _repository.Save(ArchivedSongVersion.Create(_song, new SongDiff(), new AgentLoginData(_user3), SongArchiveReason.PropertiesUpdated, String.Empty)); _queries.CreateReport(_song.Id, SongReportType.Other, "39.39.39.39", "It's Miku, not Rin", null); var report = _repository.List <SongReport>().First(); report.Entry.Should().Be(_song, "Report was created for song"); report.Version.Should().BeNull("Version"); var notification = _repository.List <UserMessage>().FirstOrDefault(); notification.Should().BeNull("notification was not created"); }
public ArchivedSongVersionDetailsContract(ArchivedSongVersion archived, ArchivedSongVersion comparedVersion, ContentLanguagePreference languagePreference) { ArchivedVersion = new ArchivedSongVersionContract(archived); ComparedVersion = comparedVersion != null ? new ArchivedSongVersionContract(comparedVersion) : null; ComparedVersionId = comparedVersion != null ? comparedVersion.Id : 0; Song = new SongContract(archived.Song, languagePreference); Name = Song.Name; ComparableVersions = archived.Song.ArchivedVersionsManager.Versions .Where(v => v != archived) .Select(a => new ArchivedObjectVersionContract(a)) .ToArray(); Versions = ComparedSongsContract.Create(archived, comparedVersion); ComparedVersionId = Versions.SecondId; }
public ArchivedSongVersionDetailsContract(ArchivedSongVersion archived, ArchivedSongVersion comparedVersion, ContentLanguagePreference languagePreference) { ArchivedVersion = new ArchivedSongVersionContract(archived); ComparedVersion = comparedVersion != null ? new ArchivedSongVersionContract(comparedVersion) : null; ComparedVersionId = comparedVersion != null ? comparedVersion.Id : 0; Song = new SongContract(archived.Song, languagePreference); Name = Song.Name; ComparableVersions = archived.Song.ArchivedVersionsManager.Versions .Where(v => v != archived) .Select(a => new ArchivedObjectVersionContract(a)) .ToArray(); Versions = ComparedSongsContract.Create(archived, comparedVersion); ComparedVersionId = Versions.SecondId; }
public void CreateReport_NotifyIfUnambiguous() { var editor = user2; repository.Save(ArchivedSongVersion.Create(song, new SongDiff(), new AgentLoginData(editor), SongArchiveReason.PropertiesUpdated, String.Empty)); queries.CreateReport(song.Id, SongReportType.Other, "39.39.39.39", "It's Miku, not Rin", null); var report = repository.List <SongReport>().First(); Assert.AreEqual(song, report.Entry, "Report was created for song"); Assert.IsNull(report.Version, "Version"); var notification = repository.List <UserMessage>().FirstOrDefault(); Assert.IsNotNull(notification, "notification was created"); Assert.AreEqual(editor, notification.Receiver, "notification was receiver is editor"); Assert.AreEqual(string.Format(EntryReportStrings.EntryVersionReportTitle, song.DefaultName), notification.Subject, "Notification subject"); }
public void CreateReport_NotifyIfUnambiguous() { var editor = _user2; _repository.Save(ArchivedSongVersion.Create(_song, new SongDiff(), new AgentLoginData(editor), SongArchiveReason.PropertiesUpdated, String.Empty)); _queries.CreateReport(_song.Id, SongReportType.Other, "39.39.39.39", "It's Miku, not Rin", null); var report = _repository.List <SongReport>().First(); report.Entry.Should().Be(_song, "Report was created for song"); report.Version.Should().BeNull("Version"); var notification = _repository.List <UserMessage>().FirstOrDefault(); notification.Should().NotBeNull("notification was created"); notification.Receiver.Should().Be(editor, "notification was receiver is editor"); notification.Subject.Should().Be(string.Format(EntryReportStrings.EntryVersionReportTitle, _song.DefaultName), "Notification subject"); }
public void CreateReport_Version() { var version = ArchivedSongVersion.Create(_song, new SongDiff(), new AgentLoginData(_user), SongArchiveReason.PropertiesUpdated, String.Empty); _repository.Save(version); CallCreateReport(SongReportType.Other, version.Version); var report = _repository.List <SongReport>().First(); report.VersionNumber.Should().Be(version.Version, "Version number"); report.VersionBase.Should().NotBeNull("VersionBase"); var notification = _repository.List <UserMessage>().FirstOrDefault(); notification.Should().NotBeNull("Notification was created"); notification.Receiver.Should().Be(_user, "Notification receiver"); notification.Subject.Should().Be(string.Format(EntryReportStrings.EntryVersionReportTitle, _song.DefaultName), "Notification subject"); notification.Message.Should().Be(string.Format(EntryReportStrings.EntryVersionReportBody, MarkdownHelper.CreateMarkdownLink(_entryLinkFactory.GetFullEntryUrl(_song), _song.DefaultName), "It's Miku, not Rin"), "Notification message"); }
public ArchivedSongVersionDetailsContract(ArchivedSongVersion archived, ArchivedSongVersion comparedVersion, IUserPermissionContext permissionContext) { ParamIs.NotNull(() => archived); ArchivedVersion = new ArchivedSongVersionContract(archived); ComparedVersion = comparedVersion != null ? new ArchivedSongVersionContract(comparedVersion) : null; ComparedVersionId = comparedVersion != null ? comparedVersion.Id : 0; Song = new SongContract(archived.Song, permissionContext.LanguagePreference); Name = Song.Name; ComparableVersions = archived.Song.ArchivedVersionsManager .GetPreviousVersions(archived, permissionContext) .Select(a => ArchivedObjectVersionWithFieldsContract.Create(a, a.Diff.ChangedFields.Value, a.Reason)) .ToArray(); Versions = ComparedSongsContract.Create(archived, comparedVersion); ComparedVersionId = Versions.SecondId; }
public void CreateReport_Version() { var version = ArchivedSongVersion.Create(song, new SongDiff(), new AgentLoginData(user), SongArchiveReason.PropertiesUpdated, String.Empty); repository.Save(version); queries.CreateReport(song.Id, SongReportType.Other, "39.39.39.39", "It's Miku, not Rin", version.Version); var report = repository.List <SongReport>().First(); Assert.AreEqual(version.Version, report.VersionNumber, "Version number"); Assert.IsNotNull(report.VersionBase, "VersionBase"); var notification = repository.List <UserMessage>().FirstOrDefault(); Assert.IsNotNull(notification, "Notification was created"); Assert.AreEqual(user, notification.Receiver, "Notification receiver"); Assert.AreEqual(string.Format(EntryReportStrings.EntryVersionReportTitle, song.DefaultName), notification.Subject, "Notification subject"); Assert.AreEqual(string.Format(EntryReportStrings.EntryVersionReportBody, MarkdownHelper.CreateMarkdownLink(entryLinkFactory.GetFullEntryUrl(song), song.DefaultName), "It's Miku, not Rin"), notification.Message, "Notification message"); }
public static ArchivedSongContract GetAllProperties(ArchivedSongVersion version) { var data = new ArchivedSongContract(); var xmlCache = new XmlCache<ArchivedSongContract>(); var thisVersion = xmlCache.Deserialize(version.Version, version.Data); data.Id = thisVersion.Id; data.LengthSeconds = thisVersion.LengthSeconds; data.NicoId = thisVersion.NicoId; data.Notes = thisVersion.Notes; data.OriginalVersion = thisVersion.OriginalVersion; data.SongType = thisVersion.SongType; data.TranslatedName = thisVersion.TranslatedName; DoIfExists(version, SongEditableFields.Artists, xmlCache, (v, doc) => SetArtists(data, v, doc)); DoIfExists(version, SongEditableFields.Lyrics, xmlCache, v => data.Lyrics = v.Lyrics); DoIfExists(version, SongEditableFields.Names, xmlCache, v => data.Names = v.Names); DoIfExists(version, SongEditableFields.PVs, xmlCache, v => data.PVs = v.PVs); DoIfExists(version, SongEditableFields.WebLinks, xmlCache, v => data.WebLinks = v.WebLinks); return data; }
public ArchivedSongVersionContract(ArchivedSongVersion archivedVersion) : base(archivedVersion) { ChangedFields = (archivedVersion.Diff != null ? archivedVersion.Diff.ChangedFields.Value : SongEditableFields.Nothing); Reason = archivedVersion.Reason; }
protected void AddEntryEditedEntry(IDatabaseContext <ActivityEntry> ctx, Song entry, EntryEditEvent editEvent, ArchivedSongVersion archivedVersion) { var user = ctx.OfType <User>().GetLoggedUser(PermissionContext); var activityEntry = new SongActivityEntry(entry, editEvent, user, archivedVersion); AddActivityfeedEntry(ctx, activityEntry); }
public static ComparedSongsContract Create(ArchivedSongVersion firstData, ArchivedSongVersion secondData) { return(new ComparedSongsContract(Create(firstData, secondData, ArchivedSongContract.GetAllProperties, d => d.Id))); }
public ArchivedSongVersionContract(ArchivedSongVersion archivedVersion) : base(archivedVersion) { ChangedFields = (archivedVersion.Diff != null ? archivedVersion.Diff.ChangedFields : SongEditableFields.Nothing); Reason = archivedVersion.Reason; }
protected async Task AddEntryEditedEntryAsync(IDatabaseContext <ActivityEntry> ctx, Song entry, EntryEditEvent editEvent, ArchivedSongVersion archivedVersion) { var user = await ctx.OfType <User>().GetLoggedUserAsync(PermissionContext); var activityEntry = new SongActivityEntry(entry, editEvent, user, archivedVersion); await AddActivityfeedEntryAsync(ctx, activityEntry); }
protected void AddEntryEditedEntry(ISession session, Song entry, EntryEditEvent editEvent, ArchivedSongVersion archivedVersion) { var user = GetLoggedUser(session); var activityEntry = new SongActivityEntry(entry, editEvent, user, archivedVersion); AddActivityfeedEntry(session, activityEntry); }