<commit_before>﻿using System;
using System.Linq;
using System.Reflection;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Composing;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.ModelsBuilder.Embedded.Building;
using Umbraco.ModelsBuilder.Embedded.Configuration;
using Umbraco.Web;
using Umbraco.Web.PublishedCache.NuCache;
using Umbraco.Web.Features;

namespace Umbraco.ModelsBuilder.Embedded.Compose
{


    [ComposeBefore(typeof(NuCacheComposer))]
    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public sealed class ModelsBuilderComposer : ICoreComposer
    {
        public void Compose(Composition composition)
        {
            composition.Configs.Add<IModelsBuilderConfig>(() => new ModelsBuilderConfig());

            if (IsExternalModelsBuilderInstalled() == true)
            {
                ComposeForExternalModelsBuilder(composition);
                return;
            }

            composition.Components().Append<ModelsBuilderComponent>();
            composition.Register<UmbracoServices>(Lifetime.Singleton);

            composition.RegisterUnique<ModelsGenerator>();
            composition.RegisterUnique<LiveModelsProvider>();
            composition.RegisterUnique<OutOfDateModelsStatus>();
            composition.RegisterUnique<ModelsGenerationError>();

            if (composition.Configs.ModelsBuilder().ModelsMode == ModelsMode.PureLive)
                ComposeForLiveModels(composition);
            else if (composition.Configs.ModelsBuilder().EnableFactory)
                ComposeForDefaultModelsFactory(composition);
        }

        private static bool IsExternalModelsBuilderInstalled()
        {
            var assemblyNames = new[]
            {
                "Umbraco.ModelsBuider",
                "ModelsBuilder.Umbraco"
            };

            try
            {
                foreach (var name in assemblyNames)
                {
                    var assembly = Assembly.Load(name);

                    if (assembly != null)
                    {
                        return true;
                    }
                }
            }
            catch (Exception)
            {
                //swallow exception, DLL must not be there
            }

            return false;
        }

        private void ComposeForExternalModelsBuilder(Composition composition)
        {
            composition.Logger.Info<ModelsBuilderComposer>("ModelsBuilder.Embedded is disabled, the external ModelsBuilder was detected.");
            composition.Components().Append<DisabledModelsBuilderComponent>();
            composition.Dashboards().Remove<ModelsBuilderDashboard>();
        }
<commit_msg>Update ModelsBuilderComposer.cs<commit_after>﻿using System;
using System.Linq;
using System.Reflection;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Composing;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.ModelsBuilder.Embedded.Building;
using Umbraco.ModelsBuilder.Embedded.Configuration;
using Umbraco.Web;
using Umbraco.Web.PublishedCache.NuCache;
using Umbraco.Web.Features;

namespace Umbraco.ModelsBuilder.Embedded.Compose
{


    [ComposeBefore(typeof(NuCacheComposer))]
    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public sealed class ModelsBuilderComposer : ICoreComposer
    {
        public void Compose(Composition composition)
        {
            composition.Configs.Add<IModelsBuilderConfig>(() => new ModelsBuilderConfig());

            if (IsExternalModelsBuilderInstalled() == true)
            {
                ComposeForExternalModelsBuilder(composition);
                return;
            }

            composition.Components().Append<ModelsBuilderComponent>();
            composition.Register<UmbracoServices>(Lifetime.Singleton);

            composition.RegisterUnique<ModelsGenerator>();
            composition.RegisterUnique<LiveModelsProvider>();
            composition.RegisterUnique<OutOfDateModelsStatus>();
            composition.RegisterUnique<ModelsGenerationError>();

            if (composition.Configs.ModelsBuilder().ModelsMode == ModelsMode.PureLive)
                ComposeForLiveModels(composition);
            else if (composition.Configs.ModelsBuilder().EnableFactory)
                ComposeForDefaultModelsFactory(composition);
        }

        private static bool IsExternalModelsBuilderInstalled()
        {
            var assemblyNames = new[]
            {
                "Umbraco.ModelsBuilder",
                "ModelsBuilder.Umbraco"
            };

            try
            {
                foreach (var name in assemblyNames)
                {
                    var assembly = Assembly.Load(name);

                    if (assembly != null)
                    {
                        return true;
                    }
                }
            }
            catch (Exception)
            {
                //swallow exception, DLL must not be there
            }

            return false;
        }

        private void ComposeForExternalModelsBuilder(Composition composition)
        {
            composition.Logger.Info<ModelsBuilderComposer>("ModelsBuilder.Embedded is disabled, the external ModelsBuilder was detected.");
            composition.Components().Append<DisabledModelsBuilderComponent>();
            composition.Dashboards().Remove<ModelsBuilderDashboard>();
        }

{'fraction_non_alphanumeric': 0.08337955259752265, 'fraction_numerical': 0.0, 'mean_word_length': 2.1545189504373177, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, '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': '4740876', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1235, 'n_words': 217}