Updated validator definitions, updated ToXml logic to take into account new Property Editors, added Serialization and Deserialization methods

for property editor's to override if necessary, updated the ContentItemBinder to bind the db and dto models so now that validator filter
just validates against the model and doesn't actually do any data lookups itself (much nicer). Now saves and retreives from the database !!
This commit is contained in:
Shannon Deminick
2013-05-27 21:32:37 -10:00
parent 7d7ca4530b
commit cf631974a8
22 changed files with 300 additions and 95 deletions

View File

@@ -2,6 +2,7 @@
using System.Xml;
using System.Xml.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Core.Models
{
@@ -17,7 +18,7 @@ namespace Umbraco.Core.Models
string nodeName = UmbracoSettings.UseLegacyXmlSchema ? "data" : property.Alias.ToSafeAlias();
var xd = new XmlDocument();
XmlNode xmlNode = xd.CreateNode(XmlNodeType.Element, nodeName, "");
var xmlNode = xd.CreateNode(XmlNodeType.Element, nodeName, "");
//Add the property alias to the legacy schema
if (UmbracoSettings.UseLegacyXmlSchema)
@@ -27,9 +28,51 @@ namespace Umbraco.Core.Models
xmlNode.Attributes.Append(alias);
}
//This seems to fail during testing
xmlNode.AppendChild(property.PropertyType.DataType(property.Id).Data.ToXMl(xd));
//TODO: We'll need to clean this up eventually but for now here's what we're doing:
// * Check if the property's DataType is assigned from a Property Editor or a legacy IDataType
// * Get the XML result from the IDataType if there is one, otherwise just construct a simple
// XML construct from the value returned from the Property Editor.
// More details discussed here: https://groups.google.com/forum/?fromgroups=#!topic/umbraco-dev/fieWZzHj7oY
//var dataType = ApplicationContext.Current.Services.DataTypeService.GetDataTypeDefinitionById(property.PropertyType.DataTypeDefinitionId);
//if (dataType == null) throw new InvalidOperationException("No data type definition found with id " + property.PropertyType.DataTypeDefinitionId);
var propertyEditor = PropertyEditorResolver.Current.GetById(property.PropertyType.DataTypeId);
if (propertyEditor != null)
{
switch (property.PropertyType.DataTypeDatabaseType)
{
case DataTypeDatabaseType.Nvarchar:
case DataTypeDatabaseType.Integer:
xmlNode.AppendChild(xd.CreateTextNode(property.Value.ToXmlString<string>()));
break;
case DataTypeDatabaseType.Ntext:
//put text in cdata
xmlNode.AppendChild(xd.CreateCDataSection(property.Value.ToXmlString<string>()));
break;
case DataTypeDatabaseType.Date:
//treat dates differently, output the format as xml format
if (property.Value == null)
{
xmlNode.AppendChild(xd.CreateTextNode(string.Empty));
}
else
{
var dt = (DateTime)property.Value;
xmlNode.AppendChild(xd.CreateTextNode(dt.ToXmlString<DateTime>()));
}
break;
default:
throw new ArgumentOutOfRangeException();
}
}
else
{
//NOTE: An exception will be thrown if this doesn't exist
var legacyDataType = property.PropertyType.DataType(property.Id);
xmlNode.AppendChild(legacyDataType.Data.ToXMl(xd));
}
var element = xmlNode.GetXElement();
return element;
}

View File

@@ -1,4 +1,5 @@
using umbraco.interfaces;
using System;
using umbraco.interfaces;
namespace Umbraco.Core.Models
{
@@ -20,6 +21,10 @@ namespace Umbraco.Core.Models
{
Mandate.ParameterNotNull(propertyType, "propertyType");
var dataType = ApplicationContext.Current.Services.DataTypeService.GetDataTypeById(propertyType.DataTypeId);
if (dataType == null)
throw new InvalidOperationException("No IDataType found for control ID " + propertyType.DataTypeId);
dataType.DataTypeDefinitionId = propertyType.DataTypeDefinitionId;
dataType.Data.PropertyId = propertyId;
return dataType;