CodeSmith-2-MyGeneration Converter
Required Files:
CodeSmith-2-MyGeneration Converter
CodeSmith Freeware
Latest Version of MyGeneration
Overview:
CodeSmith-2-MyGeneration is an extensible application that will partially convert a CodeSmith template into a MyGeneration template, giving the MyGeneration template developer a good starting point for thier migration to MyGeneration from CodeSmith.
Extensibility:
There are 2 ways to add functionality to the CodeSmith-2-MyGeneration converter. First, by adding entries to the Xml Mapping files found in the application folder. Second, by adding plugin class files in the Plugins folder in the application folder.
Xml Mapping Files:
The xml mapping files are very simple. Two of them exist by default: Default.csmap and Default.vbmap. You can add to them or add your own with the ".csmap" or ".vbmap" extension. Below is a sample of how these files must look:
<?xml version="1.0" encoding="utf-8" ?>
<maps>
<map source="Response.WriteLine()" target="output.writeln("")" isregexp="False"/>
<map source="Response.WriteLine(" target="output.writeln(" isregexp="False"/>
<map source=".cst" target=".zeus" isregexp="False"/>
</maps> |
Dynamically Compiled Plugins:
The dynamic plugins are simply C# (.plugin.cs) or VB.Net (.plugin.vb) classes that implement an interface located in the MyGeneration.CodeSmithConversion.dll assembly. You can create these files in VisualStudio.Net by just referencing that DLL, or just write them in a text editor. These plugins are compiled dynamically and added to a Plug-in collection in memory. Each Plug-in implements the method "Process(CstTemplate template, ILog log)", which allows the plugin developer to change information in the CodeSmith template object (API mappings, etc) before the template is converted to the MyGeneration format. You can also write to the log any information you wish to send to the Console. If you do use visual studio to create the plugin (I highly recommend it), you will have auto-complete which will help you with the API. It's a simple API and most experienced programmers will quickly catch on.
using System;
using System.IO;
using System.Collections;
using System.Text;
using System.Reflection;
using MyGeneration.CodeSmithConversion;
using MyGeneration.CodeSmithConversion.Plugins;
using MyGeneration.CodeSmithConversion.Template;
/*
The DLLs Referenced are:
System.dll
System.Xml.dll
System.Data.dll
System.Drawing.dll
System.Windows.Forms.dll
MyGeneration.CodeSmithConversion.dll
*/
namespace MyGeneration.CodeSmithConversion
{
/// <summary>
/// A Sample Plugin for customizing the CodeSmith conversion.
/// </summary>
public class SamplePlugin : ICstProcessor
{
/// <summary>
/// You must have a constructor with 0 parameters.
/// </summary>
public SamplePlugin() {}
/// <summary>
/// This is the method where you have the ability to change the parsed CST
/// Template object before the translation completes.
/// </summary>
/// <param name="template"></param>
public void Process(CstTemplate template, ILog log)
{
foreach (CstToken token in template.Tokens)
{
// I put this break here just to save on performance because this sample plugin does nothing.
break;
// If the token is a template code token, then do the replacements.
if ((token.TokenType == CstTokenType.Code) ||
(token.TokenType == CstTokenType.ResponseWriteShortcutCode) ||
(token.TokenType == CstTokenType.RunAtServerCode))
{
if (template.Language == CstTemplate.LANGUAGE_CSHARP)
{
token.Text = token.Text.Replace("Response.WriteLine()", "output.writeln(\"\")");
}
if (template.Language == CstTemplate.LANGUAGE_VBNET)
{
token.Text = token.Text.Replace("Response.WriteLine", "output.writeln \"\")");
}
}
log.AddEntry("Ran Special Plugin Conversion.");
}
}
/// <summary>
/// Authors name
/// </summary>
public string Author
{
get { return "Justin Greenwood"; }
}
/// <summary>
/// Plugin Description/Name
/// </summary>
public string Name
{
get { return "Sample Plugin"; }
}
}
} |