/// <summary> /// static method to enumerate available templates /// </summary> /// <param name="fileExtension">extension to find in templates. *.* is treated as blank</param> /// <param name="templatepath">path to look for template files</param> /// <returns>list of CodeTemplate objects matching the inputs</returns> public static List <CodeTemplate> GetAvailableTemplates(string fileExtension = "", string templatepath = "") { if (fileExtension == "*.*") { fileExtension = ""; } string path = Path.GetDirectoryName(Application.ExecutablePath); if (path != null) { path = Path.Combine(path, "templates"); } if (!string.IsNullOrEmpty(templatepath)) { path = templatepath; } var templateList = new List <CodeTemplate>(); if (!Directory.Exists(path)) { return(templateList); } string[] arrFiles = Directory.GetFiles(path, "*.trt"); Exception lastException = null; string errorFile = ""; foreach (string templatefile in arrFiles) { try { var template = new CodeTemplate(templatefile); if (template.FileExtension.ToLower() == fileExtension.ToLower() || fileExtension == "") { templateList.Add(template); } } catch (Exception ex) { lastException = ex; errorFile = Path.GetFileName(templatefile); } } if (lastException != null) { MessageBox.Show("At least one of the templates to be loaded had an error.\r\nThe last error was on file " + errorFile + "\r\n\r\nThe error was:\r\n\r\n" + lastException.Message + "\r\n\r\nUntil the issue is corrected, this template cannot be loaded.\r\nTo stop getting this error, rename the file extension or delete the template.", "Template Load Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(templateList); }
/// <summary> /// static method to retrieve a generator using the template /// </summary> /// <param name="template">template used to find generator</param> /// <returns>CodeGenerator object</returns> public static CodeGenerator GetGenerator(CodeTemplate template) { CodeGenerator generator = null; if (template.DriverLibrary == "SODA") { generator = new SodaBase(template); } else if (template.CodeLanguage == "Ruby") { if (template.DriverLibrary == "Celerity") { generator = new RubyCelerity(template); } else if (template.DriverLibrary == "WatiR") { generator = new RubyWatiR(template); } } else if (template.DriverLibrary == "WatiN") { if (template.CodeLanguage == "C#") { generator = new WatiNCSharp(template); } else if (template.CodeLanguage == "VB.Net") { generator = new WatiNCSharp(template); } } if (generator == null) { throw new FileNotFoundException("No mapping found for generator template"); } return(generator); }
public WatiNVBNet(CodeTemplate template) : base(template) { }
public WatiNCSharp(CodeTemplate template) : base(template) { LineEnding = ";"; StatementClosure = "}"; }
protected WatiNBase(CodeTemplate template) : base(template) { }
public SodaBase(CodeTemplate template) : base(template) { }
protected CodeGenerator(CodeTemplate template) { Template = template; }
protected RubyBase(CodeTemplate template) : base(template) { }