1
0
Fork 0
Code-Statistics/CodeStatistics/Output/GenerateHtml.cs

43 lines
1.2 KiB
C#

using System;
using System.IO;
using System.Text;
using CodeStatisticsCore.Handling;
namespace CodeStatistics.Output{
class GenerateHtml{
public enum Result{
Succeeded, TemplateError, IoError
}
private readonly TemplateList templates;
private readonly Variables variables;
public string LastError { get; private set; }
public GenerateHtml(TemplateList templateList, Variables variables){
this.templates = templateList;
this.variables = variables;
this.LastError = string.Empty;
}
public Result ToFile(string file){
string contents;
try{
contents = templates.ProcessTemplate("html", variables);
}catch(Exception e){
LastError = e.Message;
return Result.TemplateError;
}
try{
File.WriteAllText(file, contents, Encoding.UTF8);
return File.Exists(file) ? Result.Succeeded : Result.IoError;
}catch(Exception e){
LastError = e.ToString();
return Result.IoError;
}
}
}
}