private void CopyMediaFile(string mediaPath, string destinationPath, string mediaFile, string newFileName) { var sourceFileName = Path.Combine(mediaPath, mediaFile); try { DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationPath); if (DirectoryOperationsHelper.IsFileExist(sourceFileName)) { DirectoryOperationsHelper.DeleteFileIfExist(Path.Combine(destinationPath, newFileName)); DirectoryOperationsHelper.Copy(sourceFileName, Path.Combine(destinationPath, newFileName)); _logger.Info("Media file ( " + sourceFileName + " ) successfully copied with new Name " + newFileName + " on location " + destinationPath); } else { _logger.Info("Media file ( " + sourceFileName + " ) does not exist on Media file Location"); } } catch (Exception ex) { _logger.Error(""); _logger.Error("Message: Media file ( " + sourceFileName + " ) does not exist on Media file Location. Exception : " + ex.Message); _logger.Error("StackTrace:" + ex.StackTrace); } }
private string GetFileName(string sourceFile, MediaLocation mediaLocation) { var fileNameWithoutExtention = Path.GetFileNameWithoutExtension(sourceFile); var archiveFileName = fileNameWithoutExtention + "_" + DateTime.Now.ToString("MMddyyyyHHmmss") + ".txt"; var destinationFile = Path.Combine(mediaLocation.PhysicalPath, archiveFileName); var archiveFilePath = string.Empty; try { var archiveFolderPath = Path.Combine(_memberUploadbyAcesSourceFolderPath, DateTime.Today.ToString("yyyyMMdd"), "Archive"); archiveFilePath = Path.Combine(archiveFolderPath, archiveFileName); DirectoryOperationsHelper.CreateDirectoryIfNotExist(archiveFolderPath); DirectoryOperationsHelper.Copy(sourceFile, archiveFilePath); DirectoryOperationsHelper.Move(sourceFile, destinationFile); _logger.Info("Source Path: " + sourceFile); _logger.Info("Destination Path: " + destinationFile); } catch (Exception ex) { _logger.Error("Error while archiving file."); _logger.Error("Message: " + ex.Message); _logger.Error("Stack trace: " + ex.StackTrace); } _logger.Info("Archive Path: " + archiveFilePath); return(destinationFile); }
private void DownloadAttestationForm(string sourceFile, string destinationFolder, string destinationFileName = "") { if (DirectoryOperationsHelper.IsDirectoryExist(destinationFolder)) { var fileName = !string.IsNullOrEmpty(destinationFileName) ? destinationFileName : Path.GetFileNameWithoutExtension(sourceFile) + ".pdf"; destinationFileName = Path.Combine(destinationFolder, fileName); _logger.Info("source: " + sourceFile); _logger.Info("destination: " + destinationFileName); if (DirectoryOperationsHelper.IsFileExist(destinationFileName)) { DirectoryOperationsHelper.Delete(destinationFileName); } DirectoryOperationsHelper.Copy(sourceFile, destinationFileName); } }
private void CopyFileToClientLocation(string folderPath) { _logger.Info("Source Path CopyFileToClientLocation : " + folderPath); if (DirectoryOperationsHelper.IsDirectoryExist(_clientLocationFolder)) { _logger.Info("Destination Location Exists: " + _clientLocationFolder); if (DirectoryOperationsHelper.IsDirectoryExist(folderPath)) { _logger.Info("Source Path Exists: " + folderPath); var crossfilePath = DirectoryOperationsHelper.GetFiles(folderPath); if (!crossfilePath.IsNullOrEmpty()) { _logger.Info("Number of Crosswalk Found:" + crossfilePath); foreach (var filePath in crossfilePath) { var fileName = Path.GetFileName(filePath); if (string.IsNullOrWhiteSpace(fileName)) { continue; } var destinationFileName = Path.Combine(_clientLocationFolder, fileName); DirectoryOperationsHelper.Copy(filePath, destinationFileName); _logger.Info("Source: " + filePath); _logger.Info("Destination: " + destinationFileName); } } else { _logger.Info("No Crosswalk Found"); } } } else { _logger.Info("Destination Path not exist : " + _clientLocationFolder); } }
private void AttachAttestationForm(string sourcePath, string searchPattern, string destinationFolder, string destinationFileName = "") { if (DirectoryOperationsHelper.IsDirectoryExist(sourcePath)) { var files = DirectoryOperationsHelper.GetFiles(sourcePath, "*" + searchPattern + ".pdf"); if (files != null && files.Any()) { foreach (var file in files) { var destinationFile = Path.Combine(destinationFolder, !string.IsNullOrEmpty(destinationFileName) ? destinationFileName + ".pdf" : Path.GetFileNameWithoutExtension(file) + ".pdf"); if (DirectoryOperationsHelper.IsFileExist(destinationFile)) { DirectoryOperationsHelper.Delete(destinationFile); } DirectoryOperationsHelper.Copy(file, destinationFile); } } else { _logger.Info(string.Format("No file Found in folder : {0} for search pattern : {1}", sourcePath, searchPattern)); } } }
public void CreateCumulativeFileAndPost(string incrementalFilePath, string cumulativeFilePath, string finalFilename) { var incrementalDataTable = CreateDataTable(incrementalFilePath); var cumulativeDataTable = CreateDataTable(cumulativeFilePath); DirectoryOperationsHelper.DeleteFileIfExist(finalFilename); _logger.Info("Cumulative file Path: " + cumulativeFilePath); _logger.Info("Incremental file Path: " + incrementalFilePath); _logger.Info("final file Path: " + finalFilename); if (cumulativeDataTable == null || cumulativeDataTable.Rows == null || cumulativeDataTable.Rows.Count <= 0) { if (incrementalDataTable != null && incrementalDataTable.Rows != null && incrementalDataTable.Rows.Count > 0) { DirectoryOperationsHelper.DeleteFileIfExist(cumulativeFilePath); DirectoryOperationsHelper.Copy(incrementalFilePath, cumulativeFilePath); DirectoryOperationsHelper.Copy(cumulativeFilePath, finalFilename); } } else if (incrementalDataTable == null || incrementalDataTable.Rows == null || incrementalDataTable.Rows.Count <= 0) { if (cumulativeDataTable.Rows != null && cumulativeDataTable.Rows.Count > 0) { DirectoryOperationsHelper.Copy(cumulativeFilePath, finalFilename); } } else { var nameOfCustomerIdColumn = GetColumnName(cumulativeDataTable, "Id_$$"); var nameOfEventIdColumn = GetColumnName(cumulativeDataTable, "Event Id_$$"); var nameOfEventDateColumn = GetColumnName(cumulativeDataTable, "Event Date_$$"); var tempAccumulativeDataTable = CreateAccumulativeDataTable(cumulativeDataTable, incrementalDataTable, nameOfCustomerIdColumn, nameOfEventIdColumn, nameOfEventDateColumn); if (tempAccumulativeDataTable != null && tempAccumulativeDataTable.Rows != null && tempAccumulativeDataTable.Rows.Count > 0) { if (DirectoryOperationsHelper.IsFileExist(cumulativeFilePath)) { _logger.Info("Final Record: " + tempAccumulativeDataTable.Rows.Count); } _csvReader.ConvertDataTableToCsv(tempAccumulativeDataTable, cumulativeFilePath, "_$$"); if (DirectoryOperationsHelper.IsFileExist(cumulativeFilePath)) { _logger.Info("Final Record: " + tempAccumulativeDataTable.Rows.Count); } if (DirectoryOperationsHelper.IsDirectoryExist(Path.GetDirectoryName(cumulativeFilePath))) { _logger.Info("cumulativeFilePath: " + cumulativeFilePath + " exists"); } else { _logger.Info("cumulativeFilePath: " + cumulativeFilePath + " Not exists"); } DirectoryOperationsHelper.Copy(cumulativeFilePath, finalFilename); } } }
private void GenerateReportForShortName(IEnumerable <CorporateAccount> accounts) { var distinctAcesClientShortName = accounts.Where(x => !string.IsNullOrWhiteSpace(x.AcesClientShortName)).Select(t => t.AcesClientShortName) .Distinct(); foreach (var acesClientShortName in distinctAcesClientShortName) { var accountShortNamewise = accounts.Where(d => d.AcesClientShortName == acesClientShortName); if (!accountShortNamewise.IsNullOrEmpty()) { _logger.Info("starting for Shortname " + acesClientShortName); var destinationFoler = _settings.UniversalProviderFilePath; DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationFoler); DirectoryOperationsHelper.CreateDirectoryIfNotExist(_folderArchivedPath); var fileNameWithoutExtention = acesClientShortName + "_Universal_Provider"; var fileName = fileNameWithoutExtention + ".txt"; var destinationFile = Path.Combine(destinationFoler, fileName); if (DirectoryOperationsHelper.IsFileExist(destinationFile)) { var archiveFileName = fileNameWithoutExtention + "_" + DateTime.Today.AddDays(-1).ToString("ddMMyyyy") + ".txt"; var archiveFilePath = Path.Combine(_folderArchivedPath, archiveFileName); DirectoryOperationsHelper.DeleteFileIfExist(archiveFilePath); DirectoryOperationsHelper.Move(destinationFile, archiveFilePath); } WriteCsvHeader(destinationFile); foreach (var account in accountShortNamewise) { try { _logger.Info("starting for account " + account.Tag); GenerateUniversalProviderList(account, destinationFile); _logger.Info("completed for Account " + account.Tag); } catch (Exception exception) { _logger.Error("some error occurred while created Member List for Account " + account.Tag); _logger.Error("Message: " + exception.Message); _logger.Error("Stack Trace: " + exception.StackTrace); } } if (DirectoryOperationsHelper.IsFileExist(destinationFile)) { _logger.Info("Universal Provider Report generated : " + destinationFile); DirectoryOperationsHelper.CreateDirectoryIfNotExist(_settings.UniversalProviderFileSftpPath); _logger.Info("Deleting old files from SFTP."); DirectoryOperationsHelper.DeleteFileIfExist(Path.Combine(_settings.UniversalProviderFileSftpPath, acesClientShortName + "_Universal_Provider.txt")); _logger.Info("Old files deleted from SFTP."); _logger.Info("Copying file to SFTP location : " + _settings.UniversalProviderFileSftpPath); var sftpFilePath = Path.Combine(_settings.UniversalProviderFileSftpPath, fileName); DirectoryOperationsHelper.Copy(destinationFile, sftpFilePath); _logger.Info("File copied : " + sftpFilePath); } } } }
public void PollForReportGeneration() { if (!_daysOfWeek.Contains(DateTime.Today.DayOfWeek)) { _logger.Info(string.Format("Today is {0}. Job is set to run on {1} .", DateTime.Today.DayOfWeek, string.Join(", ", _daysOfWeek))); return; } if (_accountIds.IsNullOrEmpty()) { _logger.Info("No accounts found for Gift Certificate Report."); return; } var corporateAccounts = _corporateAccountRepository.GetByIds(_accountIds); var toDate = DateTime.Today; var fromDate = new DateTime(toDate.Year, 1, 1); foreach (var corporateAccount in corporateAccounts) { try { var customSettingFilePath = string.Format(_customSettingFile, corporateAccount.Tag); var customSettings = _customSettingManager.Deserialize(customSettingFilePath); var exportFromTime = customSettings.LastTransactionDate ?? _cutOffDate; var filter = new HealthPlanGiftCertificateReportFilter { Tag = corporateAccount.Tag, FromDate = exportFromTime.Date, ToDate = toDate }; fromDate = filter.FromDate.HasValue ? filter.FromDate.Value : fromDate; _logger.Info(string.Format("Generating for account with ID : {0} and tag : {1} from {2} to {3}", corporateAccount.Id, corporateAccount.Tag, fromDate.ToShortDateString(), toDate.ToShortDateString())); var pageNumber = 1; const int pageSize = 100; var list = new List <HealthPlanGiftCertificateReportViewModel>(); while (true) { int totalRecords; var model = _eventCustomerReportingService.GetForHealthPlanGiftCertificateReport(pageNumber, pageSize, filter, out totalRecords); if (model == null || model.Collection == null || !model.Collection.Any()) { break; } list.AddRange(model.Collection); _logger.Info(String.Format("PageNumber:{0} Totalrecords: {1} Current Length: {2}\n\n", pageNumber, totalRecords, list.Count)); pageNumber++; if (list.Count >= totalRecords) { break; } } if (!list.Any()) { _logger.Info(string.Format("No records found for account with ID : {0} and tag : {1}", corporateAccount.Id, corporateAccount.Tag, fromDate.ToShortDateString(), toDate.ToShortDateString())); continue; } var internalLocation = string.Format(_giftCertificateReportInternalLocation, corporateAccount.FolderName); if (!DirectoryOperationsHelper.IsDirectoryExist(internalLocation)) { DirectoryOperationsHelper.CreateDirectory(internalLocation); } var fileName = @"\" + string.Format("CCI_offline_HealthFair_{0}.csv", DateTime.Today.ToString("yyyy_MM_dd"));//CCI_offline_HealthFair_YYYY_MM_DD var internalFilePath = internalLocation + fileName; WriteCsv(list, internalFilePath); if (DirectoryOperationsHelper.IsFileExist(internalFilePath)) { var folder = Path.Combine(string.Format(_giftCertificateReportDownloadPath, corporateAccount.FolderName), DateTime.Today.Year.ToString()); if (!DirectoryOperationsHelper.IsDirectoryExist(folder)) { DirectoryOperationsHelper.CreateDirectory(folder); } var filePath = folder + fileName; DirectoryOperationsHelper.Copy(internalFilePath, filePath); } _logger.Info(string.Format("Completed Gift Certificate Report for account with ID : {0} and tag : {1} from {2} to {3}", corporateAccount.Id, corporateAccount.Tag, fromDate.ToShortDateString(), toDate.ToShortDateString())); customSettings.LastTransactionDate = toDate; _customSettingManager.SerializeandSave(customSettingFilePath, customSettings); } catch (Exception ex) { _logger.Info(string.Format("Error occured for account with ID : {0} and tag : {1} \nMessage : {2} \nStack Trace : {3}", corporateAccount.Id, corporateAccount.Tag, ex.Message, ex.StackTrace)); } } }
private void GenerateCrosswalkInboundReport(CrosswalkInboundFilter filter) { var account = _corporateAccountRepository.GetById(filter.AccountId); filter.Tag = account.Tag; if (account.IsHealthPlan) { filter.StopSendingPdftoHealthPlanDate = _settings.StopSendingPdftoHealthPlanDate; } var model = _crosswalkInboundReportService.GetCrosswalkInboundReportList(filter, _logger); if (model != null) { var folder = string.Format(_settings.FloridaBlueInboundReportPath, account.FolderName, DateTime.Now.ToString("yyyy-MM-dd")); if (!Directory.Exists(folder)) { DirectoryOperationsHelper.CreateDirectory(folder); } var fileName = _pipeDelimitedReportHelper.GetReportName(ReportType.CrosswalkInbound) + ".txt"; var zipFileName = _pipeDelimitedReportHelper.GetReportName(ReportType.CrosswalkZip); if (model.Collection != null && model.Collection.Any()) { _logger.Info("generating File"); var tempMediaLocation = _mediaRepository.GetTempMediaFileLocation().PhysicalPath + zipFileName + "\\"; if (!Directory.Exists(tempMediaLocation)) { DirectoryOperationsHelper.CreateDirectory(tempMediaLocation); } var resultPostedToPlanFileName = Path.Combine(_resultPostedToPlanPath, string.Format("ResultPostedto_{0}.xml", account.Tag)); var resultPosted = _resultPdfPostedSerializer.Deserialize(resultPostedToPlanFileName); resultPosted = resultPosted == null || resultPosted.Customer.IsNullOrEmpty() ? new ResultPdfPostedXml { Customer = new List <CustomerInfo>() } : resultPosted; foreach (var crosswalkViewModel in model.Collection) { var hafResultPdfLocation = _mediaRepository.GetPremiumVersionResultPdfLocation(crosswalkViewModel.EventId, crosswalkViewModel.CustomerId); var hafResultPdfFileName = _mediaRepository.GetPdfFileNameForHealthPlanResultReport(); var pcpResultPdfFileName = _mediaRepository.GetPdfFileNameForPcpResultReport(); _logger.Info(" Event Id: " + crosswalkViewModel.EventId + " Customer Id: " + crosswalkViewModel.CustomerId); if (DirectoryOperationsHelper.IsFileExist(tempMediaLocation + crosswalkViewModel.FileName)) { var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(tempMediaLocation + crosswalkViewModel.FileName); var files = DirectoryOperationsHelper.GetFiles(tempMediaLocation, fileNameWithoutExtension + "*.pdf"); crosswalkViewModel.FileName = fileNameWithoutExtension + "_" + files.Count() + ".pdf"; } if (File.Exists(hafResultPdfLocation.PhysicalPath + hafResultPdfFileName)) { var destinationFileName = GetFileName(resultPosted.Customer, crosswalkViewModel.EventId, crosswalkViewModel.CustomerId, Path.GetFileNameWithoutExtension(crosswalkViewModel.FileName), (long)ResultFormatType.PDF); crosswalkViewModel.FileName = destinationFileName + ".pdf"; _logger.Info("Copying File.. filePath from : " + hafResultPdfLocation.PhysicalPath + hafResultPdfFileName); _logger.Info("Copying File.. filePath To : " + tempMediaLocation + crosswalkViewModel.FileName); DirectoryOperationsHelper.Copy(hafResultPdfLocation.PhysicalPath + hafResultPdfFileName, tempMediaLocation + crosswalkViewModel.FileName); resultPosted.Customer.Add(GetCustomerInfo(crosswalkViewModel)); } else if (File.Exists(hafResultPdfLocation.PhysicalPath + pcpResultPdfFileName)) { var destinationFileName = GetFileName(resultPosted.Customer, crosswalkViewModel.EventId, crosswalkViewModel.CustomerId, Path.GetFileNameWithoutExtension(crosswalkViewModel.FileName), (long)ResultFormatType.PDF); crosswalkViewModel.FileName = destinationFileName + ".pdf"; _logger.Info("Copying File.. filePath from : " + hafResultPdfLocation.PhysicalPath + pcpResultPdfFileName); _logger.Info("Copying File.. filePath To : " + tempMediaLocation + crosswalkViewModel.FileName); DirectoryOperationsHelper.Copy(hafResultPdfLocation.PhysicalPath + pcpResultPdfFileName, tempMediaLocation + crosswalkViewModel.FileName); resultPosted.Customer.Add(GetCustomerInfo(crosswalkViewModel)); } else { _logger.Info("file not found"); } } _resultPdfPostedSerializer.SerializeandSave(resultPostedToPlanFileName, resultPosted); _pipeDelimitedReportHelper.Write(model.Collection, folder, fileName); DirectoryOperationsHelper.Copy(folder + "\\" + fileName, tempMediaLocation + fileName); _logger.Info("generating Zip "); _zipHelper.CreateZipFiles(tempMediaLocation, folder + "\\" + zipFileName + ".zip"); if (_sendReportToSftp) { try { _logger.Info("Sending zip to SFTP."); var destinationPath = _destinationSftpPath + "\\" + account.FolderName + "\\Download\\Reports"; SendFilesToSftp(Path.Combine(folder, zipFileName + ".zip"), destinationPath, zipFileName + ".zip"); _logger.Info("Zip sent to SFTP."); } catch (Exception ex) { _logger.Info("Error sending zip to SFTP."); _logger.Error("Message : " + ex.Message); _logger.Error("Stack Trace : " + ex.StackTrace); } } _logger.Info("Deleting temp folder: " + tempMediaLocation); DirectoryOperationsHelper.DeleteDirectory(tempMediaLocation, true); _logger.Info("Deleting text file: " + folder + "\\" + fileName); DirectoryOperationsHelper.Delete(folder + "\\" + fileName); } else { _logger.Info("No Data found for account Id: " + filter.AccountId); } } else { _logger.Info("No record found for " + account.Tag); } }
private void CreateCrossWalkFile(string csvFilePath, IEnumerable <AnthemPdfCrossWalkVeiwModel> modelData) { try { if (modelData.IsNullOrEmpty()) { _logger.Info("No Data found to generate crosswalk file "); return; } try { DirectoryOperationsHelper.DeleteFiles(csvFilePath, "CrosswalkFile_*.csv"); } catch (Exception exception) { _logger.Error(" While deleting old files"); _logger.Error("message: " + exception); _logger.Error("stack Trace: " + exception.StackTrace); } DirectoryOperationsHelper.CreateDirectoryIfNotExist(_crosswalkFilePath); DirectoryOperationsHelper.CreateDirectoryIfNotExist(csvFilePath); var filePath = Path.Combine(_crosswalkFilePath, "CrosswalkFile_" + _crosswalkFileYear + ".csv"); bool createHeaderRow = !DirectoryOperationsHelper.IsFileExist(filePath); _logger.Info("File Path: " + filePath); if (createHeaderRow) { _logger.Info("Header info being created"); } var csvFileName = Path.Combine(csvFilePath, "CrosswalkFile_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".csv"); using (var streamWriter = new StreamWriter(filePath, append: !createHeaderRow)) { var members = (typeof(AnthemPdfCrossWalkVeiwModel)).GetMembers(); if (createHeaderRow) { var header = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel)) { continue; } } else { continue; } string propertyName = memberInfo.Name; bool isHidden = false; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is DisplayNameAttribute) { propertyName = (attribute as DisplayNameAttribute).DisplayName; } } } if (isHidden) { continue; } header.Add(propertyName); } streamWriter.Write(string.Join(",", header.ToArray()) + Environment.NewLine); } var sanitizer = new CSVSanitizer(); foreach (var model in modelData) { var values = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel)) { continue; } } else { continue; } bool isHidden = false; FormatAttribute formatter = null; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is FormatAttribute) { formatter = (FormatAttribute)attribute; } } } if (isHidden) { continue; } var obj = propInfo.GetValue(model, null); if (obj == null) { values.Add(string.Empty); } else if (formatter != null) { values.Add(formatter.ToString(obj)); } else { values.Add(sanitizer.EscapeString(obj.ToString())); } } streamWriter.Write(string.Join(",", values.ToArray()) + Environment.NewLine); } streamWriter.Close(); _logger.Info("crosswalk .csv has been created at following location: "); _logger.Info(filePath); if (DirectoryOperationsHelper.IsFileExist(filePath)) { DirectoryOperationsHelper.DeleteFileIfExist(csvFileName); DirectoryOperationsHelper.Copy(filePath, csvFileName); } } } catch (Exception ex) { _logger.Error("While Generating crosswalk file: message " + ex.Message + " stack trace: " + ex.StackTrace); } }
private void GenerateReportForShortName(IEnumerable <CorporateAccount> accounts) { var distinctAcesClientShortName = accounts.Where(x => !string.IsNullOrWhiteSpace(x.AcesClientShortName)).Select(t => t.AcesClientShortName) .Distinct(); foreach (var acesClientShortName in distinctAcesClientShortName) { var accountShortNamewise = accounts.Where(a => a.AcesClientShortName == acesClientShortName); if (!accountShortNamewise.IsNullOrEmpty()) { var destinationFoler = _folderPath; //Path.Combine(_folderPath, clientId); DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationFoler); DirectoryOperationsHelper.CreateDirectoryIfNotExist(_folderArchivedPath); var fileNameWithoutExtention = acesClientShortName + "_Universal_Member"; var fileName = fileNameWithoutExtention + ".txt"; var destinationFile = Path.Combine(destinationFoler, fileName); if (DirectoryOperationsHelper.IsFileExist(destinationFile)) { var archiveFileName = fileNameWithoutExtention + "_" + DateTime.Today.AddDays(-1).ToString("ddMMyyyy") + ".txt"; var archiveFilePath = Path.Combine(_folderArchivedPath, archiveFileName); DirectoryOperationsHelper.DeleteFileIfExist(archiveFilePath); DirectoryOperationsHelper.Move(destinationFile, archiveFilePath); } var suppressedRecordsFile = Path.Combine(destinationFoler, acesClientShortName + "_Suppressed_Member_Records.txt"); if (DirectoryOperationsHelper.IsFileExist(suppressedRecordsFile)) { var archivesuppressedRecordsFileName = acesClientShortName + "_Suppressed_Member_Records_" + DateTime.Today.AddDays(-1).ToString("ddMMyyyy") + ".txt"; var archiveFilePath = Path.Combine(_folderArchivedPath, archivesuppressedRecordsFileName); DirectoryOperationsHelper.Move(suppressedRecordsFile, Path.Combine(_folderArchivedPath, archivesuppressedRecordsFileName)); } WriteCsvHeader(destinationFile); _logger.Info("starting for account AcesClientShortName " + acesClientShortName); foreach (var corporateAccount in accountShortNamewise) { try { _logger.Info("starting for account Tag " + corporateAccount.Tag); var filter = new UniversalMemberListModelFilter { AccountId = corporateAccount.Id, Tag = corporateAccount.Tag }; var pageNumber = 1; while (true) { int totalRecords = 0; var customers = _customerRepository.GetCustomerForUniversalMemberReport(filter, pageNumber, PageSize, out totalRecords); if (customers.IsNullOrEmpty()) { break; } var customerIds = customers.Select(x => x.CustomerId); var pcpCollection = _primaryCarePhysicianRepository.GetCustomerPcpWithoutAddress( customers.Select(x => x.CustomerId)); var customerEligilityCollection = _customerEligibilityRepository.GetCustomerEligibilityByCustomerIds(customerIds); var languages = _languageRepository.GetAll(); var collection = new List <UniversalMemberViewModel>(); var suppressedRecordsCollection = new List <UniversalMemberViewModel>(); foreach (var customer in customers) { var customerPcps = pcpCollection.Where(pcp => pcp.CustomerId == customer.CustomerId).ToArray(); var customerEligibilityStatus = customerEligilityCollection.Where(x => x.CustomerId == customer.CustomerId).ToArray(); var pcpStartDate = (DateTime?)null; var pcpEndDate = (DateTime?)null; var pcpId = (long?)null; if (!customerPcps.IsNullOrEmpty()) { var activePcp = customerPcps.SingleOrDefault(x => x.IsActive); if (activePcp != null) { pcpStartDate = activePcp.DataRecorderMetaData.DateCreated; pcpId = activePcp.Id; } } var eligibilityStartDate = (DateTime?)null; var eligibilityEndDate = (DateTime?)null; if (!customerEligibilityStatus.IsNullOrEmpty()) { var customerEligibilityforCurrentYear = customerEligibilityStatus.FirstOrDefault(x => x.IsEligible.HasValue && x.IsEligible.Value && x.ForYear == DateTime.Today.Year); if (customerEligibilityforCurrentYear != null) { var year = customerEligibilityforCurrentYear.ForYear; eligibilityStartDate = new DateTime(year, 1, 1); eligibilityEndDate = new DateTime(year, 12, 31); } } var language = languages.SingleOrDefault(x => x.Id == customer.LanguageId); var model = SetUniversalMemberViewModelData(customer, corporateAccount, language, pcpStartDate, pcpEndDate, eligibilityStartDate, eligibilityEndDate, pcpId); if (string.IsNullOrWhiteSpace(model.FirstName) || string.IsNullOrWhiteSpace(model.LastName) || model.DoB == null || string.IsNullOrWhiteSpace(model.ClientMemberId)) { suppressedRecordsCollection.Add(model); } else { collection.Add(model); } } WriteCsv(collection, destinationFile); if (!suppressedRecordsCollection.IsNullOrEmpty()) { WriteCsvHeader(suppressedRecordsFile); WriteCsv(suppressedRecordsCollection, suppressedRecordsFile); } _logger.Info((pageNumber * PageSize) + " out of " + totalRecords); if ((pageNumber * PageSize) >= totalRecords) { break; } pageNumber++; } _logger.Info("completed for Account " + corporateAccount.Tag); } catch (Exception exception) { _logger.Error("some error occurred while created Member List for Account " + corporateAccount.Tag); _logger.Error("Message: " + exception.Message); _logger.Error("Stack Trace: " + exception.StackTrace); } } if (DirectoryOperationsHelper.IsFileExist(destinationFile)) { _logger.Info("Universal Member Report generated : " + destinationFile); DirectoryOperationsHelper.CreateDirectoryIfNotExist(_sftpFolderPath); _logger.Info("Deleting old file from SFTP."); DirectoryOperationsHelper.DeleteFileIfExist(Path.Combine(_sftpFolderPath, acesClientShortName + "_Universal_Member.txt")); _logger.Info("Old file deleted from SFTP."); _logger.Info("Copying file to SFTP location : " + _sftpFolderPath); var sftpFilePath = Path.Combine(_sftpFolderPath, fileName); DirectoryOperationsHelper.Copy(destinationFile, sftpFilePath); _logger.Info("File copied : " + sftpFilePath); } } } }
public void Parse() { try { if (_settings.StopHansonResultParse) { _logger.Info("Service has stop. If want enable please check setting."); return; } _logger.Info("\n\n\n====================================== Blood Result Parsing - " + Directory.GetParent(_bloodResultFolderLocation).Name + "\\" + (new DirectoryInfo(_bloodResultFolderLocation)).Name + " ===========================================\n"); if (!Directory.Exists(_bloodResultFolderLocation)) { _logger.Info("Blood Result Parsing - Folder does not exist at location" + _bloodResultFolderLocation); return; } var files = Directory.GetFiles(_bloodResultFolderLocation).Where(x => x.Contains("csv")); if (files.IsNullOrEmpty()) { _logger.Info("Blood Result Parsing - No File Found For Parsing at " + _bloodResultFolderLocation); return; } if (!Directory.Exists(_bloodResultArchiveFolderLocation)) { Directory.CreateDirectory(_bloodResultArchiveFolderLocation); } var mediaLocation = _mediaRepository.GetBloodResultParseMediaLocation(); var archiveMediaLocation = Path.Combine(mediaLocation.PhysicalPath, "Archive", DateTime.Today.ToString("MMddyyyy")); var failedRecordsLocation = Path.Combine(mediaLocation.PhysicalPath, "Failed", DateTime.Today.ToString("MMddyyyy")); foreach (var file in files) { _logger.Info("Blood Result Parsing - Files: " + file + " Started"); var fileName = Path.GetFileName(file); if (string.IsNullOrEmpty(fileName)) { return; } DirectoryOperationsHelper.CreateDirectoryIfNotExist(archiveMediaLocation); var mediaFilePath = Path.Combine(mediaLocation.PhysicalPath, fileName); DirectoryOperationsHelper.DeleteFileIfExist(mediaFilePath); _logger.Info("Moving file to media location : " + mediaFilePath); DirectoryOperationsHelper.Move(file, mediaFilePath); _logger.Info("File moved : " + fileName); var newFileName = Path.GetFileNameWithoutExtension(file) + "_" + DateTime.Now.ToString("MMddyyyhhmmss"); var parseLogger = _logManager.GetLogger(newFileName); var bloodResultParser = new BloodResultParser(mediaFilePath, parseLogger, _csvReader, _logManager); var customerScreeningData = bloodResultParser.Parse(); _logger.Info("Blood Result Parsing - Files: " + file + " Completed"); if (customerScreeningData.IsNullOrEmpty()) { DirectoryOperationsHelper.Copy(mediaFilePath, Path.Combine(_bloodResultArchiveFolderLocation, newFileName + Path.GetExtension(mediaFilePath))); DirectoryOperationsHelper.Move(mediaFilePath, Path.Combine(archiveMediaLocation, newFileName + Path.GetExtension(mediaFilePath))); continue; } Save(customerScreeningData, UploadedBy); DirectoryOperationsHelper.Copy(mediaFilePath, Path.Combine(archiveMediaLocation, newFileName + Path.GetExtension(mediaFilePath))); _logger.Info("Blood Result Parsing - Files: " + file + " copied on Archive location"); DirectoryOperationsHelper.Move(mediaFilePath, _bloodResultArchiveFolderLocation + newFileName + Path.GetExtension(mediaFilePath)); _logger.Info("Blood Result Parsing - Files: " + file + " moved on Client location"); var resultLog = bloodResultParser.BloodTestResultParserLogs; if (!resultLog.IsNullOrEmpty() && resultLog.Any(x => !x.IsSuccessful)) { var failedFileName = newFileName + "_ErrorLog.csv"; var failedRecordsFilePath = Path.Combine(failedRecordsLocation, failedFileName); _logger.Info("Creating error log file : " + failedFileName); DirectoryOperationsHelper.CreateDirectoryIfNotExist(failedRecordsLocation); UpdateFailedRecords(failedRecordsFilePath, resultLog.Where(x => !x.IsSuccessful)); _logger.Info("Moving error log file to archive location."); DirectoryOperationsHelper.Copy(failedRecordsFilePath, Path.Combine(_bloodResultArchiveFolderLocation, failedFileName)); } } } catch (Exception ex) { _logger.Error("Blood Result parsing: " + ex.Message + "\n" + ex.StackTrace, ex); } }
public void PollForCustomerEligibilityUpload() { try { if (_settings.StopCustomerEligibilityUpload) { _logger.Info("Customer Eligibility Upload Polling Agent stopped @:" + DateTime.Now); return; } _logger.Info("Entering Customer Eligibility Upload Polling Agent @:" + DateTime.Now); var sftpFileLocation = _settings.CustomerEligibilityUploadSftpPath; var mediaLocation = _mediaRepository.GetCustomerEligibilityUploadFolderLocation(); var archiveFolder = Path.Combine(mediaLocation.PhysicalPath, "Archive", DateTime.Today.ToString("yyyyMMdd")); var failedFolder = Path.Combine(mediaLocation.PhysicalPath, "Failed", DateTime.Today.ToString("yyyyMMdd")); var getFilesFromSftp = DirectoryOperationsHelper.GetFiles(sftpFileLocation, "*.txt").Where(x => x.ToLower().Contains("outtake") && x.ToLower().Contains("eligibility")); if (getFilesFromSftp.IsNullOrEmpty()) { _logger.Info("No files found for parsing."); return; } DirectoryOperationsHelper.CreateDirectoryIfNotExist(archiveFolder); DirectoryOperationsHelper.CreateDirectoryIfNotExist(failedFolder); var timeStamp = DateTime.Now.ToString("yyyyMMddhhmmss"); foreach (var file in getFilesFromSftp) { var fileName = Path.GetFileNameWithoutExtension(file); MoveFile(file, Path.Combine(mediaLocation.PhysicalPath, fileName + "_" + timeStamp + ".txt")); } var filesToParse = DirectoryOperationsHelper.GetFiles(mediaLocation.PhysicalPath, "*.txt"); _logger.Info("Number of files to Parse:" + filesToParse.Count()); foreach (var file in filesToParse) { var fileName = Path.GetFileName(file); try { var patientData = _pipeDelimitedReportHelper.ReadWithTextQualifier(file); var columns = patientData.Columns.Cast <DataColumn>().Select(x => x.ColumnName.ToLower()).ToArray(); var missingColumnNames = _corporateUploadHelper.CheckAllCustomerEligibilityUploadColumnExist(columns); if (!string.IsNullOrEmpty(missingColumnNames)) { _logger.Info("Column Name(" + missingColumnNames + ") missing in file(" + fileName + ")"); MoveFile(file, Path.Combine(failedFolder, fileName)); continue; } var recordsInFile = patientData.Rows.Count; if (recordsInFile == 0) { _logger.Info("No record found in " + fileName); MoveFile(file, Path.Combine(archiveFolder, fileName)); continue; } _logger.Info("Parsing file: " + fileName); _logger.Info("Total number of records in file: " + recordsInFile); var failedRecords = new List <CustomerEligibilityUploadViewModel>(); var parseEligibilityData = ParseEligibilityData(patientData.AsEnumerable(), failedRecords); if (parseEligibilityData.Any()) { foreach (var customerEligibility in parseEligibilityData) { try { _logger.Info("Getting customer for AcesId: " + customerEligibility.AcesId); List <Customer> customers = null; var errorMesage = string.Empty; if (!string.IsNullOrWhiteSpace((customerEligibility.AcesId)) || !string.IsNullOrWhiteSpace(customerEligibility.MemberId)) { if (!string.IsNullOrWhiteSpace(customerEligibility.AcesId)) { customers = _customerRepository.GetCustomersByAcesId(customerEligibility.AcesId); if (customers.IsNullOrEmpty()) { errorMesage = "Customer not found for AcesId: " + customerEligibility.AcesId; _logger.Info(errorMesage); } } else { errorMesage = "AcesId not provided for Member Id: " + customerEligibility.MemberId; _logger.Info(errorMesage); } if (customers.IsNullOrEmpty()) { if (!string.IsNullOrWhiteSpace(customerEligibility.MemberId)) { customers = _customerRepository.GetCustomersByMemberId(customerEligibility.MemberId); if (customers.IsNullOrEmpty()) { errorMesage = errorMesage + ", " + "Customer not found for Member ID: " + customerEligibility.MemberId; _logger.Info(errorMesage); } } else { errorMesage = errorMesage + " , " + "Member Id not provided for AcesId: " + customerEligibility.AcesId; _logger.Info(errorMesage); } } if (customers.IsNullOrEmpty()) { customerEligibility.Error = errorMesage; failedRecords.Add(customerEligibility); _logger.Info("Record not parsed: " + errorMesage); continue; } bool?eligibility = null; if (customerEligibility.Eligibility.ToLower() == CustomerEligibilityYes.ToLower()) { eligibility = true; } else if (customerEligibility.Eligibility.ToLower() == CustomerEligibilityNo.ToLower()) { eligibility = false; } int eligibilityYear = Convert.ToInt32(customerEligibility.EligibilityYear); foreach (var customer in customers) { _customerEligibilityService.Save(customer.CustomerId, eligibilityYear, eligibility, OrgRoleId, _logger); _logger.Info("Customer Eligibility inserted successfully for CustomerID: " + customer.CustomerId); } } else { errorMesage = "Aces Id or Member Id not provided "; customerEligibility.Error = errorMesage; failedRecords.Add(customerEligibility); _logger.Info("Record not parsed " + errorMesage); } } catch (Exception ex) { customerEligibility.Error = "Some error occurred while saving record."; failedRecords.Add(customerEligibility); _logger.Error(string.Format("Error occurred while saving record for AcesId: {0}.\nMessage: {1}\n\tStackTrace: {2}", customerEligibility.AcesId, ex.Message, ex.StackTrace)); } } } CreateFailedUploadFile(fileName, failedFolder, failedRecords); MoveFile(file, Path.Combine(archiveFolder, fileName)); } catch (Exception ex) { _logger.Error(string.Format("Error occurred while processing the {0}.\nMessage: {1}\n\tStackTrace: {2}", file, ex.Message, ex.StackTrace)); MoveFile(file, Path.Combine(failedFolder, fileName)); } } _logger.Info("File parsing completed @ " + DateTime.Now); try { _logger.Info("Copying failed file at SFTP"); var failedFiles = DirectoryOperationsHelper.GetFiles(failedFolder, "*.txt"); if (failedFiles.IsNullOrEmpty()) { _logger.Info("No failed files found to copy at SFTP."); return; } _logger.Info("Creating failed folder at SFTP " + sftpFileLocation); var sftpFailedFolder = Path.Combine(sftpFileLocation, "FailedCustomerRecords", DateTime.Today.ToString("yyyyMMdd")); DirectoryOperationsHelper.CreateDirectoryIfNotExist(sftpFailedFolder); foreach (var file in failedFiles) { var failedFileName = Path.GetFileName(file); try { DirectoryOperationsHelper.Copy(file, Path.Combine(sftpFailedFolder, failedFileName)); } catch (Exception ex) { _logger.Error(string.Format("Copying faield file not succeed for {0}. \nException Message: {1}\n\tStackTrace:{2}", failedFileName, ex.Message, ex.StackTrace)); } } _logger.Info("All failed files copied at " + sftpFailedFolder + " location."); } catch (Exception ex) { _logger.Error(string.Format("Exception occurred during copying failed file at SFTP. \nException Message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace)); return; } } catch (Exception ex) { _logger.Error(string.Format("Exception occurred during execution of servcie. \nException Message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace)); return; } }