Example #1
0
        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, "");
                }
            }
        }