예제 #1
0
        bool TryEnumerateProjects(Func <ExecutionEnvironment> env, out IEnumerable <ResharperProjectUpdater> projects)
        {
            projects = new ResharperProjectUpdater[0];

            if (SolutionManager == null)
            {
                return(false);
            }

            ResharperLogger.Debug("SolutionManager found");

            var solution = Solution;

            if (solution == null)
            {
                return(false);
            }


            ResharperLogger.Debug("Solution found");

            var monitors = (
                from proj in solution.GetAllProjects()
                where ProjectIsOpenWrapEnabled(proj)
                let scope = PathFinder.GetCurrentScope(_env.Descriptor.DirectoryStructure, new OpenFileSystem.IO.Path(proj.ProjectFile.Location.FullPath))
                            let descriptor = _env.ScopedDescriptors.ContainsKey(scope) ? _env.ScopedDescriptors[scope] : _env.ScopedDescriptors[string.Empty]
                                             select new ResharperProjectUpdater(descriptor.File, proj, env)
                ).ToList();

            projects = monitors;
            return(true);
        }
예제 #2
0
        void Refresh()
        {
            lock (_lock)
            {
                ResharperLogger.Debug("Refreshing list of projects.");

                IEnumerable <ResharperProjectUpdater> tempCurrentProjects;
                ListProjects(_environment, out tempCurrentProjects);
                var currentProjects = tempCurrentProjects.ToList();

                foreach (var project in currentProjects.ToList())
                {
                    var existing = currentProjects.FirstOrDefault(x => string.Equals(x.ProjectPath, project.ProjectPath, StringComparison.OrdinalIgnoreCase));
                    if (existing != null)
                    {
                        currentProjects.Remove(project);
                        continue;
                    }
                    _monitor.RegisterListener(project.Descriptor, _projectRepository, project);
                    _knownProjects.Add(project);
                }
                foreach (var oldProject in currentProjects)
                {
                    _monitor.UnregisterListener(oldProject);
                }
            }
        }
예제 #3
0
        void HandleChanges(object sender, resharper::JetBrains.Application.ChangeEventArgs changeeventargs)
        {
            var solutionChanges = changeeventargs.ChangeMap.GetChange(Solution) as resharper::JetBrains.ProjectModel.SolutionChange;

            if (solutionChanges == null)
            {
                ResharperLogger.Debug("Unknown solution change");
                return;
            }
            if (HasSolutionChanges(solutionChanges) ||
                HasProjectChanges(solutionChanges))
            {
                ResharperLogger.Debug("Scheduled refresh of projects");
                ScheduleRefresh();
            }
        }
예제 #4
0
// ReSharper disable UnusedMember.Global
        public void BootstrapSolution(Func <ExecutionEnvironment> environment, IPackageRepository projectRepository)
// ReSharper restore UnusedMember.Global
        {
            if (!_isInitialized)
            {
                lock (_lock)
                {
                    if (_isInitialized)
                    {
                        return;
                    }
                    _environment       = environment;
                    _projectRepository = projectRepository;


                    IEnumerable <ResharperProjectUpdater> listeners = null;
                    bool success;
                    try
                    {
                        success = ListProjects(environment, out listeners);
                    }
                    catch (Exception e)
                    {
                        ResharperLogger.Debug("Exception when updating resharper: \r\n" + e);
                        success = false;
                    }

                    if (success)
                    {
                        RegisterChangeMonitor();
                        foreach (var project in listeners)
                        {
                            _monitor.RegisterListener(project.Descriptor, projectRepository, project);
                        }
                        _knownProjects = listeners.ToList();
                        _isInitialized = true;
                    }
                    else
                    {
                        ResharperLogger.Debug("Import failed, rescheduling in one second.");
                        _initializeTimer = new Timer(x => BootstrapSolution(environment, projectRepository), null, RETRY_DELAY_MS, Timeout.Infinite);
                    }
                }
            }
        }
예제 #5
0
        void RefreshProjects()
        {
            if (_shuttingDown)
            {
                return;
            }
            _output.Write("Changes detected, updating assembly references ({0}).", GetHashCode());
            foreach (var project in _solution.GetAllProjects())
            {
                if (project.ProjectFile == null)
                {
                    continue;
                }
                var projectPath = project.ProjectFile.Location.FullPath;
                if (!_assemblyMap.ContainsKey(projectPath))
                {
                    continue;
                }
                var existingOpenWrapReferences = project.GetAssemblyReferences()
                                                 .Where(x => x.GetProperty(ISWRAP) != null).ToList();

                var existingOpenWrapReferencePaths = existingOpenWrapReferences
                                                     .Select(assemblyRef => assemblyRef.HintLocation()).ToList();

                var assemblies = _assemblyMap[projectPath];
                foreach (var path in assemblies
                         .Where(x => !existingOpenWrapReferencePaths.Contains(x)))
                {
                    ResharperLogger.Debug("Adding reference {0} to {1}", projectPath, path);

                    var assembly = project.AddAssemblyReference(path);
                    assembly.SetProperty(ISWRAP, true);
                }
                foreach (var toRemove in existingOpenWrapReferencePaths.Where(x => !assemblies.Contains(x)))
                {
                    string remove = toRemove;
                    ResharperLogger.Debug("Removing reference {0} from {1}",
                                          projectPath,
                                          toRemove);
                    project.RemoveAssemblyReference(existingOpenWrapReferences.First(x => x.HintLocation() == remove));
                }
            }
        }
예제 #6
0
        public void AssembliesUpdated(IEnumerable <Exports.IAssembly> resolvedAssemblies)
        {
            ResharperLocks.WriteCookie("Updating references...",
                                       () =>
            {
                if (_project.ProjectFile == null)
                {
                    return;
                }
                string projectFilePath = _project.ProjectFile.GetPresentableProjectPath();

                var resolvedAssemblyPaths = resolvedAssemblies.Select(x => x.File.Path.FullPath).ToList();

                var owProjectAssemblyReferences = _project.GetAssemblyReferences()
                                                  .Where(x => x.GetProperty(ISWRAP) != null).ToList();

                var owProjectAssemblyReferencePaths = owProjectAssemblyReferences
                                                      .Select(x => x.HintLocation.FullPath).ToList();

                foreach (var path in resolvedAssemblyPaths
                         .Where(x => !owProjectAssemblyReferencePaths.Contains(x) &&
                                _ignoredAssemblies.Any(i => x.Contains(i + ".dll")) == false))
                {
                    ResharperLogger.Debug("Adding reference {0} to {1}", projectFilePath, path);

                    var assembly = _project.AddAssemblyReference(path);
                    assembly.SetProperty(ISWRAP, true);
                }
                foreach (var toRemove in owProjectAssemblyReferencePaths.Where(x => !resolvedAssemblyPaths.Contains(x)))
                {
                    string remove = toRemove;
                    ResharperLogger.Debug("Removing reference {0} to {1}",
                                          projectFilePath,
                                          toRemove);
                    _project.RemoveModuleReference(
                        owProjectAssemblyReferences.First(
                            x => x.HintLocation.FullPath == remove));
                }
            });
        }