17 using System.Globalization;
19 using erminas.SmartAPI.CMS.Project;
20 using erminas.SmartAPI.Exceptions;
21 using erminas.SmartAPI.Utils;
23 namespace erminas.SmartAPI.CMS.Converter
25 internal abstract class TextContentConverter : IAttributeConverter<string>
27 public string ConvertFrom(
IProjectObject parent, XmlElement element, RedDotAttribute attribute)
30 if (!element.IsAttributeSet(parent, attribute.ElementName))
35 Guid guid = element.GetGuid(attribute.ElementName);
36 return parent.
Project.
GetTextContent(guid, lang, ((
int) Type).ToString(CultureInfo.InvariantCulture));
39 public bool IsReadOnly {
get;
private set; }
41 public void WriteTo(
IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
string value)
43 if (
string.IsNullOrEmpty(value))
45 element.SetAttributeValue(attribute.ElementName, null);
49 Guid guid = element.IsAttributeSet(parent, attribute.ElementName)
50 ? element.GetGuid(attribute.ElementName)
53 var languageVariantName = element.GetAttributeValue(
"languagevariantid");
58 ((
int) Type).ToString(CultureInfo.InvariantCulture),
61 element.SetAttributeValue(attribute.ElementName, textGuid.ToRQLString());
65 string.Format(
"Could not set {0} text for {1} in language {2}",
66 Type.ToString().ToLower(), parent, languageVariantName), e);
71 protected abstract TextType Type {
get; }
73 protected enum TextType
80 internal class DefaultTextConverter : TextContentConverter
82 protected override TextType Type
84 get {
return TextType.Default; }
88 internal class SampleTextConverter : TextContentConverter
90 protected override TextType Type
92 get {
return TextType.Sample; }