void OnProjectItemRemoved(object sender, ProjectItemEventArgs e)
        {
            if (e.Project != project)
            {
                return;
            }

            ReferenceProjectItem reference = e.ProjectItem as ReferenceProjectItem;

            if (reference != null)
            {
                try {
                    IProjectContent referencedContent = AssemblyParserService.GetExistingProjectContentForReference(reference);
                    if (referencedContent != null)
                    {
                        lock (ReferencedContents) {
                            ReferencedContents.Remove(referencedContent);
                        }
                        OnReferencedContentsChanged(EventArgs.Empty);
                    }
                } catch (Exception ex) {
                    MessageService.ShowException(ex);
                }
            }

            if (e.ProjectItem.ItemType == ItemType.Import)
            {
                UpdateDefaultImports(project.Items);
            }
            else if (e.ProjectItem.ItemType == ItemType.Compile)
            {
                ParserService.ClearParseInformation(e.ProjectItem.FileName);
            }
        }
        void AddReference(ReferenceProjectItem reference, bool updateInterDependencies, CancellationToken cancellationToken)
        {
            try {
                cancellationToken.ThrowIfCancellationRequested();
                AddReferencedContent(AssemblyParserService.GetProjectContentForReference(reference));
                if (updateInterDependencies)
                {
                    UpdateReferenceInterDependencies();
                }
                OnReferencedContentsChanged(EventArgs.Empty);

                // Refresh the reference if required.
                // If the user removes the reference and then re-adds it, there might be other references
                // in the project depending on it, so we do the refresh after the old reference was added.
                AssemblyParserService.RefreshProjectContentForReference(reference);
            } catch (OperationCanceledException) {
                throw;
            } catch (ObjectDisposedException e) {
                // ObjectDisposedException can happen if project gets disposed while LoadSolutionProjectsThread is running.
                // We will ignore the ObjectDisposedException and throw OperationCanceledException instead.
                cancellationToken.ThrowIfCancellationRequested();
                MessageService.ShowException(e);
            } catch (Exception e) {
                MessageService.ShowException(e);
            }
        }
Esempio n. 3
0
 internal static void InitializeParserService()
 {
     if (parserDescriptors == null)
     {
         parserDescriptors = AddInTree.BuildItems <ParserDescriptor>("/Workspace/Parser", null, false);
         AssemblyParserService.Initialize();
         LoadSolutionProjects.Initialize();
     }
 }
        void AddReference(ReferenceProjectItem reference, bool updateInterDependencies)
        {
            try {
                AddReferencedContent(AssemblyParserService.GetProjectContentForReference(reference));
                if (updateInterDependencies)
                {
                    UpdateReferenceInterDependencies();
                }
                OnReferencedContentsChanged(EventArgs.Empty);

                // Refresh the reference if required.
                // If the user removes the reference and then re-adds it, there might be other references
                // in the project depending on it, so we do the refresh after the old reference was added.
                AssemblyParserService.RefreshProjectContentForReference(reference);
            } catch (Exception e) {
                MessageService.ShowException(e);
            }
        }
        internal void ReInitialize1(IProgressMonitor progressMonitor)
        {
            var mscorlib = AssemblyParserService.GetRegistryForReference(new ReferenceProjectItem(project, "mscorlib")).Mscorlib;

            // don't fetch mscorlib within lock - finding the correct registry might access the project, causing
            // a deadlock between IProject.SyncRoot and the ReferencedContents lock
            lock (ReferencedContents) {
                ReferencedContents.Clear();
                AddReferencedContent(mscorlib);
            }
            // prevent adding event handler twice
            ProjectService.ProjectItemAdded   -= OnProjectItemAdded;
            ProjectService.ProjectItemRemoved -= OnProjectItemRemoved;
            initializing = true;
            try {
                Initialize1(progressMonitor);
            } finally {
                initializing = false;
            }
        }