11using AventStack . ExtentReports . Core ;
22using AventStack . ExtentReports . Reporter . Configuration ;
3+ using AventStack . ExtentReports . Reporter . TemplateEngine ;
34using AventStack . ExtentReports . Views . Commons ;
45using AventStack . ExtentReports . Views . Logger ;
56
@@ -35,10 +36,16 @@ public override void Flush(ReportAggregates reportAggregates)
3536 File . WriteAllText ( SavePath + "Index.html" , source ) ;
3637 source = RazorEngineManager . Instance . Razor . RunCompile ( "LoggerDashboard" , typeof ( ExtentLoggerReporter ) , this ) ;
3738 File . WriteAllText ( SavePath + "Dashboard.html" , source ) ;
38- source = RazorEngineManager . Instance . Razor . RunCompile ( "LoggerTag" , typeof ( ExtentLoggerReporter ) , this ) ;
39- File . WriteAllText ( SavePath + "Tag.html" , source ) ;
40- source = RazorEngineManager . Instance . Razor . RunCompile ( "LoggerException" , typeof ( ExtentLoggerReporter ) , this ) ;
41- File . WriteAllText ( SavePath + "Exception.html" , source ) ;
39+ if ( CategoryContext . Context . Count > 0 )
40+ {
41+ source = RazorEngineManager . Instance . Razor . RunCompile ( "LoggerTag" , typeof ( ExtentLoggerReporter ) , this ) ;
42+ File . WriteAllText ( SavePath + "Tag.html" , source ) ;
43+ }
44+ if ( ExceptionInfoContext . Context . Count > 0 )
45+ {
46+ source = RazorEngineManager . Instance . Razor . RunCompile ( "LoggerException" , typeof ( ExtentLoggerReporter ) , this ) ;
47+ File . WriteAllText ( SavePath + "Exception.html" , source ) ;
48+ }
4249 }
4350
4451 public override void Start ( )
@@ -47,7 +54,7 @@ public override void Start()
4754 AddTemplates ( ) ;
4855 }
4956
50- private void AddTemplates ( )
57+ private static void AddTemplates ( )
5158 {
5259 string [ ] templates = new string [ ]
5360 {
@@ -60,7 +67,7 @@ private void AddTemplates()
6067 "Partials.LoggerNavRight" ,
6168 "LoggerMacro"
6269 } ;
63- AddTemplates < ILoggerMarker > ( templates ) ;
70+ TemplateLoadService . LoadTemplate < ILoggerMarker > ( templates ) ;
6471
6572 templates = new string [ ]
6673 {
@@ -74,27 +81,7 @@ private void AddTemplates()
7481 "CommonsRow" ,
7582 "CommonsTag"
7683 } ;
77- AddTemplates < ICommonsMarker > ( templates ) ;
78- }
79-
80- private void AddTemplates < T > ( string [ ] templates )
81- {
82- foreach ( string template in templates )
83- {
84- var resourceName = typeof ( T ) . Namespace + "." + template + ".cshtml" ;
85- using ( var resourceStream = typeof ( T ) . Assembly . GetManifestResourceStream ( resourceName ) )
86- {
87- using ( var reader = new StreamReader ( resourceStream ) )
88- {
89- if ( resourceStream != null )
90- {
91- var arr = template . Split ( '.' ) ;
92- var name = arr . Length > 1 ? arr [ arr . Length - 1 ] : arr [ 0 ] ;
93- RazorEngineManager . Instance . Razor . AddTemplate ( name , reader . ReadToEnd ( ) ) ;
94- }
95- }
96- }
97- }
84+ TemplateLoadService . LoadTemplate < ICommonsMarker > ( templates ) ;
9885 }
9986 }
10087}
0 commit comments