<commit_before>﻿[assembly: Microsoft.Owin.OwinStartup("AcademyPlatformOwinStartup", typeof(AcademyPlatform.Web.Umbraco.Startup.AcademyPlatformOwinStartup))]
namespace AcademyPlatform.Web.Umbraco.Startup
{
    using System.Collections.Generic;
    using System.Web.Security;

    using global::Umbraco.Core.Configuration;
    using global::Umbraco.Web;
    using global::Umbraco.Web.Routing;

    using Hangfire;
    using Hangfire.Common;
    using Hangfire.Dashboard;
    using Hangfire.Server;

    using Microsoft.Owin;

    using Newtonsoft.Json;

    using Owin;


    public class AcademyPlatformOwinStartup : UmbracoDefaultOwinStartup
    {
        public override void Configuration(IAppBuilder app)
        {
            base.Configuration(app);

            GlobalConfiguration.Configuration.UseLog4NetLogProvider();
            GlobalConfiguration.Configuration.UseSqlServerStorage(nameOrConnectionString: "Hangfire");

            GlobalJobFilters.Filters.Add(new PrepareUmbracoRequestFilter());
            JobHelper.SetSerializerSettings(new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
            app.UseHangfireServer();
            app.UseHangfireDashboard("/hangfire", new DashboardOptions { AuthorizationFilters = new IAuthorizationFilter[] { new RoleAuthorizationFilter() } });
        }
    }

    public class RoleAuthorizationFilter : IAuthorizationFilter
    {
        public bool Authorize(IDictionary<string, object> owinEnvironment)
        {
            OwinContext owinContext = new OwinContext(owinEnvironment);
            return owinContext.Request.User.IsInRole("Hangfire");
            //TODO add authorization for local requests<commit_msg>Setting hangfire job expiration(deletion period) to 1 week. Setting heartbeat to 1 minute<commit_after>﻿[assembly: Microsoft.Owin.OwinStartup("AcademyPlatformOwinStartup", typeof(AcademyPlatform.Web.Umbraco.Startup.AcademyPlatformOwinStartup))]
namespace AcademyPlatform.Web.Umbraco.Startup
{
    using System;
    using System.Collections.Generic;
    using System.Web.Security;

    using global::Umbraco.Core.Configuration;
    using global::Umbraco.Web;
    using global::Umbraco.Web.Routing;

    using Hangfire;
    using Hangfire.Common;
    using Hangfire.Dashboard;
    using Hangfire.Server;
    using Hangfire.SqlServer;

    using Microsoft.Owin;

    using Newtonsoft.Json;

    using Owin;


    public class AcademyPlatformOwinStartup : UmbracoDefaultOwinStartup
    {
        public override void Configuration(IAppBuilder app)
        {
            base.Configuration(app);

            GlobalConfiguration.Configuration.UseLog4NetLogProvider();
            GlobalConfiguration.Configuration.UseSqlServerStorage("Hangfire", new SqlServerStorageOptions
                                                                                                              {
                                                                                                                  JobExpirationCheckInterval = TimeSpan.FromDays(7),
                                                                                                                  QueuePollInterval = TimeSpan.FromMinutes(1)
                                                                                                              });

            GlobalJobFilters.Filters.Add(new PrepareUmbracoRequestFilter());
            JobHelper.SetSerializerSettings(new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
            app.UseHangfireServer();
            app.UseHangfireDashboard("/hangfire", new DashboardOptions { AuthorizationFilters = new IAuthorizationFilter[] { new RoleAuthorizationFilter() } });
        }
    }

    public class RoleAuthorizationFilter : IAuthorizationFilter
    {
        public bool Authorize(IDictionary<string, object> owinEnvironment)
        {
            OwinContext owinContext = new OwinContext(owinEnvironment);
            return owinContext.Request.User.IsInRole("Hangfire");
            //TODO add authorization for local requests
{'fraction_non_alphanumeric': 0.0713953488372093, 'fraction_numerical': 0.0013953488372093023, 'mean_word_length': 2.4463141025641026, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3315391', 'n_tokens_mistral': 1045, 'n_tokens_neox': 1001, 'n_words': 184}