public virtual void AddToArguments(StartArguments startArguments) { }
/// <summary> /// executed via reflection. /// </summary> /// <param name="args"></param> /// <returns></returns> public static IGame Load(StartArguments args) { return(new GameClient(args)); }
public MyProcObservable(StartArguments startArguments) : base(startArguments) { }
/// <summary> /// executed via reflection. /// </summary> /// <param name="args"></param> /// <returns></returns> public static IGameServer Load(StartArguments args) { return(new GameServer(args)); }
public TestGameServer() : base(StartArguments.Empty()) { }
private void Execute(object objArgs) { string cwd = null; try { _exception = null; cwd = Environment.CurrentDirectory; StartArguments args = (StartArguments)objArgs; ObjectHandle obj = _workerDomain.CreateInstanceFrom(GetType().Assembly.Location, typeof(DomainHook).FullName); if (obj == null) { throw new ApplicationException("Unable to hook child application domain."); } using (DomainHook hook = (DomainHook)obj.Unwrap()) { hook.Capture(args.StdInput == null ? String.Empty : args.StdInput.ReadToEnd()); try { string[] arguments = args.Arguments; Environment.CurrentDirectory = WorkingDirectory; #if NET20 || NET35 _exitCode = _workerDomain.ExecuteAssembly(_executable, AppDomain.CurrentDomain.Evidence, arguments); #else _exitCode = _workerDomain.ExecuteAssembly(_executable, arguments); #endif } finally { string line, stdout, stderr; hook.GetOutput(out stdout, out stderr); if (_outputReceived != null) { using (StringReader r = new StringReader(stdout)) while (null != (line = r.ReadLine())) { _outputReceived(this, new ProcessOutputEventArgs(line, false)); } using (StringReader r = new StringReader(stderr)) while (null != (line = r.ReadLine())) { _outputReceived(this, new ProcessOutputEventArgs(line, true)); } } } } } catch (ThreadAbortException) { return; } catch (Exception e) { _exitCode = -1; try { ThreadStart savestack = Delegate.CreateDelegate(typeof(ThreadStart), e, "InternalPreserveStackTrace", false, false) as ThreadStart; if (savestack != null) { savestack(); } _exception = e; } catch { _exception = new TargetInvocationException(e); } } finally { _isRunning = false; _running = null; if (cwd != null) { Environment.CurrentDirectory = cwd; } if (_processExited != null) { _processExited(this, new ProcessExitedEventArgs(_exitCode)); } } }
/// <summary> /// Starts the sample application and returns the <see cref="Uri"/> on which the application /// can be reached. /// </summary> /// <param name="targetFramework">The target framework under which to run the sample app. Must be a version supported in the TargetFrameworks of the sample app</param> /// <param name="environmentVariables">The environment variables to start the sample app with. The DOTNET_STARTUP_HOOKS environment variable will be added.</param> /// <returns></returns> public Uri Start(string targetFramework, IDictionary <string, string> environmentVariables = null) { var projectDirectory = Path.Combine(SolutionPaths.Root, "sample", ElasticApmStartuphookSampleProjectName); Publish(projectDirectory, targetFramework); var startupHookAssembly = UnzipStartupHook(); environmentVariables ??= new Dictionary <string, string>(); environmentVariables["DOTNET_STARTUP_HOOKS"] = startupHookAssembly; var arguments = new StartArguments("dotnet", $"{ElasticApmStartuphookSampleProjectName}.dll") { WorkingDirectory = Path.Combine(projectDirectory, _publishDirectory, targetFramework), SendControlCFirst = true, Environment = environmentVariables }; var startHandle = new ManualResetEvent(false); ExceptionDispatchInfo e = null; Uri uri = null; var capturedLines = new List <string>(); var endpointRegex = new Regex(@"\s*Now listening on:\s*(?<endpoint>http\:[^\s]*)"); _process = new ObservableProcess(arguments); _process.SubscribeLines( line => { capturedLines.Add(line.Line); var match = endpointRegex.Match(line.Line); if (match.Success) { try { var endpoint = match.Groups["endpoint"].Value.Trim(); uri = new Uri(endpoint); } catch (Exception exception) { e = ExceptionDispatchInfo.Capture(exception); } startHandle.Set(); } }, exception => e = ExceptionDispatchInfo.Capture(exception)); var timeout = TimeSpan.FromMinutes(2); var signalled = startHandle.WaitOne(timeout); if (!signalled) { throw new Exception($"Could not start sample application within timeout {timeout}: " + string.Join(Environment.NewLine, capturedLines)); } _process.CancelAsyncReads(); e?.Throw(); return(uri); }