@@ -28,11 +28,14 @@ public static IPublishedContent ConvertValueToContent(string id, string contentT
2828 if ( string . IsNullOrWhiteSpace ( contentTypeAlias ) )
2929 return null ;
3030
31+ if ( dataJson == null )
32+ return null ;
33+
3134 if ( UmbracoContext . Current == null )
3235 return ConvertValue ( id , contentTypeAlias , dataJson ) ;
3336
3437 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 ) ,
3639 ( ) =>
3740 {
3841 return ConvertValue ( id , contentTypeAlias , dataJson ) ;
@@ -41,22 +44,17 @@ public static IPublishedContent ConvertValueToContent(string id, string contentT
4144
4245 private static IPublishedContent ConvertValue ( string id , string contentTypeAlias , string dataJson )
4346 {
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 ) ) )
4548 {
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 ) ;
5250 var properties = new List < IPublishedProperty > ( ) ;
5351
5452 // Convert all the properties
5553 var data = JsonConvert . DeserializeObject ( dataJson ) ;
5654 var propValues = ( ( JObject ) data ) . ToObject < Dictionary < string , object > > ( ) ;
5755 foreach ( var jProp in propValues )
5856 {
59- var propType = publishedContentType . GetPropertyType ( jProp . Key ) ;
57+ var propType = contentTypes . PublishedContentType . GetPropertyType ( jProp . Key ) ;
6058 if ( propType != null )
6159 {
6260 /* 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
6563 * we go on to convert the value for the view.
6664 */
6765 var propEditor = PropertyEditorResolver . Current . GetByAlias ( propType . PropertyEditorAlias ) ;
68- var propPreValues = Services . DataTypeService . GetPreValuesCollectionByDataTypeId (
69- propType . DataTypeId ) ;
66+ var propPreValues = GetPreValuesCollectionByDataTypeId ( propType . DataTypeId ) ;
7067
7168 var contentPropData = new ContentPropertyData (
7269 jProp . Value ,
@@ -78,7 +75,7 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
7875 /* Now that we have the DB stored value, we actually need to then convert it into it's
7976 * XML serialized state as expected by the published property by calling ConvertDbToString
8077 */
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 ) ) ;
8279
8380 Property prop2 = null ;
8481 try
@@ -91,15 +88,14 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
9188 */
9289 prop2 = new Property ( propType2 , newValue ) ;
9390 }
94- catch ( Exception ex )
91+ catch ( Exception ex )
9592 {
9693 LogHelper . Error < DocTypeGridEditorHelper > ( "[DocTypeGridEditor] Error creating Property object." , ex ) ;
9794 }
9895
9996 if ( prop2 != null )
10097 {
101- var newValue2 = propEditor . ValueEditor . ConvertDbToString ( prop2 , propType2 ,
102- ApplicationContext . Current . Services . DataTypeService ) ;
98+ var newValue2 = propEditor . ValueEditor . ConvertDbToString ( prop2 , propType2 , Services . DataTypeService ) ;
10399
104100 properties . Add ( new DetachedPublishedProperty ( propType , newValue2 ) ) ;
105101 }
@@ -118,11 +114,46 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
118114 var containerNode = pcr != null && pcr . HasPublishedContent ? pcr . PublishedContent : null ;
119115
120116 return new DetachedPublishedContent ( nameObj != null ? nameObj . ToString ( ) : null ,
121- publishedContentType ,
117+ contentTypes . PublishedContentType ,
122118 properties . ToArray ( ) ,
123119 containerNode ) ;
124120 }
125121
126122 }
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 ; }
127158 }
128159}
0 commit comments