public AlbumImportResult ImportOne(string url) { PermissionContext.VerifyPermission(PermissionToken.MikuDbImport); MikuDbAlbumContract[] existing = HandleQuery(session => session.Query<MikuDbAlbum>().Select(a => new MikuDbAlbumContract(a)).ToArray()); var importer = new AlbumImporter(existing); var imported = importer.ImportOne(url); if (imported.AlbumContract == null) return imported; HandleTransaction(session => { SysLog(string.Format("importing album from MikuDB with URL '{0}'", url)); var newAlbum = new MikuDbAlbum(imported.AlbumContract); session.Save(newAlbum); }); return imported; }
public int ImportNew() { PermissionContext.VerifyPermission(PermissionToken.MikuDbImport); MikuDbAlbumContract[] existing = HandleQuery(session => session.Query<MikuDbAlbum>().Select(a => new MikuDbAlbumContract(a)).ToArray()); var importer = new AlbumImporter(existing); var imported = importer.ImportNew(); return HandleTransaction(session => { AuditLog("importing new albums from MikuDB", session); //var all = session.Query<MikuDbAlbum>(); //foreach (var album in all) // session.Delete(album); var newAlbums = new List<MikuDbAlbum>(); foreach (var contract in imported) { var newAlbum = new MikuDbAlbum(contract.AlbumContract); session.Save(newAlbum); newAlbums.Add(newAlbum); } return newAlbums.Count; }); }