Exemple #1
0
        /// <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();
        }
Exemple #2
0
        private void CreateFile(Tuple <string, string, string> idlcode, string filePath, string nSpace, string version = "")
        {
            var cmd = new ThriftCmd();

            Directory.CreateDirectory(filePath);

            var guid = cmd.Execute(Language.CSharp, filePath, idlcode.Item3);

            string idlpath = idlcode.Item1.Replace(".", "\\");

            string codePath = Path.Combine(filePath, guid, "Code", idlpath) + @"\*.cs";

            string dllName   = idlcode.Item1 + ".dll";
            string thriftdll = ThriftDLL.ResolvePath(Path.Combine(filePath, guid));
            string cscPath   = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe";

            cscPath = Csc.ResolvePath(Path.Combine(filePath, guid));
            string dllname          = Path.Combine(filePath, guid, "Out", dllName);
            string AssemblyInfoPath = AssemblyInfo.ResolvePath(Path.Combine(filePath, guid), nSpace, version);
            string dll = $"{cscPath} /target:library /out:{dllname} /reference:{thriftdll} {AssemblyInfoPath} {codePath}";


            Console.WriteLine(RunCmd(dll));
            Console.WriteLine();


            ConsoleColor currentForeColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;

            Console.WriteLine("生成成功:");
            Console.WriteLine();
            Console.WriteLine(Path.Combine(filePath, guid, "Out"));
            Console.WriteLine();
            Console.ForegroundColor = currentForeColor;

            Console.WriteLine("按任意键继续...");
            Console.ReadLine();
        }