@@ -28,11 +28,14 @@ public static IPublishedContent ConvertValueToContent(string id, string contentT
28
28
if ( string . IsNullOrWhiteSpace ( contentTypeAlias ) )
29
29
return null ;
30
30
31
+ if ( dataJson == null )
32
+ return null ;
33
+
31
34
if ( UmbracoContext . Current == null )
32
35
return ConvertValue ( id , contentTypeAlias , dataJson ) ;
33
36
34
37
return ( IPublishedContent ) ApplicationContext . Current . ApplicationCache . RequestCache . GetCacheItem (
35
- string . Concat ( "DocTypeGridEditorHelper.ConvertValueToContent_" , id , "_" , contentTypeAlias ) ,
38
+ string . Concat ( "Our.Umbraco.DocTypeGridEditor.Helpers. DocTypeGridEditorHelper.ConvertValueToContent_" , id , "_" , contentTypeAlias ) ,
36
39
( ) =>
37
40
{
38
41
return ConvertValue ( id , contentTypeAlias , dataJson ) ;
@@ -41,22 +44,17 @@ public static IPublishedContent ConvertValueToContent(string id, string contentT
41
44
42
45
private static IPublishedContent ConvertValue ( string id , string contentTypeAlias , string dataJson )
43
46
{
44
- using ( var timer = DisposableTimer . DebugDuration < DocTypeGridEditorHelper > ( string . Format ( "ConvertValueToContent ({0}, {1})" , id , contentTypeAlias ) ) )
47
+ using ( var timer = ApplicationContext . Current . ProfilingLogger . DebugDuration < DocTypeGridEditorHelper > ( string . Format ( "ConvertValue ({0}, {1})" , id , contentTypeAlias ) ) )
45
48
{
46
- Guid contentTypeGuid ;
47
- if ( Guid . TryParse ( contentTypeAlias , out contentTypeGuid ) )
48
- contentTypeAlias = Services . ContentTypeService . GetAliasByGuid ( contentTypeGuid ) ;
49
-
50
- var publishedContentType = PublishedContentType . Get ( PublishedItemType . Content , contentTypeAlias ) ;
51
- var contentType = ApplicationContext . Current . Services . ContentTypeService . GetContentType ( contentTypeAlias ) ;
49
+ var contentTypes = GetContentTypesByAlias ( contentTypeAlias ) ;
52
50
var properties = new List < IPublishedProperty > ( ) ;
53
51
54
52
// Convert all the properties
55
53
var data = JsonConvert . DeserializeObject ( dataJson ) ;
56
54
var propValues = ( ( JObject ) data ) . ToObject < Dictionary < string , object > > ( ) ;
57
55
foreach ( var jProp in propValues )
58
56
{
59
- var propType = publishedContentType . GetPropertyType ( jProp . Key ) ;
57
+ var propType = contentTypes . PublishedContentType . GetPropertyType ( jProp . Key ) ;
60
58
if ( propType != null )
61
59
{
62
60
/* Because we never store the value in the database, we never run the property editors
@@ -65,8 +63,7 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
65
63
* we go on to convert the value for the view.
66
64
*/
67
65
var propEditor = PropertyEditorResolver . Current . GetByAlias ( propType . PropertyEditorAlias ) ;
68
- var propPreValues = Services . DataTypeService . GetPreValuesCollectionByDataTypeId (
69
- propType . DataTypeId ) ;
66
+ var propPreValues = GetPreValuesCollectionByDataTypeId ( propType . DataTypeId ) ;
70
67
71
68
var contentPropData = new ContentPropertyData (
72
69
jProp . Value ,
@@ -78,7 +75,7 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
78
75
/* Now that we have the DB stored value, we actually need to then convert it into it's
79
76
* XML serialized state as expected by the published property by calling ConvertDbToString
80
77
*/
81
- var propType2 = contentType . CompositionPropertyTypes . Single ( x => x . Alias . InvariantEquals ( propType . PropertyTypeAlias ) ) ;
78
+ var propType2 = contentTypes . ContentType . CompositionPropertyTypes . Single ( x => x . Alias . InvariantEquals ( propType . PropertyTypeAlias ) ) ;
82
79
83
80
Property prop2 = null ;
84
81
try
@@ -91,15 +88,14 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
91
88
*/
92
89
prop2 = new Property ( propType2 , newValue ) ;
93
90
}
94
- catch ( Exception ex )
91
+ catch ( Exception ex )
95
92
{
96
93
LogHelper . Error < DocTypeGridEditorHelper > ( "[DocTypeGridEditor] Error creating Property object." , ex ) ;
97
94
}
98
95
99
96
if ( prop2 != null )
100
97
{
101
- var newValue2 = propEditor . ValueEditor . ConvertDbToString ( prop2 , propType2 ,
102
- ApplicationContext . Current . Services . DataTypeService ) ;
98
+ var newValue2 = propEditor . ValueEditor . ConvertDbToString ( prop2 , propType2 , Services . DataTypeService ) ;
103
99
104
100
properties . Add ( new DetachedPublishedProperty ( propType , newValue2 ) ) ;
105
101
}
@@ -118,11 +114,46 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
118
114
var containerNode = pcr != null && pcr . HasPublishedContent ? pcr . PublishedContent : null ;
119
115
120
116
return new DetachedPublishedContent ( nameObj != null ? nameObj . ToString ( ) : null ,
121
- publishedContentType ,
117
+ contentTypes . PublishedContentType ,
122
118
properties . ToArray ( ) ,
123
119
containerNode ) ;
124
120
}
125
121
126
122
}
123
+
124
+ private static PreValueCollection GetPreValuesCollectionByDataTypeId ( int dataTypeId )
125
+ {
126
+ return ( PreValueCollection ) ApplicationContext . Current . ApplicationCache . RuntimeCache . GetCacheItem (
127
+ string . Concat ( "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetPreValuesCollectionByDataTypeId_" , dataTypeId ) ,
128
+ ( ) => Services . DataTypeService . GetPreValuesCollectionByDataTypeId ( dataTypeId ) ) ;
129
+ }
130
+
131
+ private static ContentTypeContainer GetContentTypesByAlias ( string contentTypeAlias )
132
+ {
133
+ Guid contentTypeGuid ;
134
+ if ( Guid . TryParse ( contentTypeAlias , out contentTypeGuid ) )
135
+ contentTypeAlias = GetContentTypeAliasByGuid ( contentTypeGuid ) ;
136
+
137
+ return ( ContentTypeContainer ) ApplicationContext . Current . ApplicationCache . RuntimeCache . GetCacheItem (
138
+ string . Concat ( "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypesByAlias_" , contentTypeAlias ) ,
139
+ ( ) => new ContentTypeContainer
140
+ {
141
+ PublishedContentType = PublishedContentType . Get ( PublishedItemType . Content , contentTypeAlias ) ,
142
+ ContentType = Services . ContentTypeService . GetContentType ( contentTypeAlias )
143
+ } ) ;
144
+ }
145
+
146
+ private static string GetContentTypeAliasByGuid ( Guid contentTypeGuid )
147
+ {
148
+ return ( string ) ApplicationContext . Current . ApplicationCache . RuntimeCache . GetCacheItem (
149
+ string . Concat ( "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypeAliasByGuid_" , contentTypeGuid ) ,
150
+ ( ) => Services . ContentTypeService . GetAliasByGuid ( contentTypeGuid ) ) ;
151
+ }
152
+ }
153
+
154
+ public class ContentTypeContainer
155
+ {
156
+ public PublishedContentType PublishedContentType { get ; set ; }
157
+ public IContentType ContentType { get ; set ; }
127
158
}
128
159
}
0 commit comments