private void ProcessQueue(CancellationToken cancellationToken)
        {
            _processingQueue = true;
            try
            {
                Dictionary <string, ProjectToUpdate> projectByFilePathMap = null;
                List <ProjectToUpdate> projectList = null;

                while (_queue.TryReceive(out var currentProject))
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    if (projectByFilePathMap == null)
                    {
                        projectByFilePathMap = new Dictionary <string, ProjectToUpdate>(StringComparer.OrdinalIgnoreCase);
                        projectList          = new List <ProjectToUpdate>();
                    }

                    // Ensure that we don't process the same project twice. However, if a project *does*
                    // appear more than once in the update queue, ensure that AllowAutoRestore is set to true
                    // if any of the updates requires it.
                    if (projectByFilePathMap.TryGetValue(currentProject.FilePath, out var trackedProject))
                    {
                        if (currentProject.AllowAutoRestore && !trackedProject.AllowAutoRestore)
                        {
                            trackedProject.AllowAutoRestore = true;
                        }

                        continue;
                    }

                    // TODO: Handle removing project

                    projectByFilePathMap.Add(currentProject.FilePath, currentProject);
                    projectList.Add(currentProject);

                    // update or add project
                    if (_projectFiles.TryGetValue(currentProject.FilePath, out var projectFileInfo))
                    {
                        projectFileInfo = ReloadProject(projectFileInfo);
                        _projectFiles[currentProject.FilePath] = projectFileInfo;
                    }
                    else
                    {
                        projectFileInfo = LoadProject(currentProject.FilePath);
                        AddProject(projectFileInfo);
                    }
                }

                if (projectByFilePathMap != null)
                {
                    foreach (var project in projectList)
                    {
                        UpdateProject(project.FilePath);
                    }

                    foreach (var project in projectList)
                    {
                        if (_projectFiles.TryGetValue(project.FilePath, out var projectFileInfo))
                        {
                            _packageDependencyChecker.CheckForUnresolvedDependences(projectFileInfo, project.AllowAutoRestore);
                        }
                    }
                }
            }
            finally
            {
                _processingQueue = false;
            }
        }
Exemplo n.º 2
0
        private void ProcessQueue(CancellationToken cancellationToken)
        {
            _processingQueue = true;
            try
            {
                Dictionary <string, ProjectToUpdate> projectByFilePathMap = null;
                List <ProjectToUpdate> projectList = null;

                while (_queue.TryReceive(out var currentProject))
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    if (projectByFilePathMap == null)
                    {
                        projectByFilePathMap = new Dictionary <string, ProjectToUpdate>(StringComparer.OrdinalIgnoreCase);
                        projectList          = new List <ProjectToUpdate>();
                    }

                    // Ensure that we don't process the same project twice. However, if a project *does*
                    // appear more than once in the update queue, ensure that AllowAutoRestore is set to true
                    // if any of the updates requires it.
                    if (projectByFilePathMap.TryGetValue(currentProject.FilePath, out var trackedProject))
                    {
                        if (currentProject.AllowAutoRestore && !trackedProject.AllowAutoRestore)
                        {
                            trackedProject.AllowAutoRestore = true;
                        }

                        continue;
                    }

                    // TODO: Handle removing project

                    projectByFilePathMap.Add(currentProject.FilePath, currentProject);
                    projectList.Add(currentProject);

                    // update or add project
                    _failedToLoadProjectFiles.Remove(currentProject.FilePath);

                    ProjectLoadedEventArgs loadedEventArgs;

                    if (_projectFiles.TryGetValue(currentProject.FilePath, out ProjectFileInfo projectFileInfo))
                    {
                        (projectFileInfo, loadedEventArgs) = ReloadProject(projectFileInfo);
                        if (projectFileInfo == null)
                        {
                            _failedToLoadProjectFiles.Add(currentProject.FilePath);
                            continue;
                        }

                        currentProject.LoadedEventArgs         = loadedEventArgs;
                        _projectFiles[currentProject.FilePath] = projectFileInfo;
                    }
                    else
                    {
                        (projectFileInfo, loadedEventArgs) = LoadProject(currentProject.FilePath, currentProject.ProjectIdInfo);
                        if (projectFileInfo == null)
                        {
                            _failedToLoadProjectFiles.Add(currentProject.FilePath);
                            continue;
                        }

                        currentProject.LoadedEventArgs = loadedEventArgs;
                        AddProject(projectFileInfo);
                    }
                }

                if (projectByFilePathMap != null)
                {
                    foreach (var project in projectList)
                    {
                        UpdateProject(project.FilePath);

                        // Fire loaded events
                        if (project.LoadedEventArgs != null)
                        {
                            foreach (var eventSink in _eventSinks)
                            {
                                try
                                {
                                    eventSink.ProjectLoaded(project.LoadedEventArgs);
                                }
                                catch (Exception ex)
                                {
                                    _logger.LogError(ex, "Exception thrown while calling event sinks");
                                }
                            }
                        }
                    }

                    foreach (var project in projectList)
                    {
                        if (_projectFiles.TryGetValue(project.FilePath, out var projectFileInfo))
                        {
                            _packageDependencyChecker.CheckForUnresolvedDependences(projectFileInfo, project.AllowAutoRestore);
                        }
                    }
                }
            }
            finally
            {
                _processingQueue = false;
            }

            _fileSystemWatcher.Watch(".cs", _onDirectoryFileChanged);
        }