示例#1
0
 public bool InsertLog(Common.Log log)
 {
     return(ExecuteSPCommand("Insert",
                             "@Type", log.Type,
                             "@Source", log.Source,
                             "@Name", log.Name,
                             "@Text", log.Text,
                             "@IPAddress", log.IPAddress,
                             "@Browser", log.Browser,
                             "@ReferenceGuid", log.ReferenceGuid,
                             "@UserGuid", log.UserGuid));
 }
示例#2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            try
            {
                ConfigureMvcServices(services);

                Log.Logger().Information("Configure Dependency Injection...");
                Ioc.Init(ConfigurationProvider);

                return(Ioc.Container.CreateServiceProvider(services));
            }
            catch (Exception e)
            {
                Log.Logger().Error(e, "Application failed to start");

                throw;
            }
        }
示例#3
0
        public Startup(IHostingEnvironment env)
        {
            try
            {
                var configuration = AppSettingsFileProvider.LoadConfiguration(env.ContentRootPath, env.EnvironmentName);

                ConfigurationProvider = new AppConfigurationProvider(configuration, env.ContentRootPath);

                LoggerConfig.Configure(ConfigurationProvider);
            }
            catch (Exception e)
            {
                var message = $"Application failed to start. Message: {e.Message}, StackTrace: {e.StackTrace}";
                Console.WriteLine(message);
                Log.Logger().Error(e, message);

                throw;
            }
        }
示例#4
0
        public Startup(IHostingEnvironment env)
        {
            try
            {
                var builder = new ConfigurationBuilder()
                              .SetBasePath(env.ContentRootPath)
                              .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                              .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                              .AddEnvironmentVariables();
                var configuration = builder.Build();

                ConfigurationProvider = new CustomConfigurationProvider(configuration, env.ContentRootPath);

                LoggerConfig.Configure(ConfigurationProvider);
            }
            catch (Exception e)
            {
                Log.Logger().Error(e, "Application failed to start");
                throw;
            }
        }
示例#5
0
        public void ConfigureServices(IServiceCollection services)
        {
            try
            {
                Log.Logger().Information("Configure Dependency Injection...");
                DependencyMapper.Configure(services, ConfigurationProvider);

                services.Configure <FormOptions>(x => x.ValueCountLimit = int.MaxValue);

                Log.Logger().Information("Configure ApplicationContext...");
                services
                .AddDbContext <ApplicationContext>(options => options.UseSqlServer(ConfigurationProvider.ConnectionString));

                Log.Logger().Information("Configure MVC services...");
                var builder = services.AddMvc();
                builder.AddMvcOptions(x => x.Filters.Add(new GlobalExceptionHandler()));
                services.AddJwtBearerAuthentication();
            }
            catch (Exception e)
            {
                Log.Logger().Error(e, "Application failed to start");
                throw;
            }
        }
示例#6
0
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              ILoggerFactory loggerFactory,
                              SeedManager seedManager,
                              MigrationManager migrationManager)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                loggerFactory.AddSerilog();
                Log.Logger().Information("Application is starting...");
                Log.Logger().Information("Configuration:");

                ConfigurationProvider.GetType().GetProperties().ToList().ForEach(prop =>
                {
                    Log.Logger().Information("[{name}] = '{value}'", prop.Name, prop.GetValue(ConfigurationProvider));
                });

                DateTimeContext.Initialize(ConfigurationProvider.TimeZone);

                Log.Logger().Information("Configure EF Mappings...");
                MappingConfig.RegisterMappings();

                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                    app.UseDatabaseErrorPage();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error"); //todo IS incorrect page diesnt exist yet!!
                    app.UseHsts();
                    app.UseHttpsRedirection();
                }

                app.UseStaticFiles(new StaticFileOptions {
                    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot"))
                });
                app.UseSession();
                app.UseAuthentication();

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

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

                //migrationManager.EnsureCreated(ConfigurationProvider);
                //migrationManager.ApplyMigrations(ConfigurationProvider);
                seedManager.Seed(ConfigurationProvider);
            }
            catch (Exception e)
            {
                Log.Logger().Error(e, "Application failed to start");

                throw;
            }
            finally
            {
                stopwatch.Stop();
                Log.Logger().Information("Startup time: {Seconds}s", stopwatch.Elapsed.Seconds);
            }
        }
示例#7
0
        private void ConfigureMvcServices(IServiceCollection services)
        {
            Log.Logger().Information("Configure ApplicationContext...");
            //DbContextConfiguration.UseSqlDataBase<DataBase>(services, ConfigurationProvider);
            DbContextConfiguration.UseInMemoryDatabase <DataBase>(services, option =>
                                                                  option.ConfigureWarnings(y => y.Ignore(InMemoryEventId.TransactionIgnoredWarning)));

            Log.Logger().Information("Configure Identity...");
            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <DataBase>()
            .AddDefaultTokenProviders();

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings
                options.Password.RequireDigit           = false;
                options.Password.RequiredLength         = 6;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequiredUniqueChars    = 3;

                // Lockout settings
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromHours(1);
                options.Lockout.MaxFailedAccessAttempts = 10;
                options.Lockout.AllowedForNewUsers      = true;

                // User settings
                options.User.RequireUniqueEmail = true;
            });

            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.HttpOnly   = true;
                options.Cookie.Expiration = TimeSpan.FromDays(150);
                options.LoginPath         = $"/{nameof(AccountController).ToControllerName()}/{nameof(AccountController.Login)}";
                options.AccessDeniedPath  = $"/{nameof(AccountController).ToControllerName()}/{nameof(AccountController.AccessDenied)}";
                options.SlidingExpiration = true;
            });

            services.AddDistributedMemoryCache();

            services.AddSession(options =>
            {
                options.IdleTimeout     = TimeSpan.FromDays(1);
                options.Cookie.HttpOnly = true;
            });

            Log.Logger().Information("Configure MVC services...");

            var builder = services.AddMvc(options => options.EnableEndpointRouting = false) //area bug-fix for .net core 2.2. kill me in next release
                          .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            builder.AddMvcOptions(x =>
            {
                //x.Filters.Add<AntiforgeryFilter>();
                x.Filters.Add(new GlobalExceptionHandler());
                x.Filters.Add(new AuthorizeFilter());
                x.ModelBinderProviders.Insert(0, new BinderProvider());
            });

            builder.AddControllersAsServices();
        }
示例#8
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, BasicSeedManager seedManager, MigrationManager migrationManager)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                loggerFactory.AddSerilog();

                Log.Logger().Information("Application is starting...");
                Log.Logger().Information("Configuration:");

                ConfigurationProvider.GetType().GetProperties().ToList().ForEach(prop =>
                {
                    Log.Logger().Information("[{name}] = '{value}'", prop.Name,
                                             prop.GetValue(ConfigurationProvider));
                });

                DateTimeContext.Initialize(ConfigurationProvider.TimeZone);

                Log.Logger().Information("Configure EF Mappings...");
                MappingConfig.RegisterMappings();


                Log.Logger().Information("Configure Jwt Bearer Authentication...");
                app.ConfigJwtBearerMiddleware();

                app.UseDefaultFiles();
                app.UseStaticFiles();

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

                    routes.MapRoute(
                        name: "admin",
                        template: "{*url}",
                        defaults: new { controller = "Default", action = "Index" }
                        );
                });



                //app.Use(async (context, next) =>
                //{
                //  await next();
                //  if (context.Response.StatusCode == 404 &&
                //      !Path.HasExtension(context.Request.Path.Value) &&
                //      !context.Request.Path.Value.StartsWith("/api/"))
                //  {
                //    context.Request.Path = "/index.html";
                //    await next();
                //  }
                //});

                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();

                    migrationManager.ApplyMigrations(ConfigurationProvider);

                    //seedManager.Seed();
                }
                else
                {
                    app.UseExceptionHandler("/error");
                }
            }
            catch (Exception e)
            {
                Log.Logger().Error(e, "Application failed to start");
                throw;
            }
            finally
            {
                stopwatch.Stop();
                Log.Logger().Information("Startup time: {Seconds}s", stopwatch.Elapsed.Seconds);
            }
        }
示例#9
0
 private void RecordLog(string logMessage)
 {
     Common.Log L = new Common.Log("", Properties.Settings.Default.EnableDebugLogging);
     L.WriteFilelog("HL7ReportsDataAndBusiness", "Reports web service", logMessage);
 }