<commit_before>using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Reflection;
using System.Diagnostics;
using NHibernate;
using NHibernate.Criterion;
using DBlog.Data;
using DBlog.Data.Hibernate;
using DBlog.WebServices;
using DBlog.TransitData;
using System.Configuration;

public class Global : DBlog.Tools.Web.HostedApplication
{
    private SystemFeedUpdateService mFeedUpdateService = new SystemFeedUpdateService();

    public Global()
    {

    }

    protected override void Application_Start(Object sender, EventArgs e)
    {
        HttpContext.Current.Cache.Insert("Pages", DateTime.Now, null,
           System.DateTime.MaxValue, System.TimeSpan.Zero,
           System.Web.Caching.CacheItemPriority.NotRemovable,
           null);

        base.Application_Start(sender, e);

        DBlog.Data.Hibernate.Session.Configuration.AddAssembly("DBlog.Data");
        DBlog.Data.Hibernate.Session.Configuration.AddAssembly("DBlog.Data.Hibernate");

        using (DBlog.Data.Hibernate.Session.OpenConnection(WebService.GetNewConnection()))
        {
            CreateAdministrator();
        }

        DBlog.WebServices.Blog blog = new DBlog.WebServices.Blog();

        if (EventLogEnabled)
        {
            EventLog.WriteEntry(string.Format("Running with back-end web services {0}.", blog.GetVersion()), EventLogEntryType.Information);
        }

        if (ServicesEnabled)
        {
            mFeedUpdateService.Start();
        }
    }

    protected void Session_Start(Object sender, EventArgs e)
    {

    }

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        DBlog.Data.Hibernate.Session.BeginRequest();

        string path = Request.Path.Substring(Request.ApplicationPath.Length).Trim("/".ToCharArray());

        // rewrite ShowPost.aspx link to a slug
        if (path == "ShowPost.aspx" && ! string.IsNullOrEmpty(Request["id"]))
        {
            using (DBlog.Data.Hibernate.Session.OpenConnection(WebService.GetNewConnection()))
            {
                ISession session = DBlog.Data.Hibernate.Session.Current;
                int id = 0;
                if (int.TryParse(Request["Id"], out id))
                {
                    Post post = session.Load<Post>(id);
                    if (post != null && !string.IsNullOrEmpty(post.Slug))
                    {
                        Response.RedirectPermanent(post.Slug);
                    }
                }
            }
        }
        // rewrite a slug link to a ShowPost.aspx internal url
        else if (path.IndexOf('.') < 0)
        {
            string[] parts = Request.Path.Split('/');
            string slug = parts[parts.Length - 1];
            if (! String.IsNullOrEmpty(slug))
            {
                HttpContext.Current.RewritePath(string.Format("ShowPost.aspx?slug={0}", slug));
            }
        }
    }

    protected void Application_EndRequest(Object sender, EventArgs e)
    {
        DBlog.Data.Hibernate.Session.EndRequest();
        GC.Collect();
    }

    protected void Application_AuthenticateRequest(Object sender, EventArgs e)
    {

    }

    protected override void Application_Error(Object sender, EventArgs e)
    {
        base.Application_Error(sender, e);
    }

    protected override void Application_End(Object sender, EventArgs e)
    {
        if (ServicesEnabled)
        {<commit_msg>Rewriting slugged ShowPost.aspx.<commit_after>using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Reflection;
using System.Diagnostics;
using NHibernate;
using NHibernate.Criterion;
using DBlog.Data;
using DBlog.Data.Hibernate;
using DBlog.WebServices;
using DBlog.TransitData;
using System.Configuration;

public class Global : DBlog.Tools.Web.HostedApplication
{
    private SystemFeedUpdateService mFeedUpdateService = new SystemFeedUpdateService();

    public Global()
    {

    }

    protected override void Application_Start(Object sender, EventArgs e)
    {
        HttpContext.Current.Cache.Insert("Pages", DateTime.Now, null,
           System.DateTime.MaxValue, System.TimeSpan.Zero,
           System.Web.Caching.CacheItemPriority.NotRemovable,
           null);

        base.Application_Start(sender, e);

        DBlog.Data.Hibernate.Session.Configuration.AddAssembly("DBlog.Data");
        DBlog.Data.Hibernate.Session.Configuration.AddAssembly("DBlog.Data.Hibernate");

        using (DBlog.Data.Hibernate.Session.OpenConnection(WebService.GetNewConnection()))
        {
            CreateAdministrator();
        }

        DBlog.WebServices.Blog blog = new DBlog.WebServices.Blog();

        if (EventLogEnabled)
        {
            EventLog.WriteEntry(string.Format("Running with back-end web services {0}.", blog.GetVersion()), EventLogEntryType.Information);
        }

        if (ServicesEnabled)
        {
            mFeedUpdateService.Start();
        }
    }

    protected void Session_Start(Object sender, EventArgs e)
    {

    }

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        DBlog.Data.Hibernate.Session.BeginRequest();

        string path = Request.Path.Substring(Request.ApplicationPath.Length).Trim("/".ToCharArray());
        if (! string.IsNullOrEmpty(path))
        {
            // rewrite ShowPost.aspx link to a slug
            if (path == "ShowPost.aspx" && !string.IsNullOrEmpty(Request["id"]))
            {
                using (DBlog.Data.Hibernate.Session.OpenConnection(WebService.GetNewConnection()))
                {
                    ISession session = DBlog.Data.Hibernate.Session.Current;
                    int id = 0;
                    if (int.TryParse(Request["Id"], out id))
                    {
                        Post post = session.Load<Post>(id);
                        if (post != null && !string.IsNullOrEmpty(post.Slug))
                        {
                            Response.RedirectPermanent(post.Slug);
                        }
                    }
                }
            }
            // rewrite a slug link
            else if (path == "ShowPost.aspx" && !string.IsNullOrEmpty(Request["slug"]))
            {
                Response.RedirectPermanent(Request["slug"]);
            }
            // rewrite a slug link to a ShowPost.aspx internal url
            else if (path.IndexOf('.') < 0)
            {
                string[] parts = Request.Path.Split('/');
                string slug = parts[parts.Length - 1];
                if (!String.IsNullOrEmpty(slug))
                {
                    HttpContext.Current.RewritePath(string.Format("ShowPost.aspx?slug={0}", slug));
                }
            }
        }
    }

    protected void Application_EndRequest(Object sender, EventArgs e)
    {
        DBlog.Data.Hibernate.Session.EndRequest();
        GC.Collect();
    }

    protected void Application_AuthenticateRequest(Object sender, EventArgs e)
    {

    }

    protected override void Application_Error(Object sender, EventArgs e)
    {
        base.Application_Error(sender, e);
    }

    protected override void Application_End(Object sender, EventArgs e)
    {
        if (ServicesEnabled)
        {
{'fraction_non_alphanumeric': 0.10420650095602295, 'fraction_numerical': 0.0013657470636438131, 'mean_word_length': 2.134845890410959, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5256833', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1909, 'n_words': 372}