public void Compile(string outputPath, GenerationSet metaData, CodeGenerationSettings settings, string target) { var generationInfo = new CodeGenerationInfo(outputPath, metaData, settings); if (settings.Options.HasFlag(CodeGenerationOptions.OmitCode) == false && settings.Options.HasFlag(CodeGenerationOptions.OmitBaseCode) == false) { var filename = this.CompileAll(outputPath, generationInfo, target); this.PrintResult(filename); } else if (settings.Options.HasFlag(CodeGenerationOptions.OmitCode) == true) { var filename = this.CompileBase(outputPath, generationInfo, target); this.PrintResult(filename); } else if (settings.Options.HasFlag(CodeGenerationOptions.OmitBaseCode) == true) { var tempPath = PathUtility.GetTempPath(true); try { var readerPath = this.CompileBase(tempPath, generationInfo, target); var filename = this.Compile(outputPath, readerPath, generationInfo, target); this.PrintResult(filename); } finally { DirectoryUtility.Delete(tempPath); } } }
public void Generate(string outputPath, GenerationSet metaData, CodeGenerationSettings settings) { var path = PathUtility.GetFullPath(outputPath); var generationInfo = new CodeGenerationInfo(path, metaData, settings); if (settings.Options.HasFlag(CodeGenerationOptions.OmitCode) == false) { var codes = this.GenerateCodes(generationInfo); foreach (var item in codes) { var codePath = FileUtility.WriteAllText(item.Value, Encoding.UTF8, path, item.Key); this.PrintResult(codePath); } } if (settings.Options.HasFlag(CodeGenerationOptions.OmitBaseCode) == false) { var codes = this.GenerateBaseCodes(generationInfo); foreach (var item in codes) { var codePath = FileUtility.WriteAllText(item.Value, Encoding.UTF8, path, item.Key); this.PrintResult(codePath); } } }
public void Compile(string outputPath, GenerationSet metaData, CodeGenerationSettings settings, string target) { if (target == null) { throw new ArgumentNullException(nameof(target)); } var generationInfo = new CodeGenerationInfo(outputPath, metaData, settings); var codes1 = this.GenerateCodes(generationInfo); var codes2 = this.GenerateBaseCodes(generationInfo); var codes3 = codes1.Concat(codes2).ToDictionary(item => item.Key, item => item.Value); var codes = TypeScriptCompiler.Compile(codes3, target == string.Empty ? "ES5" : target); if (Directory.Exists(outputPath) == false) { Directory.CreateDirectory(outputPath); } foreach (var item in codes) { string codePath = Path.Combine(outputPath, item.Key); using (StreamWriter sw = new StreamWriter(codePath, false, Encoding.UTF8)) { sw.WriteLine(item.Value); this.PrintResult(codePath); } } }
public CodeGenerationInfo(string outputPath, GenerationSet metaData, CodeGenerationSettings settings) { this.metaData = metaData; this.settings = settings; if (this.settings.BasePath != string.Empty) { var relativePath = UriUtility.MakeRelativeOfDirectory(new DirectoryInfo(outputPath).FullName, DirectoryUtility.GetAbsolutePath(outputPath, settings.BasePath)); this.RelativePath = relativePath + Path.DirectorySeparatorChar; } }
public static GenerationSet Process(GenerationSet generationSet) { if (ReplaceSettings.ReplaceRevision != long.MinValue) { generationSet.Revision = ReplaceSettings.ReplaceRevision; } if (ReplaceSettings.ReplaceHashValue != null) { generationSet.TablesHashValue = ReplaceSettings.ReplaceHashValue; generationSet.TypesHashValue = ReplaceSettings.ReplaceHashValue; } return(generationSet); }
public GenerationSet Gerneration(TagInfo tags, string filterExpression, bool isDevmode, long revision) { this.Dispatcher.VerifyAccess(); if (filterExpression == null) { throw new ArgumentNullException(nameof(filterExpression)); } if (revision == -1) { var tables = this.GetTables().Select(item => this.GetTableInfo(item)) .ToArray(); var types = this.GetTypes().Select(item => this.GetTypeInfo(item)) .ToArray(); var codeSet = new GenerationSet(types, tables) { Name = this.DataBaseName, Revision = this.Revision, }; codeSet = codeSet.Filter(tags); if (filterExpression != string.Empty) { codeSet = codeSet.Filter(filterExpression); } return(codeSet); } else { var dataSet = this.DataBase.GetDataSet(this.authentication, revision); var tables = dataSet.Tables.Select(item => item.TableInfo).ToArray(); var types = dataSet.Types.Select(item => item.TypeInfo).ToArray(); var codeSet = new GenerationSet(types, tables) { Name = this.DataBaseName, Revision = this.Revision, }; codeSet = codeSet.Filter(tags); if (filterExpression != string.Empty) { codeSet = codeSet.Filter(filterExpression); } return(codeSet); } }
public void Generate(string outputPath, GenerationSet metaData, CodeGenerationSettings settings) { var generationInfo = new CodeGenerationInfo(metaData, settings) { RelativePath = string.Empty, }; if (settings.BasePath != string.Empty) { var relativePath = UriUtility.MakeRelativeOfDirectory(new DirectoryInfo(outputPath).FullName, DirectoryUtility.GetAbsolutePath(outputPath, settings.BasePath)); generationInfo.RelativePath = relativePath + "/"; } { var codes = this.Generate(generationInfo); var dirInfo = new DirectoryInfo(outputPath); var rootPath = generationInfo.Namespace.Replace('.', Path.DirectorySeparatorChar); foreach (var item in codes) { var ext = Path.GetExtension(item.Key); var filename = FileUtility.RemoveExtension(item.Key).Replace('.', Path.DirectorySeparatorChar) + ext; filename = Path.Combine(dirInfo.FullName, filename); FileUtility.Prepare(filename); using (StreamWriter sw = new StreamWriter(filename, false, Encoding.UTF8)) { sw.WriteLine(item.Value); this.PrintResult(filename); } } } if (settings.Options.HasFlag(CodeGenerationOptions.OmitBaseCode) == false) { var codes = this.GenerateBases(generationInfo); var codesPath = DirectoryUtility.GetAbsolutePath(outputPath, settings.BasePath); foreach (var item in codes) { var codePath = FileUtility.Prepare(codesPath, item.Key); using (var writer = new StreamWriter(codePath, false, Encoding.UTF8)) { writer.WriteLine(item.Value); this.PrintResult(codePath); } } } }
public void Generate(string outputPath, GenerationSet metaData, CodeGenerationSettings settings) { var generationInfo = new CodeGenerationInfo(metaData, settings); var codes = this.Generate(generationInfo); foreach (var item in codes) { string codePath = FileUtility.Prepare(outputPath, item.Key); using (StreamWriter sw = new StreamWriter(codePath, false, Encoding.UTF8)) { sw.WriteLine(item.Value); this.PrintResult(codePath); } } }
public CodeGenerationInfo(GenerationSet metaData, CodeGenerationSettings settings) { this.metaData = metaData; this.settings = settings; this.EnumFomrat = (v) => $"0x{(int)v:x8}"; }