public void ProcessFile(string fileNameAndPath, string outputDir, string failedDir, string processedDir, string callerRef, string sentTo) { DocConverterFactory factory = new DocConverterFactory(); factory._logFile = _logFile; factory.StartConverter(); FileInfo file = new FileInfo(fileNameAndPath); try { IDocConverter converter = factory.GetDocConverter(file.FullName); converter.Convert(file.FullName, file.FullName, outputDir, processedDir, callerRef, sentTo); } catch (Exception e) { string mailMsg = "The file ''" + file.FullName + "'' has been moved to the directory " + failedDir + @"\" + Properties.Settings.Default.FailedSubDirConvert + ";" + Environment.NewLine + Environment.NewLine + "Reason:" + Environment.NewLine + "There was an issue converting this file to TIF format. " + Environment.NewLine + e.Message; MailUtils.SendEmail("Error", "Converting File", mailMsg, fileNameAndPath); FileUtils.MoveToDir(file, failedDir + @"\" + Properties.Settings.Default.FailedSubDirConvert); throw new FormatConversionException("Error: ''" + file.FullName + "'' has been moved to the directory " + failedDir + "; " + Environment.NewLine + e.Message); } factory.ShutdownConverter(); }
public void ProcessFile(string fileNameAndPath) { try { writeToDebugLog("ProcessFile", "----------------------------------------------------------"); writeToDebugLog("ProcessFile", "Processing: " + fileNameAndPath); string extWithPeriod = Path.GetExtension(fileNameAndPath); string ext = extWithPeriod.Replace(".", ""); string callerRef = getCallerRef(fileNameAndPath); //writeToDebugLog("ProcessFile", "callerRef=" + callerRef); string sentTo = getSentTo(fileNameAndPath); //writeToDebugLog("ProcessFile", "sentTo=" + sentTo); if (fileNameAndPath.Contains(THUMBS_DB)) { return; } else if (_validExtList.Contains(ext, StringComparer.OrdinalIgnoreCase)) { writeToDebugLog("ProcessFile", "ext=" + ext + " is a valid extension. Processing..."); writeToDebugLog("ProcessFile", "DocConverter - Initializing."); Controller controller = new Controller(); controller._logFile = _debugLog; writeToDebugLog("ProcessFile", "DocConverter - Sending sourceFile=" + fileNameAndPath + "; failedDir=" + this._failedDir + "; processedDir=" + this._processedDir); controller.ProcessFile(fileNameAndPath, this._outputDir, this._failedDir, "", callerRef, sentTo); writeToDebugLog("ProcessFile", "DocConverter - Completed."); //Move original data file to processed dir string origNameOnly = Path.GetFileName(fileNameAndPath); string datafileProcessedNameAndPath = Path.Combine(_processedDir, origNameOnly); bool processedFileExists = File.Exists(datafileProcessedNameAndPath); writeToDebugLog("ProcessFile", "Processed sourceFile(" + datafileProcessedNameAndPath + ") exists=" + processedFileExists); if (File.Exists(fileNameAndPath)) //jvc make sure not already moved due to fail { writeToDebugLog("ProcessFile", "Moving sourcefile to processedDir: " + datafileProcessedNameAndPath); FileUtils.MoveToDir(new FileInfo(fileNameAndPath), _processedDir); writeToDebugLog("ProcessFile", "Move file complete."); } writeToDebugLog("ProcessFile", "Processing Complete: " + fileNameAndPath); _EventLog.WriteToLog("--> ProcessFile - Complete: " + fileNameAndPath); } else { writeToDebugLog("ProcessFile", "Skipped File: " + fileNameAndPath); _EventLog.WriteToLog("-->** Skipped File: " + fileNameAndPath); string mailMsg = "The file ''" + fileNameAndPath + "'' was skipped because it is not in a supported format (" + Properties.Settings.Default.ValidFileExt + ")." + Environment.NewLine + "It has been moved to the directory " + _failedDir + @"\" + Properties.Settings.Default.FailedSubDirUnsupported + "."; MailUtils.SendEmail("Warning", "Unsupported File Format", mailMsg, fileNameAndPath); FileUtils.MoveToDir(new FileInfo(fileNameAndPath), _failedDir + @"\" + Properties.Settings.Default.FailedSubDirUnsupported); } //Israel 5/13/2015 -- address generated name collision. int milliseconds = 2000; Thread.Sleep(milliseconds); } catch (FormatConversionException ex) { writeToDebugLog("ProcessFile", "ERROR: " + ex.Message); _EventLog.WriteToLog("ERROR Processing: " + fileNameAndPath + "; " + ex.Message); } catch (Exception e) { string erMsg = "ERROR Processing: " + fileNameAndPath + "; " + Environment.NewLine + e.Message + "." + Environment.NewLine + Environment.NewLine + "Stack Trace:" + Environment.NewLine + e.StackTrace; writeToDebugLog("ProcessFile", erMsg); _EventLog.WriteToLog(erMsg); if (File.Exists(fileNameAndPath)) { string mailMsg = "The file ''" + fileNameAndPath + "'' has been moved to the directory " + this._failedDir + ";" + Environment.NewLine + Environment.NewLine + "Reason:" + Environment.NewLine + "There was an issue while processing this file. " + e.Message + "." + Environment.NewLine + Environment.NewLine + "Stack Trace:" + Environment.NewLine + e.StackTrace; MailUtils.SendEmail("Error", "Exception Processing Inbound File", mailMsg, fileNameAndPath); writeToDebugLog("ProcessFile", "Moving sourcefile to failedDir: " + fileNameAndPath); FileUtils.MoveToDir(new FileInfo(fileNameAndPath), this._failedDir); writeToDebugLog("ProcessFile", "Move file complete."); } else { string mailMsg = "There was an exception processing file ''" + fileNameAndPath + "'';" + Environment.NewLine + Environment.NewLine + "Reason:" + Environment.NewLine + e.Message + "." + Environment.NewLine + Environment.NewLine + "Stack Trace:" + Environment.NewLine + e.StackTrace; MailUtils.SendEmail("Error", "Exception Processing Inbound File", mailMsg, ""); } } }