public MahuaApiCommandDesciptor Resolve(Type cmdType) { var description = ((DescriptionAttribute)cmdType.GetCustomAttribute(typeof(DescriptionAttribute))).Description; var re = new MahuaApiCommandDesciptor { Summary = description, CommandName = cmdType.Name, CommandResultName = typeof(ApiMahuaCommand).IsAssignableFrom(cmdType) ? string.Empty : $"{cmdType.Name}Result", CommandHandlerName = $"{cmdType.Name}Handler" }; return(re); }
public string Generate(MahuaApiCommandDesciptor mahuaApiCommandDesciptor) { var className = mahuaApiCommandDesciptor.CommandHandlerName; var dirPath = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, className); var dir = new DirectoryInfo(dirPath); if (dir.Exists) { dir.Delete(true); Thread.Sleep(100); } Directory.CreateDirectory(dir.FullName); var mahuaEventCs = new MahuaApiCommandHandlerCS { Session = new Dictionary <string, object> { ["Des"] = mahuaApiCommandDesciptor } }; mahuaEventCs.Initialize(); var cs = mahuaEventCs.TransformText(); WriteFileWithUtf8Bom(cs, Path.Combine(dirPath, $"{className}.cs"), true); var mahuaEventMyTemplateXml = new MahuaApiCommandHandlerMyTemplateXml { Session = new Dictionary <string, object> { ["Des"] = mahuaApiCommandDesciptor } }; mahuaEventMyTemplateXml.Initialize(); var xml = mahuaEventMyTemplateXml.TransformText(); WriteFileWithUtf8Bom(xml, Path.Combine(dirPath, "MyTemplate.vstemplate"), false); File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logo.png"), Path.Combine(dirPath, "__TemplateIcon.png")); File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logo.png"), Path.Combine(dirPath, "__PreviewImage.png")); Process.Start("7z.exe", $"a {className}.zip .\\{className}\\*"); return($"{className}.zip"); }