Exemple #1
0
        private bool CheckAndReportIfRootYearFolderExists(string fileYear, Document document)
        {
            if (Directory.Exists(Path.Combine(RootDir, fileYear))) return true;

            // Error, cannot create root level network share folder.  Log to Database.
            // Error Root Level Folder Missing
            // Directory.CreateDirectory(Path.Combine(rootDir,fileYear));
            // Log error to DocumentationIssues
            LogError(document.Id, document.Location, document.FilenameAndPath,
                     "Could not create root folder, log to skip this file", document.FileNumber);
            return false;
        }
Exemple #2
0
        private bool CheckAndLogIfFileExists(FileSystemInfo fileinfo, Document document)
        {
            if (fileinfo.Exists) return true;

            // Log error to DocumentationIssues
            const string msg = "This file does not exist";
            LogError(document.Id, document.Location, "This file does not exist", msg, document.FileNumber);
            Console.WriteLine(
                "This file did not exist, logged it to the database and moving on to the next file.");

            return false;
        }
Exemple #3
0
        private async void ProcessDocument(Document document)
        {
            Console.WriteLine("Current File #: {0}", _fileCount);
            Console.WriteLine("Working on document {0}", document.Id);

            var fileinfo = new FileInfo(document.FilenameAndPath);

            if (!CheckAndLogIfFileExists(fileinfo, document))
            {
                _errorCount++;
                return;
            }

            // file exists begin process to create new folders
            var fileYear = "DOCS" + document.CreatedOn.Year.ToString(CultureInfo.InvariantCulture);
            var fileMonth = document.CreatedOn.ToString("MMM");

            Console.WriteLine("File Exists, checking to make sure the directories needed exist.");

            if (!CheckAndReportIfRootYearFolderExists(fileYear, document))
            {
                _errorCount++;
                return;
            }

            if (!Directory.Exists(Path.Combine(RootDir, fileYear, fileMonth)))
            {
                // Create the month folder
                Directory.CreateDirectory(Path.Combine(RootDir, fileYear, fileMonth));
                Console.WriteLine("The month folder did not exist, created {0} folder",
                                  fileMonth);
            }

            // Call method to update location in database and move tile
            await UpdateDocumentAsync(document.Id, Path.Combine(RootDir, fileYear, fileMonth));
            fileinfo.MoveTo(Path.Combine(RootDir, fileYear, fileMonth, document.Filename));
            //File.Move(Path.Combine(location, fileName), Path.Combine(rootDir, fileYear, fileMonth, fileName));

            LogError(document.Id, document.Location, document.FilenameAndPath, "SUCCESS", document.FileNumber);
            //runLoop = false;
            Console.WriteLine(
                "Successfully moved and logged the file, checking for more files.");
            _fileCount++;
        }