当前位置: 首页>>代码示例>>C#>>正文


C# IProgressMonitor.CreateSubTask方法代码示例

本文整理汇总了C#中IProgressMonitor.CreateSubTask方法的典型用法代码示例。如果您正苦于以下问题:C# IProgressMonitor.CreateSubTask方法的具体用法?C# IProgressMonitor.CreateSubTask怎么用?C# IProgressMonitor.CreateSubTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IProgressMonitor的用法示例。


在下文中一共展示了IProgressMonitor.CreateSubTask方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindReferencesAsync

		/// <summary>
		/// Finds all references to the specified entity.
		/// The results are reported using the callback.
		/// FindReferences may internally use parallelism, and may invoke the callback on multiple
		/// threads in parallel.
		/// </summary>
		public static async Task FindReferencesAsync(IEntity entity, IProgressMonitor progressMonitor, Action<SearchedFile> callback)
		{
			if (entity == null)
				throw new ArgumentNullException("entity");
			if (progressMonitor == null)
				throw new ArgumentNullException("progressMonitor");
			if (callback == null)
				throw new ArgumentNullException("callback");
			SD.MainThread.VerifyAccess();
			if (SD.ParserService.LoadSolutionProjectsThread.IsRunning) {
				progressMonitor.ShowingDialog = true;
				MessageService.ShowMessage("${res:SharpDevelop.Refactoring.LoadSolutionProjectsThreadRunning}");
				progressMonitor.ShowingDialog = false;
				return;
			}
			double totalWorkAmount;
			List<ISymbolSearch> symbolSearches = PrepareSymbolSearch(entity, progressMonitor.CancellationToken, out totalWorkAmount);
			double workDone = 0;
			ParseableFileContentFinder parseableFileContentFinder = new ParseableFileContentFinder();
			foreach (ISymbolSearch s in symbolSearches) {
				progressMonitor.CancellationToken.ThrowIfCancellationRequested();
				using (var childProgressMonitor = progressMonitor.CreateSubTask(s.WorkAmount / totalWorkAmount)) {
					await s.FindReferencesAsync(new SymbolSearchArgs(childProgressMonitor, parseableFileContentFinder), callback);
				}
				
				workDone += s.WorkAmount;
				progressMonitor.Progress = workDone / totalWorkAmount;
			}
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:35,代码来源:FindReferenceService.cs

示例2: RunThread

			void RunThread()
			{
				while (true) {
					JobTask task;
					// copy fields from this class into local variables to ensure thread-safety
					// with concurrent Clear() calls
					double totalWork, workDone;
					IProgressMonitor progressMonitor;
					lock (lockObj) {
						// enqueued null: quit thread and restart (used for cancellation)
						if (actions.Count == 0 || this.actions.Peek() == null) {
							this.threadIsRunning = false;
							this.progressMonitor.Dispose();
							this.progressMonitor = null;
							// restart if necessary:
							if (actions.Count > 0) {
								actions.Dequeue(); // dequeue the null
								WorkbenchSingleton.SafeThreadAsyncCall(StartRunningIfRequired);
							}
							return;
						}
						task = this.actions.Dequeue();
						totalWork = this.totalWork;
						workDone = this.workDone;
						progressMonitor = this.progressMonitor;
					}
					progressMonitor.Progress = workDone / totalWork;
					progressMonitor.TaskName = task.name;
					try {
						using (IProgressMonitor subTask = progressMonitor.CreateSubTask(task.cost / totalWork)) {
							task.Run(subTask);
						}
						lock (lockObj) {
							this.workDone += task.cost;
						}
					} catch (OperationCanceledException) {
						// ignore cancellation
					} catch (Exception ex) {
						MessageService.ShowException(ex, "Error on LoadSolutionProjects thread");
					}
				}
			}
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:42,代码来源:LoadSolutionProjects.cs

示例3: RenameSymbolAsync

		public static async Task RenameSymbolAsync(ISymbol symbol, string newName, IProgressMonitor progressMonitor, Action<Error> errorCallback)
		{
			if (symbol == null)
				throw new ArgumentNullException("symbol");
			if (progressMonitor == null)
				throw new ArgumentNullException("progressMonitor");
			SD.MainThread.VerifyAccess();
			if (SD.ParserService.LoadSolutionProjectsThread.IsRunning) {
				progressMonitor.ShowingDialog = true;
				MessageService.ShowMessage("${res:SharpDevelop.Refactoring.LoadSolutionProjectsThreadRunning}");
				progressMonitor.ShowingDialog = false;
				return;
			}
			double totalWorkAmount;
			List<ISymbolSearch> symbolSearches = PrepareSymbolSearch(symbol, progressMonitor.CancellationToken, out totalWorkAmount);
			double workDone = 0;
			ParseableFileContentFinder parseableFileContentFinder = new ParseableFileContentFinder();
			var errors = new List<Error>();
			var changes = new List<PatchedFile>();
			foreach (ISymbolSearch s in symbolSearches) {
				progressMonitor.CancellationToken.ThrowIfCancellationRequested();
				using (var childProgressMonitor = progressMonitor.CreateSubTask(s.WorkAmount / totalWorkAmount)) {
					var args = new SymbolRenameArgs(newName, childProgressMonitor, parseableFileContentFinder);
					args.ProvideHighlightedLine = false;
					await s.RenameAsync(args, file => changes.Add(file), error => errors.Add(error));
				}
				
				workDone += s.WorkAmount;
				progressMonitor.Progress = workDone / totalWorkAmount;
			}
			if (errors.Count == 0) {
				foreach (var file in changes) {
					ApplyChanges(file);
				}
			} else {
				foreach (var error in errors) {
					errorCallback(error);
				}
			}
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:40,代码来源:FindReferenceService.cs

示例4: SetupSolutionLoadSolutionProjects

		static ProjectSection SetupSolutionLoadSolutionProjects(Solution newSolution, StreamReader sr, IProgressMonitor progressMonitor)
		{
			if (progressMonitor == null)
				throw new ArgumentNullException("progressMonitor");
			
			string solutionDirectory = Path.GetDirectoryName(newSolution.FileName);
			
			ProjectSection nestedProjectsSection = null;
			IList<ProjectLoadInformation> projectsToLoad = new List<ProjectLoadInformation>();
			IList<IList<ProjectSection>> readProjectSections = new List<IList<ProjectSection>>();
			
			// process the solution file contents
			while (true) {
				string line = sr.ReadLine();
				
				if (line == null) {
					break;
				}
				Match match = projectLinePattern.Match(line);
				if (match.Success) {
					string projectGuid  = match.Result("${ProjectGuid}");
					string title        = match.Result("${Title}");
					string location     = match.Result("${Location}");
					string guid         = match.Result("${Guid}");
					
					if (!FileUtility.IsUrl(location)) {
						location = FileUtility.NormalizePath(Path.Combine(solutionDirectory, location));
					}
					
					if (projectGuid == FolderGuid) {
						SolutionFolder newFolder = SolutionFolder.ReadFolder(sr, title, location, guid);
						newSolution.AddFolder(newFolder);
					} else {
						ProjectLoadInformation loadInfo = new ProjectLoadInformation(newSolution, location, title);
						loadInfo.TypeGuid = projectGuid;
						loadInfo.Guid = guid;
						projectsToLoad.Add(loadInfo);
						IList<ProjectSection> currentProjectSections = new List<ProjectSection>();
						ReadProjectSections(sr, currentProjectSections);
						readProjectSections.Add(currentProjectSections);
					}
					match = match.NextMatch();
				} else {
					match = globalSectionPattern.Match(line);
					if (match.Success) {
						ProjectSection newSection = ProjectSection.ReadGlobalSection(sr, match.Result("${Name}"), match.Result("${Type}"));
						// Don't put the NestedProjects section into the global sections list
						// because it's transformed to a tree representation and the tree representation
						// is transformed back to the NestedProjects section during save.
						if (newSection.Name == "NestedProjects") {
							nestedProjectsSection = newSection;
						} else {
							newSolution.Sections.Add(newSection);
						}
					}
				}
			}
			// load projects
			for(int i=0; i<projectsToLoad.Count; i++) {
				ProjectLoadInformation loadInfo = projectsToLoad[i];
				IList<ProjectSection> projectSections = readProjectSections[i];
				loadInfo.ProjectSections = projectSections;
				
				// set the target platform
				SolutionItem projectConfig = newSolution.GetProjectConfiguration(loadInfo.Guid);
				loadInfo.Platform = AbstractProject.GetPlatformNameFromKey(projectConfig.Location);
				
				loadInfo.ProgressMonitor = progressMonitor;
				progressMonitor.Progress = (double)i / projectsToLoad.Count;
				progressMonitor.TaskName = "Loading " + loadInfo.ProjectName;
				
				using (IProgressMonitor nestedProgressMonitor = progressMonitor.CreateSubTask(1.0 / projectsToLoad.Count)) {
					loadInfo.ProgressMonitor = nestedProgressMonitor;
					IProject newProject = ProjectBindingService.LoadProject(loadInfo);
					newProject.IdGuid = loadInfo.Guid;
					newProject.ProjectSections.AddRange(projectSections);
					newSolution.AddFolder(newProject);
				}
			}
			return nestedProjectsSection;
		}
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:81,代码来源:Solution.cs

示例5: Initialize

		void Initialize(IProgressMonitor progressMonitor, List<FileName> filesToParse)
		{
			IReadOnlyCollection<ProjectItem> projectItems = project.Items.CreateSnapshot();
			lock (lockObj) {
				if (disposed) {
					return;
				}
			}

			double scalingFactor = 1.0 / (projectItems.Count + LoadingReferencesWorkAmount);
			using (IProgressMonitor initReferencesProgressMonitor = progressMonitor.CreateSubTask(LoadingReferencesWorkAmount * scalingFactor),
			       parseProgressMonitor = progressMonitor.CreateSubTask(projectItems.Count * scalingFactor))
			{
				var resolveReferencesTask = Task.Run(
					delegate {
						DoResolveReferences(initReferencesProgressMonitor);
					}, initReferencesProgressMonitor.CancellationToken);
				
				ParseFiles(filesToParse, parseProgressMonitor);
				
				resolveReferencesTask.Wait();
			}
		}
开发者ID:jrenzas,项目名称:SharpDevelop,代码行数:23,代码来源:ProjectContentContainer.cs

示例6: ReadSolution

		public void ReadSolution(Solution solution, IProgressMonitor progress)
		{
			ReadFormatHeader();
			ReadVersionProperties(solution);
			
			// Read solution folder and project entries:
			var solutionEntries = new List<ProjectLoadInformation>();
			var projectInfoDict = new Dictionary<Guid, ProjectLoadInformation>();
			var solutionFolderDict = new Dictionary<Guid, SolutionFolder>();
			int projectCount = 0;
			bool fixedGuidConflicts = false;
			
			ProjectLoadInformation information;
			while ((information = ReadProjectEntry(solution)) != null) {
				solutionEntries.Add(information);
				if (projectInfoDict.ContainsKey(information.IdGuid)) {
					// resolve GUID conflicts
					SD.Log.WarnFormatted("Detected duplicate GUID in .sln file: {0} is used for {1} and {2}", information.IdGuid, information.ProjectName, projectInfoDict[information.IdGuid].ProjectName);
					information.IdGuid = Guid.NewGuid();
					fixedGuidConflicts = true;
				}
				projectInfoDict.Add(information.IdGuid, information);
				
				if (information.TypeGuid == ProjectTypeGuids.SolutionFolder) {
					solutionFolderDict.Add(information.IdGuid, CreateSolutionFolder(solution, information));
				} else {
					projectCount++;
				}
			}
			
			progress.CancellationToken.ThrowIfCancellationRequested();
			
			// Read global sections:
			if (currentLine != "Global") {
				if (currentLine == null)
					throw Error("Unexpected end of file");
				else
					throw Error("Unknown line: " + currentLine);
			}
			NextLine();
			
			Dictionary<Guid, SolutionFolder> guidToParentFolderDict = null;
			
			SolutionSection section;
			while ((section = ReadSection(isGlobal: true)) != null) {
				switch (section.SectionName) {
					case "SolutionConfigurationPlatforms":
						var configurations = LoadSolutionConfigurations(section);
						foreach (var config in configurations.Select(c => c.Configuration).Distinct(ConfigurationAndPlatform.ConfigurationNameComparer))
							solution.ConfigurationNames.Add(config, null);
						foreach (var platform in configurations.Select(c => c.Platform).Distinct(ConfigurationAndPlatform.ConfigurationNameComparer))
							solution.PlatformNames.Add(platform, null);
						break;
					case "ProjectConfigurationPlatforms":
						LoadProjectConfigurations(section, projectInfoDict);
						break;
					case "NestedProjects":
						guidToParentFolderDict = LoadNesting(section, solutionFolderDict);
						break;
					default:
						solution.GlobalSections.Add(section);
						break;
				}
			}
			if (currentLine != "EndGlobal")
				throw Error("Expected 'EndGlobal'");
			NextLine();
			if (currentLine != null)
				throw Error("Expected end of file");
			
			solution.LoadPreferences();
			
			// Now that the project configurations have been set, we can actually load the projects:
			int projectsLoaded = 0;
			foreach (var projectInfo in solutionEntries) {
				// Make copy of IdGuid just in case the project binding writes to projectInfo.IdGuid
				Guid idGuid = projectInfo.IdGuid;
				ISolutionItem solutionItem;
				if (projectInfo.TypeGuid == ProjectTypeGuids.SolutionFolder) {
					solutionItem = solutionFolderDict[idGuid];
				} else {
					// Load project:
					projectInfo.ActiveProjectConfiguration = projectInfo.ConfigurationMapping.GetProjectConfiguration(solution.ActiveConfiguration);
					progress.TaskName = "Loading " + projectInfo.ProjectName;
					using (projectInfo.ProgressMonitor = progress.CreateSubTask(1.0 / projectCount)) {
						solutionItem = LoadProjectWithErrorHandling(projectInfo);
					}
					if (solutionItem.IdGuid != idGuid) {
						Guid projectFileGuid = solutionItem.IdGuid;
						if (!projectInfoDict.ContainsKey(projectFileGuid)) {
							// We'll use the GUID from the project file.
							// Register that GUID in the dictionary to avoid its use by multiple projects.
							projectInfoDict.Add(projectFileGuid, projectInfo);
						} else {
							// Cannot use GUID from project file due to conflict.
							// To fix the problem without potentially introducing new conflicts in other .sln files that contain the project,
							// we generate a brand new GUID:
							solutionItem.IdGuid = Guid.NewGuid();
						}
						SD.Log.WarnFormatted("<ProjectGuid> in project '{0}' is '{1}' and does not match the GUID stored in the solution ({2}). "
//.........这里部分代码省略.........
开发者ID:ratoy,项目名称:SharpDevelop,代码行数:101,代码来源:SolutionLoader.cs

示例7: ReadSolution

		public void ReadSolution(Solution solution, IProgressMonitor progress)
		{
			ReadFormatHeader();
			ReadVersionProperties(solution);
			
			// Read solution folder and project entries:
			var solutionEntries = new List<ProjectLoadInformation>();
			var projectInfoDict = new Dictionary<Guid, ProjectLoadInformation>();
			var solutionFolderDict = new Dictionary<Guid, SolutionFolder>();
			int projectCount = 0;
			bool fixedGuidConflicts = false;
			
			ProjectLoadInformation information;
			while ((information = ReadProjectEntry(solution)) != null) {
				solutionEntries.Add(information);
				if (projectInfoDict.ContainsKey(information.IdGuid)) {
					// resolve GUID conflicts
					information.IdGuid = Guid.NewGuid();
					fixedGuidConflicts = true;
				}
				projectInfoDict.Add(information.IdGuid, information);
				
				if (information.TypeGuid == ProjectTypeGuids.SolutionFolder) {
					solutionFolderDict.Add(information.IdGuid, CreateSolutionFolder(solution, information));
				} else {
					projectCount++;
				}
			}
			
			progress.CancellationToken.ThrowIfCancellationRequested();
			
			// Read global sections:
			if (currentLine != "Global") {
				if (currentLine == null)
					throw Error("Unexpected end of file");
				else
					throw Error("Unknown line: " + currentLine);
			}
			NextLine();
			
			Dictionary<Guid, SolutionFolder> guidToParentFolderDict = null;
			
			SolutionSection section;
			while ((section = ReadSection(isGlobal: true)) != null) {
				switch (section.SectionName) {
					case "SolutionConfigurationPlatforms":
						var configurations = LoadSolutionConfigurations(section);
						foreach (var config in configurations.Select(c => c.Configuration).Distinct(ConfigurationAndPlatform.ConfigurationNameComparer))
							solution.ConfigurationNames.Add(config, null);
						foreach (var platform in configurations.Select(c => c.Platform).Distinct(ConfigurationAndPlatform.ConfigurationNameComparer))
							solution.PlatformNames.Add(platform, null);
						break;
					case "ProjectConfigurationPlatforms":
						LoadProjectConfigurations(section, projectInfoDict);
						break;
					case "NestedProjects":
						guidToParentFolderDict = LoadNesting(section, solutionFolderDict);
						break;
					default:
						solution.GlobalSections.Add(section);
						break;
				}
			}
			if (currentLine != "EndGlobal")
				throw Error("Expected 'EndGlobal'");
			NextLine();
			if (currentLine != null)
				throw Error("Expected end of file");
			
			solution.LoadPreferences();
			
			// Now that the project configurations have been set, we can actually load the projects:
			int projectsLoaded = 0;
			foreach (var projectInfo in solutionEntries) {
				ISolutionItem solutionItem;
				if (projectInfo.TypeGuid == ProjectTypeGuids.SolutionFolder) {
					solutionItem = solutionFolderDict[projectInfo.IdGuid];
				} else {
					// Load project:
					projectInfo.ActiveProjectConfiguration = projectInfo.ConfigurationMapping.GetProjectConfiguration(solution.ActiveConfiguration);
					progress.TaskName = "Loading " + projectInfo.ProjectName;
					using (projectInfo.ProgressMonitor = progress.CreateSubTask(1.0 / projectCount)) {
						solutionItem = ProjectBindingService.LoadProject(projectInfo);
					}
					projectsLoaded++;
					progress.Progress = (double)projectsLoaded / projectCount;
				}
				// Add solutionItem to solution:
				SolutionFolder folder;
				if (guidToParentFolderDict != null && guidToParentFolderDict.TryGetValue(projectInfo.IdGuid, out folder)) {
					folder.Items.Add(solutionItem);
				} else {
					solution.Items.Add(solutionItem);
				}
			}
			
			solution.IsDirty = fixedGuidConflicts; // reset IsDirty=false unless we've fixed GUID conflicts
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:98,代码来源:SolutionLoader.cs


注:本文中的IProgressMonitor.CreateSubTask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。