// ==================================================================== // private 関数 // ==================================================================== // -------------------------------------------------------------------- // インポート元を解凍 // -------------------------------------------------------------------- private String Extract() { String tempFolder = YlCommon.TempPath() + "\\"; Directory.CreateDirectory(tempFolder); ZipFile.ExtractToDirectory(_importSrcPath, tempFolder); String[] files = Directory.GetFiles(tempFolder, "*", SearchOption.AllDirectories); if (files.Length == 0) { throw new Exception("ゆかりすたー情報ファイルにインポートできるデータが存在しません。"); } return(files[0]); }
// ==================================================================== // protected 関数 // ==================================================================== // -------------------------------------------------------------------- // エクスポート処理 // ワーカースレッドで実行される前提 // -------------------------------------------------------------------- protected override Task ImportExportByWorker(Object?_) { String tempExportPath = YlCommon.TempPath(); MusicInfoContextDefault musicInfoContextDefault = new(); musicInfoContextDefault.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; MusicInfoContextExport musicInfoContextExport = new(tempExportPath); musicInfoContextExport.CreateDatabase(); // コピー // peopleInMemory.AddRange(peopleInMusicInfo) のように DbSet 全体を追加すると、アプリ終了時にタスクが終了しないため、Where を挟む Description = "エクスポートしています..."; musicInfoContextExport.Songs.AddRange(musicInfoContextDefault.Songs.Where(x => true)); musicInfoContextExport.People.AddRange(musicInfoContextDefault.People.Where(x => true)); musicInfoContextExport.TieUps.AddRange(musicInfoContextDefault.TieUps.Where(x => true)); musicInfoContextExport.TieUpGroups.AddRange(musicInfoContextDefault.TieUpGroups.Where(x => true)); musicInfoContextExport.Makers.AddRange(musicInfoContextDefault.Makers.Where(x => true)); musicInfoContextExport.SongAliases.AddRange(musicInfoContextDefault.SongAliases.Where(x => true)); musicInfoContextExport.TieUpAliases.AddRange(musicInfoContextDefault.TieUpAliases.Where(x => true)); musicInfoContextExport.ArtistSequences.AddRange(musicInfoContextDefault.ArtistSequences.Where(x => true)); musicInfoContextExport.LyristSequences.AddRange(musicInfoContextDefault.LyristSequences.Where(x => true)); musicInfoContextExport.ComposerSequences.AddRange(musicInfoContextDefault.ComposerSequences.Where(x => true)); musicInfoContextExport.ArrangerSequences.AddRange(musicInfoContextDefault.ArrangerSequences.Where(x => true)); musicInfoContextExport.TieUpGroupSequences.AddRange(musicInfoContextDefault.TieUpGroupSequences.Where(x => true)); musicInfoContextExport.Tags.AddRange(musicInfoContextDefault.Tags.Where(x => true)); musicInfoContextExport.TagSequences.AddRange(musicInfoContextDefault.TagSequences.Where(x => true)); musicInfoContextExport.SaveChanges(); // 古いファイルを削除 try { File.Delete(_exportYukaListerPath); } catch (Exception) { } _abortCancellationTokenSource.Token.ThrowIfCancellationRequested(); // 出力 // データベースファイルをそのまま圧縮しようとするとプロセスが使用中というエラーになることがある(2 回に 1 回くらい)ため、 // いったんデータベースファイルをコピーしてから圧縮する Description = "保存しています..."; String tempFolder = YlCommon.TempPath(); Directory.CreateDirectory(tempFolder); File.Copy(tempExportPath, tempFolder + "\\" + FILE_NAME_EXPORT_MUSIC_INFO); ZipFile.CreateFromDirectory(tempFolder, _exportYukaListerPath, CompressionLevel.Optimal, false); _abortCancellationTokenSource.Token.ThrowIfCancellationRequested(); return(Task.CompletedTask); }