void DoResolveReferences(IProgressMonitor progressMonitor)
        {
            var          referenceItems            = project.ResolveAssemblyReferences(progressMonitor.CancellationToken);
            const double assemblyResolvingProgress = 0.3;             // 30% asm resolving, 70% asm loading

            progressMonitor.Progress += assemblyResolvingProgress;
            progressMonitor.CancellationToken.ThrowIfCancellationRequested();

            List <FileName>           assemblyFiles = new List <FileName>();
            List <IAssemblyReference> newReferences = new List <IAssemblyReference>();

            foreach (var reference in referenceItems)
            {
                ProjectReferenceProjectItem projectReference = reference as ProjectReferenceProjectItem;
                if (projectReference != null)
                {
                    newReferences.Add(projectReference);
                }
                else
                {
                    assemblyFiles.Add(reference.FileName);
                }
            }

            foreach (var file in assemblyFiles)
            {
                progressMonitor.CancellationToken.ThrowIfCancellationRequested();
                if (File.Exists(file))
                {
                    try {
                        var pc = SD.AssemblyParserService.GetAssembly(file, false, progressMonitor.CancellationToken);
                        if (pc != null)
                        {
                            newReferences.Add(pc);
                        }
                    } catch (IOException ex) {
                        LoggingService.Warn(ex);
                    } catch (BadImageFormatException ex) {
                        LoggingService.Warn(ex);
                    }
                }
                progressMonitor.Progress += (1.0 - assemblyResolvingProgress) / assemblyFiles.Count;
            }
            lock (lockObj) {
                if (!disposed)
                {
                    projectContent  = projectContent.RemoveAssemblyReferences(this.references).AddAssemblyReferences(newReferences);
                    this.references = newReferences.ToArray();
                    SD.ParserService.InvalidateCurrentSolutionSnapshot();
                    SD.MainThread.InvokeAsyncAndForget(
                        delegate {
                        assemblyModel.UpdateReferences(projectContent.AssemblyReferences.Select(ResolveReferenceForAssemblyModel).Where(r => r != null).ToList());
                    });
                }
            }
        }
Ejemplo n.º 2
0
 public CSharpCodeCompletionStrategy(CodeEditor codeEditor)
     : base(codeEditor)
 {
     codeEditor.InternalAssembliesLoaded += (sender, args) => {
         projectContent = projectContent.AddAssemblyReferences(args.Value);
     };
     codeEditor.InternalAssembliesUnloaded += (sender, args) => {
         projectContent = projectContent.RemoveAssemblyReferences(args.Value);
     };
 }
        static Task SerializeAsync(string cacheFileName, IProjectContent pc)
        {
            if (cacheFileName == null)
            {
                return(Task.FromResult <object>(null));
            }
            Task task = IOTaskScheduler.Factory.StartNew(
                delegate {
                pc = pc.RemoveAssemblyReferences(pc.AssemblyReferences);
                int serializableFileCount = 0;
                List <string> nonSerializableUnresolvedFiles = new List <string>();
                foreach (var unresolvedFile in pc.Files)
                {
                    if (IsSerializable(unresolvedFile))
                    {
                        serializableFileCount++;
                    }
                    else
                    {
                        nonSerializableUnresolvedFiles.Add(unresolvedFile.FileName);
                    }
                }
                // remove non-serializable parsed files
                if (nonSerializableUnresolvedFiles.Count > 0)
                {
                    pc = pc.RemoveFiles(nonSerializableUnresolvedFiles);
                }
                if (serializableFileCount > 3)
                {
                    LoggingService.Debug("Serializing " + serializableFileCount + " files to " + cacheFileName);
                    SaveToCache(cacheFileName, pc);
                }
                else
                {
                    RemoveCache(cacheFileName);
                }
            }, SD.ShutdownService.DelayedShutdownToken);

            SD.ShutdownService.AddBackgroundTask(task);
            return(task);
        }
		static Task SerializeAsync(string cacheFileName, IProjectContent pc)
		{
			if (cacheFileName == null)
				return Task.FromResult<object>(null);
			Task task = IOTaskScheduler.Factory.StartNew(
				delegate {
					pc = pc.RemoveAssemblyReferences(pc.AssemblyReferences);
					int serializableFileCount = 0;
					List<string> nonSerializableUnresolvedFiles = new List<string>();
					foreach (var unresolvedFile in pc.Files) {
						if (IsSerializable(unresolvedFile))
							serializableFileCount++;
						else
							nonSerializableUnresolvedFiles.Add(unresolvedFile.FileName);
					}
					// remove non-serializable parsed files
					if (nonSerializableUnresolvedFiles.Count > 0)
						pc = pc.RemoveFiles(nonSerializableUnresolvedFiles);
					if (serializableFileCount > 3) {
						LoggingService.Debug("Serializing " + serializableFileCount + " files to " + cacheFileName);
						SaveToCache(cacheFileName, pc);
					} else {
						RemoveCache(cacheFileName);
					}
				}, SD.ShutdownService.DelayedShutdownToken);
			SD.ShutdownService.AddBackgroundTask(task);
			return task;
		}