17 using erminas.SmartAPI.CMS.Project;
18 using erminas.SmartAPI.CMS.Project.ContentClasses;
19 using erminas.SmartAPI.Exceptions;
21 namespace erminas.SmartAPI.CMS
30 T ForCurrentLanguage {
get; }
31 T ForMainLanguage {
get; }
33 T
this[
string languageAbbreviation] {
get; }
36 public interface ILanguageDependentValue<T> : ILanguageDependentReadValue<T>
38 T ForAllLanguages {
set; }
39 new T ForCurrentLanguage {
get;
set; }
40 new T ForMainLanguage {
get;
set; }
42 new T
this[
string languageAbbreviation] {
get;
set; }
46 internal abstract class AbstractLanguageDependendReadValue<T> : ILanguageDependentReadValue<T>
48 protected AbstractLanguageDependendReadValue(IPartialRedDotProjectObject parent)
53 public T ForCurrentLanguage
55 get {
return this[Parent.Project.LanguageVariants.Current]; }
58 public T ForMainLanguage
60 get {
return this[Parent.Project.LanguageVariants.Main]; }
65 get {
return this[languageVariant.Abbreviation]; }
68 public abstract T
this[
string languageAbbreviation] {
get; }
69 public IPartialRedDotProjectObject Parent {
get;
private set; }
72 internal class LanguageDependentValue<T> : ILanguageDependentValue<T>
74 private readonly RedDotAttribute _attribute;
75 private readonly IPartialRedDotProjectObject _parent;
77 public LanguageDependentValue(IPartialRedDotProjectObject parent, RedDotAttribute attribute)
80 _attribute = attribute;
83 public T ForAllLanguages
87 foreach (var curLanguage
in _parent.Project.LanguageVariants)
89 this[curLanguage] = value;
94 public T ForCurrentLanguage
96 get {
return this[_parent.Project.LanguageVariants.Current]; }
97 set {
this[_parent.Project.LanguageVariants.Current] = value; }
100 public T ForMainLanguage
102 get {
return this[_parent.Project.LanguageVariants.Main]; }
103 set {
this[_parent.Project.LanguageVariants.Main] = value; }
108 get {
return this[languageVariant.Abbreviation]; }
109 set {
this[languageVariant.Abbreviation] = value; }
112 public virtual T
this[
string languageAbbreviation]
116 var xmlElement = ((ILanguageDependentXmlBasedObject) _parent).GetElementForLanguage(languageAbbreviation);
117 return _attribute.ReadFrom<T>(_parent, xmlElement);
121 var element = ((ILanguageDependentXmlBasedObject) _parent).GetElementForLanguage(languageAbbreviation);
122 _attribute.WriteTo(_parent, element, value);
126 public IPartialRedDotProjectObject Parent
128 get {
return _parent; }
131 public void SetAllLanguagesFrom(ILanguageDependentValue<T> value)
133 CheckLanguageVariantCompatibility(value);
134 foreach (var language
in Parent.Project.LanguageVariants)
136 this[language] = value[language];
140 private void CheckLanguageVariantCompatibility(ILanguageDependentValue<T> value)
142 if (_parent.Session == value.Parent.Session && _parent.Project.Equals(value.Parent.Project))
147 Parent.Project.LanguageVariants.Any(
148 lang => !value.Parent.Project.LanguageVariants.ContainsName(lang.Name)))
152 "Unable to assign values for all languages from project {0} to project {1} as the language variants are incompatible",
153 value.Parent.Project, _parent.Project));