/*----------------------------------------------------------------------
Prof-It for C#
Copyright (c) 2004 Klaus Lehner, University of Linz
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
----------------------------------------------------------------------*/
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Runtime.Serialization.Formatters.Binary;
using at.jku.ssw.ProfIt.Components;
namespace at.jku.ssw.ProfIt.CodeGen{
/// <summary>
/// Summary description for ProcessStarter.
/// </summary>
public class ProcessStarter {
private Solution solution;
private static Process currentProcess;
public ProcessStarter() {
}
/// <summary>
/// Starts the currentProcess and redirects output to the output window
/// of Prof-It. This method only reacts on ReadLine() not on Read(), because
/// there were update-problems. This has to be fixed lateron.
/// </summary>
private void start() {
Console.WriteLine("[Profiler] Starting solution '" + solution.ExecutableFileName + "'");
currentProcess = new Process();
currentProcess.StartInfo.FileName = solution.ExecutableFileName;
currentProcess.StartInfo.UseShellExecute = solution.ExecuteInOwnWindow;
currentProcess.StartInfo.RedirectStandardOutput = !solution.ExecuteInOwnWindow;
currentProcess.StartInfo.RedirectStandardInput = false;
currentProcess.StartInfo.Arguments = solution.StartParameters;
currentProcess.StartInfo.CreateNoWindow = !solution.ExecuteInOwnWindow;
currentProcess.Exited += new EventHandler(p_Exited);
currentProcess.EnableRaisingEvents = true;
Console.WriteLine("[Prof-It] Working Directory is " + solution.StartProject.WorkingDirectory);
currentProcess.StartInfo.WorkingDirectory = solution.StartProject.WorkingDirectory;
if (!File.Exists(solution.CounterFileName) || !File.Exists(solution.CounterFileName2)) {
CounterConverter.StoreCounters(solution);
}
currentProcess.Start();
string s=null;
if (currentProcess.StartInfo.RedirectStandardOutput) {
while ((s = currentProcess.StandardOutput.ReadLine()) != null) {
Console.WriteLine(s);
}
}
}
/// <summary>
/// Runs the specified solution
/// </summary>
/// <param name="solution"></param>
public void RunSolution(Solution solution) {
this.solution = solution;
CounterConverter.StoreCounters(solution);
Thread thread = new Thread(new ThreadStart(start));
thread.IsBackground = true;
thread.Start();
}
/// <summary>
/// Kills the current process
/// </summary>
public static void KillCurrentProcess() {
if (currentProcess != null) {
currentProcess.Kill();
}
}
private void p_Exited(object sender, EventArgs e) {
CounterFileChanged(null, null);
ProcessExited(sender, e);
}
public event System.EventHandler CounterFileChanged;
public event System.EventHandler ProcessExited;
}
}
|