Ejemplo n.º 1
0
        /// <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 customerTask = customerProcessor.GetAsync(new CustomerSearch {
                CompanyId = source.CompanyId,
            }, token);

            await Task.WhenAll(companyTask, loginUserTask, appConTask, customerTask);

            var company            = companyTask.Result.First();
            var loginUser          = loginUserTask.Result.First();
            var appCon             = appConTask.Result;
            var customerDictionary = customerTask.Result.ToDictionary(x => x.Code);

            var definition = new KanaHistoryCustomerFileDefinition(new DataExpression(appCon));

            definition.CustomerIdField.GetModelsByCode = val => customerDictionary;
            var parser = new CsvParser {
                Encoding      = encoding,
                StreamCreator = new PlainTextMemoryStreamCreator(),
            };

            var importer = definition.CreateImporter(x => new { x.PayerName, x.SourceBankName, x.SourceBranchName, x.CustomerId }, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;
            importer.LoadAsync   = () => kanaHistoryCustomerProcessor.GetAsync(new KanaHistorySearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => kanaHistoryCustomerProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

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

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
Ejemplo n.º 2
0
        private void ImportKanaHistoryCustomer()
        {
            ImportSetting importSetting = null;
            var           task          = Util.GetMasterImportSettingAsync(Login, ImportFileType.KanaHistory);

            // 取込設定取得
            ProgressDialog.Start(ParentForm, task, false, SessionKey);
            importSetting = task.Result;

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

            definition.CustomerIdField.GetModelsByCode = val =>
            {
                Dictionary <string, Customer> product = null;
                ServiceProxyFactory.LifeTime(factory =>
                {
                    var customerMaster     = factory.Create <CustomerMasterClient>();
                    CustomersResult result = customerMaster.GetByCode(
                        Login.SessionKey, Login.CompanyId, val);
                    if (result.ProcessResult.Result)
                    {
                        product = result.Customers
                                  .ToDictionary(c => c.Code);
                    }
                });
                return(product ?? new Dictionary <string, Customer>());
            };

            var importer = definition.CreateImporter(m => new { m.PayerName, m.SourceBankName, m.SourceBranchName, m.CustomerId });

            importer.UserId      = Login.UserId;
            importer.UserCode    = Login.UserCode;
            importer.CompanyId   = Login.CompanyId;
            importer.CompanyCode = Login.CompanyCode;
            importer.LoadAsync   = async() => await GetKanaHistoryCustomerAsync();

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

            importer.InitializeWorker = async worker => worker.SetLegalPersonalities(await GetLegalPersonalitiesAsync());

            var importResult = DoImport(importer, importSetting);

            if (!importResult)
            {
                return;
            }
            grdKanaHistoryCustomer.Rows.Clear();
        }