Ejemplo n.º 1
0
        public void NotFoundInsertFound()
        {
            var dbName = GetTempDBName();

            using (var cache = new CacheDB(dbName))
            {
                var sourceCodeFile = new SourceCodeFile("XXX", "test");

                cache.TryGetValue(sourceCodeFile, out var codeInfo).Should().Be(false);

                var newCodeInfo = BuildDummyCodeInfo(sourceCodeFile);

                cache.Add(newCodeInfo);

                cache.TryGetValue(sourceCodeFile, out codeInfo).Should().Be(true);

                codeInfo.Should().BeEquivalentTo(newCodeInfo);
            }

            File.Delete(dbName);
        }
        public List <Duplicate> Execute()
        {
            ProcessUpdate?.Invoke($"Updating Cache ({Configuration.CacheFileName})");

            using (var cacheDB = new CacheDB(Configuration.CacheFileName))
            {
                var methodExtractor = new MethodExtractor();
                var finder          = new DuplicateFinder(Configuration);

                var files = Directory.EnumerateFiles(Configuration.SourceDirectory, "*.prg", SearchOption.AllDirectories).ToList();
                ProcessUpdate?.Invoke($"Found {files.Count} source files");

                var index = 1;
                foreach (var fileName in files)
                {
                    var sourceCodeFile = new SourceCodeFile(fileName);

                    ProcessUpdate?.Invoke($"[{index++} of {files.Count}] {sourceCodeFile.RelativeFileName(Configuration.SourceDirectory)}");

                    try
                    {
                        if (!cacheDB.TryGetValue(sourceCodeFile, out var codeInfo))
                        {
                            codeInfo = methodExtractor.Execute(sourceCodeFile);
                            cacheDB.Add(codeInfo);
                        }
                        finder.AddSourceCodeFile(sourceCodeFile, codeInfo);
                    }
                    catch
                    {
                        ProcessUpdate?.Invoke("File could not be parsed and will be skipped");
                    }
                }

                ProcessUpdate?.Invoke("Identifying duplicates");
                var result = finder.Execute();
                ProcessUpdate?.Invoke($"{(result.Count > 0 ? result.Count.ToString() : "No")} duplicates found");

                return(result);
            }
        }