예제 #1
0
        private void WaitForDBInit(string connectionString, Microsoft.Extensions.Hosting.IHostApplicationLifetime lifetime = null)
        {
            var connection = new MySqlConnection(connectionString);
            int retries    = 1;

            while (retries < 7)
            {
                try
                {
                    Console.WriteLine("Connecting to db. Trial: {0}", retries);
                    connection.Open();
                    connection.Close();
                    break;
                }
                catch (MySqlException e)
                {
                    Console.WriteLine(e.StackTrace);
                    Thread.Sleep((int)Math.Pow(2, retries) * 1000);
                    Console.WriteLine("retrying");
                    retries++;
                }
            }
            if (retries >= 7 && lifetime != null)
            {
                lifetime.StopApplication();
            }
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              Microsoft.Extensions.Hosting.IHostApplicationLifetime lifetime)
        {
            if (env.IsDevelopment())
            {
                //app.UseDeveloperExceptionPage();
            }

            //global error handler
            app.UseExceptionHandler(a => a.Run(async context =>
            {
                var exceptionHandlerPathFeature = context.Features.Get <Microsoft.AspNetCore.Diagnostics.IExceptionHandlerPathFeature>();
                var exception = exceptionHandlerPathFeature.Error;

                var result = System.Text.Json.JsonSerializer.Serialize(new { error = "unhandled exception" });
                if (env.IsDevelopment())
                {
                    result = System.Text.Json.JsonSerializer.Serialize(new { error = exception.Message });
                }
                context.Response.ContentType = "application/json";

                context.Response.StatusCode = 500;
                await context.Response.Body.WriteAsync(System.Text.Encoding.ASCII.GetBytes(result));
            }));

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            if (Configuration["init"] != "true")
            {
                return;
            }

            //run via --init, so we init db and exit
            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService <PatientContext>();
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
            }
            lifetime.StopApplication();
        }
예제 #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.Extensions.Hosting.IHostApplicationLifetime lifetime)
        {
            try {
                app.ApplicationServices.GetService(typeof(RedirectService));
            }
            catch (MongoDB.Driver.MongoConfigurationException)
            {
                lifetime.StopApplication();
            }
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseReactDevelopmentServer(npmScript: "start");
                }
            });
        }
예제 #4
0
    public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostApplicationLifetime lifeTime)
    {
        var serverAddressesFeature =
            app.ServerFeatures.Get <IServerAddressesFeature>();

        app.UseStaticFiles();

        app.Run(async(context) =>
        {
            context.Response.ContentType = "text/html";
            string url      = context.Request.GetDisplayUrl();
            Uri response    = new Uri(url);
            string query    = response.Query;
            string htmlFile = "%RESPONSE%";
            try
            {
                htmlFile = System.IO.File.ReadAllText("index.html");
            }
            catch (Exception)
            {
            }

            if (query.StartsWith("?code="))
            {
                bool success = await Server.RequestToken(query);
                if (success)
                {
                    await context.Response.WriteAsync(htmlFile.Replace("%RESPONSE%", "<span>Authorization Complete!</span><h3>Return to 3ds Max to begin your export!</h3>"));
                }
                else
                {
                    await context.Response.WriteAsync(htmlFile.Replace("%RESPONSE%", "<h2>Authorization Denied!</h2>"));
                }
            }
            else
            {
                await context.Response.WriteAsync(htmlFile.Replace("%RESPONSE%", "<h2>Authorization Denied!</h2>"));
            }

            lifeTime.StopApplication();
        });
    }