/// <summary>インポート処理</summary> /// <param name="source"></param> /// <param name="token"></param> /// <returns></returns> public async Task <ImportResult> ImportAsync(MasterImportSource source, CancellationToken token = default(CancellationToken)) { var mode = (ImportMethod)source.ImportMethod; var encoding = Encoding.GetEncoding(source.EncodingCodePage); var csv = encoding.GetString(source.Data); var companyTask = companyProcessor.GetAsync(new CompanySearch { Id = source.CompanyId, }, token); var loginUserTask = loginUserProcessor.GetAsync(new LoginUserSearch { Ids = new[] { source.LoginUserId }, }, token); var appConTask = applicationControlProcessor.GetAsync(source.CompanyId, token); var agencyTask = paymentAgencyProcessor.GetAsync(new MasterSearchOption { CompanyId = source.CompanyId, }, token); await Task.WhenAll(companyTask, loginUserTask, appConTask, agencyTask); var company = companyTask.Result.First(); var loginUser = loginUserTask.Result.First(); var appCon = appConTask.Result; var agencyDictionary = agencyTask.Result.ToDictionary(x => x.Code); var definition = new KanaHistoryPaymentAgencyFileDefinition(new DataExpression(appCon)); definition.PaymentAgencyIdField.GetModelsByCode = val => agencyDictionary; var parser = new CsvParser { Encoding = encoding, StreamCreator = new PlainTextMemoryStreamCreator(), }; var importer = definition.CreateImporter(x => new { x.PayerName, x.SourceBankName, x.SourceBranchName, x.PaymentAgencyId }, parser); importer.UserId = source.LoginUserId; importer.UserCode = loginUser.Code; importer.CompanyId = source.CompanyId; importer.CompanyCode = company.Code; importer.LoadAsync = () => kanaHistoryPaymentAgencyProcessor.GetAsync(new KanaHistorySearch { CompanyId = source.CompanyId, }, token); importer.RegisterAsync = x => kanaHistoryPaymentAgencyProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token); var result = await importer.ImportAsync(csv, mode, token, null); result.Logs = importer.GetErrorLogs(); return(result); }
private void ImportKanaHistoryPaymentAgency() { ImportSetting importSetting = null; var task = Util.GetMasterImportSettingAsync(Login, ImportFileType.KanaHistory); ProgressDialog.Start(ParentForm, task, false, SessionKey); importSetting = task.Result; var definition = new KanaHistoryPaymentAgencyFileDefinition(new DataExpression(ApplicationControl)); definition.PaymentAgencyIdField.GetModelsByCode = val => { Dictionary <string, PaymentAgency> product = null; ServiceProxyFactory.LifeTime(factory => { var paymentMaster = factory.Create <PaymentAgencyMasterClient>(); PaymentAgenciesResult result = paymentMaster.GetByCode( Login.SessionKey, Login.CompanyId, val); if (result.ProcessResult.Result) { product = result.PaymentAgencies .ToDictionary(c => c.Code); } }); return(product ?? new Dictionary <string, PaymentAgency>()); }; var importer = definition.CreateImporter(m => new { m.PayerName, m.SourceBankName, m.SourceBranchName, m.PaymentAgencyId }); importer.UserId = Login.UserId; importer.UserCode = Login.UserCode; importer.CompanyId = Login.CompanyId; importer.CompanyCode = Login.CompanyCode; importer.LoadAsync = async() => await GetKanaHistoryPaymentAgencyAsync(); importer.RegisterAsync = async unitOfWork => await RegisterForPaymentAgencyImportAsync(unitOfWork); var importResult = DoImport(importer, importSetting); if (!importResult) { return; } grdKanaHistoryCustomer.Rows.Clear(); rdoCustomer.Focus(); }
/// <summary>決済代行会社エクスポート</summary> private void ExportKanaHistoryPaymentAgency() { string serverPath = null; var task = ServiceProxyFactory.LifeTime(async factory => { var service = factory.Create <GeneralSettingMasterClient>(); GeneralSettingResult result = await service.GetByCodeAsync( Login.SessionKey, Login.CompanyId, "サーバパス"); if (result.ProcessResult.Result) { serverPath = result.GeneralSetting?.Value; } }); Task <List <KanaHistoryPaymentAgency> > loadTask = GetKanaHistoryPaymentAgencyAsync(); ProgressDialog.Start(ParentForm, Task.WhenAll(task, loadTask), false, SessionKey); List <KanaHistoryPaymentAgency> list = loadTask.Result; if (!list.Any()) { ShowWarningDialog(MsgWngNoExportData); return; } if (!Directory.Exists(serverPath)) { serverPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); } var filePath = string.Empty; var fileName = $"決済代行会社学習履歴{DateTime.Today:yyyyMMdd}.csv"; if (!ShowSaveExportFileDialog(serverPath, fileName, out filePath)) { return; } var definition = new KanaHistoryPaymentAgencyFileDefinition(new DataExpression(ApplicationControl)); var exporter = definition.CreateExporter(); exporter.UserId = Login.UserId; exporter.UserCode = Login.UserCode; exporter.CompanyId = CompanyId; exporter.CompanyCode = Login.CompanyCode; ProgressDialog.Start(ParentForm, (cancel, progress) => { return(exporter.ExportAsync(filePath, list, cancel, progress)); }, true, SessionKey); if (exporter.Exception != null) { NLogHandler.WriteErrorLog(this, exporter.Exception, SessionKey); ShowWarningDialog(MsgErrExportError); return; } grdKanaHistoryCustomer.Rows.Clear(); rdoCustomer.Focus(); DispStatusMessage(MsgInfFinishExport); }