Viewing application/x-csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Net.XpFramework.Runner
{
class Executor
{
private static int KEY = 0;
private static int VALUE = 1;
private static char[] PATH_SEPARATOR = new char[] { Path.PathSeparator };
private static char[] KVAL_SEPARATOR = new char[] { '=' };
public static int Execute(string base_dir, string runner, string tool, string[] includes, string[] args)
{
var env = System.Environment.GetEnvironmentVariable("USE_XP");
IEnumerable<string> use_xp = null;
if (null == env)
{
if (!File.Exists(base_dir + "xp.ini"))
{
throw new FileNotFoundException("Cannot find xp.ini in " + base_dir);
}
foreach (var line in File.ReadAllLines(base_dir + "xp.ini"))
{
var parsed = line.Split(KVAL_SEPARATOR, 2);
if (parsed[KEY] == "use")
{
use_xp = Paths.Translate(base_dir, parsed[VALUE].Split(PATH_SEPARATOR));
}
}
}
else
{
use_xp = Paths.Translate(System.Environment.CurrentDirectory, env.Split(PATH_SEPARATOR));
}
var executor = "php";
var argv = String.Format(
"-dinclude_path=\".;{0}\" -duser_dir=\"{1}\" -dmagic_quotes_gpc=0",
String.Join(new string(PATH_SEPARATOR), includes),
String.Join(new string(PATH_SEPARATOR), use_xp.ToArray())
);
foreach (var ini in Paths.Locate(use_xp, "php.ini", false))
{
foreach (var line in File.ReadAllLines(ini))
{
var parsed = line.Split(KVAL_SEPARATOR, 2);
if (parsed[KEY] == "executor")
{
executor = parsed[VALUE];
}
else
{
argv += " -d" + parsed[KEY] + "=\"" + parsed[VALUE] + "\"";
}
}
}
var proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = executor;
proc.StartInfo.Arguments = argv + " \"" + Paths.Locate(use_xp, "tools\\" + runner + ".php", true).First() + "\" " + tool;
if (args.Length > 0)
{
proc.StartInfo.Arguments += " \"" + String.Join("\" \"", args) + "\"";
}
proc.StartInfo.UseShellExecute = false;
try
{
proc.Start();
proc.WaitForExit();
return proc.ExitCode;
}
finally
{
proc.Close();
}
}
}
}
|
Download
You can download the file
«Executor.cs»
by using
this link.
|