예제 #1
0
		internal IAsyncOperation RunTest (UnitTest test, IExecutionHandler context, bool buildOwnerObject, bool checkCurrentRunOperation)
		{
			string testName = test.FullName;
			
			if (buildOwnerObject) {
				IBuildTarget bt = test.OwnerObject as IBuildTarget;
				if (bt != null && bt.NeedsBuilding (IdeApp.Workspace.ActiveConfiguration)) {
					if (!IdeApp.ProjectOperations.CurrentRunOperation.IsCompleted) {
						MonoDevelop.Ide.Commands.StopHandler.StopBuildOperations ();
						IdeApp.ProjectOperations.CurrentRunOperation.WaitForCompleted ();
					}
	
					AsyncOperation retOper = new AsyncOperation ();
					
					IAsyncOperation op = IdeApp.ProjectOperations.Build (bt);
					retOper.TrackOperation (op, false);
						
					op.Completed += delegate {
						// The completed event of the build operation is run in the gui thread,
						// so we need a new thread, because refreshing must be async
						System.Threading.ThreadPool.QueueUserWorkItem (delegate {
							if (op.Success) {
								RefreshTests ();
								test = SearchTest (testName);
								if (test != null) {
									Gtk.Application.Invoke (delegate {
										// RunTest must run in the gui thread
										retOper.TrackOperation (RunTest (test, context, false), true);
									});
								}
								else
									retOper.SetCompleted (false);
							}
						});
					};
					
					return retOper;
				}
			}
			
			if (checkCurrentRunOperation && !IdeApp.ProjectOperations.ConfirmExecutionOperation ())
				return NullProcessAsyncOperation.Failure;
			
			Pad resultsPad = IdeApp.Workbench.GetPad <TestResultsPad>();
			if (resultsPad == null) {
				resultsPad = IdeApp.Workbench.ShowPad (new TestResultsPad (), "MonoDevelop.NUnit.TestResultsPad", GettextCatalog.GetString ("Test results"), "Bottom", "md-solution");
			}
			
			// Make the pad sticky while the tests are runnig, so the results pad is always visible (even if minimized)
			// That's required since when running in debug mode, the layout is automatically switched to debug.
			
			resultsPad.Sticky = true;
			resultsPad.BringToFront ();
			
			TestSession session = new TestSession (test, context, (TestResultsPad) resultsPad.Content);
			
			session.Completed += delegate {
				Gtk.Application.Invoke (delegate {
					resultsPad.Sticky = false;
				});
			};

			OnTestSessionStarting (new TestSessionEventArgs { Session = session, Test = test });

			session.Start ();

			if (checkCurrentRunOperation)
				IdeApp.ProjectOperations.CurrentRunOperation = session;
			
			return session;
		}
		public override IAsyncOperation Refresh ()
		{
			AsyncOperation oper = new AsyncOperation ();
			System.Threading.ThreadPool.QueueUserWorkItem (delegate {
				lock (locker) {
					try {
						while (Status == TestStatus.Loading) {
							Monitor.Wait (locker);
						}
						if (RefreshRequired) {
							lastAssemblyTime = GetAssemblyTime ();
							UpdateTests ();
							OnCreateTests (); // Force loading
							while (Status == TestStatus.Loading) {
								Monitor.Wait (locker);
							}
						}
						oper.SetCompleted (true);
					} catch {
						oper.SetCompleted (false);
					}
				}
			});
			return oper;
		}
		public AsyncOperation<BuildResult> Rebuild (IBuildTarget entry, OperationContext operationContext = null)
		{
			if (currentBuildOperation != null && !currentBuildOperation.IsCompleted) return currentBuildOperation;

			var cs = new CancellationTokenSource ();
			ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetRebuildProgressMonitor ().WithCancellationSource (cs);

			var t = RebuildAsync (entry, monitor, operationContext);
			t = t.ContinueWith (ta => {
				currentBuildOperationOwner = null;
				return ta.Result;
			});

			var op = new AsyncOperation<BuildResult> (t, cs);

			return currentBuildOperation = op;
		}
		AsyncOperation<BuildResult> Build (IBuildTarget entry, bool skipPrebuildCheck, CancellationToken? cancellationToken = null, OperationContext operationContext = null)
		{
			if (currentBuildOperation != null && !currentBuildOperation.IsCompleted) return currentBuildOperation;

			ITimeTracker tt = Counters.BuildItemTimer.BeginTiming ("Building " + entry.Name);
			try {
				var cs = new CancellationTokenSource ();
				if (cancellationToken != null)
					cs = CancellationTokenSource.CreateLinkedTokenSource (cs.Token, cancellationToken.Value);
				ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetBuildProgressMonitor ().WithCancellationSource (cs);
				BeginBuild (monitor, tt, false);
				var t = BuildSolutionItemAsync (entry, monitor, tt, skipPrebuildCheck, operationContext);
				currentBuildOperation = new AsyncOperation<BuildResult> (t, cs);
				currentBuildOperationOwner = entry;
				t.ContinueWith ((ta) => currentBuildOperationOwner = null);
			} catch {
				tt.End ();
				throw;
			}
			return currentBuildOperation;
		}
		async Task ExecuteAsync (IBuildTarget entry, ExecutionContext context, CancellationTokenSource cs, bool buildBeforeExecuting)
		{
			if (buildBeforeExecuting) {
				if (!await CheckAndBuildForExecute (entry, context))
					return;
			}

			ProgressMonitor monitor = new ProgressMonitor (cs);

			var t = ExecuteSolutionItemAsync (monitor, entry, context);

			var op = new AsyncOperation (t, cs);
			CurrentRunOperation = op;
			currentRunOperationOwner = entry;

			await t;

			var error = monitor.Errors.FirstOrDefault ();
			if (error != null)
				IdeApp.Workbench.StatusBar.ShowError (error.Message);
			currentRunOperationOwner = null;
		}
		public AsyncOperation Clean (IBuildTarget entry, OperationContext operationContext = null)
		{
			if (currentBuildOperation != null && !currentBuildOperation.IsCompleted) return currentBuildOperation;
			
			ITimeTracker tt = Counters.BuildItemTimer.BeginTiming ("Cleaning " + entry.Name);
			try {
				var cs = new CancellationTokenSource ();
				ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetCleanProgressMonitor ().WithCancellationSource (cs);

				OnStartClean (monitor, tt);

				var t = CleanAsync (entry, monitor, tt, false, operationContext);

				t = t.ContinueWith (ta => {
					currentBuildOperationOwner = null;
					return ta.Result; 
				});

				var op = new AsyncOperation<BuildResult> (t, cs);
				currentBuildOperation = op;
				currentBuildOperationOwner = entry;
			}
			catch {
				tt.End ();
				throw;
			}
			
			return currentBuildOperation;
		}
예제 #7
0
		void OnTestSessionCompleted ()
		{
			RefreshDetails ();
			runningTestOperation = null;
			this.buttonRunAll.Sensitive = true;
			this.buttonStop.Sensitive = false;

		}
예제 #8
0
		public IAsyncOperation Rebuild (IBuildTarget entry)
		{
			if (currentBuildOperation != null && !currentBuildOperation.IsCompleted) return currentBuildOperation;
			
			var asyncOperation = new AsyncOperation ();
			IAsyncOperation cleanOperation = Clean (entry);

			asyncOperation.TrackOperation (cleanOperation, false);
			
			cleanOperation.Completed += (aop) => {
				if (aop.Success)
					asyncOperation.TrackOperation (Build (entry), true);
			};
			
			return asyncOperation;
		}
예제 #9
0
		async Task ExecuteAsync (IBuildTarget entry, ExecutionContext context, CancellationTokenSource cs, ConfigurationSelector configuration, RunConfiguration runConfiguration, bool buildBeforeExecuting)
		{
			if (configuration == null)
				configuration = IdeApp.Workspace.ActiveConfiguration;
			
			var bth = context.ExecutionHandler as IConfigurableExecutionHandler;
			var rt = entry as IRunTarget;
			if (bth != null && rt != null) {
				var h = await bth.Configure (rt, context, configuration, runConfiguration);
				if (h == null)
					return;
				context = new ExecutionContext (h, context.ConsoleFactory, context.ExecutionTarget);
			}
			
			if (buildBeforeExecuting) {
				if (!await CheckAndBuildForExecute (entry, context, configuration, runConfiguration))
					return;
			}

			ProgressMonitor monitor = new ProgressMonitor (cs);

			var t = ExecuteSolutionItemAsync (monitor, entry, context, configuration, runConfiguration);

			var op = new AsyncOperation (t, cs);
			CurrentRunOperation = op;
			currentRunOperationOwner = entry;

			await t;

			var error = monitor.Errors.FirstOrDefault ();
			if (error != null)
				IdeApp.Workbench.StatusBar.ShowError (error.DisplayMessage);
			currentRunOperationOwner = null;
		}
예제 #10
0
		AsyncOperation RunTest (ITreeNavigator nav, IExecutionHandler mode, bool bringToFront = true)
		{
			if (nav == null)
				return null;
			UnitTest test = nav.DataItem as UnitTest;
			if (test == null)
				return null;
			NUnitService.ResetResult (test.RootTest);
			
			this.buttonRunAll.Sensitive = false;
			this.buttonStop.Sensitive = true;

			if (bringToFront)
				IdeApp.Workbench.GetPad<TestPad> ().BringToFront ();
			runningTestOperation = testService.RunTest (test, mode);
			runningTestOperation.Task.ContinueWith (t => OnTestSessionCompleted (), TaskScheduler.FromCurrentSynchronizationContext ());
			return runningTestOperation;
		}
예제 #11
0
		// Forces the reloading of tests, if they have changed
		public virtual IAsyncOperation Refresh ()
		{
			AsyncOperation op = new AsyncOperation ();
			op.SetCompleted (true);
			return op;
		}
		public void AddOperation (AsyncOperation op)
		{
			Operations.Add (op);
			op.Task.ContinueWith (CheckForCompletion);
		}
		public void AddRunOperation (AsyncOperation runOperation)
		{
			if (runOperation == null)
				return;
			if (runOperation.IsCompleted)//null or complete doesn't change anything, just ignore
				return;
			if (currentRunOperation.IsCompleted) {//if MultipleAsyncOperations is complete, we can't just restart Task.. start new one
				currentRunOperation = new MultipleAsyncOperation ();
				currentRunOperation.AddOperation (runOperation);
				OnCurrentRunOperationChanged (EventArgs.Empty);
			} else {//Some process is already running... attach this one to it...
				currentRunOperation.AddOperation (runOperation);
			}
		}
		public IAsyncOperation RunTest (UnitTest test, IExecutionHandler context, bool buildOwnerObject)
		{
			string testName = test.FullName;
			
			if (buildOwnerObject) {
				IBuildTarget bt = test.OwnerObject as IBuildTarget;
				if (bt != null && bt.NeedsBuilding (IdeApp.Workspace.ActiveConfiguration)) {
					if (!IdeApp.ProjectOperations.CurrentRunOperation.IsCompleted) {
						MonoDevelop.Ide.Commands.StopHandler.StopBuildOperations ();
						IdeApp.ProjectOperations.CurrentRunOperation.WaitForCompleted ();
					}
	
					AsyncOperation retOper = new AsyncOperation ();
					
					IAsyncOperation op = IdeApp.ProjectOperations.Build (bt);
					retOper.TrackOperation (op, false);
						
					op.Completed += delegate {
						// The completed event of the build operation is run in the gui thread,
						// so we need a new thread, because refreshing must be async
						System.Threading.ThreadPool.QueueUserWorkItem (delegate {
							if (op.Success) {
								RefreshTests ();
								test = SearchTest (testName);
								if (test != null) {
									Gtk.Application.Invoke (delegate {
										// RunTest must run in the gui thread
										retOper.TrackOperation (RunTest (test, context, false), true);
									});
								}
								else
									retOper.SetCompleted (false);
							}
						});
					};
					
					return retOper;
				}
			}
			
			Pad resultsPad = IdeApp.Workbench.GetPad <TestResultsPad>();
			if (resultsPad == null) {
				resultsPad = IdeApp.Workbench.ShowPad (new TestResultsPad (), "MonoDevelop.NUnit.TestResultsPad", GettextCatalog.GetString ("Test results"), "Bottom", "md-solution");
			}
			
			resultsPad.BringToFront ();
			TestSession session = new TestSession (test, context, (TestResultsPad) resultsPad.Content);
			session.Start ();
			return session;
		}
    /// <summary>
    /// Sets up everything that is necessary to start the StyleCop analysis and then kicks off the worker thread.
    /// </summary>
    /// <param name="projectOperations">The <see cref="ProjectOperations"/> object being used.</param>
    /// <param name="entry">MonoDevelop build target i.e. a Solution or Project</param>
    /// <param name="fullAnalysis">True if a full analysis should be performed.</param>
    /// <param name="styleCopProjects">Collection of StyleCop projects to analyze.</param>
    /// <returns>AsyncOperation object which can be used to i.e. listen to the Completed event which is invoked when the operation is completed.</returns>
    internal static AsyncOperation StyleCopAnalysis(this ProjectOperations projectOperations, IBuildTarget entry, bool fullAnalysis, IList<CodeProject> styleCopProjects)
    {
      if (projectOperations.CurrentRunOperation != null && !projectOperations.CurrentRunOperation.IsCompleted)
      {
        return projectOperations.CurrentRunOperation;
      }

      if (currentStyleCopOperation != null && !currentStyleCopOperation.IsCompleted)
      {
        return currentStyleCopOperation;
      }

      CancellationTokenSource cs = new CancellationTokenSource();
      styleCopTimer.BeginTiming("Starting StyleCop analysis on " + entry.Name);
      styleCopProgressMonitor = IdeApp.Workbench.ProgressMonitors.GetBuildProgressMonitor();
      projectOperations.CurrentRunOperation = currentStyleCopOperation = new AsyncOperation(RunStyleCopAnalysisAsync(fullAnalysis, styleCopProjects), cs);

      return currentStyleCopOperation;
    }