<commit_before>﻿// <copyright file="PreApplicationStart.cs" company="Katana contributors">
//   Copyright 2011-2012 Katana contributors
// </copyright>
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Configuration;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Web;
using System.Web.Hosting;
using Microsoft.Owin.Host.SystemWeb;
using Microsoft.Owin.Host.SystemWeb.Infrastructure;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;

[assembly: PreApplicationStartMethod(typeof(PreApplicationStart), "Initialize")]

namespace Microsoft.Owin.Host.SystemWeb
{
    /// <summary>
    /// Registers the OWIN request processing module at application startup.
    /// </summary>
    public static class PreApplicationStart
    {
        private const string TraceName = "Microsoft.Owin.Host.SystemWeb.PreApplicationStart";

        /// <summary>
        /// Registers the OWIN request processing module.
        /// </summary>
        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
            Justification = "Initialize must never throw on server startup path")]
        public static void Initialize()
        {
            try
            {
                DynamicModuleUtility.RegisterModule(typeof(OwinHttpModule));
            }
            catch (Exception ex)
            {
                ITrace trace = TraceFactory.Create(TraceName);
                trace.WriteError(Resources.Trace_RegisterModuleException, ex);
            }

            try
            {
                string appSetting = ConfigurationManager.AppSettings[Constants.OwinSetCurrentDirectory];
                if (string.Equals("true", appSetting, StringComparison.OrdinalIgnoreCase))
                {
                    string physicalPath = HostingEnvironment.MapPath("~");
                    if (physicalPath != null)
                    {
                        Directory.SetCurrentDirectory(physicalPath);
                    }
                }
            }
            catch (Exception ex)
            {
                ITrace trace = TraceFactory.Create(TraceName);
                trace.WriteError(Resources.Trace_SetCurrentDirectoryException, ex);
            }
        }
    }
}
<commit_msg>SystemWeb: PreAppStart should not swallow exceptions.<commit_after>﻿// <copyright file="PreApplicationStart.cs" company="Katana contributors">
//   Copyright 2011-2012 Katana contributors
// </copyright>
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Web;
using System.Web.Hosting;
using Microsoft.Owin.Host.SystemWeb;
using Microsoft.Owin.Host.SystemWeb.Infrastructure;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;

[assembly: PreApplicationStartMethod(typeof(PreApplicationStart), "Initialize")]

namespace Microsoft.Owin.Host.SystemWeb
{
    /// <summary>
    /// Registers the OWIN request processing module at application startup.
    /// </summary>
    [EditorBrowsable(EditorBrowsableState.Never)]
    public static class PreApplicationStart
    {
        private const string TraceName = "Microsoft.Owin.Host.SystemWeb.PreApplicationStart";

        /// <summary>
        /// Registers the OWIN request processing module.
        /// </summary>
        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
            Justification = "Initialize must never throw on server startup path")]
        public static void Initialize()
        {
            try
            {
                DynamicModuleUtility.RegisterModule(typeof(OwinHttpModule));
            }
            catch (Exception ex)
            {
                ITrace trace = TraceFactory.Create(TraceName);
                trace.WriteError(Resources.Trace_RegisterModuleException, ex);
                throw;
            }

            try
            {
                string appSetting = ConfigurationManager.AppSettings[Constants.OwinSetCurrentDirectory];
                if (string.Equals("true", appSetting, StringComparison.OrdinalIgnoreCase))
                {
                    string physicalPath = HostingEnvironment.MapPath("~");
                    if (physicalPath != null)
                    {
                        Directory.SetCurrentDirectory(physicalPath);
                    }
                }
            }
            catch (Exception ex)
            {
                ITrace trace = TraceFactory.Create(TraceName);
                trace.WriteError(Resources.Trace_SetCurrentDirectoryException, ex);
                throw;
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.08812793325221624, 'fraction_numerical': 0.0055623153137493485, 'mean_word_length': 2.3087981598619898, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6740345', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1341, 'n_words': 386}