Merge branch 'master' into issue131_optimized

This commit is contained in:
kjac
2014-06-16 16:43:07 +02:00
6 changed files with 17 additions and 9 deletions
+2
View File
@@ -2,6 +2,8 @@ Archetype
=========
![alt tag](http://imulus.github.io/Archetype/images/logo.png)
![alt tag](http://imulus.github.io/Archetype/images/example1.png)
## Installation
Install the selected <a href='https://github.com/imulus/Archetype/releases'>release</a> through the Umbraco package installer or via <a href='http://www.nuget.org/packages/Archetype/'>NuGet</a>.
@@ -4,6 +4,7 @@ using Archetype.Models;
using Newtonsoft.Json;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
namespace Archetype.Extensions
{
@@ -46,7 +47,7 @@ namespace Archetype.Extensions
}
}
internal Models.ArchetypeModel DeserializeJsonToArchetype(string sourceJson, int dataTypeId)
internal Models.ArchetypeModel DeserializeJsonToArchetype(string sourceJson, int dataTypeId, PublishedContentType hostContentType = null)
{
try
{
@@ -56,7 +57,7 @@ namespace Archetype.Extensions
{
// Get list of configured properties and their types and map them to the deserialized archetype model
var preValue = GetArchetypePreValueFromDataTypeId(dataTypeId);
RetrieveAdditionalProperties(ref archetype, preValue);
RetrieveAdditionalProperties(ref archetype, preValue, hostContentType);
}
catch (Exception ex)
{
@@ -110,7 +111,7 @@ namespace Archetype.Extensions
/// </summary>
/// <param name="archetype">The Archetype to add the additional metadata to</param>
/// <param name="preValue">The configuration of the Archetype</param>
private void RetrieveAdditionalProperties(ref Models.ArchetypeModel archetype, ArchetypePreValue preValue)
private void RetrieveAdditionalProperties(ref Models.ArchetypeModel archetype, ArchetypePreValue preValue, PublishedContentType hostContentType = null)
{
foreach (var fieldset in preValue.Fieldsets)
{
@@ -125,6 +126,7 @@ namespace Archetype.Extensions
propertyInst.DataTypeGuid = property.DataTypeGuid.ToString();
propertyInst.DataTypeId = GetDataTypeByGuid(property.DataTypeGuid).Id;
propertyInst.PropertyEditorAlias = property.PropertyEditorAlias;
propertyInst.HostContentType = hostContentType;
}
}
}
@@ -29,7 +29,7 @@ namespace Archetype.Models
{
var property = GetProperty(propertyAlias);
if (property == null || string.IsNullOrEmpty(property.Value.ToString()))
if (property == null || property.Value == null || string.IsNullOrEmpty(property.Value.ToString()))
return default(T);
return property.GetValue<T>();
@@ -43,7 +43,7 @@ namespace Archetype.Models
public bool HasValue(string propertyAlias)
{
var property = GetProperty(propertyAlias);
if (property == null)
if (property == null || property.Value == null)
return false;
return !string.IsNullOrEmpty(property.Value.ToString());
@@ -57,4 +57,4 @@ namespace Archetype.Models
#endregion
}
}
}
@@ -31,7 +31,7 @@ namespace Archetype.Models
internal string SerializeForPersistence()
{
var json = JObject.Parse(JsonConvert.SerializeObject(this));
var propertiesToRemove = new String[] { "propertyEditorAlias", "dataTypeId", "dataTypeGuid" };
var propertiesToRemove = new String[] { "propertyEditorAlias", "dataTypeId", "dataTypeGuid", "hostContentType" };
json.Descendants().OfType<JProperty>()
.Where(p => propertiesToRemove.Contains(p.Name))
@@ -25,6 +25,9 @@ namespace Archetype.Models
[JsonProperty("dataTypeGuid")]
internal string DataTypeGuid { get; set; }
[JsonProperty("hostContentType")]
internal PublishedContentType HostContentType { get; set; }
public T GetValue<T>()
{
@@ -80,7 +83,7 @@ namespace Archetype.Models
private PublishedPropertyType CreateDummyPropertyType(int dataTypeId, string propertyEditorAlias)
{
return new PublishedPropertyType(null,
return new PublishedPropertyType(this.HostContentType,
new PropertyType(new DataTypeDefinition(-1, propertyEditorAlias)
{
Id = dataTypeId
@@ -40,7 +40,8 @@ namespace Archetype.PropertyConverters
return defaultValue;
var archetype = new ArchetypeHelper().DeserializeJsonToArchetype(source.ToString(),
(propertyType != null ? propertyType.DataTypeId : -1));
(propertyType != null ? propertyType.DataTypeId : -1),
(propertyType != null ? propertyType.ContentType : null));
return archetype;
}