19 using erminas.SmartAPI.CMS.Project;
20 using erminas.SmartAPI.CMS.Project.Folder;
21 using erminas.SmartAPI.Exceptions;
22 using erminas.SmartAPI.Utils;
24 namespace erminas.SmartAPI.CMS.Converter
26 internal class XslFileConverter : IAttributeConverter<IFile>
28 private const string ELTXSLFILE =
"eltxslfile";
29 private const string ELTFOLDERGUID =
"eltfolderguid";
31 public IFile ConvertFrom(
IProjectObject parent, XmlElement element, RedDotAttribute attribute)
33 ConverterHelper.EnsureValidProjectObject(parent);
36 if (!element.TryGetGuid(ELTFOLDERGUID, out folderGuid) || !element.IsAttributeSet(parent, ELTXSLFILE))
42 return new File(folder, element.GetAttributeValue(ELTXSLFILE));
45 public bool IsReadOnly
50 public void WriteTo(
IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
IFile value)
52 ConverterHelper.EnsureValidProjectObject(parent);
54 ConverterHelper.CheckReadOnly(
this, parent, attribute);
58 SetEmptyValues(element);
62 if (ConverterHelper.AreFromTheSameProject(parent, value))
64 SetValuesFromSameProject(element, value);
68 SetValuesFromDifferentProjects(parent, element, attribute, value);
71 private static void SetEmptyValues(IXmlReadWriteWrapper element)
73 element.SetAttributeValue(ELTFOLDERGUID, null);
74 element.SetAttributeValue(ELTXSLFILE, null);
77 private static void SetValuesFromDifferentProjects(
IProjectObject parent, IXmlReadWriteWrapper element,
78 RedDotAttribute attribute,
IFile value)
84 string.Format(
"No such folder {0} in project {1} for setting of {2}",
88 var ownFile = ownFolder.Files.GetByNamePattern(value.
Name).SingleOrDefault();
93 "No such file {3} in folder {0} in project {1} for setting of {2}",
97 element.SetAttributeValue(ELTFOLDERGUID, ownFolder.Guid.ToRQLString());
98 element.SetAttributeValue(ELTXSLFILE, ownFile.Name);
101 private static void SetValuesFromSameProject(IXmlReadWriteWrapper element,
IFile value)
103 element.SetAttributeValue(ELTFOLDERGUID, value.
Folder.
Guid.ToRQLString());
104 element.SetAttributeValue(ELTXSLFILE, value.
Name);