private void CreateFailedUploadFile(string file, MediaLocation mediaLocation, List <MemberUploadbyAcesFailedCustomerModel> failedRecords, CorporateUpload corportateUpload) { if (failedRecords.Any()) { try { var nameWithoutExt = Path.GetFileNameWithoutExtension(file); var fileName = nameWithoutExt + "_Failed_" + DateTime.Now.ToString("MMddyyyyHHmmss") + ".txt"; var sourceFailedLocation = Path.Combine(mediaLocation.PhysicalPath, fileName); DirectoryOperationsHelper.DeleteFileIfExist(sourceFailedLocation); _logger.Info("Number of failed Records: " + failedRecords.Count); _logger.Info("Creating file for failed records..."); _pipeDelimitedReportHelper.Write(failedRecords.OrderBy(x => x.CustomerId), mediaLocation.PhysicalPath, fileName); _logger.Info("failed records file created."); _logger.Info("Failed file Coping in Client Location."); var targetFailedFoler = Path.Combine(_memberUploadbyAcesSourceFolderPath, DateTime.Today.ToString("yyyyMMdd"), "Failed"); DirectoryOperationsHelper.CreateDirectoryIfNotExist(targetFailedFoler); var targetFailedLocation = Path.Combine(targetFailedFoler, fileName); DirectoryOperationsHelper.CopyWithReplace(sourceFailedLocation, targetFailedLocation); _memberUploadByAcesHelper.UploadFailedFile(sourceFailedLocation, corportateUpload); _logger.Info("Failed Record Path:" + sourceFailedLocation); _logger.Info("Client Failed Record Path:" + targetFailedLocation); _logger.Info("Failed file Copied in Client Location."); } catch (Exception ex) { _logger.Error(string.Format("Error occurred while creating failed records file. \nException Message: {0}\n\tStackTrace: {1}", ex.Message, ex.StackTrace)); } } }
private void CopyMediaFile(string sourceFileName, string destinationPath, string newFileName) { try { DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationPath); if (DirectoryOperationsHelper.IsFileExist(sourceFileName)) { var destinationFile = Path.Combine(destinationPath, newFileName); DirectoryOperationsHelper.CopyWithReplace(sourceFileName, destinationFile); _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("Message: Media file ( " + sourceFileName + " ) does not exist on Media file Location. Exception : " + ex.Message); _logger.Error("StackTrace:" + ex.StackTrace); } }