protected void ExecuteTool()
{
try {
if ((((ushort)GetKeyState(0x91)) & 0xffff) != 0) {
Debugger.Break();
}
if (skip) {
return;
}
if (StartMessage.Is()) {
Messages.Enqueue( new BuildMessage( StartMessage));
}
Guid iid = Guid.NewGuid();
string pipeName = @"\pipe\ptk_{0}_{1}".format(Process.GetCurrentProcess().Id, Index);
Result = true;
using (var server = new RpcServerApi(iid)) {
string currentProjectName = string.Empty;
//Allow up to 5 connections over named pipes
server.AddProtocol(RpcProtseq.ncacn_np, pipeName, 5);
//Authenticate via WinNT
// server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
//Start receiving calls
server.StartListening();
//When a call comes, do the following:
server.OnExecute +=
(client, arg) => {
// deserialize the message object and replay thru this logger.
var message = JsonSerializer.DeserializeFromString<BuildMessage>(arg.ToUtf8String());
if (!filters.Any(each => each.IsMatch(message.Message))) {
Messages.Enqueue(message);
}
if (cancellationTokenSource.IsCancellationRequested) {
return new byte[1] {
0x01
};
}
return new byte[0];
};
foreach (var project in projectFiles) {
if (cancellationTokenSource.IsCancellationRequested) {
Result = false;
return;
}
currentProjectName = project;
if (ProjectStartMessage.Is()) {
Messages.Enqueue(new BuildMessage(ProjectStartMessage));
}
try {
// no logo, thanks.
var parameters = " /nologo";
// add properties lines.
if (!Properties.IsNullOrEmpty()) {
parameters = parameters + " /p:" + Properties.Select(each => each.ItemSpec).Aggregate((c, e) => c + ";" + e);
}
parameters = parameters + @" /noconsolelogger ""/logger:ClrPlus.Scripting.MsBuild.Building.Logger,{0};{1};{2}"" ""{3}""".format(Assembly.GetExecutingAssembly().Location, pipeName, iid, project);
if ((((ushort)GetKeyState(0x91)) & 0xffff) != 0) {
Debugger.Break();
}
var proc = AsyncProcess.Start(
new ProcessStartInfo(MSBuildExecutable, parameters) {
WindowStyle = ProcessWindowStyle.Normal
,
}, _environment);
while (!proc.WaitForExit(20)) {
if (cancellationTokenSource.IsCancellationRequested) {
proc.Kill();
}
}
// StdErr = proc.StandardError.Where(each => each.Is()).Select(each => (ITaskItem)new TaskItem(each)).ToArray();
// StdOut = proc.StandardOutput.Where(each => each.Is()).Select(each => (ITaskItem)new TaskItem(each)).ToArray();
if (proc.ExitCode != 0) {
Result = false;
return;
}
;
} catch (Exception e) {
Messages.Enqueue( new BuildMessage( "{0},{1},{2}".format(e.GetType().Name, e.Message, e.StackTrace)) {
EventType = "BuildError",
});
Result = false;
return;
}
if (ProjectEndMessage.Is()) {
Messages.Enqueue(new BuildMessage (ProjectEndMessage));
}
}
}
if (EndMessage.Is()) {
Messages.Enqueue(new BuildMessage(EndMessage));
}
} catch (Exception e) {
Messages.Enqueue(new BuildMessage("{0},{1},{2}".format(e.GetType().Name, e.Message, e.StackTrace)) {
EventType = "BuildError",
});
} finally {
Completed.Set();
}
}