private long UpsertLibrary(ExportedLibraryDto dto) { var fileId = mediaFileRepository.GetMediaFileLongId_FromGUID(dto.CoverFileId); var libraryDto = new CreateLibraryDto(dto.Name, fileId); return(libraryRepository.UpsertLibrary(libraryDto, dto.UniqueId, dto.Settings)); }
public void ImportLibrary_SeriesSequence_ShouldReference_FileSeries() { var files = new List <MediaFile> { new MediaFile(-1, "https://google.ca", MediaFileType.IMAGE_TYPE, "f1", DateTime.Now, UniqueIdUtil.GenerateUniqueId()), new MediaFile(-1, "https://google.com", MediaFileType.IMAGE_TYPE, "f2", DateTime.Now, UniqueIdUtil.GenerateUniqueId()) }; var publishers = new List <ExportedPublisherSimpleDto> { }; var calendars = new List <Calendar> { }; var series = new List <ExportedSeriesSimpleDto> { new ExportedSeriesSimpleDto( new Series(-1, "s1", "", -1, "", -1, -1, -1, false, UniqueIdUtil.GenerateUniqueId()), null, null, null ) }; var sequences = new List <ExportedSeriesSequenceSimpleDto> { new ExportedSeriesSequenceSimpleDto( new SeriesSequence(-1, "s1", "", -1, false, false, 0, -1, UniqueIdUtil.GenerateUniqueId()), files[0].UniqueId, series[0].Details.UniqueId ), new ExportedSeriesSequenceSimpleDto( new SeriesSequence(-1, "s1", "", -1, false, false, 0, -1, UniqueIdUtil.GenerateUniqueId()), null, series[0].Details.UniqueId ) }; var dto = new ExportedLibraryDto( "lib", UniqueIdUtil.GenerateUniqueId(), null, new List <ExportedVideoSimpleDto>(), new List <ExportedCharacterSimpleDto>(), new List <ExportedCharacterSimpleDto>(), series, publishers, new List <ExportedLocationSimpleDto>(), calendars, new List <ExportedPlaylistSimpleDto>(), new List <Ingvilt.Dto.Tags.Tag>(), new List <Ingvilt.Dto.Tags.Tag>(), files, sequences, new List <Ingvilt.Dto.Export.SeriesTagExportDto>(), new List <Ingvilt.Dto.Export.VideoTagExportDto>(), new List <Ingvilt.Dto.Export.FileTagExportDto>(), new List <Ingvilt.Dto.Export.CharacterTagExportDto>(), new List <Ingvilt.Dto.Export.VideoMediaFilesExportDto>(), new List <Ingvilt.Dto.Export.FileLocationExportDto>(), new List <Ingvilt.Dto.Export.CharacterMediaFilesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideoLocationExportDto>(), new List <Ingvilt.Dto.Export.VideoCharacterActorExportDto>(), new List <Ingvilt.Dto.Export.VideoCreatorExportDto>(), new LibrarySettings() ); new ImportLibraryService().ImportLibrary(dto); var libraryId = repository.GetLibraries(new InfinitePagination(), "").Result.Results[0].LibraryId; var sequencesList = new SeriesSequenceRepository().GetAllSequencesInAllSeries(new InfinitePagination(), libraryId).Result.Results; var retFiles = mediaFileRepository.GetMediaFiles(new InfinitePagination(), "f1").Result.Results; var retSeries = new SeriesRepository().GetSeries(new InfinitePagination()).Result.Results; var expectedSequences = new List <SeriesSequence> { sequences[0].Details, sequences[1].Details }; expectedSequences[0].SeriesId = retSeries[0].SeriesId; expectedSequences[1].SeriesId = retSeries[0].SeriesId; expectedSequences[0].CoverFile = retFiles[0].MediaId; CollectionAssert.AreEquivalent(expectedSequences, sequencesList); }
private async Task UpsertCalendars(ExportedLibraryDto dto) { foreach (var calendar in dto.Calendars) { calendar.LibraryId = libraryId; } await calendarRepository.UpsertCalendars(dto.Calendars, ids); }
private async Task UpsertPublishers(ExportedLibraryDto dto) { foreach (var publisher in dto.Publishers) { publisher.Details.LibraryId = libraryId; publisher.Details.LogoFileId = GetFileId(publisher.FileId); } await publisherRepository.UpsertPublishers(dto.Publishers, ids); }
private async Task UpsertPlaylists(ExportedLibraryDto dto) { foreach (var sequence in dto.Playlists) { sequence.Details.CoverFile = GetFileId(sequence.FileId); sequence.Details.LibraryId = libraryId; } await playlistRepository.UpsertPlaylists(dto.Playlists, ids); }
private async Task UpsertSeriesSequences(ExportedLibraryDto dto) { foreach (var sequence in dto.SeriesSequences) { sequence.Details.CoverFile = GetFileId(sequence.FileId); sequence.Details.SeriesId = GetSeriesId(sequence.SeriesId); } await seriesSequenceRepository.UpsertSeriesSequences(dto.SeriesSequences, ids); }
private async Task UpsertLocations(ExportedLibraryDto dto) { foreach (var location in dto.Locations) { location.Details.LibraryId = libraryId; location.Details.CoverFileId = GetFileId(location.FileId); location.Details.PublisherId = GetPublisherId(location.PublisherId); } await locationRepository.UpsertLocations(dto.Locations, ids); }
private async Task UpsertSeries(ExportedLibraryDto dto) { foreach (var series in dto.Series) { series.Details.LibraryId = libraryId; series.Details.LogoFileId = GetFileId(series.FileId); series.Details.PublisherId = GetPublisherId(series.PublisherId); series.Details.CalendarId = GetCalendarId(series.CalendarId); } await seriesRepository.UpsertSeries(dto.Series, ids); }
private async Task ImportEntities(ExportedLibraryDto dto) { await UpsertPublishers(dto); await UpsertCalendars(dto); await UpsertLocations(dto); await UpsertSeries(dto); await UpsertVideos(dto); await UpsertCharacters(dto.Characters); await UpsertCharacters(dto.Creators); await UpsertSeriesSequences(dto); await UpsertPlaylists(dto); }
private async Task UpsertVideos(ExportedLibraryDto dto) { foreach (var video in dto.Videos) { video.Details.LibraryId = libraryId; video.Details.CoverFileId = GetFileId(video.FileId); video.Details.PublisherId = GetPublisherId(video.PublisherId); video.Details.SeriesId = GetSeriesId(video.SeriesId); } await videoRepository.UpsertVideos(dto.Videos, ids); }
public void ImportLibrary_Location_ShouldReferencePublisher() { var files = new List <MediaFile> { new MediaFile(-1, "https://google.ca", MediaFileType.IMAGE_TYPE, "f1", DateTime.Now, UniqueIdUtil.GenerateUniqueId()), new MediaFile(-1, "https://google.com", MediaFileType.IMAGE_TYPE, "f2", DateTime.Now, UniqueIdUtil.GenerateUniqueId()) }; var publishers = new List <ExportedPublisherSimpleDto> { new ExportedPublisherSimpleDto( new Publisher(-1, "p1", "", -1, "", -1, false, UniqueIdUtil.GenerateUniqueId()), null ) }; var locations = new List <ExportedLocationSimpleDto> { new ExportedLocationSimpleDto( new Location(-1, "l1", "d", -1, -1, -1, false, UniqueIdUtil.GenerateUniqueId()), null, publishers[0].Details.UniqueId ), new ExportedLocationSimpleDto( new Location(-1, "l2", "d", -1, -1, -1, false, UniqueIdUtil.GenerateUniqueId()), null, null ) }; var dto = new ExportedLibraryDto( "lib", UniqueIdUtil.GenerateUniqueId(), null, new List <ExportedVideoSimpleDto>(), new List <ExportedCharacterSimpleDto>(), new List <ExportedCharacterSimpleDto>(), new List <ExportedSeriesSimpleDto>(), publishers, locations, new List <Ingvilt.Dto.Calendars.Calendar>(), new List <ExportedPlaylistSimpleDto>(), new List <Ingvilt.Dto.Tags.Tag>(), new List <Ingvilt.Dto.Tags.Tag>(), files, new List <ExportedSeriesSequenceSimpleDto>(), new List <Ingvilt.Dto.Export.SeriesTagExportDto>(), new List <Ingvilt.Dto.Export.VideoTagExportDto>(), new List <Ingvilt.Dto.Export.FileTagExportDto>(), new List <Ingvilt.Dto.Export.CharacterTagExportDto>(), new List <Ingvilt.Dto.Export.VideoMediaFilesExportDto>(), new List <Ingvilt.Dto.Export.FileLocationExportDto>(), new List <Ingvilt.Dto.Export.CharacterMediaFilesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideoLocationExportDto>(), new List <Ingvilt.Dto.Export.VideoCharacterActorExportDto>(), new List <Ingvilt.Dto.Export.VideoCreatorExportDto>(), new LibrarySettings() ); new ImportLibraryService().ImportLibrary(dto); var locs = new LocationRepository().GetLocations(new InfinitePagination()).Result.Results; var library = repository.GetLibraries(new InfinitePagination(), "").Result.Results[0]; var retPubs = new PublisherRepository().GetPublishers(new InfinitePagination()).Result.Results; var expectedLocs = new List <Location> { locations[0].Details, locations[1].Details }; expectedLocs[0].LibraryId = library.LibraryId; expectedLocs[1].LibraryId = library.LibraryId; expectedLocs[0].PublisherId = retPubs[0].PublisherId; CollectionAssert.AreEquivalent(expectedLocs, locs); }
public void ImportLibrary_WithFile() { var publishers = new List <ExportedPublisherSimpleDto>(); var files = new List <MediaFile> { new MediaFile(-1, "https://google.ca", MediaFileType.IMAGE_TYPE, "", DateTime.Now, UniqueIdUtil.GenerateUniqueId()), new MediaFile(-1, "https://google.com", MediaFileType.IMAGE_TYPE, "", DateTime.Now, UniqueIdUtil.GenerateUniqueId()) }; var libraryName = "lib"; var libraryGUID = UniqueIdUtil.GenerateUniqueId(); var dto = new ExportedLibraryDto( libraryName, libraryGUID, files[0].UniqueId, new List <ExportedVideoSimpleDto>(), new List <ExportedCharacterSimpleDto>(), new List <ExportedCharacterSimpleDto>(), new List <ExportedSeriesSimpleDto>(), publishers, new List <ExportedLocationSimpleDto>(), new List <Ingvilt.Dto.Calendars.Calendar>(), new List <ExportedPlaylistSimpleDto>(), new List <Ingvilt.Dto.Tags.Tag>(), new List <Ingvilt.Dto.Tags.Tag>(), files, new List <ExportedSeriesSequenceSimpleDto>(), new List <Ingvilt.Dto.Export.SeriesTagExportDto>(), new List <Ingvilt.Dto.Export.VideoTagExportDto>(), new List <Ingvilt.Dto.Export.FileTagExportDto>(), new List <Ingvilt.Dto.Export.CharacterTagExportDto>(), new List <Ingvilt.Dto.Export.VideoMediaFilesExportDto>(), new List <Ingvilt.Dto.Export.FileLocationExportDto>(), new List <Ingvilt.Dto.Export.CharacterMediaFilesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideoLocationExportDto>(), new List <Ingvilt.Dto.Export.VideoCharacterActorExportDto>(), new List <Ingvilt.Dto.Export.VideoCreatorExportDto>(), new LibrarySettings() ); new ImportLibraryService().ImportLibrary(dto); var retFiles = mediaFileRepository.GetMediaFiles(new InfinitePagination()).Result.Results; foreach (var file in files) { foreach (var retFile in retFiles) { if (file.UniqueId == retFile.UniqueId) { file.MediaId = retFile.MediaId; break; } } } var libraries = repository.GetLibraries(new InfinitePagination(), "").Result.Results; var library = libraries[0]; var expectedLibrary = new Library(library.LibraryId, libraryName, files[0].MediaId, false, libraryGUID); Assert.IsTrue(retFiles.Count == 2); Assert.AreEqual(1, libraries.Count); Assert.AreEqual(expectedLibrary, library); Assert.AreNotSame(DatabaseConstants.DEFAULT_ID, library.BackgroundImageId); }
public async Task ImportLibrary(ExportedLibraryDto dto) { var resetConnection = !DataAccessUtil.UsePersistentConnection; DataAccessUtil.UsePersistentConnection = true; await UpsertFiles(dto); UpsertTags(dto); libraryId = UpsertLibrary(dto); await ImportEntities(dto); await ImportRelationships(dto); if (resetConnection) { DataAccessUtil.ClosePersistentConnection(); DataAccessUtil.UsePersistentConnection = false; } }
private async Task ImportRelationships(ExportedLibraryDto dto) { await videoRepository.UpsertCharactersInVideos(dto.CharactersInVideos, ids); await videoRepository.UpsertCreatorsOfVideos(dto.VideoCreators, ids); mediaFileRepository.UpsertFilesOnCharacters(dto.FilesOnCharacters, ids); mediaFileRepository.UpsertFilesOnLocations(dto.FilesOnLocations, ids); mediaFileRepository.UpsertFilesOnVideos(dto.FilesOnVideos, ids); tagRepository.UpsertTagsOnCharacters(dto.TagsOnCharacters, ids); tagRepository.UpsertTagsOnFiles(dto.TagsOnFiles, ids); tagRepository.UpsertTagsOnSeries(dto.TagsOnSeries, ids); tagRepository.UpsertTagsOnVideos(dto.TagsOnVideos, ids); seriesSequenceRepository.UpsertVideosInSequences(dto.VideosInSeriesSequences, ids); playlistRepository.UpsertVideosInSequences(dto.VideosInPlaylists, ids); await locationRepository.UpsertVideosAtLocations(dto.VideosOnLocations, ids); }
private void ImportLibrary_Character_ShouldReference_FileCalendar(bool creator) { var files = new List <MediaFile> { new MediaFile(-1, "https://google.ca", MediaFileType.IMAGE_TYPE, "f1", DateTime.Now, UniqueIdUtil.GenerateUniqueId()), new MediaFile(-1, "https://google.com", MediaFileType.IMAGE_TYPE, "f2", DateTime.Now, UniqueIdUtil.GenerateUniqueId()) }; var publishers = new List <ExportedPublisherSimpleDto> { }; var series = new List <ExportedSeriesSimpleDto> { }; var videos = new List <ExportedVideoSimpleDto> { }; var calendars = new List <Calendar> { new Calendar(-1, "", "", "", -1, false, UniqueIdUtil.GenerateUniqueId()) }; var characters = new List <ExportedCharacterSimpleDto> { new ExportedCharacterSimpleDto( new Character(-1, "c1", "", null, null, null, 0, -1, -1, -1, false, creator, UniqueIdUtil.GenerateUniqueId()), files[0].UniqueId, calendars[0].UniqueId ), new ExportedCharacterSimpleDto( new Character(-1, "c1", "", null, null, null, 0, -1, -1, -1, false, creator, UniqueIdUtil.GenerateUniqueId()), null, null ) }; var emptyCharacters = new List <ExportedCharacterSimpleDto>(); var dto = new ExportedLibraryDto( "lib", UniqueIdUtil.GenerateUniqueId(), null, videos, creator ? emptyCharacters : characters, creator ? characters : emptyCharacters, series, publishers, new List <ExportedLocationSimpleDto>(), calendars, new List <ExportedPlaylistSimpleDto>(), new List <Ingvilt.Dto.Tags.Tag>(), new List <Ingvilt.Dto.Tags.Tag>(), files, new List <ExportedSeriesSequenceSimpleDto>(), new List <Ingvilt.Dto.Export.SeriesTagExportDto>(), new List <Ingvilt.Dto.Export.VideoTagExportDto>(), new List <Ingvilt.Dto.Export.FileTagExportDto>(), new List <Ingvilt.Dto.Export.CharacterTagExportDto>(), new List <Ingvilt.Dto.Export.VideoMediaFilesExportDto>(), new List <Ingvilt.Dto.Export.FileLocationExportDto>(), new List <Ingvilt.Dto.Export.CharacterMediaFilesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideoLocationExportDto>(), new List <Ingvilt.Dto.Export.VideoCharacterActorExportDto>(), new List <Ingvilt.Dto.Export.VideoCreatorExportDto>(), new LibrarySettings() ); new ImportLibraryService().ImportLibrary(dto); var charactersList = new CharacterRepository().GetCharacters(new InfinitePagination(), creator).Result.Results; var library = repository.GetLibraries(new InfinitePagination(), "").Result.Results[0]; var retFiles = mediaFileRepository.GetMediaFiles(new InfinitePagination(), "f1").Result.Results; var retCalendars = new CalendarRepository().GetCalendars(new InfinitePagination()).Result.Results; var expectedChars = new List <Character> { characters[0].Details, characters[1].Details }; expectedChars[0].LibraryId = library.LibraryId; expectedChars[1].LibraryId = library.LibraryId; expectedChars[0].CoverMediaId = retFiles[0].MediaId; expectedChars[0].CalendarId = retCalendars[0].CalendarId; CollectionAssert.AreEquivalent(expectedChars, charactersList); }
private void UpsertTags(ExportedLibraryDto dto) { tagRepository.UpsertCharacterTags(dto.CharacterTags); tagRepository.UpsertVideoTags(dto.VideoTags); }
private async Task UpsertFiles(ExportedLibraryDto dto) { await mediaFileRepository.UpsertMediaFiles(dto.Files, ids); }