[Adapdev-commits] Adapdev/src/Adapdev.CodeGen NVelocityTemplate.cs,NONE,1.1 Adapdev.CodeGen.csproj,1
Status: Beta
Brought to you by:
intesar66
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.CodeGen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30391/src/Adapdev.CodeGen Modified Files: Adapdev.CodeGen.csproj CodeGenerator.cs INVelocityTemplate.cs NVelocityCodeTemplate.cs NVelocityTableCodeTemplate.cs Added Files: NVelocityTemplate.cs Log Message: Index: Adapdev.CodeGen.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.CodeGen/Adapdev.CodeGen.csproj,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Adapdev.CodeGen.csproj 16 Nov 2005 07:01:47 -0000 1.7 --- Adapdev.CodeGen.csproj 29 Mar 2006 05:30:53 -0000 1.8 *************** *** 212,215 **** --- 212,220 ---- /> <File + RelPath = "NVelocityTemplate.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TableCodeDomTemplate.cs" SubType = "Code" Index: CodeGenerator.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.CodeGen/CodeGenerator.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CodeGenerator.cs 16 Nov 2005 07:01:47 -0000 1.5 --- CodeGenerator.cs 29 Mar 2006 05:30:53 -0000 1.6 *************** *** 102,105 **** --- 102,145 ---- /// <summary> + /// Processes the I code DOM template. + /// </summary> + /// <param name="template">The template.</param> + /// <param name="codeType">Type of the code.</param> + /// <param name="refAssemblies">The ref assemblies.</param> + /// <returns></returns> + public string ProcessICodeDomTemplate(ICodeDomTemplate template, LanguageType codeType, params string[] refAssemblies) + { + CodeCompileUnit ccu = template.GetCodeCompileUnit(); + string output = String.Empty; + + foreach(string s in refAssemblies) + { + ccu.ReferencedAssemblies.Add(s); + } + + if (ccu != null) + { + // Obtains an ICodeGenerator from a CodeDomProvider class. + CodeDomProvider provider = CodeProviderFactory.GetCodeProvider(codeType); + ICodeGenerator gen = provider.CreateGenerator(); + + // Creates a StreamWriter to an output file. + using(StringWriter sw = new StringWriter()) + { + // Generates source code using the code generator. + gen.GenerateCodeFromCompileUnit(ccu, sw, new CodeGeneratorOptions()); + output = sw.GetStringBuilder().ToString(); + } + + // Process any custom code + template.ProcessCustomCode(); + } + this.OnICodeDomTemplateProcessed(new ICodeDomTemplateEventArgs(template)); + + return output; + } + + + /// <summary> /// Processes the <see cref="ICodeTemplate"/> to a file. /// </summary> Index: NVelocityCodeTemplate.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.CodeGen/NVelocityCodeTemplate.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** NVelocityCodeTemplate.cs 16 Nov 2005 07:01:47 -0000 1.6 --- NVelocityCodeTemplate.cs 29 Mar 2006 05:30:53 -0000 1.7 *************** *** 107,110 **** --- 107,129 ---- } + /// <summary> + /// Adds the context. + /// </summary> + /// <param name="key">The key.</param> + /// <param name="value">The value.</param> + public void AddContext(string key, object value) + { + this.context.Put(key, value); + } + + /// <summary> + /// Gets the output. + /// </summary> + /// <returns></returns> + public string GetOutput() + { + return this.GetCode(); + } + public string GetConversionExpression(string objectType) { --- NEW FILE: NVelocityTemplate.cs --- using System; using System.IO; using Adapdev.IO; using NVelocity; using NVelocity.App; namespace Adapdev.CodeGen { /// <summary> /// Summary description for NVelocityTemplate. /// </summary> public class NVelocityTemplate : INVelocityTemplate { protected VelocityContext context = null; protected string content = String.Empty; public NVelocityTemplate() { if (!File.Exists("nvelocity.properties")) File.Copy(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "nvelocity.properties"), Path.Combine(".", "nvelocity.properties"), true); if (!File.Exists("directive.properties")) File.Copy(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "directive.properties"), Path.Combine(".", "directive.properties"), true); Velocity.Init("nvelocity.properties"); context = new VelocityContext(); } public void SetFileTemplate(string filePath) { if(!File.Exists(filePath)) throw new FileNotFoundException("Couldn't find file.", filePath); else this.content = FileUtil.ReadFile(filePath); } public void SetTemplate(string content) { this.content = content; } #region INVelocityTemplate Members public NVelocity.VelocityContext Context { get { return this.context; } } public void AddContext(string key, object value) { this.context.Put(key, value); } public string GetOutput() { if(this.content.Length > 0) { context.Put("template", this); StringWriter writer = new StringWriter(); Velocity.Evaluate(context, writer, "output", this.content); return writer.GetStringBuilder().ToString(); } else { return String.Empty; } } #endregion } } Index: INVelocityTemplate.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.CodeGen/INVelocityTemplate.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** INVelocityTemplate.cs 16 Nov 2005 07:01:47 -0000 1.5 --- INVelocityTemplate.cs 29 Mar 2006 05:30:53 -0000 1.6 *************** *** 14,17 **** --- 14,28 ---- /// <value></value> VelocityContext Context{get;} + /// <summary> + /// Adds the context. + /// </summary> + /// <param name="key">The key.</param> + /// <param name="value">The value.</param> + void AddContext(string key, object value); + /// <summary> + /// Gets the output. + /// </summary> + /// <returns></returns> + string GetOutput(); } } Index: NVelocityTableCodeTemplate.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.CodeGen/NVelocityTableCodeTemplate.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** NVelocityTableCodeTemplate.cs 3 Mar 2006 05:22:54 -0000 1.14 --- NVelocityTableCodeTemplate.cs 29 Mar 2006 05:30:53 -0000 1.15 *************** *** 362,365 **** --- 362,384 ---- } + /// <summary> + /// Adds the context. + /// </summary> + /// <param name="key">The key.</param> + /// <param name="value">The value.</param> + public void AddContext(string key, object value) + { + this.context.Put(key, value); + } + + /// <summary> + /// Gets the output. + /// </summary> + /// <returns></returns> + public string GetOutput() + { + return this.GetCode(); + } + public string GetConversionExpression(string objectType) { |