<commit_before>﻿using System;
using System.IO;
using System.Threading;
using System.Web;
using System.Web.Hosting;
using System.Web.Http;
using System.Web.Http.Cors;
using Hangfire;
using Hangfire.SqlServer;
using LightInject;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Nancy;
using Owin;
using UGSK.K3.Pulse.AppServices;
using UGSK.K3.Pulse.AppServices.Impl;
using UGSK.K3.Pulse.Config;
using UGSK.K3.Pulse.Infrastructure;
using UGSK.K3.Pulse.Infrastructure.Impl;
using UGSK.K3.Pulse.Processors;
using UGSK.K3.Pulse.Processors.SyncAdapters;

[assembly: OwinStartup(typeof(UGSK.K3.Pulse.Startup))]

namespace UGSK.K3.Pulse
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var container = new ServiceContainer();
            container.Register<ICounterProcessor, DefaultCounterProcessorAdapter>(new PerScopeLifetime());
            container.Register<DefaultCounterProcessorAdapter, DefaultCounterProcessorAdapter>(new PerRequestLifeTime());
            container.Register<IIndexProcessor, DefaultIndexProcessor>(new PerScopeLifetime());
            container.Register<ILogger, DefaultLogger>(new PerScopeLifetime());
            container.Register<IBroadcaster, SignalRBroadcaster>(new PerRequestLifeTime());
            container.Register<IDataStorage, DapperDataStorage>(new PerScopeLifetime());
            container.Register<ICounterQuery, CounterQuery>(new PerScopeLifetime());
            container.Register<PerWeekDailyAverageStatisticProcessor, PerWeekDailyAverageStatisticProcessor>(new PerRequestLifeTime());
            container.Register<PreviousDateStatProcessor, PreviousDateStatProcessor>(new PerRequestLifeTime());
            container.Register(typeof(CommonProcessorAdapter<>), typeof(CommonProcessorAdapter<>), new PerRequestLifeTime());

            container.RegisterApiControllers();

            container.EnableSignalR();

            var config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute("default", "api/{Controller}");
            config.EnableCors(new EnableCorsAttribute("*", "*", "get"));

            container.EnableWebApi(config);
            container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider(); // for 4.5 async purposes

            app.UseWebApi(config);

            app.UseCors(CorsOptions.AllowAll);

            app.MapSignalR();

            app.UseHangfire(conf =>
            {
                conf.UseSqlServerStorage(GlobalOptions.HangfireSqlServer.ConnectionsStringName, new SqlServerStorageOptions { PrepareSchemaIfNecessary = GlobalOptions.HangfireSqlServer.PrepareSchemaIfNecessary });
                conf.UseServer();
                conf.UseActivator(new ContainerJobActivator(container));
            });
            app.UseHangfireDashboard();
           

            InitializeJobs();

            app.UseNancy(options =>
              options.PerformPassThrough = context =>
                  context.Response.StatusCode == HttpStatusCode.NotFound);
        }

        public static void InitializeJobs()
        {
            RecurringJob.AddOrUpdate<CommonProcessorAdapter<PerWeekDailyAverageStatisticProcessor>>(PerWeekDailyAverageStatisticProcessor.Name, p => p.Process(DateTime.Now.AddDays(-1).Date), "0 1 * * *");

            RecurringJob.AddOrUpdate<CommonProcessorAdapter<PreviousDateStatProcessor>>(PreviousDateStatProcessor.Name, p => p.Process(DateTime.Now.AddDays(-1).Date), "35 * * * *");

            RecurringJob.AddOrUpdate("test of unslept state", () => WriteLog("start app"), "1 * * * *");

            // perform to update statistic if it has not been updated (worker failed, app wasn't run early)
            RecurringJob.Trigger(PerWeekDailyAverageStatisticProcessor.Name);
            RecurringJob.Trigger(PreviousDateStatProcessor.Name);
            RecurringJob.Trigger("test of unslept state");
        }
<commit_msg>changed hangfire configuration<commit_after>﻿using System;
using System.IO;
using System.Threading;
using System.Web;
using System.Web.Hosting;
using System.Web.Http;
using System.Web.Http.Cors;
using Hangfire;
using Hangfire.SqlServer;
using LightInject;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Nancy;
using Owin;
using UGSK.K3.Pulse.AppServices;
using UGSK.K3.Pulse.AppServices.Impl;
using UGSK.K3.Pulse.Config;
using UGSK.K3.Pulse.Infrastructure;
using UGSK.K3.Pulse.Infrastructure.Impl;
using UGSK.K3.Pulse.Processors;
using UGSK.K3.Pulse.Processors.SyncAdapters;
using GlobalConfiguration = Hangfire.GlobalConfiguration;

[assembly: OwinStartup(typeof(UGSK.K3.Pulse.Startup))]

namespace UGSK.K3.Pulse
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var container = new ServiceContainer();
            container.Register<ICounterProcessor, DefaultCounterProcessorAdapter>(new PerScopeLifetime());
            container.Register<DefaultCounterProcessorAdapter, DefaultCounterProcessorAdapter>(new PerRequestLifeTime());
            container.Register<IIndexProcessor, DefaultIndexProcessor>(new PerScopeLifetime());
            container.Register<ILogger, DefaultLogger>(new PerScopeLifetime());
            container.Register<IBroadcaster, SignalRBroadcaster>(new PerRequestLifeTime());
            container.Register<IDataStorage, DapperDataStorage>(new PerScopeLifetime());
            container.Register<ICounterQuery, CounterQuery>(new PerScopeLifetime());
            container.Register<PerWeekDailyAverageStatisticProcessor, PerWeekDailyAverageStatisticProcessor>(new PerRequestLifeTime());
            container.Register<PreviousDateStatProcessor, PreviousDateStatProcessor>(new PerRequestLifeTime());
            container.Register(typeof(CommonProcessorAdapter<>), typeof(CommonProcessorAdapter<>), new PerRequestLifeTime());

            container.RegisterApiControllers();

            container.EnableSignalR();

            var config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute("default", "api/{Controller}");
            config.EnableCors(new EnableCorsAttribute("*", "*", "get"));

            container.EnableWebApi(config);
            container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider(); // for 4.5 async purposes

            app.UseWebApi(config);

            app.UseCors(CorsOptions.AllowAll);

            app.MapSignalR();


            GlobalConfiguration.Configuration.UseActivator(new ContainerJobActivator(container));
            GlobalConfiguration.Configuration.UseSqlServerStorage(GlobalOptions.HangfireSqlServer.ConnectionsStringName, new SqlServerStorageOptions { PrepareSchemaIfNecessary = GlobalOptions.HangfireSqlServer.PrepareSchemaIfNecessary });
            app.UseHangfireServer();

            app.UseHangfireDashboard();


            InitializeJobs();

            app.UseNancy(options =>
              options.PerformPassThrough = context =>
                  context.Response.StatusCode == HttpStatusCode.NotFound);
        }

        public static void InitializeJobs()
        {
            RecurringJob.AddOrUpdate<CommonProcessorAdapter<PerWeekDailyAverageStatisticProcessor>>(PerWeekDailyAverageStatisticProcessor.Name, p => p.Process(DateTime.Now.AddDays(-1).Date), "0 1 * * *");

            RecurringJob.AddOrUpdate<CommonProcessorAdapter<PreviousDateStatProcessor>>(PreviousDateStatProcessor.Name, p => p.Process(DateTime.Now.AddDays(-1).Date), "35 * * * *");

            RecurringJob.AddOrUpdate("test of unslept state", () => WriteLog("start app"), "1 * * * *");

            // perform to update statistic if it has not been updated (worker failed, app wasn't run early)
            RecurringJob.Trigger(PerWeekDailyAverageStatisticProcessor.Name);
            RecurringJob.Trigger(PreviousDateStatProcessor.Name);
            RecurringJob.Trigger("test of unslept state");
        }

{'fraction_non_alphanumeric': 0.10159088062132031, 'fraction_numerical': 0.004509582863585118, 'mean_word_length': 3.5937859608745684, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1039201', 'n_tokens_mistral': 2162, 'n_tokens_neox': 2074, 'n_words': 342}