private void btnSure_Click(object sender, RoutedEventArgs e)
        {
            var serviceName = tbServiceName.Text.Trim();
            var configServcieName = tbConfigServiceName.Text.Trim();
            int.TryParse(tbPort.Text.Trim(), out int port);
            var publish = cbPublish.IsChecked;
            var nugetId = tbNugetId.Text.Trim();
            if (string.IsNullOrEmpty(serviceName))
            {
                MessageBox.Show("请输入服务名称\r\n禁止除数字/大小写字母以外的字符", "VSMenu提示");
                return;
            }
            if (!Regex.IsMatch(serviceName, "^[A-Za-z0-9]+$"))
            {
                MessageBox.Show("服务名称为静态类属性名称\r\n禁止除数字/大小写字母以外的字符\r\n\r\nThriftProxy.[服务名称]", "VSMenu提示");
                return;
            }

            if (port <= 0)
            {
                MessageBox.Show("请输入合理的端口号", "VSMenu提示");
                return;
            }

            if (!serviceName.EndsWith("Service"))
            {
                if (serviceName.EndsWith("service"))
                    serviceName = serviceName.TrimEnd("service".ToArray());
                serviceName += "Service";
            }

            if (string.IsNullOrEmpty(configServcieName))
                configServcieName = serviceName;

            var model = new ServiceModel()
            {
                ServiceName = serviceName,
                ConfigServiceName = configServcieName,
                Port = port,
                Publish = publish ?? false,
                NugetId = nugetId,
            };

            #region 记录服务名称跟端口号
            LocalDataHelper.Save(model, _dte.ActiveDocument.FullName);
            #endregion

            var errorMsg = string.Empty;
            var result = ThriftGenerator.Default.GenCsharp(_dte.ActiveDocument.FullName, _genType, out errorMsg, model);
            if (!result)
                MessageBox.Show(errorMsg, "VSMenu提示");

            this.Close();
        }
Example #2
0
        private void btnSure_Click(object sender, RoutedEventArgs e)
        {
            var serviceName = tbServiceName.Text.Trim();

            int.TryParse(tbPort.Text.Trim(), out int port);
            var publish = cbPublish.IsChecked;

            if (string.IsNullOrEmpty(serviceName))
            {
                MessageBox.Show("请输入服务名称\r\n禁止除数字/大小写字母以外的字符", "VSMenu提示");
                return;
            }
            if (!Regex.IsMatch(serviceName, "^[A-Za-z0-9]+$"))
            {
                MessageBox.Show("服务名称为静态类属性名称\r\n禁止除数字/大小写字母以外的字符\r\n\r\n.[服务名称]", "VSMenu提示");
                return;
            }

            if (port <= 0)
            {
                MessageBox.Show("请输入合理的端口号", "VSMenu提示");
                return;
            }

            var model = new ServiceModel()
            {
                ServiceName = serviceName,
                Port        = port,
                Publish     = publish ?? false,
            };

            #region 记录服务名称跟端口号
            LocalDataHelper.Save(model, _dte.ActiveDocument.FullName);
            #endregion

            var errorMsg = string.Empty;
            var result   = GrpcGenerator.Default.GenCsharp(_dte.ActiveDocument.FullName, EnumGrpcGenType.GenNuget_GrpcNet, out errorMsg, model);
            if (!result)
            {
                MessageBox.Show(errorMsg, "VSMenu提示");
            }

            this.Close();
        }