Esempio n. 1
0
        /// <inheritdoc />
        public async Task <FileInfo> FindJournalFile(DirectoryInfo journalDirectory)
        {
            try
            {
                var files = await FindJournalFiles(journalDirectory);

                return(files
                       .OrderByDescending(file => file.LastWriteTime)
                       .First());
            }
            catch (Exception ex)
            {
                Exception exception = new JournalFileNotFoundException("Could not find journal file", ex);
                exception.Data.Add("Path", journalDirectory.FullName);
                _log.LogTrace(exception, "Could not get active journal file from journal directory");
                return(await Task.FromException <FileInfo>(exception));
            }
        }
Esempio n. 2
0
        /// <inheritdoc />
        public async Task <FileInfo[]> FindJournalFiles(DirectoryInfo journalDirectory)
        {
            try
            {
                var fileFilter = !string.IsNullOrWhiteSpace(_config.GetSection("EliteAPI")["Journal"]) ? _config.GetSection("EliteAPI")["Journal"] : _codeConfig.JournalFile;

                return(journalDirectory
                       .GetFiles(fileFilter)
                       .OrderByDescending(file => file.LastWriteTime)
                       .ToArray());
            }
            catch (Exception ex)
            {
                Exception exception = new JournalFileNotFoundException("Could not find journal files", ex);
                exception.Data.Add("Path", journalDirectory.FullName);
                _log.LogTrace(exception, "Could not get journal files from journal directory");
                return(await Task.FromException <FileInfo[]>(exception));
            }
        }
Esempio n. 3
0
        private Exception CheckDirectoryValidity(DirectoryInfo directory)
        {
            if (directory == null)
            {
                return(new NullReferenceException());
            }

            if (!directory.Exists)
            {
                var exception = new JournalDirectoryNotFoundException("The journal directory does not exist");
                exception.Data.Add("Path", directory.FullName);
                return(exception);
            }

            if (directory.GetFiles("Journal.*.log").Length == 0)
            {
                var exception = new JournalFileNotFoundException("No journal files could be found in the directory");
                exception.Data.Add("Path", directory.FullName);
                return(exception);
            }

            return(null);
        }