<commit_before>﻿// <copyright file="JetApplicationHandler.cs" company="Logikfabrik">
//   Copyright (c) 2015 anton(at)logikfabrik.se. Licensed under the MIT license.
// </copyright>

namespace Logikfabrik.Umbraco.Jet
{
    using Configuration;
    using Data;
    using global::Umbraco.Core;
    using global::Umbraco.Core.Services;

    /// <summary>
    /// The <see cref="JetApplicationHandler" /> class. Class for subscribing to Umbraco application events, setting up uJet.
    /// </summary>
    public class JetApplicationHandler : ApplicationHandler
    {
        private static readonly object Lock = new object();

        private static bool configured;

        /// <summary>
        /// Called when the application is started.
        /// </summary>
        /// <param name="umbracoApplication">The Umbraco application.</param>
        /// <param name="applicationContext">The application context.</param>
        public override void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            if (!IsInstalled)
            {
                return;
            }

            if (configured)
            {
                return;
            }

            lock (Lock)
            {
                var typeResolver = TypeResolver.Instance;
                var typeRepository = TypeRepository.Instance;

                // Synchronize.
                if (JetConfigurationManager.Synchronize.HasFlag(SynchronizationMode.DataTypes))
                {
                    new DataTypeSynchronizer(
                        ApplicationContext.Current.Services.DataTypeService,
                        typeResolver,
                        typeRepository).Run();
                }

                if (JetConfigurationManager.Synchronize.HasFlag(SynchronizationMode.DocumentTypes))
                {
                    new TemplateSynchronizer(
                        ApplicationContext.Current.Services.FileService,
                        TemplateService.Instance).Run();
                    new DocumentTypeSynchronizer(
                        ApplicationContext.Current.Services.ContentTypeService,
                        ApplicationContext.Current.Services.FileService,
                        typeResolver,
                        typeRepository).Run();
                }

                if (JetConfigurationManager.Synchronize.HasFlag(SynchronizationMode.MediaTypes))
                {
                    new MediaTypeSynchronizer(
                        ApplicationContext.Current.Services.ContentTypeService,
                        typeResolver,
                        typeRepository).Run();
                }

                if (JetConfigurationManager.Synchronize.HasFlag(SynchronizationMode.MemberTypes))
                {
                    new MemberTypeSynchronizer(
                        ApplicationContext.Current.Services.MemberTypeService,
                        typeResolver,
                        typeRepository).Run();
                }

                var defaultValueService = new DefaultValueService(typeResolver, typeRepository);

                // Wire up handler for document type default values.
                ContentService.Saving += (sender, args) => defaultValueService.SetDefaultValues(args.SavedEntities);

                // Wire up handler for media type default values.
                MediaService.Saving += (sender, args) => defaultValueService.SetDefaultValues(args.SavedEntities);

                // Wire up handler for member type default values.
                MemberService.Saving += (sender, args) => defaultValueService.SetDefaultValues(args.SavedEntities);

                configured = true;
            }
        }
    }
}<commit_msg>Added basic logging to the uJet application handler.<commit_after>﻿// <copyright file="JetApplicationHandler.cs" company="Logikfabrik">
//   Copyright (c) 2015 anton(at)logikfabrik.se. Licensed under the MIT license.
// </copyright>

using Logikfabrik.Umbraco.Jet.Extensions;

namespace Logikfabrik.Umbraco.Jet
{
    using Configuration;
    using Data;
    using global::Umbraco.Core;
    using global::Umbraco.Core.Services;

    /// <summary>
    /// The <see cref="JetApplicationHandler" /> class. Class for subscribing to Umbraco application events, setting up uJet.
    /// </summary>
    public class JetApplicationHandler : ApplicationHandler
    {
        private static readonly object Lock = new object();

        private static bool configured;

        /// <summary>
        /// Called when the application is started.
        /// </summary>
        /// <param name="umbracoApplication">The Umbraco application.</param>
        /// <param name="applicationContext">The application context.</param>
        public override void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            if (!IsInstalled)
            {
                return;
            }

            if (configured)
            {
                return;
            }

            lock (Lock)
            {
                this.Info("Begin synchronizing types.");

                var typeResolver = TypeResolver.Instance;
                var typeRepository = TypeRepository.Instance;

                // Synchronize.
                if (JetConfigurationManager.Synchronize.HasFlag(SynchronizationMode.DataTypes))
                {
                    this.Info("Data type synchronization enabled. Begin synchronizing data types.");

                    new DataTypeSynchronizer(
                        ApplicationContext.Current.Services.DataTypeService,
                        typeResolver,
                        typeRepository).Run();
                }

                if (JetConfigurationManager.Synchronize.HasFlag(SynchronizationMode.DocumentTypes))
                {
                    this.Info("Document type synchronization enabled. Begin synchronizing templates.");

                    new TemplateSynchronizer(
                        ApplicationContext.Current.Services.FileService,
                        TemplateService.Instance).Run();

                    this.Info("Document type synchronization enabled. Begin synchronizing document types.");
                    new DocumentTypeSynchronizer(
                        ApplicationContext.Current.Services.ContentTypeService,
                        ApplicationContext.Current.Services.FileService,
                        typeResolver,
                        typeRepository).Run();
                }

                if (JetConfigurationManager.Synchronize.HasFlag(SynchronizationMode.MediaTypes))
                {
                    this.Info("Media type synchronization enabled. Begin synchronizing media types.");

                    new MediaTypeSynchronizer(
                        ApplicationContext.Current.Services.ContentTypeService,
                        typeResolver,
                        typeRepository).Run();
                }

                if (JetConfigurationManager.Synchronize.HasFlag(SynchronizationMode.MemberTypes))
                {
                    this.Info("Member type synchronization enabled. Begin synchronizing member types.");

                    new MemberTypeSynchronizer(
                        ApplicationContext.Current.Services.MemberTypeService,
                        typeResolver,
                        typeRepository).Run();
                }

                var defaultValueService = new DefaultValueService(typeResolver, typeRepository);

                // Wire up handler for document type default values.
                ContentService.Saving += (sender, args) => defaultValueService.SetDefaultValues(args.SavedEntities);

                // Wire up handler for media type default values.
                MediaService.Saving += (sender, args) => defaultValueService.SetDefaultValues(args.SavedEntities);

                // Wire up handler for member type default values.
                MemberService.Saving += (sender, args) => defaultValueService.SetDefaultValues(args.SavedEntities);

                configured = true;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07756838905775076, 'fraction_numerical': 0.0009726443768996961, 'mean_word_length': 1.693516699410609, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, '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': '2975738', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1702, 'n_words': 389}