Esempio n. 1
0
        /// <summary>
        ///     Determines whether [is allowed extension] [the specified extension].
        /// </summary>
        /// <param name="extension">The extension.</param>
        /// <param name="fileType">Type of the file.</param>
        /// <returns></returns>
        /// <createdOn>1/27/2016 8:00 AM</createdOn>
        /// <exception cref="System.ArgumentOutOfRangeException">null</exception>
        public static bool IsAllowedExtension(string extension, FileType fileType = FileType.Image)
        {
            var isAllowed = false;

            switch (fileType)
            {
            case FileType.Image:
                isAllowed = ImageExtensions.Contains(extension);
                break;

            case FileType.Document:
                isAllowed = DocumentExtensions.Contains(extension);
                break;

            case FileType.Presentation:
                isAllowed = PresentationExtensions.Contains(extension);
                break;

            case FileType.Spreadsheet:
                isAllowed = SpreadsheetExtensions.Contains(extension);
                break;

            case FileType.CompressedFile:
                isAllowed = CompressedFileExtensions.Contains(extension);
                break;

            case FileType.Website:
                isAllowed = WebsiteExtensions.Contains(extension);
                break;

            case FileType.Sound:
                isAllowed = SoundExtensions.Contains(extension);
                break;

            case FileType.Video:
                isAllowed = VideoExtensions.Contains(extension);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(fileType), fileType, null);
            }

            return(isAllowed);
        }
Esempio n. 2
0
 protected override StageResult Extract(int?recordBatchSize = null, int?recordLimit = null, Dictionary <string, string> options = null)
 {
     if (CompressedFileExtensions.Contains(InputFile.Extension))
     {
         using (FileStream stream = InputFile.OpenRead())
             using (IReader reader = ReaderFactory.Open(stream))
             {
                 bool fileFound = false;
                 while (reader.MoveToNextEntry())
                 {
                     if (!reader.Entry.IsDirectory)
                     {
                         fileFound = true;
                         break;
                     }
                 }
                 if (!fileFound)
                 {
                     Error("{0} has no file entries in zip archive.".F(InputFile.FullName));
                     return(StageResult.INPUT_ERROR);
                 }
                 else
                 {
                     Info("Unzipping file {0} with size {1} bytes.", reader.Entry.Key, reader.Entry.Size);
                 }
                 using (Stream rs = reader.OpenEntryStream())
                     using (StreamReader r = new StreamReader(rs))
                     {
                         ExtractedRecords.AddRange(ReadRecordsFromFileStream(this, r, WriterOptions));
                     }
             }
     }
     else
     {
         Info("Reading file {0} with size {1} bytes...", InputFile.Name, InputFile.Length);
         using (FileStream f = InputFile.OpenRead())
             using (StreamReader r = new StreamReader(f))
             {
                 ExtractedRecords.AddRange(ReadRecordsFromFileStream(this, r, WriterOptions));
             }
     }
     return(StageResult.SUCCESS);
 }