public virtual ArchivedAlbumVersion CreateArchivedVersion(XDocument data, AlbumDiff diff, AgentLoginData author, AlbumArchiveReason reason, string notes) { var archived = new ArchivedAlbumVersion(this, data, diff, author, Version, Status, reason, notes); ArchivedVersionsManager.Add(archived); Version++; return(archived); }
public AlbumDiffContract(AlbumDiff diff) { ParamIs.NotNull(() => diff); Cover = diff.Cover; Description = diff.Description; IsSnapshot = diff.IsSnapshot; Names = diff.Names; WebLinks = diff.WebLinks; }
/// <summary> /// Creates an archived version of an album. /// </summary> /// <param name="album">Album to be archived. Cannot be null.</param> /// <param name="diff">Album diff. Cannot be null.</param> /// <param name="author">User creating the archived version. Cannot be null.</param> /// <param name="reason">Reason for archiving.</param> /// <param name="notes">Free-form edit notes. Cannot be null.</param> /// <returns>Archived album version. Cannot be null.</returns> /// <exception cref="XmlException">If the entry could not be serialized. This could happen if the object contains illegal characters.</exception> public static ArchivedAlbumVersion Create(Album album, AlbumDiff diff, AgentLoginData author, AlbumArchiveReason reason, string notes) { ParamIs.NotNull(() => album); ParamIs.NotNull(() => diff); ParamIs.NotNull(() => author); ParamIs.NotNull(() => notes); var contract = new ArchivedAlbumContract(album, diff); var data = XmlHelper.SerializeToXml(contract); return(album.CreateArchivedVersion(data, diff, author, reason, notes)); }
public ArchivedAlbumVersion(Album album, XDocument data, AlbumDiff diff, AgentLoginData author, int version, EntryStatus status, AlbumArchiveReason reason, string notes) : base(data, author, version, status, notes) { ParamIs.NotNull(() => data); ParamIs.NotNull(() => diff); Album = album; Diff = diff; Reason = reason; if (diff.IncludeCover) { CoverPicture = album.CoverPictureData; } }
public ArchivedAlbumContract(Album album, AlbumDiff diff) { ParamIs.NotNull(() => album); ParamIs.NotNull(() => diff); Artists = (diff.IncludeArtists ? album.Artists.Select(a => new ArchivedArtistForAlbumContract(a)).ToArray() : null); Description = (diff.IncludeDescription ? album.Description : null); DiscType = album.DiscType; Id = album.Id; OriginalRelease = (album.OriginalRelease != null && !album.OriginalRelease.IsEmpty ? new ArchivedAlbumReleaseContract(album.OriginalRelease) : null); Pictures = (diff.IncludePictures ? album.Pictures.Select(p => new ArchivedEntryPictureFileContract(p)).ToArray() : null); PVs = (diff.IncludePVs ? album.PVs.Select(p => new ArchivedPVContract(p)).ToArray() : null); Names = (diff.IncludeNames ? album.Names.Names.Select(n => new LocalizedStringContract(n)).ToArray() : null); Songs = (diff.IncludeTracks ? album.Songs.Select(s => new SongInAlbumRefContract(s)).ToArray() : null); TranslatedName = new TranslatedStringContract(album.TranslatedName); WebLinks = (diff.IncludeWebLinks ? album.WebLinks.Select(l => new ArchivedWebLinkContract(l)).ToArray() : null); }
private AlbumContract AcceptImportedAlbum(ISession session, ContentLanguageSelection languageSelection, InspectedAlbum acceptedAlbum, int[] selectedSongIds) { Album album; var diff = new AlbumDiff(false); if (acceptedAlbum.MergedAlbum == null) { album = new Album(new LocalizedString(acceptedAlbum.ImportedAlbum.Title, languageSelection)); if (languageSelection != ContentLanguageSelection.Unspecified) album.Names.SortNames.DefaultLanguage = languageSelection; album.DiscType = DiscType.Unknown; diff.Names = true; session.Save(album); } else { album = session.Load<Album>(acceptedAlbum.MergedAlbum.Id); if (!album.Names.HasName(acceptedAlbum.ImportedAlbum.Title)) { album.CreateName(acceptedAlbum.ImportedAlbum.Title, languageSelection); diff.Names = true; } } foreach (var inspectedArtist in acceptedAlbum.Artists) { if (inspectedArtist.ExistingArtist != null) { var artist = session.Load<Artist>(inspectedArtist.ExistingArtist.Id); if (!artist.HasAlbum(album)) { session.Save(artist.AddAlbum(album)); diff.Artists = true; } } else { album.AddArtist(inspectedArtist.Name, false, ArtistRoles.Default); diff.Artists = true; } } if (acceptedAlbum.MergedAlbum == null || acceptedAlbum.MergeTracks) { foreach (var inspectedTrack in acceptedAlbum.Tracks) { if (AcceptImportedSong(session, album, inspectedTrack, languageSelection, selectedSongIds)) diff.Tracks = true; } } var importedAlbum = session.Load<MikuDbAlbum>(acceptedAlbum.ImportedAlbum.Id); importedAlbum.Status = AlbumStatus.Approved; if (importedAlbum.CoverPicture != null && album.CoverPictureData == null) { album.CoverPictureData = importedAlbum.CoverPicture; using (var stream = new MemoryStream(album.CoverPictureData.Bytes)) { var thumbs = ImageHelper.GenerateThumbs(stream, new[] { 250 }); if (thumbs.Any()) { album.CoverPictureData.Thumb250 = new PictureThumb250(thumbs.First().Bytes); } } diff.Cover = true; } if (acceptedAlbum.ImportedAlbum.Data.ReleaseYear != null && album.OriginalReleaseDate.Year == null) { album.OriginalReleaseDate.Year = acceptedAlbum.ImportedAlbum.Data.ReleaseYear; diff.OriginalRelease = true; } if (!album.WebLinks.Any(w => w.Url.Contains("mikudb.com"))) { album.CreateWebLink("MikuDB", acceptedAlbum.ImportedAlbum.SourceUrl, WebLinkCategory.Reference); diff.WebLinks = true; } album.UpdateArtistString(); AuditLog(string.Format("accepted imported album '{0}'", acceptedAlbum.ImportedAlbum.Title), session); AddEntryEditedEntry(session, album, EntryEditEvent.Created); Services.Albums.Archive(session, album, diff, AlbumArchiveReason.AutoImportedFromMikuDb); session.Update(album); session.Update(importedAlbum); return new AlbumContract(album, PermissionContext.LanguagePreference); }
public ArchivedAlbumVersion() { Diff = new AlbumDiff(); Reason = AlbumArchiveReason.Unknown; }
public ExportedAlbumContract(Album album, AlbumDiff diff) : base(album, diff) { Version = album.Version; }