コード例 #1
0
        public static async Task Main(string[] args)
        {
            var pluginHost = new PluginHost();

            // KV sample client doesn't support MTLS
            // pluginHost.PKI = PKI.SimplePKIDetails.GenerateRSA();

            pluginHost.PrepareHost(args);
            pluginHost.BuildHostApp();
            pluginHost.MapGrpcService <Services.KVService>();
            var log = pluginHost.Services.GetRequiredService <ILogger <PluginMain> >();

            log.LogInformation("Starting up Plugin Host...");
            var hostingTask = pluginHost.StartHosting();

            log.LogInformation("Capturing console cancel request");
            Console.CancelKeyPress += (o, e) => {
                log.LogInformation("Got CANCEL request");
                pluginHost.StopHosting();
                log.LogInformation("Initiated Plugin Stop");
            };

            Console.WriteLine("Running...");
            Console.WriteLine("Hit CTRL+C to exit.");

            _ = Task.Run(async() => {
                await Task.Delay(20 * 1000);
                log.LogInformation("Timedout hosting");
                pluginHost.StopHosting();
                log.LogInformation("Initiated Plugin Stop");
            });

            await hostingTask;
        }
コード例 #2
0
        public void Prepare(string[] args, PluginHost pluginHost = null)
        {
            _appBaseDir  = AppContext.BaseDirectory;
            _procModFile = Process.GetCurrentProcess().MainModule.FileName;
            _procModDir  = Path.GetDirectoryName(_procModFile);

            var logFilters = LoggingFilters ?? DefaultLoggingFilters;

            var seriLogger = LoggingUtil.ConfigureSerilog(_procModDir).CreateLogger();

            LoggerFactory.AttachSerilog(seriLogger, filters: logFilters);
            _log = LoggerFactory.CreateLogger <TFPluginServer>();
            _log.LogDebug("Logging initialized");
            _log.LogInformation("***********************************************************************************");
            _log.LogInformation("** Plugin Server Preparing...");
            _log.LogInformation("***********************************************************************************");

            //DumpEnv();

            _proto = new TFPluginProtocol();
            if (!_proto.PrepareHandshake())
            {
                if (!_proto.MagicCookieFound)
                {
                    Console.Error.WriteLine(BadInvokeMessage);
                    Environment.Exit(-1);
                    return;
                }
                if (!_proto.ProtocolVersionMatched)
                {
                    throw new Exception("Protocol version mistmatch");
                }
            }

            ResolveListenEndpoint();

            _pluginHost                      = pluginHost ?? NewPluginHost();
            _pluginHost.PKI                  = SimplePKIDetails.GenerateRSA();
            _pluginHost.ListenHost           = _listenHost;
            _pluginHost.ListenPort           = _listenPort;
            _pluginHost.AppProtocolVersion   = _proto.AppProtocolVersion;
            _pluginHost.LoggingBuilderAction = lb =>
            {
                lb.ClearProviders();
                lb.AttachSerilog(seriLogger, filters: logFilters);
            };

            _pluginHost.PrepareHost(args);
            _pluginHost.AddServices(services =>
            {
                services.AddTransient(typeof(Util.Fallback <>));

                services.AddSingleton(this);
                services.AddSingleton <ISchemaResolver, Services.SchemaResolver>();
                services.AddSingleton <Services.PluginService>();
            });
            _pluginHost.BuildHostApp();
            _pluginHost.MapGrpcService <Services.PluginService>();
        }