Esempio n. 1
0
 public CallerContext(
     PulumiFn program,
     CancellationToken cancellationToken)
 {
     this.Program           = program;
     this.CancellationToken = cancellationToken;
 }
Esempio n. 2
0
            public InlineLanguageHost(
                PulumiFn program,
                CancellationToken cancellationToken)
            {
                this._cancelToken = cancellationToken;
                this._host        = Host.CreateDefaultBuilder()
                                    .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder
                    .ConfigureKestrel(kestrelOptions =>
                    {
                        kestrelOptions.Listen(IPAddress.Any, 0, listenOptions =>
                        {
                            listenOptions.Protocols = HttpProtocols.Http2;
                        });
                    })
                    .ConfigureServices(services =>
                    {
                        services.AddLogging();

                        // to be injected into LanguageRuntimeService
                        var callerContext = new LanguageRuntimeService.CallerContext(program, cancellationToken);
                        services.AddSingleton(callerContext);

                        services.AddGrpc(grpcOptions =>
                        {
                            grpcOptions.MaxReceiveMessageSize = LanguageRuntimeService.MaxRpcMesageSize;
                            grpcOptions.MaxSendMessageSize    = LanguageRuntimeService.MaxRpcMesageSize;
                        });
                    })
                    .Configure(app =>
                    {
                        app.UseRouting();
                        app.UseEndpoints(endpoints =>
                        {
                            endpoints.MapGrpcService <LanguageRuntimeService>();
                        });
                    });
                })
                                    .Build();

                // before starting the host, set up this callback to tell us what port was selected
                this._portRegistration = this._host.Services.GetRequiredService <IHostApplicationLifetime>().ApplicationStarted.Register(() =>
                {
                    try
                    {
                        var serverFeatures = this._host.Services.GetRequiredService <IServer>().Features;
                        var addresses      = serverFeatures.Get <IServerAddressesFeature>().Addresses.ToList();
                        Debug.Assert(addresses.Count == 1, "Server should only be listening on one address");
                        var uri = new Uri(addresses[0]);
                        this._portTcs.TrySetResult(uri.Port);
                    }
                    catch (Exception ex)
                    {
                        this._portTcs.TrySetException(ex);
                    }
                });
            }
Esempio n. 3
0
 public CallerContext(
     PulumiFn program,
     ILogger?logger,
     CancellationToken cancellationToken)
 {
     this.Program           = program;
     this.Logger            = logger;
     this.CancellationToken = cancellationToken;
 }