Exemple #1
0
        /// <summary>
        /// 生成服务端dll
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="genType"></param>
        /// <param name="errorMsg"></param>
        /// <param name="resultDir"></param>
        /// <returns></returns>
        public static bool ExecuteDll(string filePath, out string errorMsg, out string resultDir)
        {
            errorMsg  = string.Empty;
            resultDir = string.Empty;

            if (!Execute(filePath, EnumGenType.Async, out errorMsg, out resultDir))
            {
                return(false);
            }

            string fileName = new FileInfo(filePath).Name;

            // 每次生成都只能生成一次文件夹路径
            string projServerDicPath = ThriftGlobal.GenServerProjDir(fileName);

            if (string.IsNullOrEmpty(projServerDicPath))
            {
                errorMsg = "Create gen temp folder error,may u have already open it!";
                return(false);
            }

            // 创建一个AssemblyInfo文件
            var projDicPath          = ThriftGlobal.GetProjDir(fileName);
            var thriftDllPath        = Path.Combine(projDicPath, "bin", "thriftProj.dll");
            var csNamespace          = string.Empty;
            var assemblyInfoCode     = GenUtilityAsync.GenAssemblyInfoCs(thriftDllPath, out csNamespace);
            var assemblyInfoFilePath = Path.Combine(resultDir, "AssemblyInfo.cs");

            Utility.WriteNewFile(assemblyInfoFilePath, assemblyInfoCode);

            // 组织这些文件成为一个project.xml文件
            var    files              = new DirectoryInfo(resultDir).GetFiles();
            var    projXml            = BuildThriftProject.MakeServerProjXml(files, csNamespace);
            string thriftProjFilePath = Path.Combine(projServerDicPath, csNamespace + ".xml");

            Utility.WriteNewFile(thriftProjFilePath, projXml);

            // 调用MSBuild生成这个项目
            var msbuildPath = ThriftGlobal.MsBuildPath();

            if (string.IsNullOrEmpty(msbuildPath))
            {
                errorMsg = "Can not find MsBuild,have u install .net framework 4?";
                return(false);
            }
            // 为防止有的客户端路径中包含空格影响参数的设置
            // 设置运行的目录在客户端当前目录调用MSBuild
            Utility.RunProcess(msbuildPath, projServerDicPath, csNamespace + ".xml");

            resultDir = Path.Combine(projServerDicPath, "bin");

            return(true);
        }
Exemple #2
0
        /// <summary>
        ///生成nuget包
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="serviceModel"></param>
        /// <param name="errorMsg"></param>
        /// <param name="resultDic"></param>
        /// <returns></returns>
        public static bool ExcuteClientNuget(string filePath, ServiceModel serviceModel, out string errorMsg, out string resultDic)
        {
            errorMsg  = string.Empty;
            resultDic = string.Empty;

            if (!ExecuteClientDll(filePath, serviceModel, out errorMsg, out resultDic))
            {
                return(false);
            }

            var fileName = new FileInfo(filePath).Name;
            // 生成nuget文件
            var projDicPath   = ThriftGlobal.GetProjDir(fileName);
            var thriftDllPath = Path.Combine(projDicPath, "bin", "thriftProj.dll");
            var nuspecXml     = GenUtilityAsync.GenNuspecXml(thriftDllPath, serviceModel.NugetId);

            if (string.IsNullOrEmpty(nuspecXml))
            {
                errorMsg = "nuspec file gen error!!!";
                return(false);
            }

            var nuspecFilePath = Path.Combine(resultDic, "Package.nuspec");

            Utility.WriteNewFile(nuspecFilePath, nuspecXml);

            // 生成nuget包
            var error = string.Empty;

            Utility.RunCmd(Utility.NugetExePath, "pack " + nuspecFilePath + " -OutputDirectory " + resultDic, out error);

            // 直接发布
            if (serviceModel.Publish)
            {
                //var nugetServer = "http://10.0.60.89:8081";
                //if (ThriftGlobal.GenAsyncVersion == EnumGenAsyncVersion.Old)
                //    nugetServer = "http://10.0.60.89:8080";

                var nugetServer = NugetServerHelper.Get();
                var nugetPks    = new DirectoryInfo(resultDic).GetFiles("*.nupkg");
                if (nugetPks.Length <= 0)
                {
                    errorMsg = "nupkg not gen";
                    return(false);
                }

                Utility.RunCmd(Utility.NugetExePath, "push " + nugetPks[0].FullName + " -s " + nugetServer.Address + " " + nugetServer.Key, out error);
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// 生成dll
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="genType"></param>
        /// <param name="errorMsg"></param>
        /// <param name="serviceModel"></param>
        /// <returns></returns>
        public static bool ExecuteClientDll(string filePath, ServiceModel serviceModel, out string errorMsg, out string resultDic)
        {
            errorMsg  = string.Empty;
            resultDic = string.Empty;
            if (serviceModel == null)
            {
                errorMsg = "服务信息数据未提供";
                return(false);
            }

            if (!Execute(filePath, EnumGenType.Async, out errorMsg, out resultDic))
            {
                return(false);
            }

            string fileName = new FileInfo(filePath).Name;

            // 每次生成都只能生成一次文件夹路径
            string projClientDicPath = ThriftGlobal.GenClientProjDir(fileName);

            if (string.IsNullOrEmpty(projClientDicPath))
            {
                errorMsg = "Create gen temp folder error,may u have already open it!";
                return(false);
            }

            // 创建一个App.config
            var clientConfigs = new DirectoryInfo(resultDic).GetFiles("client*");

            if (clientConfigs.Length > 0)
            {
                var appConfigPath = Path.Combine(resultDic, "App.config");
                var otherConfigs  = new List <FileInfo>();

                for (int i = 0; i < clientConfigs.Length; i++)
                {
                    if (i == 0)
                    {
                        clientConfigs[i].CopyTo(appConfigPath);
                        continue;
                    }
                    otherConfigs.Add(clientConfigs[i]);
                }

                ThriftGlobal.ChangeAppConfig(serviceModel, appConfigPath, otherConfigs);
            }

            // 创建一个_ThriftProxy
            var projDicPath   = ThriftGlobal.GetProjDir(fileName);
            var thriftDllPath = Path.Combine(projDicPath, "bin", "thriftProj.dll");
            var csNamespace   = string.Empty;
            var proxyCode     = GenUtilityAsync.GenAsyncProxyCs(thriftDllPath, serviceModel, out csNamespace);
            var proxyFilePath = Path.Combine(resultDic, "_ThriftProxy.cs");

            Utility.WriteNewFile(proxyFilePath, proxyCode);

            // 创建一个AssemblyInfo文件
            var assemblyInfoCode     = GenUtilityAsync.GenAssemblyInfoCs(thriftDllPath, out csNamespace);
            var assemblyInfoFilePath = Path.Combine(resultDic, "AssemblyInfo.cs");

            Utility.WriteNewFile(assemblyInfoFilePath, assemblyInfoCode);

            // 组织这些文件成为一个project.xml文件
            var    files              = new DirectoryInfo(resultDic).GetFiles();
            var    projXml            = BuildThriftProject.MakeClientProjXml(files, csNamespace);
            string thriftProjFilePath = Path.Combine(projClientDicPath, csNamespace + ".xml");

            Utility.WriteNewFile(thriftProjFilePath, projXml);

            // 调用MSBuild生成这个项目
            var msbuildPath = ThriftGlobal.MsBuildPath();

            if (string.IsNullOrEmpty(msbuildPath))
            {
                errorMsg = "Can not find MsBuild,have u install .net framework 4?";
                return(false);
            }
            // 为防止有的客户端路径中包含空格影响参数的设置
            // 设置运行的目录在客户端当前目录调用MSBuild
            Utility.RunProcess(msbuildPath, projClientDicPath, csNamespace + ".xml");

            resultDic = Path.Combine(projClientDicPath, "bin");

            return(true);
        }