<commit_before>﻿namespace GameLibrary {
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using System.ComponentModel.Composition.Hosting;
    using System.ComponentModel.Composition.Primitives;
    using System.Linq;
    using System.Windows.Controls;
    using Caliburn.Micro;
    using Framework;

    public class AppBootstrapper : Bootstrapper<IShell> {
        CompositionContainer container;

        protected override void StartDesignTime()
        {
            LogManager.GetLog = type => new SimpleLog(type);
            base.StartDesignTime();
        }

        protected override void Configure() {
            ConfigureContainer();
            ConfigureConventions();
        }

        void ConfigureContainer() {
            container = CompositionHost.Initialize(
                new AggregateCatalog(
                    AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()
                    )
                );

            var batch = new CompositionBatch();

            batch.AddExportedValue<IWindowManager>(new WindowManager());
            batch.AddExportedValue<IEventAggregator>(new EventAggregator());
            batch.AddExportedValue(container);

            container.Compose(batch);
        }

        void ConfigureConventions() {
            ConventionManager.AddElementConvention<BusyIndicator>(BusyIndicator.IsBusyProperty, "IsBusy", "IsBusyChanged");
            ConventionManager.AddElementConvention<Rating>(Rating.ValueProperty, "Value", "ValueChanged");

            var baseLocator = ViewLocator.LocateForModelType;
            ViewLocator.LocateForModelType = (modelType, displayLocation, context) =>
            {
                if (modelType.FullName.StartsWith("GameLibrary.Model"))
                {
                    var viewName = modelType.FullName.Replace("GameLibrary.Model", "GameLibrary.Views");
                    var viewType = (from assembly in AssemblySource.Instance
                                    from type in assembly.GetExportedTypes()
                                    where type.FullName == viewName
                                    select type).FirstOrDefault();

                    if (viewType != null)
                        return ViewLocator.GetOrCreateViewType(viewType);
                }

                return baseLocator(modelType, displayLocation, context);
            };
        }

        protected override object GetInstance(Type serviceType, string key) {
            var contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;
            var exports = container.GetExportedValues<object>(contract);

            if(exports.Count() > 0)
                return exports.First();

            throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract));
        }

        protected override IEnumerable<object> GetAllInstances(Type serviceType) {<commit_msg>Updated the GameLibrary sample to use the new RegEx features of the ViewLocator.<commit_after>﻿namespace GameLibrary {
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using System.ComponentModel.Composition.Hosting;
    using System.ComponentModel.Composition.Primitives;
    using System.Linq;
    using System.Windows.Controls;
    using Caliburn.Micro;
    using Framework;

    public class AppBootstrapper : Bootstrapper<IShell> {
        CompositionContainer container;

        protected override void StartDesignTime()
        {
            LogManager.GetLog = type => new SimpleLog(type);
            base.StartDesignTime();
        }

        protected override void Configure() {
            ConfigureContainer();
            ConfigureConventions();
        }

        void ConfigureContainer() {
            container = CompositionHost.Initialize(
                new AggregateCatalog(
                    AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()
                    )
                );

            var batch = new CompositionBatch();

            batch.AddExportedValue<IWindowManager>(new WindowManager());
            batch.AddExportedValue<IEventAggregator>(new EventAggregator());
            batch.AddExportedValue(container);

            container.Compose(batch);
        }

        void ConfigureConventions() {
            ConventionManager.AddElementConvention<BusyIndicator>(BusyIndicator.IsBusyProperty, "IsBusy", "IsBusyChanged");
            ConventionManager.AddElementConvention<Rating>(Rating.ValueProperty, "Value", "ValueChanged");

            ViewLocator.NameTransformer.AddRule(
                @"(?<namespace>(.*\.)*)Model\.(?<basename>[A-Za-z]\w*)",
                @"${namespace}Views.${basename}",
                @"(.*\.)*Model\.[A-Za-z]\w*"
                );
        }

        protected override object GetInstance(Type serviceType, string key) {
            var contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;
            var exports = container.GetExportedValues<object>(contract);

            if(exports.Count() > 0)
                return exports.First();

            throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract));
        }

        protected override IEnumerable<object> GetAllInstances(Type serviceType) {
{'fraction_non_alphanumeric': 0.09213156460112666, 'fraction_numerical': 0.0007268762493185535, 'mean_word_length': 2.272294887039239, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4620916', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1306, 'n_words': 259}