init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
48
Framework/Localization/ExceptionLocalizer.cs
Normal file
48
Framework/Localization/ExceptionLocalizer.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Kreta.Framework.Caching;
|
||||
|
||||
namespace Kreta.Framework.Localization
|
||||
{
|
||||
/// <summary>
|
||||
/// Kivételek nyelvesítésére szolgáló <see cref="ILocalizer"/> megvalósítás.
|
||||
/// </summary>
|
||||
internal class ExceptionLocalizer : ILocalizer
|
||||
{
|
||||
private static object SyncObject = new object();
|
||||
// <<Monostate>>
|
||||
private static readonly Dictionary<Type, FriendlyNameAttribute> friendlyNameAttributeCache = new Dictionary<Type, FriendlyNameAttribute>();
|
||||
|
||||
string ILocalizer.Localize(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
return Localize((Exception)value, cultureInfo);
|
||||
}
|
||||
|
||||
public virtual string Localize(Exception exception, CultureInfo cultureInfo)
|
||||
{
|
||||
FriendlyNameAttribute attribute;
|
||||
lock (SyncObject)
|
||||
{
|
||||
var exceptionType = exception.GetType();
|
||||
if (!friendlyNameAttributeCache.TryGetValue(exceptionType, out attribute))
|
||||
{
|
||||
attribute = (FriendlyNameAttribute)exceptionType.GetCustomAttributes(typeof(FriendlyNameAttribute), true).FirstOrDefault(); //inherited but allowed only one
|
||||
friendlyNameAttributeCache[exceptionType] = attribute;
|
||||
}
|
||||
}
|
||||
|
||||
if (attribute != null)
|
||||
{
|
||||
if (attribute.StringResourceId == -1)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return SDAServer.Instance.CacheManager.AquireCache<StringResourcesCache>().Get(attribute.StringResourceId, cultureInfo.LCID, attribute.DisplayText);
|
||||
}
|
||||
return exception.Message;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue