// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using ICSharpCode.Profiler.Controller;
using ICSharpCode.Profiler.Controller.Data;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Workbench;
namespace ICSharpCode.Profiler.AddIn
{
///
/// Description of ProfilerProcessRunner.
///
public class ProfilerProcessRunner : IProcessRunner
{
ProcessStartInfo psi;
ProfilerRunner profilerRunner;
Process runningProcess;
IProfilingDataWriter writer;
ProfilerOptions options;
readonly object lockObj = new object();
bool wasStarted;
public ProfilerProcessRunner(IProfilingDataWriter writer, ProfilerOptions options)
{
if (writer == null)
throw new ArgumentNullException("writer");
if (options == null)
throw new ArgumentNullException("options");
this.writer = writer;
this.options = options;
this.psi = new ProcessStartInfo();
wasStarted = false;
}
public Task RunInOutputPadAsync(IOutputCategory outputCategory, string program, params string[] arguments)
{
throw new NotImplementedException();
}
public void Start(string program, params string[] arguments)
{
lock (lockObj) {
if (wasStarted)
throw new InvalidOperationException();
profilerRunner = new ProfilerRunner(psi, true, writer);
profilerRunner.RunFinished += delegate { hasExited = true; };
runningProcess = profilerRunner.Run();
wasStarted = true;
}
}
public void StartCommandLine(string commandLine)
{
string[] args = ProcessRunner.CommandLineToArgumentArray(commandLine);
Start(args.FirstOrDefault() ?? "", args.Skip(1).ToArray());
}
public void Kill()
{
profilerRunner.Stop();
}
TaskCompletionSource