Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var config                = HostConfig.GetHostConfig();
            var nativeModules         = GetNativeModules(config);
            var managedModules        = GetManagedModule(config);
            HttpNativeRuntime runtime = null;

            try
            {
                int  workerProcessId = Process.GetCurrentProcess().Id;
                ILog log             = LogManager.GetLogger("WorkerProcess");
                using (NamedPipeClientStream pipeStream = new NamedPipeClientStream($"{workerProcessId}.Request"))
                {
                    Byte[] bytes = new Byte[10];
                    Char[] chars = new Char[10];

                    using (NamedPipeServerStream responsePipeStream = new NamedPipeServerStream($"{workerProcessId}.Response",
                                                                                                PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.None))
                    {
                        while (true)
                        {
                            string message = null;
                            if (!pipeStream.IsConnected)
                            {
                                pipeStream.Connect();
                                pipeStream.ReadMode = PipeTransmissionMode.Message;
                            }
                            do
                            {
                                int numBytes = pipeStream.Read(bytes, 0, bytes.Length);
                                int numChars = Encoding.UTF8.GetChars(bytes, 0, numBytes, chars, 0);
                                if (numBytes > 0)
                                {
                                    message += new String(chars, 0, numChars);
                                }
                            } while (!pipeStream.IsMessageComplete);

                            if (!string.IsNullOrEmpty(message))
                            {
                                if (runtime == null)
                                {
                                    runtime = new HttpNativeRuntime(nativeModules, managedModules);
                                    var site = config.GetRequestingSite(message);
                                    runtime.PhysicalPath = site.PhysicalPath;
                                }
                                responsePipeStream.WaitForConnection();
                                var data = runtime.ProcessRequest(message);
                                responsePipeStream.Write(data, 0, data.Length);
                                responsePipeStream.Disconnect();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                Console.Read();
            }
        }
Exemplo n.º 2
0
 public void RegisterNativeModule(HttpNativeRuntime nativeRuntime)
 {
     log.Info($"Register Native Module in PipeLine {this.GetType().ToString()}");
     nativeRuntime.ExecuteHandler += NativeRuntime_ExecuteHandler;
 }