public void Initialize() { reswFileContents = File.ReadAllText(FILE_PATH); target = new CodeGeneratorFactory().Create(FILE_PATH.Replace(".resw", string.Empty), "TestApp", reswFileContents); actual = target.GenerateCode(); }
public void Initialize() { reswFileContents = File.ReadAllText(FILE_PATH); target = new CodeGeneratorFactory().Create(FILE_PATH.Replace(".resw", string.Empty), "TestApp", reswFileContents, new VBCodeProvider(), TypeAttributes.NestedAssembly); actual = target.GenerateCode(); }
internal static void CheckGenerateCode(ICodeGenerator target, Word[] expectedWords, String message) { RelocatableModule relModule = new RelocatableModule(); target.GenerateCode(relModule); RelocatableModuleTest.CheckWords(relModule, expectedWords, message); }
public CodeForm(ICodeGenerator generator, IEnumerable <ClassNode> classes, ILogger logger) { Contract.Requires(generator != null); Contract.Requires(classes != null); InitializeComponent(); codeRichTextBox.SetInnerPadding(5, 5, 5, 5); var code = generator.GenerateCode(classes, logger); var buffer = new StringBuilder(code.Length * 2); using (var writer = new StringWriter(buffer)) { new CodeColorizer().Colorize( code, generator.Language == Language.Cpp ? Languages.Cpp : Languages.CSharp, new RtfFormatter(), StyleSheets.Default, writer ); } codeRichTextBox.Rtf = buffer.ToString(); }
public async Task <GeneratedCode <Entity> > Generate(Guid id, Guid templateId) { // Get model var entity = await GetEntity(id); // Get template var template = await _codeGenDbContext.Templates.FindAsync(templateId); // Generate and return code return(new GeneratedCode <Entity> { Model = _mapper.Map <Entity>(entity), Template = _mapper.Map <Template>(template), Value = _generator.GenerateCode(template, entity) }); }
private static async void Method11() { Console.WriteLine("请输入代码模板:"); string input = Console.ReadLine(); CodeProject project = null; CodeTemplate template = null; await _provider.ExecuteScopedWorkAsync(provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); CodeProject[] projects = contract.GetCodeProject(m => true); project = projects[0]; template = contract.CodeTemplates.FirstOrDefault(m => m.Name == input); return(Task.CompletedTask); }); if (template == null) { Console.WriteLine($"模板 {input} 不存在"); return; } ICodeGenerator generator = _provider.GetService <ICodeGenerator>(); //var model = project.Modules.First().Entities.First(); //var model = project.Modules.First(); var model = project; CodeFile file = await generator.GenerateCode(template, model); File.WriteAllText(@"D:\Temp\11.txt", file.SourceCode); Console.WriteLine(file.SourceCode); }
public void CodeGenerate_Test() { ProjectMetadata projectMetadata = new ProjectMetadata(); projectMetadata.Company = "大黄瓜科技有限公司"; projectMetadata.SiteUrl = "http://admin.destinycore.club"; projectMetadata.Creator = "大黄瓜18cm"; projectMetadata.Copyright = "大黄瓜18cm"; projectMetadata.Namespace = "Destiny.Core.Flow"; projectMetadata.SaveFilePath = @"C:\Users\Admin\Desktop\Code"; List <PropertyMetadata> propertyMetadatas = new List <PropertyMetadata>(); propertyMetadatas.Add(new PropertyMetadata() { IsNullable = false, IsPrimaryKey = false, CSharpType = "string", DisplayName = "名字", PropertyName = "Name", IsPageDto = true, }); propertyMetadatas.Add(new PropertyMetadata() { IsNullable = false, IsPrimaryKey = false, CSharpType = "string", DisplayName = "名字1", PropertyName = "Name1" }); propertyMetadatas.Add(new PropertyMetadata() { IsNullable = false, IsPrimaryKey = false, CSharpType = "int", DisplayName = "价格", PropertyName = "Price", IsPageDto = false }); projectMetadata.EntityMetadata = new EntityMetadata() { EntityName = "TestCode", DisplayName = "代码生成", PrimaryKeyType = "Guid", PrimaryKeyName = "Id", Properties = propertyMetadatas, IsCreation = true, IsModification = true, IsSoftDelete = true, AuditedUserKeyType = "Guid", IsAutoMap = true, }; ICodeGenerator codeGenerator = ServiceProvider.GetService <ICodeGenerator>(); codeGenerator.GenerateCode(projectMetadata); }
public CodeForm(ICodeGenerator generator, IEnumerable <ClassNode> classes, ILogger logger) { Contract.Requires(generator != null); Contract.Requires(classes != null); InitializeComponent(); var code = generator.GenerateCode(classes, logger); codeWebBrowser.DocumentText = new CodeColorizer().Colorize(code, generator.Language == Language.Cpp ? Languages.Cpp : Languages.CSharp); }
public void CodeGenerate_Test() { ProjectMetadata projectMetadata = new ProjectMetadata(); projectMetadata.Company = "XXXX开车公司"; projectMetadata.SiteUrl = "http://admin.destinycore.club"; projectMetadata.Creator = "王莫某"; projectMetadata.Copyright = "王莫某"; projectMetadata.Namespace = "Sukt.Core.Domain.Models"; List <PropertyMetadata> propertyMetadatas = new List <PropertyMetadata>(); propertyMetadatas.Add(new PropertyMetadata() { IsNullable = false, IsPrimaryKey = false, CSharpType = "string", DisplayName = "名字", PropertyName = "Name", IsPageDto = true, }); propertyMetadatas.Add(new PropertyMetadata() { IsNullable = false, IsPrimaryKey = false, CSharpType = "string", DisplayName = "名字1", PropertyName = "Name1" }); propertyMetadatas.Add(new PropertyMetadata() { IsNullable = false, IsPrimaryKey = false, CSharpType = "int", DisplayName = "价格", PropertyName = "Price", IsPageDto = false }); projectMetadata.EntityMetadata = new EntityMetadata() { EntityName = "TestCode", DisplayName = "代码生成", PrimaryKeyType = "Guid", PrimaryKeyName = "Id", Properties = propertyMetadatas, IsCreation = true, IsModification = true, IsSoftDelete = false, AuditedUserKeyType = "Guid", }; var savePath = @"E:\TestCodeGenerator"; ICodeGenerator codeGenerator = ServiceProvider.GetService <ICodeGenerator>(); codeGenerator.GenerateCode(projectMetadata, savePath); }
/// <inheritdoc /> public GeneratedCode GenerateTypeCode(Type type) { var typeMetadata = _metadataGenerator.GetMetadata(type); var outputType = _outputTypeMetadataGenerator.Generate(typeMetadata).OutputType; var fileParts = _typePartsCodeGenerator.GetFilePathParts(outputType); var code = _codeGenerator.GenerateCode(outputType); return(new GeneratedCode { Code = code, FilePathSegments = fileParts }); }
public void SendConfirmation(string emailValue, ConfirmationCodeType type) { var code = _codeGenerator.GenerateCode(type); var email = _emailManager.GetEmailByValue(emailValue); if (email == null) { throw new EmailNotFoundException(emailValue); } _codeManager.SaveCode(code, email); _notificationTransportService.SendNotification("", ""); }
public async Task <GeneratedCode <ValueObject> > Generate(Guid id, Guid templateId) { // Get model var valueObject = await GetValueObject(id); // Get template var template = await _codeGenDbContext.Templates.FindAsync(templateId); // Generate and return code return(new GeneratedCode <ValueObject> { Model = _mapper.Map <ValueObject>(valueObject), Template = _mapper.Map <Template>(template), Value = _generator.GenerateCode(template, valueObject) }); }
public async Task <GeneratedCode <DomainEvent> > Generate(Guid id, Guid templateId) { // Get model var domainEvent = await GetDomainEvent(id); // Get template var template = await _codeGenDbContext.Templates.FindAsync(templateId); // Generate and return code return(new GeneratedCode <DomainEvent> { Model = _mapper.Map <DomainEvent>(domainEvent), Template = _mapper.Map <Template>(template), Value = _generator.GenerateCode(template, domainEvent) }); }
private void generateEntityCode(string id, string path, ICodeGenerator codeGenerator) { if (id == null) { return; } path = Path.Combine(path, id); if (!Entities.TryGetValue(id, out var entity)) { Debug.WriteLine($"Didn't find entity id {id}, can't generate code for it (class at {path})."); return; } StringBuilder code = new StringBuilder(); codeGenerator.GenerateCode("MyGameNamespace", entity, code); //todo: namespace Debug.WriteLine($"Code for {id}:"); Debug.WriteLine(code.ToString()); Debug.WriteLine("----------"); }
public async Task <GeneratedCode <Module> > Generate(Guid id, Guid templateId) { // Get model var module = await _metaDbContext.Modules .Include(m => m.ValueObjects) .Include(m => m.Entities) .ThenInclude(e => e.DomainEvents).SingleAsync(m => m.Id == id); // Get template var template = await _codeGenDbContext.Templates.FindAsync(templateId); // Generate and return code return(new GeneratedCode <Module> { Model = _mapper.Map <Module>(module), Template = _mapper.Map <Template>(template), Value = _generator.GenerateCode(template, module) }); }
public IReadOnlyList <GeneratedPartialClass> GenerateNameReferences(IEnumerable <AdditionalText> additionalFiles) { var resolveViews = from file in additionalFiles where (file.Path.EndsWith(".xaml") || file.Path.EndsWith(".paml") || file.Path.EndsWith(".axaml")) && _pathPattern.Matches(file.Path) let xaml = file.GetText() !.ToString() let view = _classes.ResolveView(xaml) where view != null && _namespacePattern.Matches(view.Namespace) select view; var query = from view in resolveViews let names = _names.ResolveNames(view.Xaml) let code = _code.GenerateCode(view.ClassName, view.Namespace, view.XamlType, names) let fileName = $"{view.ClassName}.g.cs" select new GeneratedPartialClass(fileName, code); return(query.ToList()); }
/// <summary> /// Executes the code generation workflow. /// </summary> public CodeWriterOutput GenerateCode(Options.CodeGenOptions options) { ICodeGeneratorContext codeGeneratorContext = buildCodeGeneratorContext(options); ICodeGenerator codeGenerator = this.buildCodeGenerator(options); CodeWriterOptions writeOptions = CodeGenOptionsParser.GetCodeWriterOptions(options); if (options.OnlyUseDataContractSerializer) { CodeCompileUnit targetCodeCompileUnit = codeGenerator.GenerateDataContractCode(codeGeneratorContext); return(CodeWriter.CodeWriter.Write(targetCodeCompileUnit, writeOptions)); } else if (options.GenerateSeparateFilesEachXsd) { CodeNamespace[] targetCodeNamespaces = codeGenerator.GenerateCodes(codeGeneratorContext); return(CodeWriter.CodeWriter.Write(targetCodeNamespaces, writeOptions)); } else { CodeNamespace targetCodeNamespace = codeGenerator.GenerateCode(codeGeneratorContext); return(CodeWriter.CodeWriter.Write(targetCodeNamespace, writeOptions)); } }
public void SendConfirmation(string emailValue, ConfirmationCodeType type) { var code = _codeGenerator.GenerateCode(type); var email = _emailManager.GetEmailByValue(emailValue); if (email == null) { throw new EmailNotFoundException(emailValue); } string linkType; _codeManager.SaveCode(code, email); if (type == ConfirmationCodeType.EmailChange) { linkType = "/email-change/"; } else if (type == ConfirmationCodeType.EmailChangeConfirmation) { linkType = "/email-change-confirm/"; } else if (type == ConfirmationCodeType.EmailConfirmation) { linkType = "/email-confirm/"; } else { linkType = "/password-recover/"; } var linkWithCode = clientUrl + linkType + code.Value; _notificationTransportService.SendNotification(emailValue, linkWithCode); }
private void Generate(Helper helper) { codeGenerator.GenerateCode(helper.Template); helper.FinallyCallback(); }
/// <summary> /// Generates the code represented by the current /// <see cref="System.CodeDom.CodeNamespace"/> using /// the current <see cref="NStub.Core.ICodeGenerator"/>. /// </summary> public void GenerateCode() { _codeGenerator.GenerateCode(); }
public async Task ExecuteAsync(string destinationDirectory, string solutionName, List <KSolutionGroup> solutionGroupList) { if (string.IsNullOrWhiteSpace(solutionName)) { throw new ApplicationException("Solution name not specified"); } var sw = Stopwatch.StartNew(); ProgressChanged(this, new KickstartProgressChangedEventArgs() { ProgressPercentChange = 10, ProgressMessage = "Generation Started" }); var connectionString = "Server=localhost;"; var timeString = DateTime.Now.ToString("yyyyMMddHHmmss"); KickstartCoreService.SetCompanyNameOnProjects(solutionGroupList); KickstartCoreService.ConfigureMetaData(solutionGroupList, destinationDirectory); ProgressChanged(this, new KickstartProgressChangedEventArgs() { ProgressPercentChange = 5, ProgressMessage = "" }); //deploy sql code to temp db, convert to K objects _kickstartCoreService.BuildSqlMeta(destinationDirectory, connectionString, solutionGroupList); ProgressChanged(this, new KickstartProgressChangedEventArgs() { ProgressPercentChange = 5, ProgressMessage = "Sql objects created on WorkDb" }); AddProtoRefs(solutionGroupList); ProgressChanged(this, new KickstartProgressChangedEventArgs() { ProgressPercentChange = 5, ProgressMessage = "" }); //pass 2 //generate C objects from K objects _solutionGenerator.GenerateCSolutions(destinationDirectory, connectionString, solutionGroupList); ProgressChanged(this, new KickstartProgressChangedEventArgs() { ProgressPercentChange = 5, ProgressMessage = "Pass 2: K object transformed to C objects" }); //save the K/C meta to Excel //Excel can be tweaked, and used as Meta source //_kSolutionGroupToExcelConverter.OutputPath = Path.Combine(destinationDirectory, $"{timeString}.xlsx"); //_kSolutionGroupToExcelConverter.Convert(solutionGroupList); ProgressChanged(this, new KickstartProgressChangedEventArgs() { ProgressPercentChange = 5, ProgressMessage = "" }); //Pass 3 //generate Code from C objects _codeGenerator.GenerateCode(solutionGroupList, destinationDirectory); ProgressChanged(this, new KickstartProgressChangedEventArgs() { ProgressPercentChange = 5, ProgressMessage = "Pass 3: Code generated" }); _solutionVisitor.AddProjectsToApplication(solutionGroupList, destinationDirectory); ProgressChanged(this, new KickstartProgressChangedEventArgs() { ProgressPercentChange = 5, ProgressMessage = "Pass 3: Projects added to solution" }); if (solutionGroupList.Count > 1 || solutionGroupList.First().Solution.Count > 1) { //only do if there are multiple solutions _solutionVisitor.AddAllProjectsToMasterSln(solutionGroupList, destinationDirectory, solutionName); } ProgressChanged(this, new KickstartProgressChangedEventArgs() { ProgressPercentChange = 5, ProgressMessage = "" }); BatchFileService.GenerateRestoreScript(solutionGroupList, destinationDirectory); BatchFileService.GenerateBuildScript(solutionGroupList, destinationDirectory); BatchFileService.GenerateDeployDbScript(solutionGroupList, destinationDirectory); BatchFileService.GenerateRunServicesScript(solutionGroupList, destinationDirectory); BatchFileService.GenerateRunTestClientScript(solutionGroupList, destinationDirectory); //Pass4 //create diagrams DiagramGenerator.GenerateDiagram(destinationDirectory, solutionGroupList); ProgressChanged(this, new KickstartProgressChangedEventArgs() { ProgressPercentChange = 5, ProgressMessage = "Pass 4: Diagrams generated" }); ProgressChanged(this, new KickstartProgressChangedEventArgs() { ProgressPercentChange = 100, ProgressMessage = $"Completed in {sw.Elapsed.TotalSeconds}.{sw.Elapsed.Milliseconds}s" }); System.Console.WriteLine($"Completed in {sw.Elapsed.ToString()}"); }