Example #1
0
 public ListController(AppDbContext appDbContext, ITraktService traktService, UserManager <User> userManager, IBackgroundJobQueueService backgroundJobQueueService, LimitConfigurationList limitConfigurationList)
 {
     _appDbContext = appDbContext;
     _traktService = traktService;
     _userManager  = userManager;
     _backgroundJobQueueService = backgroundJobQueueService;
     _limitConfigurationList    = limitConfigurationList;
 }
Example #2
0
 public ListController(UserManager <User> userManager, IBackgroundJobQueueService backgroundJobQueueService, LimitConfigurationList limitConfigurationList, ITraktListRepository traktRepository, ITraktMovieRepository traktMovieRepository, ITraktShowRepository traktShowRepository, ITraktCodeRepository traktCodesRepository, ITraktService traktService)
 {
     _userManager = userManager;
     _backgroundJobQueueService = backgroundJobQueueService;
     _limitConfigurationList    = limitConfigurationList;
     _traktRepository           = traktRepository;
     _traktMovieRepository      = traktMovieRepository;
     _traktShowRepository       = traktShowRepository;
     _traktCodesRepository      = traktCodesRepository;
     _traktService = traktService;
 }
 public ProcessDonorListsRecurringJob(LimitConfigurationList limitConfigurationList, IBackgroundJobQueueService backgroundJobQueueService, ITraktListRepository traktRepository)
 {
     _limitConfigurationList    = limitConfigurationList;
     _backgroundJobQueueService = backgroundJobQueueService;
     _traktRepository           = traktRepository;
 }
Example #4
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 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();
        }
Example #5
0
        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);
            //}
        }
Example #6
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, 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"
                        }
                    }
                });
            });
        }
Example #7
0
 public GitHubGraphService(GithubAPIConfiguration githubApiConfiguration, LimitConfigurationList limitConfigurationList)
 {
     _githubApiConfiguration = githubApiConfiguration;
     _limitConfigurationList = limitConfigurationList;
 }
 public EnforceListLimitRecurringJob(LimitConfigurationList limitConfigurationList, IUserRepository userRepository, ITraktListRepository traktRepository)
 {
     _limitConfigurationList = limitConfigurationList;
     _userRepository         = userRepository;
     _traktRepository        = traktRepository;
 }
 public ProcessDonorListsRecurringJob(ITraktService traktService, LimitConfigurationList limitConfigurationList, IBackgroundJobQueueService backgroundJobQueueService)
 {
     _traktService              = traktService;
     _limitConfigurationList    = limitConfigurationList;
     _backgroundJobQueueService = backgroundJobQueueService;
 }
Example #10
0
 public UserLimitService(LimitConfigurationList limitConfigurationList)
 {
     _limitConfigurationList = limitConfigurationList;
 }
 public DonorController(AppDbContext appDbContext, LimitConfigurationList limitConfigurationList)
 {
     _appDbContext           = appDbContext;
     _limitConfigurationList = limitConfigurationList;
 }
Example #12
0
 public EnforceListLimitRecurringJob(AppDbContext appDbContext, LimitConfigurationList limitConfigurationList, ITraktService traktService)
 {
     _appDbContext           = appDbContext;
     _limitConfigurationList = limitConfigurationList;
     _traktService           = traktService;
 }
Example #13
0
 public GitHubGraphService(GithubAPIConfiguration githubApiConfiguration, LimitConfigurationList limitConfigurationList)
 {
     _githubApiConfiguration = githubApiConfiguration ?? throw new ArgumentNullException(nameof(githubApiConfiguration));
     _limitConfigurationList = limitConfigurationList ?? throw new ArgumentNullException(nameof(limitConfigurationList));
 }
Example #14
0
 public void CreateGitHubGraphServiceWithNullParametersThowsNullReferenceException(GithubAPIConfiguration githubAPIConfiguration, LimitConfigurationList limitConfigurationList)
 {
     // Arrange
     // Act
     // Assert
     Assert.Throws <ArgumentNullException>(() => { new GitHubGraphService(githubAPIConfiguration, limitConfigurationList); });
 }