Esempio n. 1
0
        private async Task ImportGLAccountsHandler(
            FileInfo input,
            EFormatType inputformat,
            FileInfo?output,
            EFormatType outputformat)
        {
            var fSyncFilePath  = input.FullName;
            var fGLAccountList = File.ReadAllText(fSyncFilePath);

            var fGLAccounts = _utilities.ReadAs <GLAccount>(inputformat, fGLAccountList);

            if (fGLAccounts is null)
            {
                return;
            }

            var fSuccessList = new List <GLAccount>();
            var fFailedList  = new List <GLAccount>();

            var fCount           = 1;
            var fTotalGLAccounts = fGLAccounts.Count;

            foreach (var fGLAccount in fGLAccounts)
            {
                var fResult = await _glaccountService.CreateOrUpdate(fGLAccount);

                if (fResult.Object == null)
                {
                    fFailedList.Add(fGLAccount);
                    _logger.LogWarning($"{fCount}/{fTotalGLAccounts}: Failed syncing GLAccount '{fGLAccount.Name}' - {fResult.ErrorMessage}");
                }
                else
                {
                    fSuccessList.Add(fResult.Object);
                    Console.WriteLine($"{fCount}/{fTotalGLAccounts} Successfully synced GLAccount '{fGLAccount.Name}'");
                }
                fCount++;
            }

            Console.WriteLine($"{fSuccessList.Count}/{fTotalGLAccounts} GLAccounts have been successfully imported");

            await _utilities.HandleOutput(outputformat, fSuccessList, output);

            if (output != null)
            {
                await _utilities.HandleOutputToFilePath(outputformat, fFailedList, $"{output?.Directory?.FullName}/failed_{output?.Name ?? "NO_FILE_PATH_PROVIDED"}");

                await _utilities.HandleOutputToFilePath(outputformat, fSuccessList, $"{output?.Directory?.FullName}/succeed_{output?.Name ?? "NO_FILE_PATH_PROVIDED"}");
            }
        }