public override void ConfigureTaskImplementation(AsyncTaskSequence sequence) { sequence.Add(() => s_logger.Info("Checking Database schema...")); sequence.Add(() => { try { Stopwatch.Start(); System.Environment.SetEnvironmentVariable("TMP", "C:\\Temp"); System.Environment.SetEnvironmentVariable("TEMP", "C:\\Temp"); DataVersionManager dvManager = new DataVersionManager(); dvManager.CurrentConnection = ConnectionManager.DefaultConnection; dvManager.Mode = VersioningStrategy.ByTick; dvManager.RegisterChangePlan(new ChangePlan_VersionOrigin()); dvManager.RegisterChangePlan(new ChangePlan_Version_1()); dvManager.GetPlan(new Version_1()).FinishedToUpgradeTo += LibraryInitializing_FinishToUpgradeTo_Version_1; dvManager.RegisterChangePlan(new ChangePlan_Version_2()); dvManager.RegisterChangePlan(new ChangePlan_Version_3()); dvManager.GetPlan(new Version_3()).FinishedToUpgradeTo += LibraryInitializing_FinishToUpgradeTo_Version_3; dvManager.RegisterChangePlan(new ChangePlan_Version_4()); dvManager.RegisterChangePlan(new ChangePlan_Version_5()); dvManager.GetPlan(new Version_5()).FinishedToUpgradeTo += LibraryInitializing_FinishedToUpgradeTo_Version_5; dvManager.FinishedToUpgradeTo += DvManager_FinishedToUpgradeTo; dvManager.UpgradeToTargetVersion(); Stopwatch.Stop(); s_logger.Info($"Completed to check Database schema. {Stopwatch.ElapsedMilliseconds}ms"); } catch (FailedOpeningDatabaseException) { throw; } catch (SQLiteException e) { s_logger.Error("Failed to check Database schema."); s_logger.Debug(e); throw; } finally { if (Stopwatch.IsRunning) { Stopwatch.Stop(); } } }); sequence.Add(() => { DirectoryNameParserManager.Load(); }); }
public override void ConfigureTaskImplementation(AsyncTaskSequence sequence) { List <Importer> importers = new List <Importer>(); DiscriminateDroppedEntries(ObjectPaths, importers, LibraryManager.Value); var workingDirectory = Configuration.ApplicationConfiguration.WorkingDirectory; var now = DateTime.Now; var copyTo = workingDirectory + "\\" + MasterDirectory + "\\" + now.Year + "\\" + now.Month.ToString("00") + "\\" + now.Day.ToString("00"); //保存先ディレクトリ準備 if (!Directory.Exists(copyTo)) { Directory.CreateDirectory(copyTo); s_logger.Debug($"Create directory:{copyTo}"); } List <Importer> willNotImport = new List <Importer>(); //構造把握+全体数計上 foreach (var task in importers) { task.Estimate(); if (task.Count == 0) { willNotImport.Add(task); } } //メタデータ分析 foreach (var task in importers) { if (task is ImportIllust) { var importer = task as ImportIllust; importer.Title = DateTime.Now.ToString("yyyyMMddHHmmss"); } else if (task is ImportBook) { var importer = task as ImportBook; string sourceDirName = ((File.GetAttributes(importer.Path) & FileAttributes.Directory) == FileAttributes.Directory) ? Path.GetFileName(importer.Path) : Path.GetDirectoryName(importer.Path); var dirNameParser = DirectoryNameParserManager.Get(sourceDirName); dirNameParser.Parse(sourceDirName); if (dirNameParser.HasTags) { importer.TagNames = dirNameParser.Tags; } if (dirNameParser.HasAuthor) { importer.AuthorName = dirNameParser.Author; } importer.Title = dirNameParser.Title; } } //画像0件のインポート単位はインポートしない foreach (var task in willNotImport) { importers.Remove(task); s_logger.Warn($"{task.Path} will not be imported."); } sequence.Add(new System.Threading.Tasks.Task(() => s_logger.Info($"Began to import."))); for (int i = 0; i < importers.Count(); ++i) { var task = importers.ElementAt(i); Guid entryNameSeedGuid = Guid.NewGuid(); var entryName = entryNameSeedGuid.ToString("N"); var t = task.GenerateTasks(LibraryManager.Value, copyTo, entryName, null, (importer, bookvm) => { bookvm.CurrentProcessProgress.Value.Count.Value = importer.Processed; bookvm.CurrentProcessProgress.Value.TotalCount.Value = importer.Count; }); sequence.AddRange(t); } sequence.Add(new System.Threading.Tasks.Task(() => s_logger.Info($"Completed to import."))); }