/// <summary> /// 解析idl文件,并生成dll /// </summary> /// <param name="idlFilePath"></param> /// <param name="outPath"></param> /// <param name="nSpace"></param> /// <param name="version"></param> public void AnalyzeIDL(string idlFilePath, string outPath, string nSpace, string version = "") { var cmd = new ThriftCmd(); Directory.CreateDirectory(outPath); string tempPathCode = Path.Combine(outPath, "Code"); Directory.CreateDirectory(tempPathCode); string dllPathCode = Path.Combine(outPath, "Out"); Directory.CreateDirectory(dllPathCode); string thriftdll = ThriftDLL.ResolvePath(outPath); string formattedLanguage = Formatter.FormatLanguage(Language.CSharp); string arguments = $"--gen \"{formattedLanguage}\" -out \"{tempPathCode}\" \"{idlFilePath}\""; ThriftExe.Execute(outPath, arguments); string codePath = Path.Combine(tempPathCode, nSpace.Replace(".", "\\")) + @"\*.cs"; string cscPath = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe"; string dllname = Path.Combine(dllPathCode, nSpace + ".dll"); string AssemblyInfoPath = AssemblyInfo.ResolvePath(outPath, nSpace, version); string dll = $"{cscPath} /target:library /out:{dllname} /reference:{thriftdll} {AssemblyInfoPath} {codePath}"; Console.WriteLine(RunCmd(dll)); Console.WriteLine(); }
public string Execute(Language language, string tempPath, string thriftIDLCode) { string formattedLanguage = Formatter.FormatLanguage(language); string guid = Guid.NewGuid().ToString(); string tempPathIDL = Path.Combine(tempPath, guid, "IDL"); string tempPathCode = Path.Combine(tempPath, guid, "Code"); string tempPathOut = Path.Combine(tempPath, guid, "Out"); Directory.CreateDirectory(tempPathIDL); Directory.CreateDirectory(tempPathCode); Directory.CreateDirectory(tempPathOut); string idlFilePath = Path.Combine(tempPathIDL, "IDL.thrift"); string arguments = $"--gen \"{formattedLanguage}\" -out \"{tempPathCode}\" \"{idlFilePath}\""; File.WriteAllText(idlFilePath, thriftIDLCode); ThriftExe.Execute(Path.Combine(tempPath, guid), arguments); return(guid); }