コード例 #1
0
        public static void ConnectAndRunModule(string host, int port, ModuleBase module) {

            var connector = new TcpConnectorSlave();
            connector.Connect(host, port);

            try {
                SingleThreadedAsync.Run(() => Loop(connector, module));
            }
            catch (Exception exp) {
                Console.Error.WriteLine("EXCEPTION: " + exp.Message);
            }
        }
コード例 #2
0
        private static async Task Loop(TcpConnectorSlave connector, ModuleBase module)
        {
            Process parentProcess = null;

            using (Request request = await connector.ReceiveRequest()) {
                if (request.Code != ModuleHelper.ID_ParentInfo)
                {
                    throw new Exception("Missing ParentInfo request (update MediatorLib.dll)");
                }
                ParentInfoMsg info = StdJson.ObjectFromUtf8Stream <ParentInfoMsg>(request.Payload);
                parentProcess = Process.GetProcessById(info.PID);
                connector.SendResponseSuccess(request.RequestID, s => { });
            }

            Thread t = new Thread(() => { ParentAliveChecker(parentProcess); });

            t.IsBackground = true;
            t.Start();

            var  helper = new ModuleHelper(module, connector);
            bool run    = true;

            while (run)
            {
                using (Request request = await connector.ReceiveRequest()) {
                    helper.ExecuteModuleRequestAsync(request);
                    bool shutdown  = request.Code == ModuleHelper.ID_Shutdown;
                    bool initAbort = request.Code == ModuleHelper.ID_InitAbort;
                    run = !shutdown && !initAbort;
                }
            }

            // Wait until parent process kills us (after Run method completed)
            while (true)
            {
                await Task.Delay(1000);
            }
        }
コード例 #3
0
 public ModuleHelper(ModuleBase module, TcpConnectorSlave connector)
 {
     this.module    = module;
     this.connector = connector;
 }