public void Start(string url) { mainContext.Server = new Server(); mainContext.LocalSettings = Settings.Default; mainContext.LocalSettings.Dump(); if (url == null) { url = mainContext.LocalSettings.WebSiteUrl; } if (url != null) { mainContext.Server.Url = url + "/WebService/Server.asmx"; } int i = mainContext.Server.Url.IndexOf("/WebService"); mainContext.ServerUrl = mainContext.Server.Url.Substring(0, i); LogService.WriteLine("Connecting to: " + mainContext.ServerUrl); if (running) { return; } if (mainContext.LocalSettings.AppArmorSandbox) { SandboxService.Initialize(); } running = true; builderThread = new Thread(Run); builderThread.Start(); }
internal static void RunCommand(bool sandboxed, string command, string args, StringBuilder output, StringBuilder error, int timeout, string workDir) { // Console.WriteLine ("> " + command + " " + args); Process p = new Process(); ProcessStartInfo pinfo = p.StartInfo; pinfo.FileName = command; pinfo.Arguments = args; if (workDir != null) { pinfo.WorkingDirectory = workDir; } pinfo.UseShellExecute = false; pinfo.RedirectStandardOutput = true; pinfo.RedirectStandardError = true; pinfo.CreateNoWindow = true; p.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { lock (output) output.Append(e.Data + "\n"); }; p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) { lock (error) error.Append(e.Data + "\n"); }; try { if (sandboxed) { SandboxService.EnterSandbox(); } p.Start(); } finally { if (sandboxed) { SandboxService.ExitSandbox(); } } p.BeginOutputReadLine(); p.BeginErrorReadLine(); if (!p.WaitForExit(timeout)) { // Wait for 5 minutes output.AppendLine("\nAborted."); try { p.Kill(); } catch { } throw new Exception("Source fetch took more than 5 minutes. Aborted."); } if (p.ExitCode != 0) { throw new Exception("Command failed."); } }