コード例 #1
0
        private async Task TryImportFile(ImportedFile currentFile)
        {
            var newFileStatus = FileStatus.Success;

            try
            {
                if (currentFile != null)
                {
                    GlobalLogger.LogInfo($"Start importing file: {currentFile.OriginalFileName} | Status: {currentFile.FileStatus}", GetType().Name, true);

                    var streamFile = _extractFileService.ExtractFile(currentFile.OriginalFileName);

                    if (_fileNameMatcher.IsFeesDataFile(currentFile.OriginalFileName))
                    {
                        newFileStatus = await ProcessFeesFileReport(currentFile, streamFile);
                    }
                    else if (_fileNameMatcher.IsAcctStatusReportNonEca(currentFile.OriginalFileName))
                    {
                        newFileStatus = await ProcessAcctStatusReportFileReport(
                            currentFile,
                            "AccountStatusReport",
                            _fileNameMatcher.AcctStatusReportNonEcaSqlLike,
                            streamFile);
                    }
                    else if (_fileNameMatcher.IsNavRegex(currentFile.OriginalFileName))
                    {
                        newFileStatus = await ProcessNavFileReport(currentFile, streamFile);
                    }
                    else if (_fileNameMatcher.IsAcctStatusReport(currentFile.OriginalFileName))
                    {
                        newFileStatus = await ProcessAcctStatusReportFileReport(
                            currentFile,
                            "ECAAccountStatusReport",
                            _fileNameMatcher.AcctStatusReportSqlLike,
                            streamFile);
                    }
                    else if (_fileNameMatcher.IsCashReport(currentFile.OriginalFileName))
                    {
                        newFileStatus = await ProcessCashReport(currentFile, streamFile);
                    }
                    else if (_fileNameMatcher.IsTradeAsReport(currentFile.OriginalFileName))
                    {
                        newFileStatus = await ProcessTradesAsReport(currentFile, streamFile);
                    }
                    else if (_fileNameMatcher.IsSytossClientInfo(currentFile.OriginalFileName))
                    {
                        newFileStatus = await ProcessSytossClientInfoReport(currentFile, streamFile);
                    }
                    else if (_fileNameMatcher.IsSytossOpenPositions(currentFile.OriginalFileName))
                    {
                        newFileStatus = await ProcessSytossOpenPositions(currentFile, streamFile);
                    }
                    else if (_fileNameMatcher.IsTradeExeReport(currentFile.OriginalFileName))
                    {
                        newFileStatus = await ProcessTradesExeReport(currentFile, streamFile);
                    }
                    else if (_fileNameMatcher.IsInterestAccruaReport(currentFile.OriginalFileName))
                    {
                        newFileStatus = await ProcessTradeInterestAccruaReport(currentFile, streamFile);
                    }
                    else if (_fileNameMatcher.IsTradeCommissionsDetReport(currentFile.OriginalFileName))
                    {
                        newFileStatus = await ProcessTradeCommissionsReport(currentFile, streamFile);
                    }
                }

                GlobalLogger.LogInfo($"File: {currentFile.OriginalFileName} has been imported.", GetType().Name, true);
            }
            catch (Exception ex)
            {
                newFileStatus = FileStatus.Failed;
                GlobalLogger.LogError($"Error while importing file {currentFile?.OriginalFileName}.", ex, GetType().Name, true);
            }
            finally
            {
                if (currentFile != null)
                {
                    currentFile.FileState  = FileState.Imported;
                    currentFile.FileStatus = newFileStatus;
                    if (newFileStatus == FileStatus.Success)
                    {
                        currentFile.ImportedDate = DateTime.UtcNow;
                    }

                    _importJobRepository.UpdateImportedFile(currentFile);
                    _importJobRepository.SaveChanges();
                }
                else
                {
                    GlobalLogger.LogInfo("Job has not found new files for importing. Waiting...", GetType().Name, true);
                }
            }
        }