1111using Umbraco . CodeGen . Parsers ;
1212using jumps . umbraco . usync . helpers ;
1313using Umbraco . Core ;
14+ using Umbraco . Core . Logging ;
1415
1516namespace Umbraco . CodeGen . Integration
1617{
@@ -26,6 +27,9 @@ public class ApplicationEvents : IApplicationEventHandler
2627 private CodeGeneratorFactory generatorFactory ;
2728 private ParserFactory parserFactory ;
2829
30+ private DateTime globalStart ;
31+ private DateTime itemStart ;
32+
2933 public void OnApplicationInitialized ( UmbracoApplicationBase umbracoApplication , ApplicationContext applicationContext )
3034 {
3135 }
@@ -50,10 +54,20 @@ public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, App
5054
5155 XmlDoc . Saved += OnDocumentTypeSaved ;
5256
53- if ( configuration . DocumentTypes . GenerateXml )
54- GenerateXml ( configuration . DocumentTypes ) ;
55- if ( configuration . MediaTypes . GenerateXml )
56- GenerateXml ( configuration . MediaTypes ) ;
57+ if ( configuration . DocumentTypes . GenerateXml )
58+ {
59+ globalStart = DateTime . Now ;
60+ LogHelper . Info < CodeGenerator > ( ( ) => "Parsing typed documenttype models" ) ;
61+ GenerateXml ( configuration . DocumentTypes ) ;
62+ LogHelper . Info < CodeGenerator > ( ( ) => String . Format ( "Parsing typed documenttype models done. Took {0:MM:ss}" , DateTime . Now - globalStart ) ) ;
63+ }
64+ if ( configuration . MediaTypes . GenerateXml )
65+ {
66+ globalStart = DateTime . Now ;
67+ LogHelper . Info < CodeGenerator > ( ( ) => "Parsing typed mediatype models" ) ;
68+ GenerateXml ( configuration . MediaTypes ) ;
69+ LogHelper . Info < CodeGenerator > ( ( ) => String . Format ( "Parsing typed mediatype models done. Took {0:MM:ss}" , DateTime . Now - globalStart ) ) ;
70+ }
5771 }
5872
5973 private T CreateFactory < T > ( string typeName )
@@ -81,18 +95,24 @@ private void GenerateXml(ContentTypeConfiguration contentTypeConfiguration)
8195 var documents = new List < XDocument > ( ) ;
8296 foreach ( var file in files )
8397 {
98+ itemStart = DateTime . Now ;
99+ LogHelper . Debug < CodeGenerator > ( ( ) => String . Format ( "Parsing file {0}" , file ) ) ;
84100 using ( var reader = File . OpenText ( file ) )
85101 {
86102 var contentType = parser . Parse ( reader ) . FirstOrDefault ( ) ;
87103 if ( contentType != null )
88104 documents . Add ( XDocument . Parse ( serializer . Serialize ( contentType ) ) ) ;
89105 }
90- }
106+ LogHelper . Debug < CodeGenerator > ( ( ) => String . Format ( "Parsing file {0} done. Took {1:MM:ss}" , file , DateTime . Now - itemStart ) ) ;
107+ }
91108
92109 var documentTypeRoot = Path . Combine ( uSyncConfiguration . USyncFolder , contentTypeConfiguration . ContentTypeName ) ;
93110 if ( ! Directory . Exists ( documentTypeRoot ) )
94111 Directory . CreateDirectory ( documentTypeRoot ) ;
112+ itemStart = DateTime . Now ;
113+ LogHelper . Info < CodeGenerator > ( ( ) => "Writing uSync definitions" ) ;
95114 WriteDocuments ( contentTypeConfiguration , documents , documentTypeRoot , "" ) ;
115+ LogHelper . Info < CodeGenerator > ( ( ) => String . Format ( "Writing uSync definitions done. Took {0:MM:ss}" , DateTime . Now - itemStart ) ) ;
96116 }
97117
98118 private void WriteDocuments (
@@ -133,11 +153,16 @@ private void OnDocumentTypeSaved(XmlDocFileEventArgs e)
133153 if ( ! typeConfig . GenerateClasses )
134154 return ;
135155
156+ itemStart = DateTime . Now ;
157+ LogHelper . Debug < CodeGenerator > ( ( ) => String . Format ( "Content type {0} saved, generating typed model" , e . Path ) ) ;
158+
136159 ContentType contentType ;
137160 using ( var reader = File . OpenText ( e . Path ) )
138161 contentType = serializer . Deserialize ( reader ) ;
139162
140- var modelPath = paths [ typeConfig . ContentTypeName ] ;
163+ LogHelper . Info < CodeGenerator > ( ( ) => String . Format ( "Generating typed model for {0}" , contentType . Alias ) ) ;
164+
165+ var modelPath = paths [ typeConfig . ContentTypeName ] ;
141166 if ( ! Directory . Exists ( modelPath ) )
142167 Directory . CreateDirectory ( modelPath ) ;
143168 var path = Path . Combine ( modelPath , contentType . Info . Alias . PascalCase ( ) + ".cs" ) ;
@@ -147,7 +172,9 @@ private void OnDocumentTypeSaved(XmlDocFileEventArgs e)
147172 var classGenerator = new CodeGenerator ( typeConfig , dataTypesProvider , generatorFactory ) ;
148173 using ( var stream = File . CreateText ( path ) )
149174 classGenerator . Generate ( contentType , stream ) ;
150- }
175+
176+ LogHelper . Debug < CodeGenerator > ( ( ) => String . Format ( "Typed model for {0} generated. Took {1:MM:ss}" , contentType . Alias , DateTime . Now - itemStart ) ) ;
177+ }
151178
152179 public void OnApplicationStarted ( UmbracoApplicationBase umbracoApplication , ApplicationContext applicationContext )
153180 {
0 commit comments