public BaseDocumentHandler(IFileProvider fileProvider, string subpath)
 {
     FileInfo = AcceptedExtensions
                .Select(x => fileProvider.GetFileInfo(subpath + x))
                .Where(x => x.Exists)
                .FirstOrDefault();
 }
        public virtual AcceptedExtensions Create(params string[] extensions)
        {
            var acceptedExtensions = AcceptedExtensions.New();

            acceptedExtensions.init(extensions);
            return(acceptedExtensions);
        }
示例#3
0
 public virtual List<FileInformation> ReadAndExclude(AcceptedExtensions acceptedExtensions, string path)
 {
     var files = _innerReader.Read(path);
     foreach (var fileInformation in files)
     {
         if (acceptedExtensions.Get(fileInformation.Extension) != null)
             _list.Add(fileInformation);
     }
     return _list;
 }
示例#4
0
        public virtual List <FileInformation> ReadAndExclude(AcceptedExtensions acceptedExtensions, string path)
        {
            var files = _innerReader.Read(path);

            foreach (var fileInformation in files)
            {
                if (acceptedExtensions.Get(fileInformation.Extension) != null)
                {
                    _list.Add(fileInformation);
                }
            }
            return(_list);
        }
        public override Stream GetStream(HttpContent parent, HttpContentHeaders headers)
        {
            _originalCount++;
            var contentDisposition = headers.ContentDisposition;

            //This is not a file?
            if (contentDisposition == null || string.IsNullOrWhiteSpace(contentDisposition.FileName))
            {
                return(base.GetStream(parent, headers));
            }

            //Content type of this file is not accepted?
            var isAccepted = AcceptedMediaTypes.Split(',')
                             .Any(mediaType => headers.ContentType.MediaType.ToLower().Contains(mediaType.ToLower()));

            if (!isAccepted)
            {
                return(Stream.Null);
            }

            //Extension of this file is not accepted?
            var extension = Path.GetExtension(contentDisposition.FileName.Replace("\"", ""));

            if (!AcceptedExtensions.ToLower().Contains(extension.ToLower()))
            {
                return(Stream.Null);
            }

            //Size of this file is larger than is allowed?
            if (contentDisposition.Size != null && contentDisposition.Size > MaxFileSize)
            {
                return(Stream.Null);
            }

            //This file is OK but we reached the MAX number of allowed files?
            if (MaxFileCount != 0 && _acceptedCount >= MaxFileCount)
            {
                return(Stream.Null);
            }

            //This is a file that we want to read
            _acceptedCount++;
            return(base.GetStream(parent, headers));
        }
示例#6
0
 protected override void Act()
 {
     Returned = Sut.Create(Extensions);
 }
示例#7
0
 protected override void Act()
 {
     Sut = new AcceptedExtensions();
 }
示例#8
0
 protected override void Act()
 {
     Sut = new AcceptedExtensions();
 }
示例#9
0
 protected override void Act()
 {
     Returned = Sut.Create(Extensions);
 }