Merge branch 'wip/106-amend-3' into 106-update
Conflicts: app/Umbraco/Umbraco.Archetype/PropertyConverters/ArchetypeValueConverter.cs
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using Archetype.Umbraco.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
namespace Archetype.Umbraco.Extensions
|
||||
{
|
||||
@@ -28,6 +22,32 @@ namespace Archetype.Umbraco.Extensions
|
||||
_app = ApplicationContext.Current;
|
||||
}
|
||||
|
||||
|
||||
internal Models.Archetype DeserializeJsonToArchetype(string sourceJson, PreValueCollection dataTypePreValues)
|
||||
{
|
||||
try
|
||||
{
|
||||
var archetype = JsonConvert.DeserializeObject<Models.Archetype>(sourceJson, _jsonSettings);
|
||||
|
||||
try
|
||||
{
|
||||
// Get list of configured properties and their types and map them to the deserialized archetype model
|
||||
var preValue = GetArchetypePreValueFromPreValuesCollection(dataTypePreValues);
|
||||
RetrieveAdditionalProperties(ref archetype, preValue);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
return archetype;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new Models.Archetype();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal Models.Archetype DeserializeJsonToArchetype(string sourceJson, int dataTypeId)
|
||||
{
|
||||
try
|
||||
@@ -72,6 +92,14 @@ namespace Archetype.Umbraco.Extensions
|
||||
}) as ArchetypePreValue;
|
||||
}
|
||||
|
||||
private ArchetypePreValue GetArchetypePreValueFromPreValuesCollection(PreValueCollection dataTypePreValues)
|
||||
{
|
||||
var preValueAsString = dataTypePreValues.PreValuesAsDictionary.First().Value.Value;
|
||||
var preValue = JsonConvert.DeserializeObject<ArchetypePreValue>(preValueAsString, _jsonSettings);
|
||||
return preValue;
|
||||
}
|
||||
|
||||
|
||||
private IDataTypeDefinition GetDataTypeByGuid(Guid guid)
|
||||
{
|
||||
return (IDataTypeDefinition) ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(
|
||||
@@ -96,6 +124,7 @@ namespace Archetype.Umbraco.Extensions
|
||||
var propertyAlias = property.Alias;
|
||||
foreach ( var propertyInst in fieldsetInst.Properties.Where(x => x.Alias == propertyAlias))
|
||||
{
|
||||
propertyInst.DataTypeGuid = property.DataTypeGuid.ToString();
|
||||
propertyInst.DataTypeId = GetDataTypeByGuid(property.DataTypeGuid).Id;
|
||||
propertyInst.PropertyEditorAlias = property.PropertyEditorAlias;
|
||||
}
|
||||
|
||||
@@ -28,9 +28,6 @@ namespace Archetype.Umbraco.Models
|
||||
|
||||
public T GetValue<T>()
|
||||
{
|
||||
// If the value is of type T, just return it
|
||||
if (Value is T)
|
||||
return (T)Value;
|
||||
|
||||
// Try Umbraco's PropertyValueConverters
|
||||
var converters = UmbracoContext.Current != null ? PropertyValueConvertersResolver.Current.Converters : Enumerable.Empty<IPropertyValueConverter>();
|
||||
@@ -41,6 +38,10 @@ namespace Archetype.Umbraco.Models
|
||||
return convertedAttempt.Result;
|
||||
}
|
||||
|
||||
// If the value is of type T, just return it
|
||||
if (Value is T)
|
||||
return (T)Value;
|
||||
|
||||
// No PropertyValueConverters matched, so try a regular type conversion
|
||||
var convertAttempt2 = Value.TryConvertTo<T>();
|
||||
if (convertAttempt2.Success)
|
||||
|
||||
@@ -42,8 +42,8 @@ namespace Archetype.Umbraco.PropertyConverters
|
||||
var archetype = new ArchetypeHelper().DeserializeJsonToArchetype(source.ToString(),
|
||||
(propertyType != null ? propertyType.DataTypeId : -1));
|
||||
|
||||
return archetype;
|
||||
return archetype;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Archetype.Umbraco.Extensions;
|
||||
using ClientDependency.Core;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
@@ -48,20 +49,14 @@ namespace Archetype.Umbraco.PropertyEditors
|
||||
protected JsonSerializerSettings _jsonSettings;
|
||||
|
||||
public ArchetypePropertyValueEditor(PropertyValueEditor wrapped)
|
||||
: base(wrapped)
|
||||
{
|
||||
var dcr = new Newtonsoft.Json.Serialization.DefaultContractResolver();
|
||||
dcr.DefaultMembersSearchFlags |= System.Reflection.BindingFlags.NonPublic;
|
||||
|
||||
_jsonSettings = new JsonSerializerSettings { ContractResolver = dcr };
|
||||
}
|
||||
: base(wrapped) { }
|
||||
|
||||
public override string ConvertDbToString(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
|
||||
{
|
||||
if (property.Value == null)
|
||||
return string.Empty;
|
||||
|
||||
var archetype = JsonConvert.DeserializeObject<Models.Archetype>(property.Value.ToString(), _jsonSettings);
|
||||
var archetype = new ArchetypeHelper().DeserializeJsonToArchetype(property.Value.ToString(), propertyType.DataTypeDefinitionId);
|
||||
|
||||
foreach (var fieldset in archetype.Fieldsets)
|
||||
{
|
||||
@@ -101,13 +96,12 @@ namespace Archetype.Umbraco.PropertyEditors
|
||||
|
||||
return archetype;
|
||||
}
|
||||
|
||||
public override object ConvertEditorToDb(ContentPropertyData editorValue, object currentValue)
|
||||
public override object ConvertEditorToDb(ContentPropertyData editorValue, object currentValue)
|
||||
{
|
||||
if (editorValue.Value == null)
|
||||
return string.Empty;
|
||||
|
||||
var archetype = JsonConvert.DeserializeObject<Models.Archetype>(editorValue.Value.ToString(), _jsonSettings);
|
||||
var archetype = new ArchetypeHelper().DeserializeJsonToArchetype(editorValue.Value.ToString(), editorValue.PreValues);
|
||||
|
||||
foreach (var fieldset in archetype.Fieldsets)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user