예제 #1
0
 public PublishLogEvent(string logType, string logMessage)
 {
     this.Id         = Guid.NewGuid();
     this.Timestamp  = DateTime.UtcNow;
     this.LogType    = logType;
     this.LogMessage = logMessage;
     this.IP         = DnsHelper.GetIpAddressAsync().GetAwaiter().GetResult();
 }
예제 #2
0
        public async Task BeEmptyWhenNoAddresses()
        {
            var hostEntryProvider = Substitute.For <IHostEntryProvider>();

            hostEntryProvider.GetHostEntryAsync().Returns(new IPHostEntry());
            var address = await DnsHelper.GetIpAddressAsync(hostEntryProvider);

            Assert.Empty(address);
        }
예제 #3
0
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime)
        {
            var log = loggerFactory
                      .AddNLog()
                      //.AddConsole()
                      //.AddDebug()
                      .CreateLogger <Startup>();

            loggerFactory.ConfigureNLog("NLog.config");

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });


            app.UseSwagger((httpRequest, swaggerDoc) =>
            {
                swaggerDoc.Host = httpRequest.Host.Value;
            });
            app.UseSwaggerUi();



            // add tenant & health check
            var localAddress = DnsHelper.GetIpAddressAsync().Result;
            var uri          = new Uri($"http://{localAddress}:{Program.PORT}/");

            log.LogInformation("Registering tenant at ${uri}");
            var registryInformation = app.AddTenant("values", "1.0.0-pre", uri, tags: new[] { "urlprefix-/values" });

            log.LogInformation("Registering additional health check");
            //var checkId = app.AddHealthCheck(registryInformation, new Uri(uri, "status"), TimeSpan.FromSeconds(15), "status");

            // prepare checkId for options injection
            //app.ApplicationServices.GetService<IOptions<HealthCheckOptions>>().Value.HealthCheckId = checkId;

            // register service & health check cleanup
            applicationLifetime.ApplicationStopping.Register(() =>
            {
                log.LogInformation("Removing tenant & additional health check");
                //app.RemoveHealthCheck(checkId);
                app.RemoveTenant(registryInformation.Id);
                _consulConfigCancellationTokenSource.Cancel();
            });
        }
예제 #4
0
        private async Task <string> GetServiceIdAsync(string serviceName, Uri uri)
        {
            var ipAddress = await DnsHelper.GetIpAddressAsync();

            return($"{serviceName}_{ipAddress.Replace(".", "_")}_{uri.Port}");
        }
예제 #5
0
        private async Task <string> GetServiceIdAsync(string serviceName, Uri uri)
        {
            var ipAddress = await DnsHelper.GetIpAddressAsync(s_hostEntryProvider).ConfigureAwait(false);

            return($"{serviceName}_{ipAddress.Replace(".", "_")}_{uri.Port}");
        }
예제 #6
0
        public async Task GetIpv6AddressAsync()
        {
            var address = await DnsHelper.GetIpAddressAsync(new DnsHostEntryProvider(), ipv4 : false);

            Assert.NotEmpty(address);
        }
예제 #7
0
        public async Task GetIpv4AddressAsync()
        {
            var address = await DnsHelper.GetIpAddressAsync();

            Assert.NotEmpty(address);
        }