private void AttachToParent(Process parentProcess) { _log.Info("Attaching the current process to the parent process \"{0}\" ({1})", parentProcess.ProcessName, parentProcess.Id); void OnParentProcessExited() { _log.Warn("Exiting because the attached parent process \"{0}\" ({1}) exited with code {2}", parentProcess.ProcessName, parentProcess.Id, parentProcess.ExitCode); _loggingInitializer?.Dispose(); Environment.Exit(1); } parentProcess.EnableRaisingEvents = true; parentProcess.Exited += (sender, args) => { OnParentProcessExited(); }; if (parentProcess.HasExited) { OnParentProcessExited(); } }
public static async Task Main(string[] args) { var logging = new LoggingInitializer(); var log = LogManager.GetLogger <Program>(); try { var brokerPath = args.Length > 0 ? args[0] : Path.GetFullPath(@"../.."); Console.WriteLine("Connecting to broker {0}", brokerPath); var client = ClientFactory.Instance.Create( new ClientOptionsBuilder() .WithDefaultConfiguration(brokerPath) .WithApplicationId("interop.samples.GreetingServer") .WithProvidedService( "interop.samples.GreetingService", s => s .WithUnaryMethod <GreetingRequest, GreetingResponse>("Unary", GreetingUnary) .WithServerStreamingMethod <GreetingRequest, GreetingResponse>("ServerStreaming", GreetingServerStreaming) .WithClientStreamingMethod <GreetingRequest, GreetingResponse>("ClientStreaming", GreetingClientStreaming) .WithDuplexStreamingMethod <GreetingRequest, GreetingResponse>("DuplexStreaming", GreetingDuplexStreaming) ) .Build()); Console.CancelKeyPress += (sender, eventArgs) => { eventArgs.Cancel = true; Console.WriteLine("Disconnecting"); client.DisconnectAsync(); }; await client.ConnectAsync().ConfigureAwait(false); Console.WriteLine("Connected"); await client.Completion; Console.WriteLine("Disconnected"); } catch (Exception ex) { Console.WriteLine("Program terminated with exception. See log for details. {0}: {1}", ex.GetType(), ex.Message); log.Error(ex, "Program terminated with exception"); logging.Dispose(); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public static async Task Main(string[] args) { var logging = new LoggingInitializer(); var log = LogManager.GetLogger <Program>(); try { var brokerPath = args.Length > 0 ? args[0] : Path.GetFullPath(@"../.."); Console.WriteLine("Connecting to {0}", brokerPath); var client = ClientFactory.Instance.Create( new ClientOptionsBuilder() .WithDefaultConfiguration(brokerPath) .WithApplicationId("interop.samples.GreetingClient") .Build()); await client.ConnectAsync(); Console.WriteLine("Connected"); var nextCase = true; while (nextCase) { Console.WriteLine( "> Select next example:\n" + "> '1': Unary Call\n" + "> '2': Server Streaming Call\n" + "> '3': Client Streaming Call\n" + "> '4': Duplex Streaming Call\n" + "> '5': Discovery\n" + "> '0': Disconnect"); var c = Console.ReadLine(); switch (c) { case "1": await UnaryRequestExampleAsync(client); break; case "2": await ServerStreamingRequestExampleAsync(client); break; case "3": await ClientStreamingRequestExampleAsync(client); break; case "4": await DuplexStreamingRequestExampleAsync(client); break; case "5": await DiscoveryExampleAsync(client); break; case "0": nextCase = false; break; default: Console.WriteLine("Unknown command: {0}", c); break; } } await client.DisconnectAsync(); Console.WriteLine("Disconnected"); } catch (Exception ex) { Console.WriteLine("Program terminated with exception. See log for details. {0}: {1}", ex.GetType(), ex.Message); log.Error(ex, "Program terminated with exception"); } finally { logging.Dispose(); } Console.WriteLine("> Press any key to exit..."); Console.ReadKey(); }
public void Dispose() { LogManager.GetLogger <TestingInitializer>().Info("Disposing tests session"); _logging.Dispose(); }