public void Processor_RunHidden_CmdWindowDir() { try { //FileVersionInfo fvi = new FileVersionInfo("filename"); HostProcessor host = new HostProcessor(); Processor p = host.CreateProcessor(); p.FileName = "cmd.exe"; p.Arguments = "/C dir /B " + Environment.CurrentDirectory; if (p.RunHidden()) { int exitCode = p.ExitCode; string s = p.Output; string errMsg = p.ErrorOutput; Assert.AreEqual(p.ExitCode, 0); Assert.IsFalse(p.DidTimeout); Assert.IsNotNull(p.Output); Assert.IsFalse(p.DidTimeout); Assert.IsFalse(p.IsRunning); //Assert.IsTrue(p.IsStarted); } else { Assert.Fail(p.LastError); } } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void Processor_RunCurlGetWebPage() { try { HostProcessor host = new HostProcessor(); Processor p = host.CreateProcessor(); //p. p.FileName = "c:\\bin\\curl.exe"; //p.Arguments = "http://example.com"; p.Arguments = "http://labobjects.com"; if (p.RunHidden()) { int exitCode = p.ExitCode; string s = p.Output; string errMsg = p.ErrorOutput; Assert.AreEqual(p.ExitCode, 0); Assert.IsNotNull(p.Output); Assert.IsFalse(p.DidTimeout); Assert.IsFalse(p.IsRunning); //Assert.IsTrue(p.IsStarted); } else { Assert.Fail(p.LastError); } } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void Processor_RunHidden_ChoiceNo() { try { //FileVersionInfo fvi = new FileVersionInfo("filename"); HostProcessor host = new HostProcessor(); Processor p = host.CreateProcessor(); p.FileName = "cmd.exe"; p.Arguments = "/C choice"; if (p.RunHidden("N")) { int exitCode = p.ExitCode; string s = p.Output; string errMsg = p.ErrorOutput; Assert.AreEqual(p.ExitCode, 2); Assert.IsFalse(p.DidTimeout); Assert.IsNotNull(p.Output); Assert.IsFalse(p.IsRunning); Assert.AreEqual("No Error", p.LastError); } else { Assert.Fail(p.LastError); } } catch (Exception ex) { Assert.Fail(ex.Message); } }
public static async Task <IActionResult> DeleteHostById( [HttpTrigger(AuthorizationLevel.Function, "delete", Route = null)] HttpRequest req, ILogger log) { int hostId; try { NameValueCollection queryStringMap = HttpUtility.ParseQueryString(req.QueryString.Value); hostId = int.Parse(queryStringMap["Id"]); } catch (Exception e) { log.LogError(e, e.Message); return(new BadRequestObjectResult("Request didn't meet syntax requirements (make sure you include everything and have the correct property types)")); } try { await HostProcessor.DeleteHostByIdAsync(connectionString, hostId); } catch (Exception e) { log.LogError(e, e.Message); return(new ConflictObjectResult("Tried to delete row that didn't exist")); } return(new OkObjectResult("Row successfully deleted")); }
public void HostProcessor_GetHost() { HostProcessor host = new HostProcessor(); var productName = host.ProductName; Assert.AreEqual("Microsoft.TestHost.x86", productName); }
public static async Task <IActionResult> GetHosts( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { IEnumerable <HostModel> Hosts = await HostProcessor.GetHostsAsync(connectionString); return(new OkObjectResult(Hosts)); }
public static async Task <IActionResult> CreateHostAndReturnId( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { // get the body in json format string requestBody = await req.ReadAsStringAsync(); JsonElement jsonBody = JsonSerializer.Deserialize <JsonElement>(requestBody); // get all of the values we need for the HostProcessor (maybe deserialize json to a HostModel instead? Or maybe just pass a HostModel with a null Id to this endpoint) string reqHostIp; string reqHostServicesAPISocketAddress; bool reqIsActive; try { reqHostIp = jsonBody.GetProperty("HostIp").GetString(); reqHostServicesAPISocketAddress = jsonBody.GetProperty("HostServicesAPISocketAddress").GetString(); reqIsActive = jsonBody.GetProperty("IsActive").GetBoolean(); } catch (Exception e) { log.LogError(e, e.Message); return(new BadRequestObjectResult("Request didn't meet syntax requirements (make sure you include everything and have the correct property types)")); } // call on the data processor and store the returned Id try { int retVal = await HostProcessor.CreateHostAndReturnIdAsync(connectionString, reqHostIp, reqHostServicesAPISocketAddress, reqIsActive); return(new OkObjectResult(retVal)); } catch (Exception e) { log.LogError(e, e.Message); return(new ConflictObjectResult("Conflict when inserting into the database")); } }
public void Test_CMDWindow() { //todo: wait for exit methid // input stream flush (or otehr helpers? // close HostProcessor host = new HostProcessor(); Processor processor = host.CreateProcessor(); processor.FileName = "cmd.exe"; processor.RedirectStandardError = true; processor.RedirectStandardOutput = true; processor.RedirectStandardInput = true; processor.WindowStyle = ProcessWindowStyle.Hidden; processor.Start(); processor.InputWriteLine("cd c:\\code"); processor.InputWriteLine("dir /b *.*"); if (processor.IsOutputAvailable) { string so = processor.OutputRead(); } if (processor.IsErrorAvailable) { string se = processor.ErrorOutputRead(); } processor.InputWriteLine("exit"); while (!processor.HasExited) { } processor.Close(); if (host.HasActiveProcessors) { } }