public void ConvertHtmlContentToPdf() { var converter = new HtmlConverter(); var setting = new GenerateSettings { HtmlFileContent = "<b>Bold Text</b><br /><br /><i>Italic Text</i>", OutputType = OutputType.PDF, }; setting.GlobalOptions.FooterHtmlUrl = "http://www.oracle.com/splash/rpls/embargoed.html"; setting.GlobalOptions.HeaderHtmlUrl = "http://wkhtmltopdf.org/libwkhtmltox/"; setting.GlobalOptions.MarginTop = "30mm"; setting.GlobalOptions.MarginBottom = "30mm"; setting.GlobalOptions.ShowFooterLine = true; setting.GlobalOptions.ShowHeaderLine = true; var filePath = converter.Convert(setting); Assert.IsTrue(File.Exists(filePath)); }
public KeePassPlugin(GenerateSettings settings) { action = new KeePassGenerate(settings); clearDelay = settings.ClearTime; }
public ActionGenerate(SDConnection connection, InitialPayload payload) : base(connection, payload) { settings = ResolveSettings <GenerateSettings>(payload, GenerateSettings.CreateDefaultSettings()); CreatePlugin(settings); }
internal void CreatePlugin(GenerateSettings settings) => plugin = new KeePassPlugin(settings);
public static string GenerateCode(List <ModelParameter> modelParameters, GenerateSettings setting) { var root = AppDomain.CurrentDomain.BaseDirectory + @"\Temps"; var rootDir = new DirectoryInfo(root); if (!rootDir.Exists) { rootDir.Create(); } var content = File.ReadAllText(Path.Combine(root, setting.TemplateFileName)); //读取路径设置 var pathBeginIndex = content.IndexOf("<##save_FilePath_Begin##>"); var pathEndIndex = content.IndexOf("<##save_FilePath_End##>"); if (pathBeginIndex < 0 || pathEndIndex <= 0) { throw new Exception($"{setting.TemplateFileName},路径的开始和结束标志没有设置!"); } //读取路径 var path = content.Substring(pathBeginIndex + "<##save_FilePath_Begin##>".Length, pathEndIndex - (pathBeginIndex + "<##save_FilePath_Begin##>".Length)); var tempBeginIndex = content.IndexOf("<##template_Begin##>"); var tempEndIndex = content.IndexOf("<##template_End##>"); var result = new StringBuilder(); if (tempBeginIndex >= 0 && tempEndIndex > 0) { foreach (var modelParameter in modelParameters) { var destFileName = path.Replace("<##Model_Class_Name##>", modelParameter.ClassName). Replace("<##model_Class_Name##>", modelParameter.FirstLowerModelName). Replace("<##Model_Namespace_Not_Root##>", modelParameter.NoRootNameSpace.Replace(".", @"\")); //文件存在,并且不允许覆盖,不执行生成 if (File.Exists(destFileName) && !setting.OverWrite) { continue; } var dInfo = new FileInfo(destFileName); var dir = dInfo.Directory; if (!dir.Exists) { dir.Create(); } var tempContent = content.Substring(tempBeginIndex + "<##template_Begin##>".Length, tempEndIndex - (tempBeginIndex + "<##template_Begin##>".Length)); tempContent = tempContent.Replace("<##Model_Class_Name##>", modelParameter.ClassName). Replace("<##model_Class_Name##>", modelParameter.FirstLowerModelName). Replace("<##Model_Description##>", modelParameter.Description); if (string.IsNullOrWhiteSpace(modelParameter.NoRootNameSpace)) { tempContent = tempContent.Replace(".<##Model_Namespace_Not_Root##>", ""); } else { tempContent = tempContent.Replace("<##Model_Namespace_Not_Root##>", modelParameter.NoRootNameSpace); } var fieldStartIndex = tempContent.IndexOf("<##field_Write_Begin##>"); if (fieldStartIndex >= 0) { var fieldEndIndex = tempContent.IndexOf("<##field_Write_End##>"); if (fieldEndIndex <= 0) { throw new Exception("字段写入没有结束标志!"); } var nextIndex = fieldEndIndex + "<##field_Write_End##>".Length; var fieldTempContent = tempContent.Substring(fieldStartIndex, nextIndex - fieldStartIndex); var newFieldTempContent = fieldTempContent.Replace("<##field_Write_Begin##>", "").Replace("<##field_Write_End##>", ""); var sb = new StringBuilder(); foreach (var fParameter in modelParameter.FieldParameterses) { sb.Append(GetFieldContent(newFieldTempContent, fParameter, modelParameter.ClassName)); } tempContent = tempContent.Replace(fieldTempContent, sb.ToString()); } File.WriteAllText(destFileName, tempContent, Encoding.UTF8); result.AppendLine($"{destFileName}生成成功!"); } } var foreachBeginIndex = content.IndexOf("<##model_Foreach_Begin##>"); var foreachEndIndex = content.IndexOf("<##model_Foreach_End##>"); if (foreachBeginIndex >= 0 && foreachEndIndex > 0) { var destFileName = path; //文件存在,并且不允许覆盖,不执行生成 if (!File.Exists(destFileName) || !setting.OverWrite) { var dInfo = new FileInfo(destFileName); var dir = dInfo.Directory; if (!dir.Exists) { dir.Create(); } var itemContent = content.Substring(foreachBeginIndex + "<##model_Foreach_Begin##>".Length, foreachEndIndex - (foreachBeginIndex + "<##model_Foreach_Begin##>".Length)); var itemSb = new StringBuilder(); foreach (var modelParameter in modelParameters) { var tempContent = itemContent.Replace("<##Model_Class_Name##>", modelParameter.ClassName). Replace("<##model_Class_Name##>", modelParameter.FirstLowerModelName). Replace("<##Model_Description##>", modelParameter.Description); if (string.IsNullOrWhiteSpace(modelParameter.NoRootNameSpace)) { tempContent = tempContent.Replace(".<##Model_Namespace_Not_Root##>", ""); } else { tempContent = tempContent.Replace("<##Model_Namespace_Not_Root##>", modelParameter.NoRootNameSpace); } var fieldStartIndex = tempContent.IndexOf("<##field_Write_Begin##>"); if (fieldStartIndex >= 0) { var fieldEndIndex = tempContent.IndexOf("<##field_Write_End##>"); if (fieldEndIndex <= 0) { throw new Exception("字段写入没有结束标志!"); } var nextIndex = fieldEndIndex + "<##field_Write_End##>".Length; var fieldTempContent = tempContent.Substring(fieldStartIndex, nextIndex - fieldStartIndex); var newFieldTempContent = fieldTempContent.Replace("<##field_Write_Begin##>", "").Replace("<##field_Write_End##>", ""); var sb = new StringBuilder(); foreach (var fParameter in modelParameter.FieldParameterses) { sb.Append(GetFieldContent(newFieldTempContent, fParameter, modelParameter.ClassName)); } tempContent = tempContent.Replace(fieldTempContent, sb.ToString()); } itemSb.AppendLine(tempContent); } File.WriteAllText(destFileName, itemSb.ToString(), Encoding.UTF8); result.AppendLine($"{destFileName}生成成功!"); } } return(result.ToString()); }