Beispiel #1
0
        public AlbumImportResult ImportOne(string url)
        {
            PermissionContext.VerifyPermission(PermissionToken.MikuDbImport);

            var existing = HandleQuery(session => session.Query <MikuDbAlbum>().FirstOrDefault(a => a.SourceUrl == url));

            if (existing != null)
            {
                return new AlbumImportResult {
                           Message = "Album with that URL has already been imported"
                }
            }
            ;

            var imported = new AlbumImporters(new WebPictureDownloader()).ImportOne(url);

            if (imported.AlbumContract == null)
            {
                return(imported);
            }

            HandleTransaction(session =>
            {
                SysLog($"importing album with URL '{url}'");

                var newAlbum = new MikuDbAlbum(imported.AlbumContract);
                session.Save(newAlbum);
                imported.AlbumContract.Id = newAlbum.Id;
            });

            return(imported);
        }

#nullable enable
Beispiel #2
0
        public AlbumContract AcceptImportedAlbum(ImportedAlbumOptions importedAlbum, int[] selectedSongIds)
        {
            PermissionContext.VerifyPermission(PermissionToken.MikuDbImport);

            return(HandleTransaction(session => {
                var inspected = Inspect(session, importedAlbum);
                var importer = new AlbumImporters().FindImporter(inspected.ImportedAlbum.SourceUrl);
                var album = AcceptImportedAlbum(session, importer, importedAlbum.SelectedLanguage, inspected, selectedSongIds);

                return album;
            }));
        }
Beispiel #3
0
        public AlbumContract[] AcceptImportedAlbums(ImportedAlbumOptions[] importedAlbumIds, int[] selectedSongIds)
        {
            PermissionContext.VerifyPermission(PermissionToken.MikuDbImport);

            return(HandleTransaction(session => {
                var importedAlbums = new List <AlbumContract>(importedAlbumIds.Length);

                foreach (var importedAlbum in importedAlbumIds)
                {
                    var inspected = Inspect(session, importedAlbum);
                    var importer = new AlbumImporters().FindImporter(inspected.ImportedAlbum.SourceUrl);
                    var album = AcceptImportedAlbum(session, importer, importedAlbum.SelectedLanguage, inspected, selectedSongIds);

                    importedAlbums.Add(album);
                }

                return importedAlbums.ToArray();
            }));
        }