private BaseFileReader readerType(FileExtention fileExtention, string filePath)
        {
            string fullFileNameWithExtentions = $"{filePath}{fileExtention.GetFileExtension()}";

            switch (fileExtention)
            {
            case FileExtention.dat:
                return(new BaseFileReader(fullFileNameWithExtentions));

            case FileExtention.dpo:
                return(new DpoFileReader(fullFileNameWithExtentions));

            case FileExtention.ipf:
                return(new IpfReader(fullFileNameWithExtentions));

            case FileExtention.pcap:
                return(new PcapReader(fullFileNameWithExtentions));

            case FileExtention.sig:
                return(new SigFileReader(fullFileNameWithExtentions));

            default:
                return(new BaseFileReader(fullFileNameWithExtentions));
            }
        }
示例#2
0
        public static int DeleteFile(string path)
        {
            string FileExtention;

            FileExtention = path.Substring((path.Length - 3), 3);
            FileExtention = FileExtention.ToUpper();

            if ((FileExtention != "TRC") && (FileExtention != "BAK") && (FileExtention != "TRN") &&
                (FileExtention != "ADF") && (FileExtention != "CER") && (FileExtention != "KEY"))
            {
                return(1);
            }

            if (!File.Exists(path))
            {
                return(2);
            }

            File.Delete(path);

            if (File.Exists(path))
            {
                return(3);
            }

            return(0);
        }
        public void ReadFromFile_FileDoesNotExists_ReturnsFileNotFoundException()
        {
            //Arrange
            var filePath = "sample_of_non_existing_file.txt";

            //Act

            //Act => Assert
            Assert.ThrowsException <FileNotFoundException>(() => FileExtention.ReadFromFile(filePath));
        }
        public NinjectConverterConfig(ConvertorParams convertorParams)
        {
            _readFileExtention = convertorParams.ReadFileExtention;
            _readFilePath      = convertorParams.ReadFilePath;

            _writeFileExtention = convertorParams.WriteFileExtention;
            _writeFilePath      = convertorParams.WriteFilePath;

            _handlerType = convertorParams.HandlerType;
        }
        public void WriteToFile_StringIsNull_ReturnsArgumentException()
        {
            //Arrange
            var    filePath = "sample.txt";
            string str      = "";

            //Act

            //Act => Assert
            Assert.ThrowsException <ArgumentException>(() => FileExtention.WriteToFile(filePath, str));
        }
        public void WriteToFile_FileDoesNotExists_ReturnsFileNotFoundException()
        {
            //Arrange
            var filePath = "sample_of_non_existing_file.txt";
            var str      = "Test string";

            //Act

            //Act => Assert
            Assert.ThrowsException <FileNotFoundException>(() => FileExtention.WriteToFile(filePath, str));
        }
        public void ReadFromFile_FileExists_ReturnsString()
        {
            //Arrange
            var filePath = "sample.txt";
            //Act
            var result = FileExtention.ReadFromFile(filePath);

            //Assert
            Assert.IsInstanceOfType(result, typeof(string));
            Assert.AreEqual(result.IndexOfAny(new char[] { '\n', '\r', '\0' }), -1);
        }
示例#8
0
        public string CreateThumbnail(string contentType, Stream fileStream)
        {
            var type = FileExtention.ResolveFileExtention(contentType);

            var res = ConvertToBase64(
                this.thumbnailGenerators.GetValueOrDefault(type).Invoke(fileStream)
                );

            fileStream.Close();

            return(res);
        }
示例#9
0
        public IActionResult NewsFile()
        {
            var path = $"{_ev.WebRootPath}/File/COVID-19 Education.pdf";

            var Memory = new MemoryStream();

            using (var Stream = new FileStream(path, FileMode.Open))
            {
                Stream.CopyTo(Memory);
            }
            Memory.Position = 0;
            return(File(Memory, FileExtention.GetContentType(path)));
        }
示例#10
0
        public IActionResult Download(int id)
        {
            var Lesson = _context.Lessons.Find(id);
            var path   = $"{_ev.WebRootPath}/File/{Lesson.Suammary}";

            if (Lesson.Suammary == null)
            {
                return(Redirect("/Home/NotFoundFile"));
            }
            var Memory = new MemoryStream();

            using (var Stream = new FileStream(path, FileMode.Open))
            {
                Stream.CopyTo(Memory);
            }
            Memory.Position = 0;
            return(File(Memory, FileExtention.GetContentType(path), Lesson.Suammary));
        }
示例#11
0
        /// <summary>
        /// Read the content of a text file
        /// </summary>
        /// <param name="filePath">File to read</param>
        /// <returns>Content of the text file</returns>
        public string ReadTextFile(string filePath)
        {
            if (filePath.EndsWith("/") || filePath.EndsWith("\\"))
            {
                throw new ArgumentException("The requested path is not a file");
            }

            //File must exists
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(string.Format("Text File {0} does not exist", filePath));
            }

            if (!FileExtention.IsExtentionSupported(filePath))
            {
                throw new ArgumentOutOfRangeException("Specified type is not supported");
            }

            StreamReaderTool streamReaderTool = new StreamReaderTool();
            string           fileContent      = streamReaderTool.ReadFile(filePath);

            return(fileContent);
        }