예제 #1
0
        public ServiceOption4Thrift(EnvDTE.DTE dte, EnumGenType genType = EnumGenType.AsyncClientDll)
        {
            _dte     = dte;
            _genType = genType;

            InitializeComponent();
        }
예제 #2
0
파일: AppData.cs 프로젝트: tidys/excel2Json
        public static EnumGenType genType       = EnumGenType.All;         // 生成的类型

        public static void init()
        {
            // 生成的类型
            string genType = AppCfg.getItem(AppCfg.genType);

            if (genType == null)
            {
                AppData.genType = EnumGenType.All;
            }
            else
            {
                AppData.genType = (EnumGenType)int.Parse(genType);
            }
        }
예제 #3
0
        private void initGenTypeCombox()
        {
            this.genTypeCombox.Items.Add("ALL");
            this.genTypeCombox.Items.Add("服务端");
            this.genTypeCombox.Items.Add("客户端");
            EnumGenType type = AppData.getGenType();

            if (type == EnumGenType.All)
            {
                this.genTypeCombox.SelectedIndex = 0;
            }
            else if (type == EnumGenType.Server)
            {
                this.genTypeCombox.SelectedIndex = 1;
            }
            else if (type == EnumGenType.Client)
            {
                this.genTypeCombox.SelectedIndex = 2;
            }
            AppData.saveCfg();
        }
예제 #4
0
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="sorceFile"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        public bool GenCsharp(string sorceFile, EnumGenType genType, out string errorMsg, ServiceModel serviceModel = null)
        {
            #region 逻辑判断
            errorMsg = string.Empty;
            if (string.IsNullOrWhiteSpace(sorceFile))
            {
                errorMsg = "请输入源文件地址";
                return(false);
            }

            if (!System.IO.File.Exists(sorceFile))
            {
                errorMsg = "您输入的地址文件不存在";
                return(false);
            }

            string ext = System.IO.Path.GetExtension(sorceFile).ToLower();
            if (ext != ".thrift")
            {
                errorMsg = "只支持thrift文件";
                return(false);
            }
            #endregion

            try
            {
                var resultDic = string.Empty;
                var result    = false;
                switch (genType)
                {
                case EnumGenType.Async:
                case EnumGenType.Origin:
                    result = GenExecutor.Execute(sorceFile, genType, out errorMsg, out resultDic);
                    break;

                case EnumGenType.AsyncDll:
                    result = GenExecutor.ExecuteDll(sorceFile, out errorMsg, out resultDic);
                    break;

                case EnumGenType.AsyncClientDll:
                    result = GenExecutor.ExecuteClientDll(sorceFile, serviceModel, out errorMsg, out resultDic);
                    break;

                case EnumGenType.AsyncClientNuget:
                    result = GenExecutor.ExcuteClientNuget(sorceFile, serviceModel, out errorMsg, out resultDic);
                    break;

                default:
                    break;
                }

                if (result)
                {
                    // 打开当前目录
                    Process.Start(resultDic);
                }
                return(result);
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                return(false);
            }
        }
예제 #5
0
        /// <summary>
        /// 生成异步或者通过的代码文件
        /// </summary>
        /// <param name="fullFilePathList"></param>
        public static bool Execute(string filePath, EnumGenType genType, out string errorMsg, out string resultDir)
        {
            errorMsg  = string.Empty;
            resultDir = string.Empty;
            if (!Utility.CheckFilePath(filePath))
            {
                errorMsg = "没有文件可以生成";
                return(false);
            }

            string fileName = new FileInfo(filePath).Name;

            // 该生成的结果文件夹
            resultDir = ThriftGlobal.GenResultDic(fileName);

            // 调用thrift命令生成cs文件
            string output;

            FileInfo[] csFiles = GenUtilityOrigin.GenThrift(filePath, resultDir, out output, out errorMsg);
            if (!string.IsNullOrEmpty(output))
            {
                var showMsg = MessageBox.Show(output + "!!! 有警告是否继续?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (showMsg == MessageBoxResult.No)
                {
                    errorMsg = "已中止,请更改对应的错误模块";
                    return(false);
                }
            }
            if (!string.IsNullOrEmpty(errorMsg))
            {
                return(false);
            }

            if (csFiles == null || csFiles.Length == 0)
            {
                errorMsg = "Thrift -gen csharp make file failure,maybe ur .thrift file has errors";
                return(false);
            }

            //如果只需要生成原生的,就直接返回
            if (genType == EnumGenType.Origin)
            {
                resultDir = csFiles[0].Directory.FullName;
                return(true);
            }

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

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

            // 组织这些文件成为一个project.xml文件
            var    projXml            = BuildThriftProject.MakeProjXml(csFiles, "thriftProj");
            string thriftProjFilePath = Path.Combine(projDicPath, "thriftProj.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, projDicPath, "thriftProj.xml");

            // 获取到生成的thrift源文件的dll
            var thriftDllPath    = Path.Combine(projDicPath, "bin", "thriftProj.dll");
            var thriftDllXmlPath = Path.Combine(projDicPath, "bin", "thriftProj.XML");

            if (!File.Exists(thriftDllPath))
            {
                // MSBuild生成thrift源文件的项目失败
                errorMsg = "Something wrong,Plz call Oliver";
                return(false);
            }

            // 判断命名空间是否符合规则
            var csNamespace = GenUtilityAsync.GetNamespace(thriftDllPath);

            if (string.IsNullOrEmpty(csNamespace))
            {
                errorMsg = "Namespace not exist";
                return(false);
            }
            var namespaceRegex = new Regex(@"^(([A-Z][a-zA-Z]{1,}\.)+)Thrift$");

            if (!namespaceRegex.IsMatch(csNamespace))
            {
                errorMsg = "Namespace not match [Xyyyy.Thrift]";
                var showMsg = MessageBox.Show(errorMsg + "!!! 是否继续?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (showMsg == MessageBoxResult.No)
                {
                    errorMsg = "已中止,请更改未符合规则的命名空间名称";
                    return(false);
                }
            }

            // 调用反射生成异步的代理类
            Dictionary <string, string> dllConfigs;
            var codeResults = GenUtilityAsync.GenAsync(thriftDllPath, thriftDllXmlPath, out dllConfigs);

            if (codeResults == null || codeResults.Count == 0)
            {
                // MSBuild生成thrift源文件的项目失败
                errorMsg = "No Service Found!!!";
                return(false);
            }
            // 把codeResult输出成文件
            resultDir = Path.Combine(resultDir, "gen-csharp-latest");
            if (!Utility.CheckDicPath(resultDir))
            {
                Utility.MakeDir(resultDir);
            }

            foreach (var codeResult in codeResults)
            {
                var asyncFileName = Path.Combine(resultDir, codeResult.Name);
                Utility.WriteNewFile(asyncFileName, codeResult.Code);
            }
            foreach (var fileInfo in csFiles)
            {
                fileInfo.CopyTo(Path.Combine(resultDir, fileInfo.Name), true);
            }
            // 输出client.dllconfig
            if (dllConfigs != null && dllConfigs.Count > 0)
            {
                foreach (var configPair in dllConfigs)
                {
                    var dllconfigFileName = Path.Combine(resultDir, configPair.Key);
                    Utility.WriteNewFile(dllconfigFileName, configPair.Value);
                }
            }
            return(true);
        }
예제 #6
0
파일: AppData.cs 프로젝트: tidys/excel2Json
 public static void setGenType(EnumGenType type)
 {
     AppData.genType = type;
     AppCfg.setItem(AppCfg.genType, type.ToString());
 }