/// <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 loginUsersTask = loginUserProcessor.GetAsync(new LoginUserSearch {
                CompanyId = source.CompanyId,
            }, token);
            var appConTask = applicationControlProcessor.GetAsync(source.CompanyId, token);

            await Task.WhenAll(companyTask, loginUsersTask, appConTask);

            var company             = companyTask.Result.First();
            var loginUserDictionary = loginUsersTask.Result.ToDictionary(x => x.Code);
            var loginUser           = loginUsersTask.Result.First(x => x.Id == source.LoginUserId);
            var appCon = appConTask.Result;

            var definition = new BankBranchFileDefinition(new DataExpression(appCon));
            var parser     = new CsvParser {
                Encoding      = encoding,
                StreamCreator = new PlainTextMemoryStreamCreator(),
            };


            var importer = definition.CreateImporter(x => new { x.BankCode, x.BranchCode }, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;

            importer.LoadAsync = () => bankBranchProcessor.GetAsync(new BankBranchSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = async x => {
                foreach (var y in x.New)
                {
                    y.CompanyId = source.CompanyId;
                }
                foreach (var y in x.Dirty)
                {
                    y.CompanyId = source.CompanyId;
                }
                foreach (var y in x.Removed)
                {
                    y.CompanyId = source.CompanyId;
                }
                return(await bankBranchProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token));
            };

            var result = await importer.ImportAsync(csv, mode, token, null);

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
Example #2
0
        private void Import()
        {
            ClearStatusMessage();
            try
            {
                ImportSetting importSetting = null;
                var           task          = Util.GetMasterImportSettingAsync(Login, ImportFileType.BankBranch);
                ProgressDialog.Start(ParentForm, task, false, SessionKey);
                importSetting = task.Result;

                var definition = new BankBranchFileDefinition(new DataExpression(ApplicationControl));

                var importer = definition.CreateImporter(m => new { m.BankCode, m.BranchCode });
                importer.UserId      = Login.UserId;
                importer.UserCode    = Login.UserCode;
                importer.CompanyId   = CompanyId;
                importer.CompanyCode = Login.CompanyCode;
                importer.LoadAsync   = async() => await GetBankBranchAsync();

                importer.RegisterAsync = async unitOfWork => await RegisterForImportAsync(unitOfWork);

                var importResult = DoImport(importer, importSetting, Clear);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
                ShowWarningDialog(MsgErrImportErrorWithoutLog);
            }
        }
Example #3
0
        private void ExportData()
        {
            try
            {
                List <BankBranch> list = null;
                var serverPath         = "";
                var loadTask           = ServiceProxyFactory.LifeTime(async factory =>
                {
                    var service = factory.Create <BankBranchMasterClient>();

                    BankBranchsResult result = await service.GetItemsAsync(SessionKey, CompanyId, new BankBranchSearch());

                    if (result.ProcessResult.Result)
                    {
                        list = result.BankBranches;
                    }
                });

                var pathTask = ServiceProxyFactory.LifeTime(async factory =>
                {
                    var generalService          = factory.Create <GeneralSettingMasterClient>();
                    GeneralSettingResult result = await generalService.GetByCodeAsync(SessionKey, CompanyId, "サーバパス");

                    if (result.ProcessResult.Result)
                    {
                        serverPath = result.GeneralSetting?.Value;
                    }
                });
                ProgressDialog.Start(ParentForm, Task.WhenAll(loadTask, pathTask), false, SessionKey);

                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 BankBranchFileDefinition(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;
                }

                DispStatusMessage(MsgInfFinishExport);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
                DispStatusMessage(MsgErrExportError);
            }
        }