Пример #1
0
        public void BeginFind(ResourceManager resourceManager, CodeReferenceConfiguration configuration, IEnumerable <ProjectFile> allSourceFiles, ITracer tracer)
        {
            var sourceFiles = allSourceFiles.Where(item => !item.IsResourceFile() && !item.IsDesignerFile()).ToArray();

            var resourceTableEntries = resourceManager.ResourceEntities
                                       .Where(entity => !entity.IsWinFormsDesignerResource)
                                       .SelectMany(entity => entity.Entries).ToArray();

            Interlocked.Exchange(ref _engine, new Engine(configuration, sourceFiles, resourceTableEntries, tracer))?.Dispose();
        }
Пример #2
0
            public Engine([NotNull] CodeReferenceConfiguration configuration, [NotNull][ItemNotNull] ICollection <ProjectFile> sourceFiles, [NotNull][ItemNotNull] ICollection <ResourceTableEntry> resourceTableEntries, [NotNull] ITracer tracer)
            {
                _backgroundThread = new Thread(() => FindCodeReferences(configuration, sourceFiles, resourceTableEntries, tracer))
                {
                    IsBackground = true,
                    Priority     = ThreadPriority.Lowest
                };

                _backgroundThread.Start();
            }
Пример #3
0
            private async Task FindCodeReferences(CodeReferenceConfiguration configuration, ICollection <ProjectFile> projectFiles, ICollection <ResourceTableEntry> resourceTableEntries, ITracer tracer)
            {
                var stopwatch = Stopwatch.StartNew();

                try
                {
                    _total = resourceTableEntries.Count + projectFiles.Count;

                    resourceTableEntries.ForEach(entry => entry.CodeReferences = null);

                    var keys = new HashSet <string>(resourceTableEntries.Select(entry => entry.Key));

                    var sourceFileTasks = projectFiles
                                          .Select(file => Task.Run(() => new FileInfo(file, configuration.Items, keys, ref _visited), _cancellationToken));

                    var sourceFiles = (await Task.WhenAll(sourceFileTasks).ConfigureAwait(false))
                                      .Where(file => file.HasConfigurations)
                                      .ToList();

                    var keyFilesLookup = new Dictionary <string, HashSet <FileInfo> >();

                    sourceFiles.ForEach(file => file.Keys.ForEach(key => keyFilesLookup.ForceValue(key, _ => new HashSet <FileInfo>()).Add(file)));

                    void FindReferences(ResourceTableEntry entry, IDictionary <string, HashSet <FileInfo> > keyFiles)
                    {
                        var key = entry.Key;

                        var files = keyFiles.GetValueOrDefault(key);

                        var references = new List <CodeReference>();

                        files?.ForEach(file => file.FindCodeReferences(entry, references, tracer));

                        entry.CodeReferences = references.AsReadOnly();

                        Interlocked.Increment(ref _visited);
                    }

                    var lookupTasks = resourceTableEntries.Select(entry => Task.Run(() => FindReferences(entry, keyFilesLookup), _cancellationToken));

                    await Task.WhenAll(lookupTasks).ConfigureAwait(false);

                    Debug.WriteLine(stopwatch.Elapsed);
                }
                catch (OperationCanceledException)
                {
                }
                finally
                {
                    stopwatch.Stop();
                }
            }
Пример #4
0
            private void FindCodeReferences([NotNull] CodeReferenceConfiguration configuration, [NotNull, ItemNotNull] ICollection <ProjectFile> projectFiles, [NotNull, ItemNotNull] ICollection <ResourceTableEntry> resourceTableEntries, [NotNull] ITracer tracer)
            {
                var stopwatch = Stopwatch.StartNew();

                try
                {
                    _total = resourceTableEntries.Count + projectFiles.Count;

                    resourceTableEntries.ForEach(entry => entry.CodeReferences = null);

                    var keys = new HashSet <string>(resourceTableEntries.Select(entry => entry.Key));

                    var sourceFiles = projectFiles.AsParallel()
                                      .Select(file => new FileInfo(file, configuration.Items, keys, ref _visited))
                                      .Where(file => file.HasConfigurations)
                                      .ToArray();

                    var keyFilesLookup = sourceFiles.Aggregate(new Dictionary <string, HashSet <FileInfo> >(),
                                                               (accumulator, file) =>
                    {
                        // ReSharper disable PossibleNullReferenceException
                        file.Keys.ForEach(key => accumulator.ForceValue(key, _ => new HashSet <FileInfo>()).Add(file));
                        // ReSharper restore PossibleNullReferenceException
                        return(accumulator);
                    });

                    resourceTableEntries.AsParallel().ForAll(entry =>
                    {
                        var key = entry.Key;

                        var files = keyFilesLookup.GetValueOrDefault(key);

                        var references = new List <CodeReference>();

                        files?.ForEach(file => file.FindCodeReferences(entry, references, tracer));

                        entry.CodeReferences = references.AsReadOnly();

                        Interlocked.Increment(ref _visited);
                    });

                    Debug.WriteLine(stopwatch.Elapsed);
                }
                catch (ThreadAbortException)
                {
                }
                finally
                {
                    stopwatch.Stop();
                }
            }
Пример #5
0
            public Engine(CodeReferenceConfiguration configuration, ICollection <ProjectFile> sourceFiles, ICollection <ResourceTableEntry> resourceTableEntries, ITracer tracer)
            {
                _cancellationToken = _cancellationTokenSource.Token;

                Task.Run(async() => await FindCodeReferences(configuration, sourceFiles, resourceTableEntries, tracer).ConfigureAwait(false), _cancellationToken);
            }