// Generates file from template // Returns generated file path public string ProcessTemplateToString(TemplateInfoRecord template) { TTSettingsDictionary settingsDictionary = template.SettingsDictionary; string templateFilePath = template.Path; host.Session["klasaInfo"] = klasaInfo; //host.Session["ustawienia"] = settingsDictionary; string templateContent = File.ReadAllText(templateFilePath); T4Callback cb = new T4Callback(); string result = textTemplatingService.ProcessTemplate(templateFilePath, templateContent, cb); return(result); }
public string ProcessTemplateToFile(TemplateInfoRecord template) { TTSettingsDictionary settingsDictionary = template.SettingsDictionary; string templateFilePath = template.Path; ITextTemplatingSessionHost host = textTemplatingService as ITextTemplatingSessionHost; host.Session["klasaInfo"] = klasaInfo; //host.Session["ustawienia"] = settingsDictionary; string templateContent = TTUtils.GetClearTemplate(templateFilePath); T4Callback cb = new T4Callback(); string result = textTemplatingService.ProcessTemplate(templateFilePath, templateContent, cb); result = ArrangeUsingRoslyn(result); //Format code string fileName = klasaInfo.Nazwa; ImmutableSetting fileNameSetting = template.ImmutableSettings.Find(x => x.Name.Contains("NazwaPliku")); if (fileNameSetting != null) { if (fileNameSetting.Value != null) { fileName = fileNameSetting.Value; } } string resultFileName = Path.Combine(Path.GetDirectoryName(templateFilePath), fileName + Path.GetFileNameWithoutExtension(templateFilePath)) + cb.fileExtension; // Writing the processed output to file: File.WriteAllText(resultFileName, result, cb.outputEncoding); // Append any error messages: if (cb.errorMessages.Count > 0) { File.AppendAllLines(resultFileName, cb.errorMessages); } return(resultFileName); }