Exemplo n.º 1
0
 private void PrepareOutputFolder(string folderPath)
 {
     if (_fileProvider.DirectoryExists(folderPath))
     {
         foreach (var path in _fileProvider.EnumerateFiles(folderPath))
         {
             _fileProvider.Delete(path);
         }
     }
     else
     {
         _fileProvider.CreateDirectory(folderPath);
     }
 }
Exemplo n.º 2
0
        public async Task <IEnumerable <string> > GetExpiredFilesAsync(CancellationToken cancellationToken)
        {
            var directoryEnum = _directoryPath.StartsWith(_fileProvider.UploadedFilesDirectory.TrimEnd('/', '\\')) ? DirectoryEnum.Uploaded : DirectoryEnum.Published;
            var expiredFiles  = (await _fileProvider.EnumerateFiles(directoryEnum, "*.expiration"))
                                .Select(Path.GetFileNameWithoutExtension)
                                .Select(f => new InternalFileId(f))
                                .Where(f => FileHasExpired(f) && FileIsIncomplete(f))
                                .Select(f => f.FileId)
                                .ToList();

            return(expiredFiles);

            bool FileHasExpired(InternalFileId fileId)
            {
                var firstLine = _fileRepFactory.Expiration(fileId).ReadFirstLine();

                return(!string.IsNullOrWhiteSpace(firstLine) &&
                       HasPassed(DateTimeOffset.ParseExact(firstLine, "O", null)));
            }

            bool FileIsIncomplete(InternalFileId fileId) =>
            _fileRepFactory.UploadLength(fileId).ReadFirstLineAsLong() != _fileRepFactory.Data(fileId).GetLength();
        }