예제 #1
0
        private IEnumerable <string> GetFilePathsFromInFolder(string basePath, string inFolder)
        {
            var fullPath = basePath;

            if (!string.IsNullOrWhiteSpace(inFolder))
            {
                fullPath = _pathCombiner.Combine(basePath, inFolder);
            }

            var filePaths = _directoryReader.GetFilePathsInFolder(fullPath);

            return(filePaths);
        }
        public void ParseFiles(string basePath, string inFolder, string type, string outFolder)
        {
            if (!string.IsNullOrWhiteSpace(basePath) &&
                !string.IsNullOrWhiteSpace(type))
            {
                var fp = basePath;
                if (!string.IsNullOrWhiteSpace(inFolder))
                {
                    fp = _pathCombiner.Combine(basePath, inFolder);
                }
                var files = _directoryReader.GetFilePathsInFolder(fp);
                if (files.Count() != 0)
                {
                    var fileContents = new List <string>();
                    foreach (var file in files)
                    {
                        var content = _fileReader.ReadFile(file);
                        fileContents.Add(content);
                    }
                    var validFiles = new List <string>();
                    foreach (var content in fileContents)
                    {
                        var parts = content.Split(";");
                        if (parts.Length == 6 && parts[0] == type)
                        {
                            validFiles.Add(content);
                            _validFiles++;
                        }
                        else
                        {
                            _invalidFiles++;
                        }
                    }

                    for (var i = 0; i < validFiles.Count; i++)
                    {
                        var fpout = basePath;
                        if (!string.IsNullOrWhiteSpace(outFolder))
                        {
                            fpout = _pathCombiner.Combine(basePath, outFolder);
                        }
                        _fileWriter.WriteFileToFolder($"{i + 1}.txt", validFiles[i], fpout);
                    }
                }
            }
        }
        public IEnumerable <FileToProcess> GetFilesToProcess(InputPath inputPath)
        {
            Assert.IsNotNull(inputPath, nameof(inputPath));

            var fullPath = inputPath.BasePath;

            if (inputPath.HasInFolder())
            {
                fullPath = _pathCombiner.Combine(inputPath.BasePath, inputPath.InFolder);
            }

            var filePaths = _directoryReader.GetFilePathsInFolder(fullPath);

            return(filePaths.Select(filePath => new FileToProcess(filePath)));
        }
        public void WriteValidFileContents(OutputPath outputPath, IEnumerable <ValidFileContents> validFiles)
        {
            Assert.IsNotNull(outputPath, nameof(outputPath));
            Assert.IsNotNull(validFiles, nameof(validFiles));

            var validFilesList = validFiles.ToList();

            for (var i = 0; i < validFilesList.Count; i++)
            {
                var absoluteOutPath = outputPath.BasePath;
                if (outputPath.HasOutFolder())
                {
                    absoluteOutPath = _pathCombiner.Combine(outputPath.BasePath, outputPath.OutFolder);
                }

                _fileWriter.WriteFileToFolder($"{i + 1}.txt", validFilesList[i].FileContents.Contents, absoluteOutPath);
            }
        }
        public void WriteFileToFolder(string filename, string contents, string folder)
        {
            var fullFilePath = _pathCombiner.Combine(folder, filename);

            System.IO.File.WriteAllText(fullFilePath, contents);
        }