public void Add(WorkspaceItem item)
 {
     foreach (Project project in item.GetAllProjects())
     {
         Add(project);
     }
 }
        public void StartAnalysis(WorkspaceItem solution)
        {
            lock (_lock) {
                tokenSource    = new CancellationTokenSource();
                processedFiles = new ConcurrentDictionary <string, object> ();
                ThreadPool.QueueUserWorkItem(delegate {
                    State = AnalysisState.Running;

                    using (var monitor = IdeApp.Workbench.ProgressMonitors.GetStatusProgressMonitor("Analyzing solution", null, false)) {
                        AnalysisState oldState;
                        AnalysisState newState;
                        try {
                            int work = 0;
                            foreach (var project in solution.GetAllProjects())
                            {
                                work += project.Files.Count(f => f.BuildAction == BuildAction.Compile);
                            }
                            monitor.BeginTask("Analyzing solution", work);
                            foreach (var project in solution.GetAllProjects())
                            {
                                if (tokenSource.IsCancellationRequested)
                                {
                                    break;
                                }
                                var content = TypeSystemService.GetProjectContext(project);
                                Parallel.ForEach(project.Files, file => {
                                    try {
                                        AnalyzeFile(file, content);
                                        monitor.Step(1);
                                    } catch (Exception ex) {
                                        LoggingService.LogError("Error while running code issue on:" + file.Name, ex);
                                    }
                                });
                            }
                            // Cleanup
                            lock (_lock) {
                                oldState = state;
                                if (tokenSource.IsCancellationRequested)
                                {
                                    newState = AnalysisState.Cancelled;
                                }
                                else
                                {
                                    newState = AnalysisState.Completed;
                                }
                                state       = newState;
                                tokenSource = null;
                            }
                            OnAnalysisStateChanged(new AnalysisStateChangeEventArgs(oldState, newState));
                        } catch (Exception e) {
                            lock (_lock) {
                                oldState    = state;
                                state       = AnalysisState.Error;
                                newState    = state;
                                tokenSource = null;
                            }
                            OnAnalysisStateChanged(new AnalysisStateChangeEventArgs(oldState, newState));
                            // Do not rethrow in a thread pool
                            MessageService.ShowException(e);
                        }
                    }
                });
            }
        }
		public void StartAnalysis (WorkspaceItem solution)
		{
			lock (_lock) {
				tokenSource = new CancellationTokenSource ();
				processedFiles = new ConcurrentDictionary<string, object> ();
				ThreadPool.QueueUserWorkItem (delegate {
					State = AnalysisState.Running;

					using (var monitor = IdeApp.Workbench.ProgressMonitors.GetStatusProgressMonitor ("Analyzing solution", null, false)) {
						AnalysisState oldState;
						AnalysisState newState;
						try {
							int work = 0;
							foreach (var project in solution.GetAllProjects ()) {
								work += project.Files.Count (f => f.BuildAction == BuildAction.Compile);
							}
							monitor.BeginTask ("Analyzing solution", work);
							foreach (var project in solution.GetAllProjects ()) {
								if (tokenSource.IsCancellationRequested)
									break;
								var content = TypeSystemService.GetProjectContext (project);
								Parallel.ForEach (project.Files, file => {
									try {
										AnalyzeFile (file, content);
										monitor.Step (1);
									} catch (Exception ex) {
										LoggingService.LogError ("Error while running code issue on:" + file.Name, ex);
									}
								});
							}
							// Cleanup
							lock (_lock) {
								oldState = state;
								if (tokenSource.IsCancellationRequested) {
									newState = AnalysisState.Cancelled;
								} else {
									newState = AnalysisState.Completed;
								}
								state = newState;
								tokenSource = null;
							}
							OnAnalysisStateChanged (new AnalysisStateChangeEventArgs (oldState, newState));
						} catch (Exception e) {
							lock (_lock) {
								oldState = state;
								state = AnalysisState.Error;
								newState = state;
								tokenSource = null;
							}
							OnAnalysisStateChanged (new AnalysisStateChangeEventArgs (oldState, newState));
							// Do not rethrow in a thread pool
							MessageService.ShowException (e);
						}
					}
				});
			}
		}
示例#4
0
		public void Add (WorkspaceItem item)
		{
			foreach (Project project in item.GetAllProjects ()) {
				Add (project);
			}
		}
示例#5
0
        public void StartAnalysis(WorkspaceItem solution)
        {
            lock (_lock) {
                tokenSource = new CancellationTokenSource();
                ThreadPool.QueueUserWorkItem(delegate {
                    State = AnalysisState.Running;

                    using (var monitor = IdeApp.Workbench.ProgressMonitors.GetStatusProgressMonitor("Analyzing solution", null, false)) {
                        int work = 0;
                        foreach (var project in solution.GetAllProjects())
                        {
                            work += project.Files.Count(f => f.BuildAction == BuildAction.Compile);
                        }
                        monitor.BeginTask("Analyzing solution", work);
                        var processedFiles = new ConcurrentDictionary <string, object> ();
                        foreach (var project in solution.GetAllProjects())
                        {
                            if (tokenSource.IsCancellationRequested)
                            {
                                break;
                            }
                            var content = TypeSystemService.GetProjectContext(project);
                            Parallel.ForEach(project.Files, file => {
                                var me    = new object();
                                var owner = processedFiles.AddOrUpdate(file.Name, me, (key, old) => old);
                                if (me != owner)
                                {
                                    return;
                                }
                                if (file.BuildAction != BuildAction.Compile || tokenSource.IsCancellationRequested)
                                {
                                    return;
                                }

                                var editor   = TextFileProvider.Instance.GetReadOnlyTextEditorData(file.FilePath);
                                var document = TypeSystemService.ParseFile(project, editor);
                                if (document == null)
                                {
                                    return;
                                }

                                var compilation = content.AddOrUpdateFiles(document.ParsedFile).CreateCompilation();
                                var resolver    = new CSharpAstResolver(compilation, document.GetAst <SyntaxTree> (), document.ParsedFile as ICSharpCode.NRefactory.CSharp.TypeSystem.CSharpUnresolvedFile);
                                var context     = document.CreateRefactoringContextWithEditor(editor, resolver, tokenSource.Token);

                                CodeIssueProvider[] codeIssueProvider = RefactoringService.GetInspectors(editor.MimeType).ToArray();
                                Parallel.ForEach(codeIssueProvider, (provider) => {
                                    var severity = provider.GetSeverity();
                                    if (severity == Severity.None || tokenSource.IsCancellationRequested)
                                    {
                                        return;
                                    }
                                    try {
                                        foreach (var issue in provider.GetIssues(context, tokenSource.Token))
                                        {
                                            AddIssue(file, provider, issue);
                                        }
                                    } catch (OperationCanceledException) {
                                        // The operation was cancelled, no-op as the user-visible parts are
                                        // handled elsewhere
                                    } catch (Exception ex) {
                                        LoggingService.LogError("Error while running code issue on:" + editor.FileName, ex);
                                    }
                                });
                                //lastMime = editor.MimeType;
                                monitor.Step(1);
                            });
                        }
                        // Cleanup
                        AnalysisState oldState;
                        AnalysisState newState;
                        lock (_lock) {
                            oldState = state;
                            if (tokenSource.IsCancellationRequested)
                            {
                                newState = AnalysisState.Cancelled;
                            }
                            else
                            {
                                newState = AnalysisState.Completed;
                            }
                            state       = newState;
                            tokenSource = null;
                        }
                        OnAnalysisStateChanged(new AnalysisStateChangeEventArgs(oldState, newState));
                        monitor.EndTask();
                    }
                });
            }
        }
		public void StartAnalysis (WorkspaceItem solution)
		{
			lock (_lock) {
				tokenSource = new CancellationTokenSource ();
				ThreadPool.QueueUserWorkItem (delegate {
					State = AnalysisState.Running;

					using (var monitor = IdeApp.Workbench.ProgressMonitors.GetStatusProgressMonitor ("Analyzing solution", null, false)) {
						int work = 0;
						foreach (var project in solution.GetAllProjects ()) {
							work += project.Files.Count (f => f.BuildAction == BuildAction.Compile);
						}
						monitor.BeginTask ("Analyzing solution", work);
						var processedFiles = new ConcurrentDictionary<string, object> ();
						foreach (var project in solution.GetAllProjects ()) {
							if (tokenSource.IsCancellationRequested)
								break;
							var content = TypeSystemService.GetProjectContext (project);
							Parallel.ForEach (project.Files, file => {
								var me = new object();
								var owner = processedFiles.AddOrUpdate(file.Name, me, (key, old) => old);
								if (me != owner)
									return;
								if (file.BuildAction != BuildAction.Compile || tokenSource.IsCancellationRequested)
									return;

								var editor = TextFileProvider.Instance.GetReadOnlyTextEditorData (file.FilePath);
								var document = TypeSystemService.ParseFile (project, editor);
								if (document == null) 
									return;

								var compilation  = content.AddOrUpdateFiles (document.ParsedFile).CreateCompilation ();
								var resolver = new CSharpAstResolver (compilation, document.GetAst<SyntaxTree> (), document.ParsedFile as ICSharpCode.NRefactory.CSharp.TypeSystem.CSharpUnresolvedFile);
								var context = document.CreateRefactoringContextWithEditor (editor, resolver, tokenSource.Token);

								CodeIssueProvider[] codeIssueProvider = RefactoringService.GetInspectors (editor.MimeType).ToArray ();
								Parallel.ForEach (codeIssueProvider, (provider) => { 
									var severity = provider.GetSeverity ();
									if (severity == Severity.None || tokenSource.IsCancellationRequested)
										return;
									try {
										foreach (var issue in provider.GetIssues (context, tokenSource.Token)) {
											AddIssue (file, provider, issue);
										}
									} catch (OperationCanceledException) {
										// The operation was cancelled, no-op as the user-visible parts are
										// handled elsewhere
									} catch (Exception ex) {
										LoggingService.LogError ("Error while running code issue on:" + editor.FileName, ex);
									}
								});
								//lastMime = editor.MimeType;
								monitor.Step (1);
							});
						}
						// Cleanup
						AnalysisState oldState;
						AnalysisState newState;
						lock (_lock) {
							oldState = state;
							if (tokenSource.IsCancellationRequested) {
								newState = AnalysisState.Cancelled;
							} else {
								newState = AnalysisState.Completed;
							}
							state = newState;
							tokenSource = null;
						}
						OnAnalysisStateChanged(new AnalysisStateChangeEventArgs(oldState, newState));
						monitor.EndTask ();
					}
				});
			}
		}