/// <summary> /// Creates a new instance of the <see cref="CodeGenConsole"/> class. /// </summary> /// <param name="assemblies">The list of additional assemblies to probe for resources.</param> /// <param name="company">The company name.</param> /// <param name="appName">The application/domain name.</param> /// <param name="apiName">The Web API name.</param> /// <param name="outputDirectory">The output path/directory; defaults to the resulting <see cref="OnRamp.Console.CodeGenConsole.GetBaseExeDirectory"/> <see cref="DirectoryInfo.Parent"/>.</param> /// <returns>The <see cref="CodeGenConsole"/> instance.</returns> public static CodeGenConsole Create(Assembly[] assemblies, string company, string appName, string apiName = "Api", string?outputDirectory = null) { var args = new CodeGeneratorArgs { OutputDirectory = string.IsNullOrEmpty(outputDirectory) ? new DirectoryInfo(GetBaseExeDirectory()).Parent : new DirectoryInfo(outputDirectory) }; args.AddAssembly(typeof(CodeGenConsole).Assembly); args.AddAssembly(assemblies); args.AddParameter(CompanyParamName, Check.NotEmpty(company, nameof(company))); args.AddParameter(AppNameParamName, Check.NotEmpty(appName, nameof(appName))); args.AddParameter(ApiNameParamName, Check.NotEmpty(apiName, nameof(apiName))); return(new CodeGenConsole(args) { BypassOnWrites = true }); }
public void Generate(File inputFile, File outputFile, CodeGeneratorArgs args) { var iTextTemplating = Package.GetGlobalService(typeof(STextTemplating)) as ITextTemplating; var t4Template = args.Template.Content; //TODO: Find a more optimal solution than concat string like this t4Template = t4Template.Replace("$(Code)", args.ModelSpecification.Code); t4Template = t4Template.Replace("$(MvvmFilePath)", inputFile.Path); t4Template = t4Template.Replace("$(TinyMVVMDir)", GetTinyMVVMInstallDirPath()); t4Template = t4Template.Replace("$(ViewModel.Name)", args.ViewModel.Name); t4Template = t4Template.Replace("$(CurrentNamespace)", outputFile.Parent.CurrentNamespace); var content = iTextTemplating.ProcessTemplate(outputFile.Path, t4Template, null, null); using (var fs = outputFile.NewFileStream()) { fs.Write(content); } }
/// <summary> /// Execute the selection code-generation. /// </summary> private async Task <CodeGenStatistics> ExecuteCodeGenerationAsync(string scriptName, string configName, int count) { // Update the files. var args = new CodeGeneratorArgs(); args.CopyFrom(Args); args.ScriptFileName ??= scriptName; args.ConfigFileName ??= configName; if (count > 0) { args.Logger?.LogInformation(new string('-', 80)); args.Logger?.LogInformation(""); } OnWriteArgs(args); // Execute the code-generation. var stats = await ExecuteCodeGenerationAsync(args).ConfigureAwait(false); // Write results. OnWriteFooter(stats); return(stats); }
/// <summary> /// Initializes a new instance of the <see cref="CodeGenConsole"/> class. /// </summary> internal CodeGenConsole(CodeGeneratorArgs args) : base(args, OnRamp.Console.SupportedOptions.All) { MastheadText = DefaultMastheadText; Args.CreateConnectionStringEnvironmentVariableName ??= csargs => $"{args.GetCompany()?.Replace(".", "_", StringComparison.InvariantCulture)}_{args.GetAppName()?.Replace(".", "_", StringComparison.InvariantCulture)}_ConnectionString"; }