<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Markup;
using Archimedes.Framework.Context;
using Archimedes.Framework.Stereotype;

namespace Archimedes.Framework.Localisation.WPF
{
    public class LocalisationExtension : MarkupExtension
    {

        public LocalisationExtension()
        {
            
        }

        public LocalisationExtension(object id)
        {
            Id = id;
        }

        /// <summary>
        /// The text-key for which the translation text should be loaded
        /// </summary>
        [ConstructorArgument("id")]
        public object Id { get; set; }


        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (!IsInDesignMode())
            {
                var localisationService = ApplicationContext.Instance.Container.Resolve<ILocalisationService>();
                if (localisationService != null)
                {
                    return localisationService.GetTranslation(Id.ToString());
                }
            }

            return Id;
        }

        private static bool? _isInDesignMode;
        public static bool IsInDesignMode()
        {
            if (!_isInDesignMode.HasValue)
            {
                _isInDesignMode = System.Reflection.Assembly.GetExecutingAssembly().Location.Contains("VisualStudio");
            }
            return _isInDesignMode.Value;
        }
    }
}<commit_msg>improved localisation extension, prevent crash in ProvideValue<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Markup;
using Archimedes.Framework.Context;
using Archimedes.Framework.Stereotype;
using log4net;

namespace Archimedes.Framework.Localisation.WPF
{
    public class LocalisationExtension : MarkupExtension
    {
        private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);


        public LocalisationExtension()
        {
            
        }

        public LocalisationExtension(object id)
        {
            Id = id;
        }

        /// <summary>
        /// The text-key for which the translation text should be loaded
        /// </summary>
        [ConstructorArgument("id")]
        public object Id { get; set; }


        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            try
            {
                if (!IsInDesignMode())
                {
                    var diContainer = ApplicationContext.Instance.Container;
                    if (diContainer != null)
                    {
                        var localisationService = diContainer.Resolve<ILocalisationService>();
                        return localisationService.GetTranslation(Id.ToString());
                    }
                    else
                    {
                        throw new NotSupportedException("Archimedes Dependency Injection Container is not ready, can not access ILocalisationService!");
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error("Failed to provide localized text!", e);
            }

            return Id;
        }

        private static bool? _isInDesignMode;
        public static bool IsInDesignMode()
        {
            if (!_isInDesignMode.HasValue)
            {
                _isInDesignMode = System.Reflection.Assembly.GetExecutingAssembly().Location.Contains("VisualStudio");
            }
            return _isInDesignMode.Value;
        }
    }
}
{'fraction_non_alphanumeric': 0.07849462365591398, 'fraction_numerical': 0.00026881720430107527, 'mean_word_length': 1.760385756676558, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '7486280', 'n_tokens_mistral': 899, 'n_tokens_neox': 860, 'n_words': 199}