public StopProcessHandlerTests() { var process1 = Substitute.For <IProcess>(); process1.Id.Returns(1); var process2 = Substitute.For <IProcess>(); process2.Id.Returns(2); Processes = new[] { process1, process2, }; Process1Key = Guid.NewGuid(); Process2Key = Guid.NewGuid(); Process3Key = Guid.NewGuid(); ProcessTracker = Substitute.For <IProcessTracker>(); ProcessTracker.GetProcessByKey(Process1Key).Returns(process1); ProcessTracker.GetProcessByKey(Process2Key).Returns(process2); ProcessTracker.GetProcessByKey(Process3Key).Returns(x => null); Handler = new StopProcessHandler(ProcessTracker); }
static void Main(string[] args) { //Debugger.Launch(); if (args.Length == 0) { ExitWithError("Must specify container-id as the first argument.", -1); } containerId = args[0]; hostJobObject = new JobObject(null); hostProcess = ProcessHelper.WrapProcess(Process.GetCurrentProcess()); var input = Console.In; var output = Console.Out; using (var transport = MessageTransport.Create(input, output)) { processTracker = new ProcessTracker(transport, hostJobObject, hostProcess, new ProcessHelper()); var createProcessHandler = new CreateProcessHandler(new ProcessRunner(), processTracker); var pingHandler = new PingHandler(); var findProcessByIdHandler = new FindProcessByIdHandler(processTracker); var stopProcessHandler = new StopProcessHandler(processTracker); var stopAllProcessesHandler = new StopAllProcessesHandler(processTracker); var waitForProcessExitHandler = new WaitForProcessExitHandler(processTracker); var dispatcher = new MessageDispatcher(); dispatcher.RegisterMethod <CreateProcessRequest>( CreateProcessRequest.MethodName, async(request) => { var result = await createProcessHandler.ExecuteAsync(request.@params); return(new CreateProcessResponse(request.id, result)); }); dispatcher.RegisterMethod <PingRequest>( PingRequest.MethodName, async(request) => { await pingHandler.ExecuteAsync(); return(new PingResponse(request.id)); }); dispatcher.RegisterMethod <FindProcessByIdRequest>( FindProcessByIdRequest.MethodName, async(request) => { var result = await findProcessByIdHandler.ExecuteAsync(request.@params); return(new FindProcessByIdResponse(request.id, result)); }); dispatcher.RegisterMethod <StopProcessRequest>( StopProcessRequest.MethodName, async(request) => { await stopProcessHandler.ExecuteAsync(request.@params); return(new StopProcessResponse(request.id)); }); dispatcher.RegisterMethod <StopAllProcessesRequest>( StopAllProcessesRequest.MethodName, async(request) => { await stopAllProcessesHandler.ExecuteAsync(request.@params); return(new StopAllProcessesResponse(request.id)); }); dispatcher.RegisterMethod <WaitForProcessExitRequest>( WaitForProcessExitRequest.MethodName, async(request) => { var result = await waitForProcessExitHandler.ExecuteAsync(request.@params); return(new WaitForProcessExitResponse(request.id, result)); }); transport.SubscribeRequest( async(request) => { var response = await dispatcher.DispatchAsync(request); await transport.PublishResponseAsync(response); }); transport.Start(); ReportOk(); exitEvent.WaitOne(); } }