コード例 #1
0
 public ScanComparer(ILogger logger, IFileReader fileReader, IDirectoryReader directoryReader, IPathReader pathReader)
 {
     this._logger     = logger;
     _fileReader      = fileReader;
     _directoryReader = directoryReader;
     _pathReader      = pathReader;
 }
コード例 #2
0
 public ProcessorStorageFilesWork(IMathBuffer maths, ICalcIO calcIO, IOperationsHistory operationsHistory, IExpressionParser mathExpressionParser, IPathReader filePathReader, ICalcInputParser inputParser)
 {
     Maths                = maths;
     CalcIO               = calcIO;
     OperationsHistory    = operationsHistory;
     MathExpressionParser = mathExpressionParser;
     FilePathReader       = filePathReader;
     InputParser          = inputParser;
 }
コード例 #3
0
        public bool Run(IProcessorStorage storage)
        {
            IMathBuffer mathBuffer = storage.Maths;

            List <string>     history          = null;
            IPathReader       pathReader       = null;
            IExpressionParser expressionParser = null;

            if (storage is IProcessorStorageFilesWork ext)
            {
                history          = ext.OperationsHistory.Data;
                pathReader       = ext.FilePathReader;
                expressionParser = ext.MathExpressionParser;
            }
            else
            {
                throw new ArgumentException();
            }

            var     newOperBuffer = new List <string>();
            var     valBuffer     = new List <double>();
            ICalcIO calcIO        = storage.CalcIO;

            using (var file = new StreamReader(pathReader.Read(calcIO)))
            {
                string expression, rawExpression;

                while ((rawExpression = expression = file.ReadLine()) != null)
                {
                    newOperBuffer.Add(expression);

                    double result = expressionParser.Parse(ref expression, valBuffer, calcIO);

                    if (double.IsNaN(result))
                    {
                        calcIO.Write("Parse error!\n");
                        return(true);
                    }

                    calcIO.Write($"[#{ valBuffer.Count }] { rawExpression } = { (rawExpression != expression ? $"{ expression } = " : "") }{ result }\n");
                }
            }

            mathBuffer.Values   = valBuffer;
            mathBuffer.AccValue = valBuffer.Last();

            history.Clear();
            history.AddRange(newOperBuffer);

            return(true);
        }
コード例 #4
0
 public RepositoryVisitor(
     IRepositoryVisitorFilter defaultRepositoryVisitorFilter,
     IParserFactory <Solution> solutionParserFactory,
     IRepositoryRegistry repositoryRegistry,
     IParserFactory <Project> projectParserFactory,
     IDirectoryReader directoryReader,
     IPathReader pathReader)
 {
     _defaultRepositoryVisitorFilter = defaultRepositoryVisitorFilter;
     _solutionParserFactory          = solutionParserFactory;
     _repositoryRegistry             = repositoryRegistry;
     _projectParserFactory           = projectParserFactory;
     _directoryReader = directoryReader;
     _pathReader      = pathReader;
 }
コード例 #5
0
 public ConfigurableAnalyzerCollection(IFileReader fileReader, IPathReader pathReader)
 {
     _fileReader   = fileReader;
     _fileAnalyzer = new FileAnalyzer(fileReader, pathReader);
     LoadConfiguration();
 }
コード例 #6
0
 public FileAnalyzer(IFileReader fileReader, IPathReader pathReader)
 {
     _fileReader = fileReader;
     _pathReader = pathReader;
 }
コード例 #7
0
 public SolutionParserFactory(IPathReader pathReader, IDirectoryReader directoryReader, IFileReader fileReader)
 {
     _pathReader      = pathReader;
     _directoryReader = directoryReader;
     _fileReader      = fileReader;
 }
コード例 #8
0
 public CSharpProjectParser(IRepositoryRegistry repositoryRegistry, IXmlReader xmlReader, IPathReader pathReader)
 {
     _repositoryRegistry = repositoryRegistry;
     _xmlReader          = xmlReader;
     _pathReader         = pathReader;
 }
コード例 #9
0
ファイル: FileService.cs プロジェクト: rmbits/ImportCsvToSQL
 public FileService(IPathReader pathReader = null, IFileRepository fileRepository = null)
 {
     _pathReader     = pathReader ?? new PathReader();
     _fileRepository = fileRepository ?? new FileRepository();
 }
コード例 #10
0
        public void SetUp()
        {
            _pathReader = new DefaultPathReader();

            #region Setup _directoryReaderMock
            var firstSetOfFiles = new List <string>
            {
                @"C:\Some\Repository\Project\File1.csproj",
                @"C:\Some\Repository\Project\File2.cs",
                @"C:\Some\Repository\Project\File3.cs",
                @"C:\Some\Repository\Project\File4.cs",
                @"C:\Some\Repository\Project\File5.cs",
                @"C:\Some\Repository\Project\Solution.sln",
            };

            var secondSetOfFiles = new List <string>
            {
                @"C:\Some\Repository\Project2\File21.csproj",
                @"C:\Some\Repository\Project2\File22.cs",
                @"C:\Some\Repository\Project2\File23.cs",
                @"C:\Some\Repository\Project2\File24.cs",
                @"C:\Some\Repository\Project2\File25.cs",
            };

            var thirdSetOfFiles = new List <string>
            {
                @"C:\Some\OtherRepo\Project\File31.csproj",
                @"C:\Some\OtherRepo\Project\File32.cs",
                @"C:\Some\OtherRepo\Project\File33.cs",
                @"C:\Some\OtherRepo\Project\File34.cs",
                @"C:\Some\OtherRepo\Project\File35.cs",
                @"C:\Some\OtherRepo\Project\OtherSolution.sln",
            };

            var fourthSetOfFiles = new List <string>
            {
                @"C:\Some\OtherRepo\Project\Project\File41.csproj",
                @"C:\Some\OtherRepo\Project\Project\File42.cs",
                @"C:\Some\OtherRepo\Project\Project\File43.cs",
                @"C:\Some\OtherRepo\Project\Project\File44.cs",
                @"C:\Some\OtherRepo\Project\Project\File45.cs",
            };

            _dictionaryOfFilesPerFolder = new Dictionary <string, List <string> >();
            _dictionaryOfFilesPerFolder.Add(@"C:\Some\Repository\Project", firstSetOfFiles);
            _dictionaryOfFilesPerFolder.Add(@"C:\Some\Repository\Project2", secondSetOfFiles);
            _dictionaryOfFilesPerFolder.Add(@"C:\Some\OtherRepo\Project", thirdSetOfFiles);
            _dictionaryOfFilesPerFolder.Add(@"C:\Some\OtherRepo\Project\Project", fourthSetOfFiles);

            _dictionaryOfDirectoriesInDirectory = new Dictionary <string, List <string> >();
            _dictionaryOfDirectoriesInDirectory.Add(@"C:\Some\Repository", new List <string>()
            {
                @"C:\Some\Repository\Project",
                @"C:\Some\Repository\Project2"
            });
            _dictionaryOfDirectoriesInDirectory.Add(@"C:\Some\OtherRepo", new List <string>()
            {
                @"C:\Some\OtherRepo\Project"
            });
            _dictionaryOfDirectoriesInDirectory.Add(@"C:\Some\OtherRepo\Project", new List <string>()
            {
                @"C:\Some\OtherRepo\Project\Project"
            });

            _directoryReaderMock = new Mock <IDirectoryReader>();
            _directoryReaderMock.Setup(x => x.EnumerateFiles(It.IsAny <string>())).Returns <string>((s =>
                                                                                                     _dictionaryOfFilesPerFolder.TryGetValue(s, out var files) ? files : new List <string>()));
            _directoryReaderMock.Setup(x => x.EnumerateDirectories(It.IsAny <string>())).Returns <string>(s => _dictionaryOfDirectoriesInDirectory.TryGetValue(s, out var directories)
                ? directories
                : new List <string>());

            #endregion

            #region Setup _IParserMocks
            _projectParserFactoryMock = new Mock <IParserFactory <Project> >();
            var projectParserMock = new Mock <IParser <Project> >();
            projectParserMock.Setup(x => x.Parse(It.IsAny <string>()))
            .Returns <string>(s => new Project(s, new List <SourceFile>()));
            _projectParserFactoryMock.Setup(x => x.CreateParser(It.IsAny <string>())).Returns(projectParserMock.Object);

            _solutionParserFactoryMock = new Mock <IParserFactory <Solution> >();
            var solutionParserMock = new Mock <IParser <Solution> >();
            solutionParserMock.Setup(x => x.Parse(It.IsAny <string>()))
            .Returns <string>(s => new Solution(s));
            _solutionParserFactoryMock.Setup(x => x.CreateParser(It.IsAny <string>())).Returns(solutionParserMock.Object);
            #endregion

            _repositoryVisitorFilterMock = new Mock <IRepositoryVisitorFilter>();
            // TODO: Check the strings for real
            _repositoryVisitorFilterMock.Setup(x => x.IsSourceFile(It.IsAny <string>())).Returns <string>(s => Path.GetExtension(s) == ".cs");
            _repositoryVisitorFilterMock.Setup(x => x.IsProjectFile(It.IsAny <string>())).Returns <string>(s => Path.GetExtension(s) == ".csproj");
            _repositoryVisitorFilterMock.Setup(x => x.IsSolutionFile(It.IsAny <string>())).Returns <string>(s => Path.GetExtension(s) == ".sln");

            _repositoryRegistryMock = new Mock <IRepositoryRegistry>();

            var repositories = new List <Repository>
            {
                new Repository(@"C:\Some\Repository"),
                new Repository(@"C:\Some\OtherRepo")
            };

            _repositoryRegistryMock.Setup(x => x.GetEnumerator()).Returns(() =>
            {
                _currentEnumerator = repositories.GetEnumerator();
                return(_currentEnumerator);
            });

            _repositoryRegistryMock.SetupGet(x => x.Current).Returns(() => _currentEnumerator.Current);

            _repositoryVisitor = new RepositoryVisitor(_repositoryVisitorFilterMock.Object, _solutionParserFactoryMock.Object, _repositoryRegistryMock.Object, _projectParserFactoryMock.Object,
                                                       _directoryReaderMock.Object, _pathReader);
        }