/// <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."); } }
protected string BuildGuiCodeSegment(CstTemplate template) { StringBuilder sbMemberCode = new StringBuilder(), sbSetupCode = new StringBuilder(); sbSetupCode.Append(BuildGuiCodeForProperties(template)); sbMemberCode.Append(BuildBindingFunctions(template)); string code = this.GuiSegmentText; code = code.Replace("§TITLE§", template.Description.Replace("\"", "\"\"")); code = code.Replace("§SETUPCODE§", sbSetupCode.ToString()); code = code.Replace("§MEMBERCODE§", sbMemberCode.ToString()); return(code); }
public CstTemplate Parse(string filename) { cstFileInfo = LoadFileText(filename, ref cstText); template = new CstTemplate(); template.RawCode = cstText; template.Filename = cstFileInfo.Name.Substring(0, cstFileInfo.Name.LastIndexOf(".")); IncludeFiles(); ReplaceComments(); ReplaceScriptBlocks(); GrabDirectives(); ReplaceEscapedASPTags(); ReplaceAspBlocks(); BuildTokens(); return(template); }
public string BuildTemplate(CstTemplate template, ILog log) { string language = template.Language.ToLower().StartsWith("c") ? "C#" : "VB.Net"; foreach (ICstProcessor cp in PluginController.Plugins) { cp.Process(template, log); } string strout = AssembleTemplate( template.Filename, language, template.TargetLanguage, template.Description, this.BuildGuiCodeSegment(template), this.BuildBodyCodeSegment(template)); return(strout); }
public static string GenerateCode(CstTemplate cstTemplate) { StringBuilder builder = new StringBuilder(); Type type; foreach (CstProperty p in cstTemplate.Properties) { type = p.SystemType; if (cstTemplate.Language == CstTemplate.LANGUAGE_CSHARP) { // } else if (cstTemplate.Language == CstTemplate.LANGUAGE_VBNET) { // } } return(builder.ToString()); }
protected override string BuildGuiCodeForProperties(CstTemplate template) { StringBuilder code = new StringBuilder(); StringBuilder tailCode = new StringBuilder(); string label = @"Dim lbl{0} As GuiLabel = ui.AddLabel(""lbl_{0}"", ""{1}"", ""{2}"")"; string textbox = @"Dim txt{0} As GuiTextBox = ui.AddTextBox(""{0}"", ""{1}"", ""{2}"")"; string combobox = @"Dim cbo{0} As GuiComboBox = ui.AddComboBox(""{0}"", ""{1}"")"; string checkbox = @"Dim chk{0} As GuiCheckBox = ui.AddCheckBox(""{0}"", ""{1}"", {2}, ""{3}"")"; string setupcontrol = @"cbo{0}_Setup(cbo{0})"; string attachevent = @"cbo{0}.AttachEvent(""onchange"", ""cbo{0}_OnChange"")"; foreach (CstProperty prop in template.Properties) { switch (prop.Type) { case "System.String": case "System.Guid": case "System.Int32": case "System.Decimal": code.Append("\t\t\t"); code.AppendFormat(label, prop.Name, prop.Name, prop.Description); code.Append(Environment.NewLine); code.Append("\t\t\t"); code.AppendFormat(textbox, prop.Name, prop.DefaultValue, prop.Description); code.Append(Environment.NewLine); code.Append(Environment.NewLine); break; case "System.Boolean": code.Append("\t\t\t"); code.AppendFormat(checkbox, prop.Name, prop.Name, prop.DefaultValue.ToLower(), prop.Description); code.Append(Environment.NewLine); code.Append(Environment.NewLine); break; case "SchemaExplorer.DatabaseSchema": case "SchemaExplorer.TableSchema": case "SchemaExplorer.CommandSchema": case "SchemaExplorer.ViewSchema": code.Append("\t\t\t"); code.AppendFormat(label, prop.Name, prop.Name, prop.Description); code.Append(Environment.NewLine); code.Append("\t\t\t"); code.AppendFormat(combobox, prop.Name, prop.Description); code.Append(Environment.NewLine); code.Append(Environment.NewLine); if (prop.Type == "SchemaExplorer.DatabaseSchema") { tailCode.Append(Environment.NewLine); tailCode.Append("\t\t\t"); tailCode.AppendFormat(setupcontrol, prop.Name); tailCode.Append(Environment.NewLine); tailCode.Append("\t\t\t"); tailCode.AppendFormat(attachevent, prop.Name); tailCode.Append(Environment.NewLine); } break; default: code.Append("\t\t\t' --- Unsupported DataType: [" + prop.Type + "] ---"); code.Append(Environment.NewLine); code.Append("\t\t\t'"); code.AppendFormat(label, prop.Name, prop.Name, prop.Description); code.Append(Environment.NewLine); code.Append("\t\t\t'"); code.AppendFormat(textbox, prop.Name, prop.DefaultValue, prop.Description); code.Append(Environment.NewLine); code.Append(Environment.NewLine); break; } } code.Append(tailCode.ToString()); return(code.ToString()); }
protected override string BuildBindingFunctions(CstTemplate template) { StringBuilder code = new StringBuilder(); StringBuilder entity = new StringBuilder(); StringBuilder entitySetup = new StringBuilder(); CstProperty dbProp = null; string setupDatabase = @" Public Sub cbo§NAME§_Setup(cbo§NAME§ As GuiComboBox) If MyMeta.IsConnected Then cbo§NAME§.BindData(MyMeta.Databases) If Not MyMeta.DefaultDatabase Is Nothing Then cbo§NAME§.SelectedValue = MyMeta.DefaultDatabase.Name §EXTRA§ End If End If End Sub" ; string setupEntity = @" Public Sub cbo§NAME§_Bind(databaseName As string) Dim cbo§NAME§ As GuiComboBox = CType(ui(""§NAME§""), GuiComboBox) Dim database As IDatabase = MyMeta.Databases(databaseName) cbo§NAME§.BindData(database.§MYMETATYPE§) End Sub" ; string databaseEventHandler = @" Public Sub cbo§NAME§_OnChange(control As GuiComboBox) Dim cbo§NAME§ As GuiComboBox = CType(ui(""§NAME§""), GuiComboBox) §EXTRA§ End Sub" ; string bindFunction = @"cbo{0}_Bind(cbo{1}.SelectedValue);"; foreach (CstProperty prop in template.Properties) { if (prop.Type == "SchemaExplorer.DatabaseSchema") { dbProp = prop; break; } } if (dbProp != null) { foreach (CstProperty prop in template.Properties) { string myMetaName = string.Empty; if (prop.Type == "SchemaExplorer.ViewSchema") { myMetaName = "Views"; } else if (prop.Type == "SchemaExplorer.TableSchema") { myMetaName = "Tables"; } else if (prop.Type == "SchemaExplorer.CommandSchema") { myMetaName = "Procedures"; } if (myMetaName != string.Empty) { entitySetup.Append(setupEntity.Replace("§NAME§", prop.Name).Replace("§MYMETATYPE§", myMetaName)); entitySetup.Append(Environment.NewLine); entitySetup.Append(Environment.NewLine); entity.AppendFormat(bindFunction, prop.Name, dbProp.Name); entity.Append(Environment.NewLine); } } code.Append(setupDatabase.Replace("§NAME§", dbProp.Name).Replace("§EXTRA§", entity.ToString())); code.Append(Environment.NewLine); code.Append(Environment.NewLine); code.Append(databaseEventHandler.Replace("§NAME§", dbProp.Name).Replace("§EXTRA§", entity.ToString())); code.Append(Environment.NewLine); code.Append(Environment.NewLine); code.Append(entitySetup.ToString()); } return(code.ToString()); }
protected string BuildBodyCodeSegment(CstTemplate template) { StringBuilder sbProps = new StringBuilder(), sbRunAtCode = new StringBuilder(), sbCode = new StringBuilder(), sbHeaders = new StringBuilder(); if (template.Debug) { sbHeaders.Append(DEBUG); } if (template.Assemblies.Count > 0) { string assemblies = string.Join(", ", template.Assemblies.ToArray(typeof(string)) as string[]); sbHeaders.Append(String.Format(REFERENCE, assemblies)); } if (template.NameSpaces.Count > 0) { string namespaces = string.Join(", ", template.NameSpaces.ToArray(typeof(string)) as string[]); sbHeaders.Append(String.Format(NAMESPACE, namespaces)); } foreach (CstProperty property in template.Properties) { sbProps.Append(this.BuildInputProperty(property)); } foreach (CstToken token in template.Tokens) { if (token.TokenType == CstTokenType.Comment) { sbCode.Append(String.Format(COMMENT, token.Text)); } else if (token.TokenType == CstTokenType.EscapedStartTag) { sbCode.Append(String.Format(STARTTAG, token.Text)); } else if (token.TokenType == CstTokenType.EscapedEndTag) { sbCode.Append(String.Format(ENDTAG, token.Text)); } else if (token.TokenType == CstTokenType.Literal) { sbCode.Append(token.Text); } else if (token.TokenType == CstTokenType.RunAtServerCode) { this.ApplyMaps(token); sbRunAtCode.Append(token.Text); } else if (token.TokenType == CstTokenType.Code) { this.ApplyMaps(token); sbCode.Append(String.Format(CODE, token.Text)); } else if (token.TokenType == CstTokenType.ResponseWriteShortcutCode) { this.ApplyMaps(token); sbCode.Append(String.Format(WRITE, token.Text)); } } string code = this.BodySegmentText; code = code.Replace("§INPUT_PROPERTIES§", sbProps.ToString()); code = code.Replace("§RUNAT_TEMPLATE_CODE§", sbRunAtCode.ToString()); code = code.Replace("§CODE§", sbCode.ToString()); code = code.Replace("§DIRECTIVES§", sbHeaders.ToString()); return(code); }
protected abstract string BuildBindingFunctions(CstTemplate template);
protected abstract string BuildGuiCodeForProperties(CstTemplate template);
private void ConvertTemplates() { if (IsFormValid) { Cursor.Current = Cursors.WaitCursor; string filename, tmp; List <string> templates = new List <string>(); foreach (string file in this.checkedListBoxTemplates.CheckedItems) { StreamWriter writer = null; try { CstParser parser = new CstParser(this); CstTemplate template = parser.Parse(this.textBoxCSTFile.Text + "\\" + file); LanguageHelper h = LanguageHelper.CreateInstance(template.Language); tmp = h.BuildTemplate(template, this); filename = this.textBoxOutFolder.Text + "\\" + file.Substring(0, file.LastIndexOf(".")) + ".zeus"; writer = File.CreateText(filename); writer.Write(tmp); writer.Flush(); writer.Close(); writer = null; templates.Add(filename); } catch (Exception ex) { if (writer != null) { writer.Close(); writer = null; } this.AddEntry(ex); } } if (templates.Count > 0) { string fileList = string.Empty; foreach (string fname in templates) { if (fileList.Length > 0) { fileList += " "; } fileList += "\"" + fname + "\""; } if (this.checkBoxLaunch.Checked) { try { this.mdi.OpenDocuments(templates.ToArray()); /*FileInfo finfo = new FileInfo(textBoxMyGenAppPath.Text); * ProcessStartInfo info = new ProcessStartInfo(finfo.FullName, fileList); * info.WorkingDirectory = finfo.DirectoryName; * System.Diagnostics.Process.Start(info);*/ } catch {} } } Cursor.Current = Cursors.Default; } }
protected override string BuildBindingFunctions(CstTemplate template) { StringBuilder code = new StringBuilder(); StringBuilder entity = new StringBuilder(); StringBuilder entitySetup = new StringBuilder(); CstProperty dbProp = null; string setupDatabase = @" public void cbo§NAME§_Setup(GuiComboBox cbo§NAME§) { if (MyMeta.IsConnected) { cbo§NAME§.BindData(MyMeta.Databases); if (MyMeta.DefaultDatabase != null) { cbo§NAME§.SelectedValue = MyMeta.DefaultDatabase.Name; §EXTRA§ } } }" ; string setupEntity = @" public void cbo§NAME§_Bind(string databaseName) { GuiComboBox cbo§NAME§ = ui[""§NAME§""] as GuiComboBox; IDatabase database = MyMeta.Databases[databaseName]; cbo§NAME§.BindData(database.§MYMETATYPE§); }" ; string databaseEventHandler = @" public void cbo§NAME§_OnChange(GuiComboBox control) { GuiComboBox cbo§NAME§ = ui[""§NAME§""] as GuiComboBox; §EXTRA§ }" ; string bindFunction = @"cbo{0}_Bind(cbo{1}.SelectedValue);"; foreach (CstProperty prop in template.Properties) { if (prop.Type == "SchemaExplorer.DatabaseSchema") { dbProp = prop; break; } } if (dbProp != null) { foreach (CstProperty prop in template.Properties) { string myMetaName = string.Empty; if (prop.Type == "SchemaExplorer.ViewSchema") { myMetaName = "Views"; } else if (prop.Type == "SchemaExplorer.TableSchema") { myMetaName = "Tables"; } else if (prop.Type == "SchemaExplorer.CommandSchema") { myMetaName = "Procedures"; } if (myMetaName != string.Empty) { entitySetup.Append(setupEntity.Replace("§NAME§", prop.Name).Replace("§MYMETATYPE§", myMetaName)); entitySetup.Append(Environment.NewLine); entitySetup.Append(Environment.NewLine); entity.AppendFormat(bindFunction, prop.Name, dbProp.Name); entity.Append(Environment.NewLine); } } code.Append(setupDatabase.Replace("§NAME§", dbProp.Name).Replace("§EXTRA§", entity.ToString())); code.Append(Environment.NewLine); code.Append(Environment.NewLine); code.Append(databaseEventHandler.Replace("§NAME§", dbProp.Name).Replace("§EXTRA§", entity.ToString())); code.Append(Environment.NewLine); code.Append(Environment.NewLine); code.Append(entitySetup.ToString()); } return(code.ToString()); }