17 using System.Collections.Generic;
 
   20 using erminas.SmartAPI.Utils;
 
   21 using erminas.SmartAPI.Utils.CachedCollections;
 
   23 namespace erminas.SmartAPI.CMS
 
   27         string Country { 
get; }
 
   32         IIndexedCachedList<int, IDateTimeFormat> DateTimeFormats { 
get; }
 
   35         bool IsStandardLanguage { 
get; }
 
   37         string Language { 
get; }
 
   38         string LanguageAbbreviation { 
get; }
 
   39         string RFCLanguageId { 
get; }
 
   44         string Country { 
get; }
 
   49         IIndexedCachedList<int, IDateTimeFormat> DateTimeFormats { 
get; }
 
   53         bool IsStandardLanguage { 
get; }
 
   55         string Language { 
get; }
 
   56         string LanguageAbbreviation { 
get; }
 
   57         string RFCLanguageId { 
get; }
 
   60     internal class SystemLocale : Locale, ISystemLocale
 
   62         internal SystemLocale(ISession session, XmlElement xmlElement) : base(session, xmlElement)
 
   66         public bool Equals(ISystemLocale other)
 
   68             return other.LCID == LCID;
 
   72     internal class DialogLocale : Locale, IDialogLocale
 
   74         internal DialogLocale(ISession session, XmlElement xmlElement) : base(session, xmlElement)
 
   78         public bool Equals(IDialogLocale other)
 
   80             return other.LCID == LCID;
 
   84     internal abstract class Locale
 
   86         private readonly ISession _session;
 
   88         protected Locale(ISession session, XmlElement xmlElement)
 
   91             LanguageAbbreviation = xmlElement.GetAttributeValue(
"id");
 
   92             Country = xmlElement.GetAttributeValue(
"country");
 
   93             Language = xmlElement.GetAttributeValue(
"language");
 
   94             IsStandardLanguage = xmlElement.GetBoolAttributeValue(
"standardlanguage").GetValueOrDefault();
 
   95             LCID = xmlElement.GetIntAttributeValue(
"lcid").GetValueOrDefault();
 
   96             RFCLanguageId = xmlElement.GetAttributeValue(
"rfclanguageid");
 
   97             DateTimeFormats = 
new IndexedCachedList<int, IDateTimeFormat>(GetFormats, x => x.TypeId, 
Caching.Enabled);
 
  100         public string Country { 
get; 
private set; }
 
  105         public IIndexedCachedList<int, IDateTimeFormat> DateTimeFormats { 
get; 
private set; }
 
  107         public override bool Equals(
object obj)
 
  109             if (ReferenceEquals(null, obj))
 
  113             if (ReferenceEquals(
this, obj))
 
  117             if (obj.GetType() != GetType())
 
  121             return Equals((Locale) obj);
 
  124         public bool Equals(Locale other)
 
  126             return Equals(LCID, other.LCID);
 
  129         public override int GetHashCode()
 
  131             return LanguageAbbreviation.GetHashCode();
 
  134         public bool IsStandardLanguage { 
get; 
private set; }
 
  135         public int LCID { 
get; 
private set; }
 
  136         public string Language { 
get; 
private set; }
 
  137         public string LanguageAbbreviation { 
get; 
private set; }
 
  138         public string RFCLanguageId { 
get; 
private set; }
 
  140         public ISession Session
 
  142             get { 
return _session; }
 
  145         public override string ToString()
 
  147             return Country + 
" (" + Language + 
")";
 
  150         private List<IDateTimeFormat> GetFormats()
 
  152             List<IDateTimeFormat> dateEntries =
 
  158             IEnumerable<DateTimeFormat> timeEntries =
 
  162             IEnumerable<DateTimeFormat> dateTimeEntries =
 
  165                 where dateEntries.All(x => x.TypeId != entry.TypeId)
 
  168             return dateEntries.Union(timeEntries).Union(dateTimeEntries).ToList();
 
  173             const string LOAD_TIME_FORMATS =
 
  174                 @"<TEMPLATE><ELEMENT action=""load"" ><{0}FORMATS action=""list"" lcid=""{1}""/></ELEMENT></TEMPLATE>";
 
  175             string formatTypeString = types.ToString().ToUpper();
 
  176             XmlDocument result = _session.ExecuteRQL(
string.Format(LOAD_TIME_FORMATS, formatTypeString, LCID),
 
  177                                                      RQL.IODataFormat.SessionKeyAndLogonGuid);
 
  179             var timeformats = result.GetElementsByTagName(formatTypeString + 
"FORMATS")[0] as XmlElement;
 
  180             if (timeformats == null)
 
  182                 var e = 
new Exception(
"could not load timeformats for lcid '" + LCID + 
"'");
 
  183                 e.Data.Add(
"result", result);
 
  187             string answerElementsName = types == 
DateTimeFormatTypes.Time ? 
"TIMEFORMAT" : 
"DATEFORMAT";
 
  188             return timeformats.GetElementsByTagName(answerElementsName);