public static GaugeVersionInfo GetInstalledGaugeVersion(IGaugeProcess gaugeProcess = null) { if (gaugeProcess == null) { gaugeProcess = GaugeProcess.ForVersion(); } gaugeProcess.Start(); var error = gaugeProcess.StandardError.ReadToEnd(); gaugeProcess.WaitForExit(); if (gaugeProcess.ExitCode != 0) { throw new GaugeVersionNotFoundException(error); } var serializer = new DataContractJsonSerializer(typeof(GaugeVersionInfo)); var versionText = SanitizeDeprecationMessage(gaugeProcess.StandardOutput.ReadToEnd()); using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(versionText))) { return((GaugeVersionInfo)serializer.ReadObject(ms)); } }
private IGaugeApiConnection StartGaugeAsDaemon(Project gaugeProject, int minPortRange, int maxPortRange) { var slugifiedName = gaugeProject.SlugifiedName(); if (ChildProcesses.ContainsKey(slugifiedName)) { if (ChildProcesses[slugifiedName].HasExited) { KillChildProcess(slugifiedName); } else { return(ApiConnections[slugifiedName]); } } var projectOutputPath = GetValidProjectOutputPath(gaugeProject); var port = GetOpenPort(minPortRange, maxPortRange); OutputPaneLogger.Debug("Opening Gauge Daemon for Project : {0}, at port: {1}", gaugeProject.Name, port); var environmentVariables = new Dictionary <string, string> { { "GAUGE_API_PORT", port.ToString(CultureInfo.InvariantCulture) }, { "gauge_custom_build_path", projectOutputPath } }; var gaugeProcess = GaugeProcess.ForDaemon(GetProjectRoot(gaugeProject), environmentVariables); gaugeProcess.Exited += (s, e) => OutputPaneLogger.Error( $"PID {gaugeProcess.Id} has exited with exit code {gaugeProcess.ExitCode}.\nSTDOUT:\n{gaugeProcess.StandardOutput.ReadToEnd()}\nSTDERR\n{gaugeProcess.StandardError.ReadToEnd()}"); gaugeProcess.OutputDataReceived += (sender, args) => { if (args.Data.StartsWith("Gauge daemon initialized")) { _initialized = true; } }; if (!gaugeProcess.Start()) { throw new GaugeApiInitializationException(gaugeProcess.StandardOutput.ReadToEnd(), gaugeProcess.StandardError.ReadToEnd()); } gaugeProcess.BeginOutputReadLine(); OutputPaneLogger.Debug("Opening Gauge Daemon with PID: {0}", gaugeProcess.Id); WaitForColdStart(); var tcpClientWrapper = new TcpClientWrapper(port); ApiPorts.Add(slugifiedName, port); ChildProcesses.Add(slugifiedName, gaugeProcess.BaseProcess); OutputPaneLogger.Debug("PID: {0} ready, waiting for messages..", gaugeProcess.Id); return(new GaugeApiConnection(tcpClientWrapper)); }