Beispiel #1
0
        public bool ProcessAllFiles(string folderPath, IArchivalHandler archivalHandler, ref List <DataFile> dataFiles)
        {
            try
            {
                log.Debug("Start ProcessAllFiles()");
                var fileTypes = FileTypes.GetFileTypes();


                dataFiles = FetchAllDataFiles(fileTypes, folderPath);
                bool atleastOneFileFound = true;

                if (dataFiles.Count() == 0)
                {
                    atleastOneFileFound = false;
                    log.Warn("No Files Found in Input Directory, Exiting Processing!");
                }
                else
                {
                    double divergencePercentage = Convert.ToDouble(ConfigurationManager.AppSettings["DivergencePercentage"]);
                    foreach (DataFile dataFile in dataFiles)
                    {
                        try
                        {
                            FileProcessStatus fileProcessStatus = FileProcessStatus.Undetermined;
                            fileProcessStatus         = ProcessInputFile(dataFile, fileTypes, folderPath, divergencePercentage);
                            fileProcessStatus         = ProcessFileArchival(fileProcessStatus, dataFile.FileName, folderPath, archivalHandler);
                            dataFile.ProcessingStatus = fileProcessStatus;
                        }
                        catch (Exception ex)
                        {
                            log.Error("File processing has unexpectedly failed for " + dataFile.FileName + " Continuing processing for other files, if any!");
                            log.Error(ex);
                        }
                    }
                    OutputStatistics(dataFiles, divergencePercentage);
                }


                log.Info("Read Completed");
                return(atleastOneFileFound);
            }

            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        public FileProcessStatus ProcessFileArchival(FileProcessStatus fileProcessStatus, string fileName, string folderPath, IArchivalHandler archivalHandler)
        {
            try
            {
                log.Debug("Start ProcessFileArchival()");
                FileProcessStatus archiveProcessStatus = FileProcessStatus.Undetermined;
                if (fileProcessStatus == FileProcessStatus.FileSuccessfullyProccessed)
                {
                    archiveProcessStatus = ArchiveFile(fileName, folderPath, FileArchivalType.Archive, archivalHandler);
                    archiveProcessStatus = FileProcessStatus.FileSuccessfullyArchived;
                }
                else if (fileProcessStatus == FileProcessStatus.FileRowsSkipped)
                {
                    archiveProcessStatus = ArchiveFile(fileName, folderPath, FileArchivalType.PartiallyProccessed, archivalHandler);
                    archiveProcessStatus = FileProcessStatus.FileSuccessfullyArchivedToPartial;
                }
                else
                {
                    archiveProcessStatus = ArchiveFile(fileName, folderPath, FileArchivalType.Error, archivalHandler);
                    archiveProcessStatus = FileProcessStatus.FileSuccessfullyArchivedToError;
                }

                return(archiveProcessStatus);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #3
0
        public FileProcessStatus ArchiveFile(string fileName, string folderPath, FileArchivalType fileArchivalType, IArchivalHandler archivalHandler)
        {
            try
            {
                log.Debug("Start ArchiveFile()");
                string            destinationFolderType;
                FileProcessStatus fileProcessStatus = FileProcessStatus.Undetermined;

                if (fileArchivalType == FileArchivalType.Archive)
                {
                    destinationFolderType = "Archive";
                }
                else if (fileArchivalType == FileArchivalType.Error)
                {
                    destinationFolderType = "Error";
                }
                else if (fileArchivalType == FileArchivalType.PartiallyProccessed)
                {
                    destinationFolderType = "PartiallyProcessed";
                }
                else
                {
                    destinationFolderType = "Archive";
                }


                string destinationFullPath = folderPath + "\\" + destinationFolderType + "\\" + fileName;
                string sourceFullPath      = folderPath + fileName;

                if (archivalHandler.CreateDirectory(folderPath + "\\" + destinationFolderType))
                {
                    if (!archivalHandler.FileExists(destinationFullPath))
                    {
                        fileProcessStatus = archivalHandler.MoveFile(sourceFullPath, destinationFullPath);
                    }
                    else
                    {
                        if (archivalHandler.DeleteFile(destinationFullPath))
                        {
                            fileProcessStatus = archivalHandler.MoveFile(sourceFullPath, destinationFullPath);
                        }
                    }
                }

                return(fileProcessStatus);
            }

            catch (Exception)
            {
                throw;
            }
        }