コード例 #1
0
 private static AnalysisTask KillProc(IVsTaskManager taskManager)
 {
   AnalysisTask result = null;
   // kill current process
   if (currentProcess != null)
   {
     try
     {
       if (!currentProcess.HasExited)
       {
         currentProcess.Kill();
         result = currentTask;
       }
     }
     catch (Exception exn)
     {
       System.Diagnostics.Trace.WriteLine("Code contracts: Task manager exception: kill process:\n" + exn.ToString());
     }
     finally
     {
       currentProcess = null;
       currentTask = null;
     }
   }
   return result;
 }
コード例 #2
0
 public ClearTasksEvent(AnalysisTask _task)
 {
   Contract.Requires(_task != null);
   task = _task;
 }
コード例 #3
0
    // Background thread loop that spawns processes 
    static void RunBackgroundTasks()
    {
			AnalysisTask task = null;
			try {
				while (true) {
					lock (backgroundTasks) {
						// exit the thread if no work is left
						if (backgroundTasks.Count == 0) {
							currentThread = null;
							return;
						}

						// dequeue a task and start a process
						task = backgroundTasks.Dequeue();
						if (task != null) {
							currentProcess = task.process;
              currentTask = task;
						}
					}

					if (task != null) {
            try
            {
              if (task.process != null)
              {
                task.process.Start();
                task.process.BeginErrorReadLine(); // redirect stderr
                if (!task.options.noRedirectOutput)
                {
                  task.process.BeginOutputReadLine(); // redirect stdout
                }
                task.WriteLine(task.options.projectName + ": Background contract analysis started.");
                task.process.WaitForExit();
              }
            }
            catch (Exception exn)
            {
              task.WriteLine(task.options.projectName + ": Background contract analysis: Exception occurred:\n" + exn.ToString());
            }
						finally {
							task.WriteLine(task.options.projectName + ": Background contract analysis done.");
              task = null;
						}
					}

					lock (backgroundTasks) {
						currentProcess = null;
            currentTask = null;
					}
				}
			}
			catch (Exception exn) {
				System.Diagnostics.Trace.WriteLine("Code contracts task manager exception:\n" + exn.ToString());
				if (task != null) {
					task.WriteLine("Code contracts task manager exception:\n" + exn.ToString());
				}
			}
			finally {
				lock (backgroundTasks) {
					currentProcess = null;
					currentThread = null;
          currentTask = null;
				}
			}
    }
コード例 #4
0
    // Main entry point; this is called by MSBuild.
    public override bool Execute()
    {
      try {
#if DEBUG
        if (!System.Diagnostics.Debugger.IsAttached)
        {
            System.Diagnostics.Debugger.Launch();
        }
#endif
        // default prefixes
        if (options.additionalOutputPrefix == null) options.additionalOutputPrefix = "  + ";
        if (options.outputPrefix == null) options.outputPrefix = "Microsoft Code Contracts: ";

#if !NoVS
        taskManager = HostObject as ITaskManager;

        if (taskManager == null) {
          taskManager = GetTaskManagerFromROT();
          if (taskManager != null) runOutOfProc = true;
        }
#endif
        if (taskManager == null && Log != null) {
          Log.LogMessage(MessageImportance.High, options.outputPrefix + "Task manager is unavailable" + (options.runInBackground ? " (unable to run in background)." : "."));
          options.runInBackground = false;  // can only send messages in background if the taskmanager is available         
        }

        if (!options.ValidateOptions(this.Log))
        {
          return false;
        }

        // Set up an analysis task
        AnalysisTask analysisTask = new AnalysisTask(taskManager, Log, options, runOutOfProc);
        return analysisTask.Run();
      }
      catch (Exception e) {
        if (Log != null) {
          Log.LogErrorFromException(e);
        }
        return false;
      }
      finally {
        taskManager = null;
      }
    }