17 using System.Collections.Generic;
18 using System.Runtime.CompilerServices;
20 using erminas.SmartAPI.CMS.Project;
21 using erminas.SmartAPI.CMS.Project.ContentClasses;
22 using erminas.SmartAPI.Utils;
24 namespace erminas.SmartAPI.CMS
28 void EnsureInitialization();
76 protected PartialRedDotObject(
ISession session, XmlElement xmlElement) : base(session, xmlElement)
87 protected PartialRedDotObject(ISession session, Guid guid) : base(session, guid)
89 IsInitialized =
false;
92 protected PartialRedDotObject(ISession session) : base(session)
94 IsInitialized =
false;
100 public bool IsInitialized {
get;
set; }
108 protected T LazyLoad<T>(ref T value)
110 if (IsInitialized || !Equals(value,
default(T)))
118 protected abstract void LoadWholeObject();
123 protected abstract XmlElement RetrieveWholeObject();
125 #region IPartialRedDotObject Members
127 public void EnsureInitialization()
135 public override sealed
string Name
137 get {
return LazyLoad(ref _name); }
138 internal set { base.Name = value; }
141 public virtual void Refresh()
143 XmlElement = (XmlElement) RetrieveWholeObject().Clone();
147 IsInitialized =
true;
150 public override sealed XmlElement XmlElement
154 EnsureInitialization();
155 return base.XmlElement;
157 protected internal set
159 base.XmlElement = value;
160 _readWriteWrapper =
new XmlReadWriteWrapper(_xmlElement,
new Dictionary<string, string>());
164 protected override sealed T GetAttributeValue<T>([CallerMemberName]
string callerName =
"")
166 EnsureInitialization();
168 return base.GetAttributeValue<T>(callerName);
172 protected override sealed
void SetAttributeValue<T>(T value, [CallerMemberName]
string callerName =
"")
174 EnsureInitialization();
176 base.SetAttributeValue(value, callerName);
183 internal abstract class LanguageDependentPartialRedDotProjectObject : PartialRedDotProjectObject,
184 ILanguageDependentXmlBasedObject
194 private readonly Dictionary<string, XmlReadWriteWrapper> _languageDepdentXmlElements =
195 new Dictionary<string, XmlReadWriteWrapper>();
197 protected LanguageDependentPartialRedDotProjectObject(
IProject project, XmlElement xmlElement)
198 : base(project, xmlElement)
202 protected LanguageDependentPartialRedDotProjectObject(
IProject project, Guid guid) : base(project, guid)
206 protected LanguageDependentPartialRedDotProjectObject(
IProject project) : base(project)
210 public IXmlReadWriteWrapper GetElementForLanguage(
string languageAbbreviation)
212 var element = _languageDepdentXmlElements.GetOrAdd(languageAbbreviation, () =>
214 using (
new LanguageContext(Project.LanguageVariants[languageAbbreviation]))
216 var read = (XmlElement) RetrieveWholeObject().Clone();
217 return new XmlReadWriteWrapper(read, _readWriteWrapper.WrittenValues);
224 public override void Refresh()
226 _languageDepdentXmlElements.Clear();