コード例 #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            #region 判断依赖是否保存
            var dependencies = DependenceHelper.Get(type);
            if (dependencies == null || dependencies.Count <= 0)
            {
                // 弹出编辑依赖的窗口
                ShowDependenceDialog();
                return;
            }
            lbDependencies.Content = $"共有{dependencies.Count}个依赖";
            #endregion

            #region 赋值
            var serviceModel = LocalDataHelper.Get(_dte.ActiveDocument.FullName);

            var configServiceName = serviceModel.ConfigServiceName ?? "";
            if (serviceModel.ServiceName == configServiceName)
            {
                configServiceName = "";
            }

            tbServiceName.Text = serviceModel.ServiceName ?? "";
            tbPort.Text        = serviceModel.Port <= 0 ? "" : serviceModel.Port.ToString();
            #endregion
        }
コード例 #2
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     #region 获取已经保存的依赖
     dependencies = DependenceHelper.Get(_type) ?? new List <DependenceModel>();
     lvDependencies.ItemsSource = dependencies;
     #endregion
 }
コード例 #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            #region 判断依赖是否保存
            // Nuget包的生成才需要
            lbDependencies.Visibility = Visibility.Hidden;
            if (_genType == EnumGenType.AsyncClientNuget)
            {
                var type         = "thrift_" + ThriftGlobal.GenAsyncVersion.ToString();
                var dependencies = DependenceHelper.Get(type);
                if (dependencies == null || dependencies.Count <= 0)
                {
                    ShowDependenceDialog();
                    return;
                }
                lbDependencies.Content    = $"共有{dependencies.Count}个依赖";
                lbDependencies.Visibility = Visibility.Visible;
            }
            #endregion

            #region 赋值
            var serviceModel = LocalDataHelper.Get(_dte.ActiveDocument.FullName);

            var configServiceName = serviceModel.ConfigServiceName ?? "";
            if (serviceModel.ServiceName == configServiceName)
            {
                configServiceName = "";
            }

            tbServiceName.Text       = serviceModel.ServiceName ?? "";
            tbConfigServiceName.Text = configServiceName;
            tbPort.Text    = serviceModel.Port <= 0 ? "" : serviceModel.Port.ToString();
            tbNugetId.Text = serviceModel.NugetId ?? "";
            #endregion
        }
コード例 #4
0
        /// <summary>
        /// 添加引用的xml标签
        /// </summary>
        /// <param name="builder"></param>
        private static void AppendReference(StringBuilder builder, string depType = "grpc")
        {
            builder.Append("<ItemGroup>");
            builder.Append(Environment.NewLine);

            // 依赖
            var dependencies = DependenceHelper.Get(depType);

            foreach (var dependence in dependencies)
            {
                builder.Append($"<PackageReference Include=\"{dependence.PackageId}\" Version=\"{dependence.Version}\" />");
                builder.Append(Environment.NewLine);
            }

            builder.Append("</ItemGroup>");
            builder.Append(Environment.NewLine);
        }
コード例 #5
0
        /// <summary>
        /// 生成Nuspec文件
        /// </summary>
        /// <param name="complieFold">编译后的数据的文件夹</param>
        /// <returns></returns>
        public static string GenNuspecXml(string complieFold, ServiceModel serviceModel, string csNamespace)
        {
            var net45File    = Directory.GetFiles(Path.Combine(complieFold, net45Fold));
            var net45Configs = Directory.GetFiles(Path.Combine(complieFold, net45Fold, dllconfigFold));

            var net46File    = Directory.GetFiles(Path.Combine(complieFold, net46Fold));
            var net46Configs = Directory.GetFiles(Path.Combine(complieFold, net46Fold, dllconfigFold));

            //var net47File = Directory.GetFiles(Path.Combine(complieFold, net47Fold));
            //var net47Configs = Directory.GetFiles(Path.Combine(complieFold, net47Fold, dllconfigFold));

            var netcore20File    = Directory.GetFiles(Path.Combine(complieFold, netcoreFold));
            var netcore20Configs = Directory.GetFiles(Path.Combine(complieFold, netcoreFold, dllconfigFold));

            var nugetId = csNamespace;

            // 输出zookeeper.config
            var grpcBuilder = new StringBuilder();

            grpcBuilder.Append("<?xml version=\"1.0\"?>");
            grpcBuilder.Append(Environment.NewLine);
            grpcBuilder.Append("<package>");
            grpcBuilder.Append(Environment.NewLine);
            grpcBuilder.Append("  <metadata>");
            grpcBuilder.Append(Environment.NewLine);
            grpcBuilder.Append("    <id>" + nugetId + "</id>");
            grpcBuilder.Append(Environment.NewLine);
            grpcBuilder.Append("    <title>" + csNamespace + "</title>");
            grpcBuilder.Append(Environment.NewLine);
            grpcBuilder.Append("    <version>1.0." + DateTime.Now.ToString("yyyyMMddHH") + "</version>");
            grpcBuilder.Append(Environment.NewLine);
            grpcBuilder.Append("    <authors>Overt</authors>");
            grpcBuilder.Append(Environment.NewLine);
            grpcBuilder.Append("    <owners>Overt</owners>");
            grpcBuilder.Append(Environment.NewLine);
            grpcBuilder.Append("    <requireLicenseAcceptance>false</requireLicenseAcceptance>");
            grpcBuilder.Append(Environment.NewLine);
            grpcBuilder.Append("    <description>" + csNamespace + "</description>");
            grpcBuilder.Append(Environment.NewLine);

            grpcBuilder.Append("    <copyright>Copyright " + DateTime.Now.Year + "</copyright>");
            grpcBuilder.Append(Environment.NewLine);

            // 依赖
            grpcBuilder.Append("    <dependencies>");
            grpcBuilder.Append(Environment.NewLine);

            var type         = $"grpc";
            var dependencies = DependenceHelper.Get(type);

            foreach (var dependence in dependencies)
            {
                grpcBuilder.Append($"      <dependency id=\"{dependence.PackageId}\" version=\"{dependence.Version}\" />");
                grpcBuilder.Append(Environment.NewLine);
            }

            grpcBuilder.Append("    </dependencies>");
            grpcBuilder.Append(Environment.NewLine);

            grpcBuilder.Append("  </metadata>");
            grpcBuilder.Append(Environment.NewLine);

            // Dll文件
            grpcBuilder.Append("  <files>");
            grpcBuilder.Append(Environment.NewLine);
            foreach (var filePath in net45File)
            {
                var file = new FileInfo(filePath);
                grpcBuilder.Append("    <file src=\"" + filePath + "\" target=\"/lib/net45/" + file.Name + "\" />");
            }
            grpcBuilder.Append(Environment.NewLine);
            foreach (var filePath in net46File)
            {
                var file = new FileInfo(filePath);
                grpcBuilder.Append("    <file src=\"" + filePath + "\" target=\"/lib/net46/" + file.Name + "\" />");
            }
            //grpcBuilder.Append(Environment.NewLine);
            //foreach (var filePath in net47File)
            //{
            //    var file = new FileInfo(filePath);
            //    grpcBuilder.Append("    <file src=\"" + filePath + "\" target=\"/lib/net47/" + file.Name + "\" />");
            //}
            grpcBuilder.Append(Environment.NewLine);
            foreach (var filePath in netcore20File)
            {
                var file = new FileInfo(filePath);
                grpcBuilder.Append("    <file src=\"" + filePath + "\" target=\"/lib/netstandard2.0/" + file.Name + "\" />");
            }

            // configs
            foreach (var config in net45Configs)
            {
                var file = new FileInfo(config);
                var name = file.Name;
                if (file.Name.ToLower().IndexOf("client") > -1)
                {
                    ChangeFmConfig(serviceModel, config);
                    name = csNamespace + ".dll" + file.Extension;

                    grpcBuilder.Append(Environment.NewLine);
                    grpcBuilder.Append("    <file src=\"" + config + "\" target=\"/content/net45/dllconfigs/" + name + "\" />");
                }
            }
            foreach (var config in net46Configs)
            {
                var file = new FileInfo(config);
                var name = file.Name;
                if (file.Name.ToLower().IndexOf("client") > -1)
                {
                    ChangeFmConfig(serviceModel, config);
                    name = csNamespace + ".dll" + file.Extension;

                    grpcBuilder.Append(Environment.NewLine);
                    grpcBuilder.Append("    <file src=\"" + config + "\" target=\"/content/net46/dllconfigs/" + name + "\" />");
                }
            }
            //foreach (var config in net47Configs)
            //{
            //    var file = new FileInfo(config);
            //    var name = file.Name;
            //    if (file.Name.ToLower().IndexOf("client") > -1)
            //    {
            //        ChangeFmConfig(serviceModel, config);
            //        name = csNamespace + ".dll" + file.Extension;

            //        grpcBuilder.Append(Environment.NewLine);
            //        grpcBuilder.Append("    <file src=\"" + config + "\" target=\"/content/net47/dllconfigs/" + name + "\" />");
            //    }
            //}

            foreach (var config in netcore20Configs)
            {
                var file = new FileInfo(config);
                var name = file.Name;

                if (name.ToLower().IndexOf("client") > -1)
                {
                    ChangeCoreConfig(serviceModel, config);
                    name = csNamespace + ".dll" + file.Extension;

                    grpcBuilder.Append(Environment.NewLine);
                    grpcBuilder.Append("    <file src=\"" + config + "\" target=\"/content/netstandard2.0/dllconfigs/" + name + "\" />");
                }
            }

            grpcBuilder.Append(Environment.NewLine);
            grpcBuilder.Append("  </files>");
            grpcBuilder.Append(Environment.NewLine);

            grpcBuilder.Append("</package>");
            grpcBuilder.Append(Environment.NewLine);

            return(grpcBuilder.ToString());
        }
コード例 #6
0
ファイル: GenUtilityAsync.cs プロジェクト: YahuiWong/vs.menu
        /// <summary>
        /// 生成Nuspec文件
        /// </summary>
        /// <param name="thriftDllPath"></param>
        /// <returns></returns>
        public static string GenNuspecXml(string thriftDllPath, string nugetId = "")
        {
            // 加载依赖
            LoadDependencies();

            // 尝试把文件加载到字节流中读取
            byte[]   b  = File.ReadAllBytes(thriftDllPath);
            Assembly a2 = Assembly.Load(b);
            // 获取其中公开的接口类型
            var interfaces = a2.GetExportedTypes().Where(c => c.IsInterface).ToArray();

            if (interfaces.Length > 0)
            {
                var csNamespace   = interfaces.First().Namespace;
                var declaringName = string.Empty;
                if (interfaces.First().DeclaringType != null)
                {
                    declaringName = interfaces.First().DeclaringType.Name;
                }

                if (string.IsNullOrEmpty(nugetId))
                {
                    nugetId = csNamespace;
                }

                // 输出zookeeper.config
                var thriftProxyBuilder = new StringBuilder();
                thriftProxyBuilder.Append("<?xml version=\"1.0\"?>");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("<package>");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("  <metadata>");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("    <id>" + nugetId + "</id>");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("    <title>" + csNamespace + "</title>");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("    <version>1.0." + DateTime.Now.ToString("yyyyMMddHH") + "</version>");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("    <authors>Sodao</authors>");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("    <owners>Sodao</owners>");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("    <requireLicenseAcceptance>false</requireLicenseAcceptance>");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("    <description>" + csNamespace + "</description>");
                thriftProxyBuilder.Append(Environment.NewLine);


                thriftProxyBuilder.Append("    <copyright>Copyright " + DateTime.Now.Year + "</copyright>");
                thriftProxyBuilder.Append(Environment.NewLine);

                // 依赖
                var type         = $"thrift_{ThriftGlobal.GenAsyncVersion}";
                var dependencies = DependenceHelper.Get(type);
                thriftProxyBuilder.Append("    <dependencies>");
                thriftProxyBuilder.Append(Environment.NewLine);
                foreach (var dependence in dependencies)
                {
                    thriftProxyBuilder.Append($"      <dependency id=\"{dependence.PackageId}\" version=\"{dependence.Version}\" />");
                    thriftProxyBuilder.Append(Environment.NewLine);
                }
                thriftProxyBuilder.Append("    </dependencies>");
                thriftProxyBuilder.Append(Environment.NewLine);

                //if (ThriftGlobal.GenAsyncVersion == EnumGenAsyncVersion.New)
                //{
                //    thriftProxyBuilder.Append("    <dependencies>");
                //    thriftProxyBuilder.Append(Environment.NewLine);
                //    thriftProxyBuilder.Append("      <dependency id=\"thrift_client\" version=\"2.1.3\" />");
                //    thriftProxyBuilder.Append(Environment.NewLine);
                //    thriftProxyBuilder.Append("    </dependencies>");
                //    thriftProxyBuilder.Append(Environment.NewLine);
                //}
                //else
                //{
                //    thriftProxyBuilder.Append("    <dependencies>");
                //    thriftProxyBuilder.Append(Environment.NewLine);
                //    thriftProxyBuilder.Append("      <dependency id=\"thrift_client\" version=\"1.0.0.1\" />");
                //    thriftProxyBuilder.Append(Environment.NewLine);
                //    thriftProxyBuilder.Append("    </dependencies>");
                //    thriftProxyBuilder.Append(Environment.NewLine);
                //}

                thriftProxyBuilder.Append("  </metadata>");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("  <files>");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("    <file src=\"" + csNamespace + ".dll.config\" target=\"/content/dllconfigs/" + csNamespace + ".dll.config\" />");
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("    <file src=\"" + csNamespace + ".dll\" target=\"/lib/net4.0/" + csNamespace + ".dll\" />");

                // XML
                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("    <file src=\"" + csNamespace + ".XML\" target=\"/lib/net4.0/" + csNamespace + ".XML\" />");

                thriftProxyBuilder.Append(Environment.NewLine);
                thriftProxyBuilder.Append("  </files>");
                thriftProxyBuilder.Append(Environment.NewLine);

                thriftProxyBuilder.Append("</package>");
                thriftProxyBuilder.Append(Environment.NewLine);

                return(thriftProxyBuilder.ToString());
            }
            return(string.Empty);
        }