Exemplo n.º 1
0
        public string DefaultResolveTemplate(IRequest req)
        {
            if (PathTemplates != null && PathTemplates.TryGetValue(req.PathInfo, out var templatePath))
            {
                var file = HostContext.VirtualFileSources.GetFile(templatePath);
                if (file == null)
                {
                    throw new FileNotFoundException($"Could not load HTML template '{templatePath}'", templatePath);
                }

                return(file.ReadAllText());
            }
            return(null);
        }
Exemplo n.º 2
0
        public void ConfigureBaseServices(IServiceCollection services, ServiceLifetime lifetime)
        {
            services.Configure <ApiSettings>(_configuration.GetSection("APISettings"));
            services.Configure <StaticUrls>(_configuration.GetSection("StaticUrls"));
            services.Configure <GoogleSettings>(_configuration.GetSection("GoogleOAuth"));
            services.Configure <FileDirectoryPathSettings>(_configuration.GetSection("FileDirectoryPath"));
            services.Configure <SmtpSettings>(_configuration.GetSection("SmtpSettings"));
            var pathSettings = _configuration.GetSection("FileDirectoryPath").Get <FileDirectoryPathSettings>();
            var cropSizes    = _configuration.GetSection("CropSizes:SizesStr").Get <string>();

            CropSizesSettings.SetSizes(cropSizes);
            var fileTemplate  = _configuration.GetSection("FileTemplateUrl:FileTemplate").Get <string>();
            var imageTemplate = _configuration.GetSection("FileTemplateUrl:ImageTemplate").Get <string>();

            PathTemplates.SetFilePathTemplate(fileTemplate);
            PathTemplates.SetImagePathTemplate(imageTemplate);

            var dbSettings = new DbSettings
            {
                DB_HOST     = _configuration.GetSection("DB_HOST").Value,
                DB_PORT     = _configuration.GetSection("DB_PORT").Value,
                DB_USER     = _configuration.GetSection("DB_USER").Value,
                DB_NAME     = _configuration.GetSection("DB_NAME").Value,
                DB_PASSWORD = _configuration.GetSection("DB_PASSWORD").Value
            };

            Console.WriteLine($"Connection string: {dbSettings?.PostgresConnectionString}");
            Console.WriteLine($"File path: {pathSettings?.FileRootPath}");
            Console.WriteLine($"Email templates: {pathSettings?.EmailTemplatePath}");
            Console.WriteLine($"Image path template: {imageTemplate}");


            services.AddSerilog(dbSettings);

            services.AddDbContext <SquadioDbContext>(builder =>
                                                     builder
                                                     .EnableSensitiveDataLogging()
                                                     .UseNpgsql(dbSettings.PostgresConnectionString,
                                                                optionsBuilder =>
                                                                optionsBuilder.MigrationsAssembly(typeof(SquadioDbContext).Assembly.FullName)));

            DependencyInjectionModule.Load(services, lifetime);

            services.AddSingleton(MappingConfig.GetMapper());

            services.AddMemoryCache();
        }