public CustomItemInformation(TemplateItem template, string baseNamespace, string baseFileRoot) { CustomItemSettings settings = new CustomItemSettings(HttpContext.Current); ICustomItemNamespaceProvider namespaceProvider = AssemblyUtil.GetNamespaceProvider(settings.NamespaceProvider); ICustomItemFolderPathProvider filePathProvider = AssemblyUtil.GetFilePathProvider(settings.FilepathProvider); GetItemInformation(template, baseNamespace, baseFileRoot, filePathProvider, namespaceProvider); }
public static ICustomItemFolderPathProvider GetFilePathProvider(string assemblyString) { TemplatePathFilePathProvider defaultProvider = new TemplatePathFilePathProvider(); //Split the assembly string into it's parts, an example would look something like this // CustomItemGenerator.Providers.TemplatePathNameSpaceProvider, CustomItemGenerator string[] assemblyParts = assemblyString.Split(','); string classType = assemblyParts[0].Trim(); string assemblyName = assemblyParts[1].Trim(); //Try and retrieve the assembly Assembly assembly; try { assembly = ReflectionUtil.LoadAssembly(assemblyName); } catch (FileNotFoundException exception) { Log.Error(exception.Message, "ClassImplementsInterface"); return(defaultProvider); } if (assembly == null) { return(defaultProvider); } //Try and retrieve the class type Type type = assembly.GetType(classType); if (type == null) { Log.Error("Type " + classType + " Not Found for " + assemblyString, "ClassImplementsInterface"); return(defaultProvider); } if (type.GetInterface(typeof(ICustomItemFolderPathProvider).FullName) == null) { return(defaultProvider); } ICustomItemFolderPathProvider provider = (ICustomItemFolderPathProvider)Activator.CreateInstance(type); if (provider == null) { return(defaultProvider); } return(provider); }
protected override void OnOK(object sender, EventArgs args) { CustomItemSettings settings = new CustomItemSettings(HttpContext.Current); ICustomItemNamespaceProvider namespaceProvider = AssemblyUtil.GetNamespaceProvider(settings.NamespaceProvider); ICustomItemFolderPathProvider filePathProvider = AssemblyUtil.GetFilePathProvider(settings.FilepathProvider); CustomItemInformation customItemInformation = new CustomItemInformation(template, CustomItemNamespace.Value, CustomItemFilePath.Value, filePathProvider, namespaceProvider); CodeGenerator codeGenerator = new CodeGenerator(customItemInformation, GenerateBaseFile.Checked, GenerateInstanceFile.Checked, GenerateInterfaceFile.Checked, GenerateStaticFile.Checked); codeGenerator.GenerateCode(); SheerResponse.Alert(codeGenerator.GenerationMessage, new string[0]); base.OnOK(sender, args); }
protected override void OnOK(object sender, EventArgs args) { foreach (ChecklistItem template in TemplateList.Items) { //Do nothing if the template has not been selected if (!template.Checked) { continue; } //Try and get the template TemplateItem templateItem = masterDb.GetItem(template.Value); if (templateItem == null) { continue; } //Using the settings item get the providers needed for creating both the namespaces for the custom items // as well as the file/folder strucutre. CustomItemSettings settings = new CustomItemSettings(HttpContext.Current); ICustomItemNamespaceProvider namespaceProvider = AssemblyUtil.GetNamespaceProvider(settings.NamespaceProvider); ICustomItemFolderPathProvider filePathProvider = AssemblyUtil.GetFilePathProvider(settings.FilepathProvider); //Get all the custom item information CustomItemInformation customItemInformation = new CustomItemInformation(templateItem, CustomItemNamespace.Value, CustomItemFilePath.Value, filePathProvider, namespaceProvider); //Generate the class file(s) CodeGenerator codeGenerator = new CodeGenerator(customItemInformation, GenerateBaseFile.Checked, GenerateInstanceFile.Checked, GenerateInterfaceFile.Checked, GenerateStaticFile.Checked); codeGenerator.GenerateCode(); } SheerResponse.Alert("Custom items sucessfully generated.", new string[0]); base.OnOK(sender, args); }
private void GetItemInformation(TemplateItem template, string baseNamespace, string baseFileRoot, ICustomItemFolderPathProvider folderPathProvider, ICustomItemNamespaceProvider namespaceProvider) { ClassName = CodeUtil.GetClassNameForTemplate(template); Template = template; BaseNamespace = baseNamespace; FullNameSpace = namespaceProvider.GetNamespace(Template, BaseNamespace); BaseFileRoot = baseFileRoot; //Get all of the direct basetemplates BaseTemplates = new List <BaseTemplateInformation>(); foreach (TemplateItem basetemplate in template.BaseTemplates) { //Skip the standard template if (basetemplate.Name == "Standard template") { continue; } BaseTemplates.Add(new BaseTemplateInformation(basetemplate, namespaceProvider)); } //Create all the needed using statements for the base templates Usings = new List <string>(); foreach (BaseTemplateInformation baseTemplateInformation in BaseTemplates) { if (!Usings.Contains(baseTemplateInformation.UsingNameSpace)) { Usings.Add(baseTemplateInformation.UsingNameSpace); } } Fields = TemplateUtil.GetTemplateFieldInformation(template); FolderPathProvider = folderPathProvider; NamespaceProvider = namespaceProvider; }
public CustomItemInformation(TemplateItem template, string baseNamespace, string baseFileRoot, ICustomItemFolderPathProvider folderPathProvider, ICustomItemNamespaceProvider namespaceProvider) { this.GetItemInformation(template, baseNamespace, baseFileRoot, folderPathProvider, namespaceProvider); }
private void GetItemInformation(TemplateItem template, string baseNamespace, string baseFileRoot, ICustomItemFolderPathProvider folderPathProvider, ICustomItemNamespaceProvider namespaceProvider) { ClassName = CodeUtil.GetClassNameForTemplate(template); Template = template; BaseNamespace = baseNamespace; FullNameSpace = namespaceProvider.GetNamespace(Template, BaseNamespace); BaseFileRoot = baseFileRoot; //Get all of the direct basetemplates BaseTemplates = new List<BaseTemplateInformation>(); foreach (TemplateItem basetemplate in template.BaseTemplates) { //Skip the standard template if (basetemplate.Name == "Standard template") continue; BaseTemplates.Add(new BaseTemplateInformation(basetemplate, namespaceProvider)); } //Create all the needed using statements for the base templates Usings = new List<string>(); foreach (BaseTemplateInformation baseTemplateInformation in BaseTemplates) { if (!Usings.Contains(baseTemplateInformation.UsingNameSpace)) { Usings.Add(baseTemplateInformation.UsingNameSpace); } } Fields = TemplateUtil.GetTemplateFieldInformation(template); FolderPathProvider = folderPathProvider; NamespaceProvider = namespaceProvider; }
public CustomItemInformation(TemplateItem template, string baseNamespace, string baseFileRoot, ICustomItemFolderPathProvider folderPathProvider, ICustomItemNamespaceProvider namespaceProvider) { this.GetItemInformation(template, baseNamespace, baseFileRoot, folderPathProvider, namespaceProvider); }