public void ProcessRequest(HttpContext context) { string loopValue = context.Request["l"]; int loops; if (!Int32.TryParse(loopValue, out loops)) { loops = 1; } string wwwroot = Path.Combine(HttpRuntime.AppDomainAppPath, "wwwroot"); string nodeDir = Path.Combine(wwwroot, "node_modules"); var npmPath = ResolveNpmPath(); var exe = new Executable(npmPath, wwwroot); for (int i = 0; i < loops; i++) { try { var result = exe.Execute("install"); context.Response.Write(@"<div style=""font-weight:bold;color:green"">Run " + (i + 1) + " success! </div>"); context.Response.Flush(); FileSystemHelpers.DeleteDirectorySafe(nodeDir); } catch (Exception ex) { context.Response.Write(@"<div style=""font-weight:bold;color:red"">Run " + (i + 1) + " failed!</div>"); context.Response.Write(@"<pre>" + ex.Message + "</pre>"); context.Response.Flush(); break; } } }
public static void Install(string packageToInstall, string installToPath) { using (new LatencyLogger("npm install " + packageToInstall + " to " + installToPath)) { var exe = new Executable(PathUtility.ResolveNpmPath(), installToPath, idleTimeout: TimeSpan.FromSeconds(3600)); var result = exe.Execute("install {0} .", packageToInstall); TestTracer.Trace(" stdout: {0}", result.Item1); TestTracer.Trace(" stderr: {0}", result.Item2); } }
public static void Install(string packageToInstall, string installToPath) { using (new LatencyLogger("npm install " + packageToInstall + " to " + installToPath)) { string programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); string npmPath = Path.Combine(programFiles, "nodejs", "npm.cmd"); var exe = new Executable(npmPath, installToPath, idleTimeout: TimeSpan.FromSeconds(3600)); var result = exe.Execute("install {0} .", packageToInstall); TestTracer.Trace(" stdout: {0}", result.Item1); TestTracer.Trace(" stderr: {0}", result.Item2); } }
public static void Execute(string workingDirectory, string commandFormat, params object[] args) { var command = String.Format(commandFormat, args); using (new LatencyLogger(NodeExe + " " + command)) { var exe = new Executable(NodeExe, workingDirectory, idleTimeout: TimeSpan.FromSeconds(3600)); exe.SetHomePath(Environment.GetEnvironmentVariable("USERPROFILE")); var result = exe.Execute(command); TestTracer.Trace(" stdout: {0}", result.Item1); TestTracer.Trace(" stderr: {0}", result.Item2); } }
private void SetupAcls(string appName, string appPoolName) { // Setup Acls for this user var icacls = new Executable(@"C:\Windows\System32\icacls.exe", Directory.GetCurrentDirectory()); // Make sure the application path exists string applicationPath = _pathResolver.GetApplicationPath(appName); Directory.CreateDirectory(applicationPath); try { // Give full control to the app folder (we can make it minimal later) icacls.Execute(@"""{0}\*"" /grant ""IIS AppPool\{1}:F"" /C /Q /T", applicationPath, appPoolName); } catch (Exception ex) { Debug.WriteLine(ex.Message); } try { // Give full control to the temp folder string windowsTemp = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Temp"); icacls.Execute(@"""{0}"" /grant ""IIS AppPool\{1}:F"" /C /Q /T", windowsTemp, appPoolName); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public static void GCDump(this Process process, string dumpFile, string resourcePath, int maxDumpCountK, ITracer tracer, TimeSpan idleTimeout) { var exe = new Executable(_gcDumpExe.Value, Path.GetDirectoryName(dumpFile), idleTimeout); exe.Execute(tracer, "\"{0}\" \"{1}\" \"{2}\" \"{3}\"", process.Id, dumpFile, resourcePath, maxDumpCountK); }
public void CleanWwwRoot() { var tracer = _traceFactory.GetTracer(); using (tracer.Step("Cleaning wwwroot")) { string activeDeploymentId = _status.ActiveDeploymentId; // Clean only required if there is an actual deployment (active deployment id is not null) if (activeDeploymentId != null) { string emptyTempPath = Path.Combine(_environment.TempPath, Guid.NewGuid().ToString()); try { // Create an empty temporary directory FileSystemHelpers.EnsureDirectory(emptyTempPath); string from = emptyTempPath; string to = _environment.WebRootPath; string previousManifest = GetDeploymentManifestPath(activeDeploymentId); string nextManifest = Path.Combine(emptyTempPath, "manifest"); // Run kudu sync from the empty directory to wwwroot using the current manifest // This will cause all previously deployed files to be removed from wwwroot var exe = new Executable(Path.Combine(_environment.ScriptPath, "kudusync.cmd"), emptyTempPath, _settings.GetCommandIdleTimeout()); Tuple<string, string> result = exe.Execute(tracer, "-f {0} -t {1} -p {2} -n {3} -v 50", from, to, previousManifest, nextManifest); if (!String.IsNullOrEmpty(result.Item1)) { tracer.Trace("Process output: {0}", result.Item1); } if (!String.IsNullOrEmpty(result.Item2)) { tracer.Trace("Process error: {0}", result.Item2); } } finally { FileSystemHelpers.DeleteDirectorySafe(emptyTempPath); } } else { tracer.Trace("No active deployment to clean"); } } }
protected virtual bool MapPath(string path, out string driveName) { var cmd = new Executable("cmd", GetWindowsFolder()); driveName = null; foreach (var letter in DriveLetters) { try { // There's probably an API for this as well but this is easy to do // Not as easy to parse out the results of net use cmd.Execute("/c net use {0}: {1}", letter, path); driveName = letter + @":\"; return true; } catch { } } return false; }
private static Tuple<string, string> GitExecute(Executable gitExe, string commandFormat, params object[] args) { var command = String.Format(commandFormat, args); TestTracer.Trace("Executing: git {0}", command); Tuple<string, string> result = gitExe.Execute(command); TestTracer.Trace(" stdout: {0}", result.Item1); TestTracer.Trace(" stderr: {0}", result.Item2); return result; }