/// <summary>インポート共通処理</summary> /// <typeparam name="TModel">Model</typeparam> /// <typeparam name="TIdentity">Id特定方法</typeparam> /// <param name="importer">インポーター</param> /// <param name="setting">取込設定</param> /// <param name="importSuccessPostAction">取込成功後のクリア処理など メッセージ表示より前に実施する項目</param> /// <returns></returns> protected bool DoImport <TModel, TIdentity>(Import.CsvImporter <TModel, TIdentity> importer, ImportSetting setting, Action importSuccessPostAction = null) where TModel : class, new() { using (var form = ApplicationContext.Create(nameof(PH9907))) { var screen = form.GetAll <PH9907>().First(); var result = screen.ConfirmImportSetting(ParentForm, importer, setting); if (result != DialogResult.OK) { DispStatusMessage(Constants.MsgInfCancelProcess, "インポート"); return(false); } importer.ErrorLogPath = setting.GetErrorLogPath(); } ImportResult res = null; DialogResult pgres = DialogResult.None; NLogHandler.WriteDebug(this, $"{typeof(TModel).Name}:インポート処理開始"); try { pgres = ProgressDialog.Start(ParentForm, async(cancel, progress) => res = await importer.ImportAsync(setting.ImportFileName, (Import.ImportMethod)setting.ImportMode, cancel, progress), true, SessionKey); } catch (Exception ex) { NLogHandler.WriteErrorLog(this, ex.InnerException, SessionKey); } NLogHandler.WriteDebug(this, $"{typeof(TModel).Name}:インポート処理終了"); var importResult = false; if (pgres == DialogResult.Cancel) { DispStatusMessage(Constants.MsgInfCancelProcess, "インポート"); } else if (pgres == DialogResult.Abort) { DispStatusMessage(Constants.MsgErrImportErrorWithoutLog); } else if (res != null) { var message = XmlMessenger.GetMessageInfo(res.GetMessageId()); if (message.Category == MessageCategory.Information) { importSuccessPostAction?.Invoke(); DispStatusMessage(message); importResult = true; } else { ShowWarningDialog(message.ID); } } return(importResult); }