예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            //ReverseProxy Fix https://docs.microsoft.com/de-de/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-3.1
            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost;
            });

            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // Config
            var hangfireConfiguration = new HangFireConfiguration();

            Configuration.Bind("Hangfire", hangfireConfiguration);
            services.AddSingleton(hangfireConfiguration);

            var deezerApiConfiguration = new DeezerApiConfiguration();

            Configuration.Bind("DeezerApi", deezerApiConfiguration);
            services.AddSingleton(deezerApiConfiguration);

            var jobConfiguration = new JobConfiguration();

            Configuration.Bind("JobConfiguration", jobConfiguration);
            services.AddSingleton(jobConfiguration);

            var delayConfiguration = new DelayConfiguration();

            Configuration.Bind("DelayConfiguration", delayConfiguration);
            services.AddSingleton(delayConfiguration);

            //Hangfire
            services.AddHangfire(x =>
            {
                x.UseSqlServerStorage(connectionString)
                .WithJobExpirationTimeout(TimeSpan.FromDays(3));
                x.UseConsole();
            });

            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(connectionString)
                                                 );
            services.AddDefaultIdentity <User>(options =>
            {
                options.User.AllowedUserNameCharacters = null;
            }).AddEntityFrameworkStores <AppDbContext>();

            //Services
            services.AddSingleton <IDeezerApiService, DeezerApiService>();
            services.AddSingleton <IDeemixService, DeemixService>();
            services.AddScoped <IDataRepository, DataRepository>();
            services.AddScoped <IConfigurationService, ConfigurationService>();

            services.AddAutoMapper(typeof(Startup));
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // Config
            var hangfireConfiguration = new HangFireConfiguration();

            Configuration.Bind("Hangfire", hangfireConfiguration);
            services.AddSingleton(hangfireConfiguration);

            var deezerApiConfiguration = new DeezerApiConfiguration();

            Configuration.Bind("DeezerApi", deezerApiConfiguration);
            services.AddSingleton(deezerApiConfiguration);

            var jobConfiguration = new JobConfiguration();

            Configuration.Bind("JobConfiguration", jobConfiguration);
            services.AddSingleton(jobConfiguration);

            var delayConfiguration = new DelayConfiguration();

            Configuration.Bind("DelayConfiguration", delayConfiguration);
            services.AddSingleton(delayConfiguration);

            //Hangfire
            services.AddHangfire(x =>
                                 x.UseSqlServerStorage(connectionString)
                                 );

            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(connectionString)
                                                 );
            services.AddDefaultIdentity <User>(options =>
            {
                options.User.AllowedUserNameCharacters = null;
            }).AddEntityFrameworkStores <AppDbContext>();

            //Services
            services.AddSingleton <IDeezerApiService, DeezerApiService>();
            services.AddSingleton <IDeemixService, DeemixService>();
            services.AddScoped <IDataRepository, DataRepository>();
            services.AddScoped <IConfigurationService, ConfigurationService>();

            services.AddAutoMapper(typeof(Startup));
        }
예제 #3
0
파일: Startup.cs 프로젝트: spoonys/Listrr
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // Config
            var hangfireConfiguration = new HangFireConfiguration();

            Configuration.Bind("Hangfire", hangfireConfiguration);
            services.AddSingleton(hangfireConfiguration);

            var listPaginationConfiguration = new ListPaginationConfiguration();

            Configuration.Bind("ListPagination", listPaginationConfiguration);
            services.AddSingleton(listPaginationConfiguration);

            var traktApiConfiguration = new TraktAPIConfiguration();

            Configuration.Bind("Trakt", traktApiConfiguration);
            services.AddSingleton(traktApiConfiguration);

            var githubApiConfiguration = new GithubAPIConfiguration();

            Configuration.Bind("GitHub", githubApiConfiguration);
            services.AddSingleton(githubApiConfiguration);

            var limitConfigurationList = new LimitConfigurationList();

            Configuration.Bind("LimitConfig", limitConfigurationList);
            services.AddSingleton(limitConfigurationList);

            var userMappingConfigurationList = new UserMappingConfigurationList();

            Configuration.Bind("UserMappingConfig", userMappingConfigurationList);
            services.AddSingleton(userMappingConfigurationList);


            // Multi Instance LB
            services.AddDbContext <DataProtectionDbContext>(options =>
                                                            options.UseSqlServer(connectionString)
                                                            );
            services.AddDataProtection()
            .PersistKeysToDbContext <DataProtectionDbContext>()
            .SetApplicationName("Listrr");
            services.AddDistributedSqlServerCache(options =>
            {
                options.ConnectionString = connectionString;
                options.SchemaName       = "dbo";
                options.TableName        = "Cache";
            });

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(connectionString)
                                                 );
            services.AddDefaultIdentity <User>(options =>
            {
                options.User.AllowedUserNameCharacters = null;
            }).AddEntityFrameworkStores <AppDbContext>();
            services.AddHangfire(x =>
                                 x.UseSqlServerStorage(connectionString));

            services.AddAuthentication()
            .AddTrakt(options =>
            {
                options.ClientId     = traktApiConfiguration.ClientId;
                options.ClientSecret = traktApiConfiguration.ClientSecret;
                options.SaveTokens   = true;

                options.ClaimActions.MapJsonSubKey(Constants.Trakt_Claim_Ids_Slug, "ids", "slug");

                options.Events.OnCreatingTicket = ctx =>
                {
                    List <AuthenticationToken> tokens = ctx.Properties.GetTokens() as List <AuthenticationToken>;
                    tokens.Add(new AuthenticationToken()
                    {
                        Name  = "TicketCreated",
                        Value = DateTime.Now.ToString()
                    });
                    ctx.Properties.StoreTokens(tokens);
                    return(Task.CompletedTask);
                };
            })
            .AddGitHub(options =>
            {
                options.ClientId                = githubApiConfiguration.ClientId;
                options.ClientSecret            = githubApiConfiguration.ClientSecret;
                options.SaveTokens              = true;
                options.Events.OnCreatingTicket = ctx =>
                {
                    List <AuthenticationToken> tokens = ctx.Properties.GetTokens() as List <AuthenticationToken>;
                    tokens.Add(new AuthenticationToken()
                    {
                        Name  = "TicketCreated",
                        Value = DateTime.Now.ToString()
                    });
                    ctx.Properties.StoreTokens(tokens);
                    return(Task.CompletedTask);
                };
            });

            services.ConfigureApplicationCookie(options =>
            {
                // Cookie settings
                options.Cookie.Name     = "Listrr";
                options.Cookie.HttpOnly = true;
                options.ExpireTimeSpan  = TimeSpan.FromHours(1);

                options.LoginPath         = "/Identity/Account/Login";
                options.AccessDeniedPath  = "/Identity/Account/AccessDenied";
                options.SlidingExpiration = true;
            });

            services.AddHttpContextAccessor();

            //ReverseProxy Fix
            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
            });

            services.AddScoped <IGitHubGraphService, GitHubGraphService>();
            services.AddScoped <IBackgroundJobQueueService, BackgroundJobQueueService>();
            services.AddScoped <ITraktListRepository, TraktListRepository>();
            services.AddScoped <ITraktMovieRepository, TraktMovieRepository>();
            services.AddScoped <ITraktShowRepository, TraktShowRepository>();
            services.AddScoped <ITraktCodeRepository, TraktCodeRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <ITraktService, TraktService>();

            services.AddControllersWithViews();
            services.AddRazorPages();
        }
예제 #4
0
파일: Startup.cs 프로젝트: spoonys/Listrr
        private void InitializeHangfire(IApplicationBuilder app, IServiceProvider serviceProvider, HangFireConfiguration hangFireConfiguration, LimitConfigurationList limitConfigurationList)
        {
            GlobalConfiguration.Configuration
            .UseActivator(new HangfireActivator(serviceProvider));

            var queues = new List <string>();

            queues.Add("system");

            foreach (var limitConfiguration in limitConfigurationList.LimitConfigurations.DistinctBy(x => x.QueueName))
            {
                queues.Add(limitConfiguration.QueueName);
            }

            app.UseHangfireServer(new BackgroundJobServerOptions
            {
                WorkerCount = hangFireConfiguration.Workers,
                Queues      = queues.ToArray()
            });

            app.UseHangfireDashboard(hangFireConfiguration.DashboardPath ?? "/jobs", new DashboardOptions
            {
                Authorization = new[] { new HangfireCustomBasicAuthenticationFilter {
                                            User = hangFireConfiguration.Username ?? "Admin", Pass = hangFireConfiguration.Password ?? "SuperSecurePWD!123"
                                        } }
            });

            RecurringJob.AddOrUpdate <GetMovieCertificationsRecurringJob>(x => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetShowCertificationsRecurringJob>(x => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetMovieGenresRecurringJob>(x => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetShowGenresRecurringJob>(x => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetCountryCodesRecurringJob>(x => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetLanguageCodesRecurringJob>(x => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetShowNetworksRecurringJob>(x => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetShowStatusRecurringJob>(x => x.Execute(), Cron.Daily);

            RecurringJob.AddOrUpdate <ProcessDonorListsRecurringJob>(x => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <ProcessUserListsRecurringJob>(x => x.Execute(), Cron.Never);
            RecurringJob.AddOrUpdate <UpdateAllListsRecurringJob>(x => x.Execute(), Cron.Never);

            RecurringJob.AddOrUpdate <EnforceListLimitRecurringJob>(x => x.Execute(), "*/5 * * * *");
            RecurringJob.AddOrUpdate <SetDonorsRecurringJob>(x => x.Execute(), "*/5 * * * *");


            ////Starting all jobs here for initial db fill
            //foreach (var recurringJob in JobStorage.Current.GetConnection().GetRecurringJobs())
            //{
            //    RecurringJob.Trigger(recurringJob.Id);
            //}
        }
예제 #5
0
파일: Startup.cs 프로젝트: spoonys/Listrr
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, HangFireConfiguration hangFireConfiguration, LimitConfigurationList limitConfigurationList)
        {
            InitializeDatabase(app);

            //ReverseProxy Fix
            app.UseForwardedHeaders();
            app.Use((context, next) =>
            {
                context.Request.Scheme = "https";
                return(next());
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            InitializeHangfire(app, serviceProvider, hangFireConfiguration, limitConfigurationList);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
                endpoints.MapHangfireDashboard(new DashboardOptions
                {
                    Authorization = new[]
                    {
                        new HangfireCustomBasicAuthenticationFilter
                        {
                            User = hangFireConfiguration.Username ?? "Admin",
                            Pass = hangFireConfiguration.Password ?? "SuperSecurePWD!123"
                        }
                    }
                });
            });
        }
예제 #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // Config
            var hangfireConfiguration = new HangFireConfiguration();

            Configuration.Bind("Hangfire", hangfireConfiguration);
            services.AddSingleton(hangfireConfiguration);

            var toplistConfiguration = new ToplistConfiguration();

            Configuration.Bind("Toplist", toplistConfiguration);
            services.AddSingleton(toplistConfiguration);

            var traktApiConfiguration = new TraktAPIConfiguration();

            Configuration.Bind("Trakt", traktApiConfiguration);
            services.AddSingleton(traktApiConfiguration);

            // Multi Instance LB
            services.AddDbContext <DataProtectionDbContext>(options =>
                                                            options.UseSqlServer(connectionString)
                                                            );

            services.AddDataProtection()
            .PersistKeysToDbContext <DataProtectionDbContext>()
            .SetApplicationName("Listrr");

            services.AddDistributedSqlServerCache(options =>
            {
                options.ConnectionString = connectionString;
                options.SchemaName       = "dbo";
                options.TableName        = "Cache";
            });


            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(connectionString)
                                                 );

            services.AddDefaultIdentity <IdentityUser>(options =>
            {
                options.User.AllowedUserNameCharacters = null;
            }).AddEntityFrameworkStores <AppDbContext>();

            services.AddHangfire(x =>
                                 x.UseSqlServerStorage(connectionString));

            services.AddAuthentication()
            .AddTrakt(options =>
            {
                options.ClientId                = traktApiConfiguration.ClientId;
                options.ClientSecret            = traktApiConfiguration.ClientSecret;
                options.SaveTokens              = true;
                options.Events.OnCreatingTicket = ctx =>
                {
                    List <AuthenticationToken> tokens = ctx.Properties.GetTokens() as List <AuthenticationToken>;
                    tokens.Add(new AuthenticationToken()
                    {
                        Name  = "TicketCreated",
                        Value = DateTime.Now.ToString()
                    });
                    ctx.Properties.StoreTokens(tokens);
                    return(Task.CompletedTask);
                };
            });

            services.ConfigureApplicationCookie(options =>
            {
                // Cookie settings
                options.Cookie.Name     = "Listrr";
                options.Cookie.HttpOnly = true;
                options.ExpireTimeSpan  = TimeSpan.FromHours(1);

                options.LoginPath         = "/Identity/Account/Login";
                options.AccessDeniedPath  = "/Identity/Account/AccessDenied";
                options.SlidingExpiration = true;
            });

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddHttpContextAccessor();

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
            });

            services.AddScoped <ITraktListDBRepository, TraktListDBRepository>();
            services.AddScoped <ITraktListAPIRepository, TraktListAPIRepository>();
            services.AddScoped <ITraktService, TraktService>();
        }
예제 #7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider, HangFireConfiguration hangFireConfiguration)
        {
            InitializeDatabase(app);

            app.UseForwardedHeaders();

            app.Use((context, next) =>
            {
                context.Request.Scheme = "https";
                return(next());
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            GlobalConfiguration.Configuration
            .UseActivator(new HangfireActivator(serviceProvider));

            app.UseHangfireServer(new BackgroundJobServerOptions
            {
                WorkerCount = hangFireConfiguration.Workers
            });

            app.UseHangfireDashboard(hangFireConfiguration.DashboardPath ?? "/jobs", new DashboardOptions
            {
                Authorization = new[] { new HangfireCustomBasicAuthenticationFilter {
                                            User = hangFireConfiguration.Username ?? "Admin", Pass = hangFireConfiguration.Password ?? "SuperSecurePWD!123"
                                        } }
            });

            RecurringJob.AddOrUpdate <GetMovieCertificationsRecurringJob>((x) => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetShowCertificationsRecurringJob>((x) => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetMovieGenresRecurringJob>((x) => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetShowGenresRecurringJob>((x) => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetCountryCodesRecurringJob>((x) => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetLanguageCodesRecurringJob>((x) => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <ProcessListsRecurringJob>((x) => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetShowNetworksRecurringJob>((x) => x.Execute(), Cron.Daily);
            RecurringJob.AddOrUpdate <GetShowStatusRecurringJob>((x) => x.Execute(), Cron.Daily);


            ////Starting all jobs here for initial db fill
            //foreach (var recurringJob in JobStorage.Current.GetConnection().GetRecurringJobs())
            //{
            //    RecurringJob.Trigger(recurringJob.Id);
            //}

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
예제 #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, HangFireConfiguration hangFireConfiguration, JobConfiguration jobConfiguration)
        {
            InitializeDatabase(app);

            //ReverseProxy Fix https://docs.microsoft.com/de-de/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-3.1
            app.UseForwardedHeaders();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            InitializeHangfire(app, serviceProvider, hangFireConfiguration, jobConfiguration);

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

                endpoints.MapHangfireDashboard(new DashboardOptions
                {
                    Authorization = new[]
                    {
                        new HangfireCustomBasicAuthenticationFilter
                        {
                            User = hangFireConfiguration.Username ?? "Admin",
                            Pass = hangFireConfiguration.Password ?? "SuperSecurePWD!123"
                        }
                    }
                });
            });
        }
예제 #9
0
        //Hangfire Initialization
        private void InitializeHangfire(IApplicationBuilder applicationBuilder, IServiceProvider serviceProvider, HangFireConfiguration hangFireConfiguration, JobConfiguration jobConfiguration)
        {
            GlobalConfiguration.Configuration.UseActivator(new HangfireActivator(serviceProvider));
            GlobalConfiguration.Configuration.UseDarkDashboard();


            applicationBuilder.UseHangfireServer(new BackgroundJobServerOptions
            {
                WorkerCount = hangFireConfiguration.Workers == 0 ? 1 : hangFireConfiguration.Workers
            });

            applicationBuilder.UseHangfireDashboard(hangFireConfiguration.DashboardPath ?? "/jobs", new DashboardOptions
            {
                Authorization = new[] { new HangfireCustomBasicAuthenticationFilter
                                        {
                                            User = hangFireConfiguration.Username ?? "Admin",
                                            Pass = hangFireConfiguration.Password ?? "SuperSecurePWD!123"
                                        } }
            });

            RecurringJob.AddOrUpdate <ScrapeGenreRecurringJob>(x => x.Execute(null), Cron.Daily);
            RecurringJob.AddOrUpdate <SizeCalculatorRecurringJob>(x => x.Execute(null), jobConfiguration.SizeCalculatorRecurringJob);
            RecurringJob.AddOrUpdate <GetUpdatesRecurringJob>(x => x.Execute(null), jobConfiguration.GetUpdatesRecurringJob);
        }
예제 #10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, HangFireConfiguration hangFireConfiguration, JobConfiguration jobConfiguration)
        {
            InitializeDatabase(app);

            //ReverseProxy Fix
            app.UseForwardedHeaders();
            app.Use((context, next) =>
            {
                context.Request.Scheme = "https";
                return(next());
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/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.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            InitializeHangfire(app, serviceProvider, hangFireConfiguration, jobConfiguration);

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

                endpoints.MapHangfireDashboard(new DashboardOptions
                {
                    Authorization = new[]
                    {
                        new HangfireCustomBasicAuthenticationFilter
                        {
                            User = hangFireConfiguration.Username ?? "Admin",
                            Pass = hangFireConfiguration.Password ?? "SuperSecurePWD!123"
                        }
                    }
                });
            });
        }