Skip to content

Commit 5c5fb18

Browse files
committed
Merge branch 'master'
2 parents c5584a3 + 2a3855a commit 5c5fb18

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

Umbraco.CodeGen.Integration/ApplicationEvents.cs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Umbraco.CodeGen.Parsers;
1212
using jumps.umbraco.usync.helpers;
1313
using Umbraco.Core;
14+
using Umbraco.Core.Logging;
1415

1516
namespace 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
}
@@ -55,10 +59,20 @@ public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, App
5559

5660
XmlDoc.Saved += OnDocumentTypeSaved;
5761

58-
if (configuration.DocumentTypes.GenerateXml)
59-
GenerateXml(configuration.DocumentTypes);
60-
if (configuration.MediaTypes.GenerateXml)
61-
GenerateXml(configuration.MediaTypes);
62+
if (configuration.DocumentTypes.GenerateXml)
63+
{
64+
globalStart = DateTime.Now;
65+
LogHelper.Info<CodeGenerator>(() => "Parsing typed documenttype models");
66+
GenerateXml(configuration.DocumentTypes);
67+
LogHelper.Info<CodeGenerator>(() => String.Format("Parsing typed documenttype models done. Took {0:MM:ss}", DateTime.Now - globalStart));
68+
}
69+
if (configuration.MediaTypes.GenerateXml)
70+
{
71+
globalStart = DateTime.Now;
72+
LogHelper.Info<CodeGenerator>(() => "Parsing typed mediatype models");
73+
GenerateXml(configuration.MediaTypes);
74+
LogHelper.Info<CodeGenerator>(() => String.Format("Parsing typed mediatype models done. Took {0:MM:ss}", DateTime.Now - globalStart));
75+
}
6276
}
6377

6478
private T CreateFactory<T>(string typeName)
@@ -86,18 +100,24 @@ private void GenerateXml(ContentTypeConfiguration contentTypeConfiguration)
86100
var documents = new List<XDocument>();
87101
foreach(var file in files)
88102
{
103+
itemStart = DateTime.Now;
104+
LogHelper.Debug<CodeGenerator>(() => String.Format("Parsing file {0}", file));
89105
using (var reader = File.OpenText(file))
90106
{
91107
var contentType = parser.Parse(reader).FirstOrDefault();
92108
if (contentType != null)
93109
documents.Add(XDocument.Parse(serializer.Serialize(contentType)));
94110
}
95-
}
111+
LogHelper.Debug<CodeGenerator>(() => String.Format("Parsing file {0} done. Took {1:MM:ss}", file, DateTime.Now - itemStart));
112+
}
96113

97114
var documentTypeRoot = Path.Combine(uSyncConfiguration.USyncFolder, contentTypeConfiguration.ContentTypeName);
98115
if (!Directory.Exists(documentTypeRoot))
99116
Directory.CreateDirectory(documentTypeRoot);
117+
itemStart = DateTime.Now;
118+
LogHelper.Info<CodeGenerator>(() => "Writing uSync definitions");
100119
WriteDocuments(contentTypeConfiguration, documents, documentTypeRoot, "");
120+
LogHelper.Info<CodeGenerator>(() => String.Format("Writing uSync definitions done. Took {0:MM:ss}", DateTime.Now - itemStart));
101121
}
102122

103123
private void WriteDocuments(
@@ -138,11 +158,16 @@ private void OnDocumentTypeSaved(XmlDocFileEventArgs e)
138158
if (!typeConfig.GenerateClasses)
139159
return;
140160

161+
itemStart = DateTime.Now;
162+
LogHelper.Debug<CodeGenerator>(() => String.Format("Content type {0} saved, generating typed model", e.Path));
163+
141164
ContentType contentType;
142165
using (var reader = File.OpenText(e.Path))
143166
contentType = serializer.Deserialize(reader);
144167

145-
var modelPath = paths[typeConfig.ContentTypeName];
168+
LogHelper.Info<CodeGenerator>(() => String.Format("Generating typed model for {0}", contentType.Alias));
169+
170+
var modelPath = paths[typeConfig.ContentTypeName];
146171
if (!Directory.Exists(modelPath))
147172
Directory.CreateDirectory(modelPath);
148173
var path = Path.Combine(modelPath, contentType.Info.Alias.PascalCase() + ".cs");
@@ -152,7 +177,9 @@ private void OnDocumentTypeSaved(XmlDocFileEventArgs e)
152177
var classGenerator = new CodeGenerator(typeConfig, dataTypesProvider, generatorFactory);
153178
using (var stream = File.CreateText(path))
154179
classGenerator.Generate(contentType, stream);
155-
}
180+
181+
LogHelper.Debug<CodeGenerator>(() => String.Format("Typed model for {0} generated. Took {1:MM:ss}", contentType.Alias, DateTime.Now - itemStart));
182+
}
156183

157184
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
158185
{

0 commit comments

Comments
 (0)