private async Task CreateProcess(IHttpContext context, int processId) { logger.Log("Starting create for process " + processId); string error; try { string commandLine; string arguments; using (var sr = new System.IO.StreamReader(context.Request.InputStream)) { commandLine = sr.ReadLine(); arguments = sr.ReadLine(); } logger.Log("Received create for process " + processId + " cmdline: " + commandLine + " arguments: " + arguments); if (parent.Create(processId)) { logger.Log("Added process entry for " + processId); await server.ReportSuccess(context, true); } else { logger.Log("Process entry for " + processId + " already exists"); await server.ReportError(context, HttpStatusCode.Conflict, "Process " + processId + " already exists"); } parent.Launch(processId, commandLine, arguments); return; } catch (Exception e) { logger.Log("Failed reading create commandline for " + processId); error = "Request failed: " + e.Message; } await server.ReportError(context, HttpStatusCode.BadRequest, error); }
private async Task Upload(IHttpContext context) { IHttpRequest req = context.Request; logger.Log("upload entered " + req.Url.AbsoluteUri); string srcDirectory = NameFromURI(req.Url); string destination = req.QueryString["dstDirectory"]; if (destination == null) { logger.Log("Upload: no destination"); await server.ReportError(context, HttpStatusCode.BadRequest, "No dstDirectory specified"); return; } Uri dstUri = null; try { dstUri = new Uri(destination); } catch (Exception e) { logger.Log("Upload: destination bad Uri " + destination + ": " + e.ToString()); } if (dstUri == null) { await server.ReportError(context, HttpStatusCode.BadRequest, "Malformed dstDirectory specified"); return; } string sourceLocation = req.QueryString["srcLocation"]; if (sourceLocation != null) { if (sourceLocation == "LOG" && parent.LogDirectory != null) { srcDirectory = parent.LogDirectory; } else { logger.Log("Upload: unknown source location: " + sourceLocation); await server.ReportError(context, HttpStatusCode.BadRequest, "Bad source location specified " + sourceLocation); return; } } List <string> sources = new List <string>(); using (StreamReader sr = new StreamReader(req.InputStream)) { string line; while ((line = await sr.ReadLineAsync()) != null) { sources.Add(line); } } string error = await parent.Upload(srcDirectory, sources, dstUri); if (error == null) { await server.ReportSuccess(context, true); } else { await server.ReportError(context, HttpStatusCode.BadRequest, error); } }