Ejemplo n.º 1
0
        public ThriftGenerate(string filePath, NetVersion netVersion)
        {
            _resourcesDir = Util.GetExpansionToolResourcesPath();

            //_thriftPath = "thrift.exe";
            _thriftPath = GetEXEFilePath("thrift.exe");

            _info = Init(filePath, netVersion);
        }
Ejemplo n.º 2
0
        public ThriftServiceInfo Init(string filePath, NetVersion netVersion)
        {
            var textThrift = File.ReadAllText(filePath);

            string dllName = string.Empty;

            if (NetVersion.Net45 == netVersion)
            {
                dllName = GetRegexGroup(textThrift, "^namespace csharp ([A-z_.]+)");
            }
            else
            {
                dllName = GetRegexGroup(textThrift, "^namespace netcore ([A-z_.]+)");
            }

            if (string.IsNullOrWhiteSpace(dllName))
            {
                throw new ArgumentNullException($"namespace {NetVersion.Net45} is null");
            }

            string thriftServiceClassName = GetRegexGroup(textThrift, "^service ([A-z_]+)");
            string serviceName            = GetRegexGroup(textThrift, "^# servicename=([A-z_]+)");
            string host    = GetRegexGroup(textThrift, "^# host=([0-9.]+)");
            string portStr = GetRegexGroup(textThrift, "^# port=(\\d+)");

            int.TryParse(portStr, out int port);
            bool isPush  = false;
            var  strPush = GetRegexGroup(textThrift, "^# nugetpush=(TRUE|true)");

            if (strPush != null)
            {
                isPush = true;
            }


            string newPath = $"{Path.GetTempPath()}thrift\\{DateTime.Now.Ticks}";

            if (!Directory.Exists(newPath))
            {
                Directory.CreateDirectory(newPath);
            }

            var info = new ThriftServiceInfo()
            {
                WorkDir                = newPath,
                ThriftFile             = filePath,
                ThriftNamespaceName    = dllName,
                ThriftServiceClassName = thriftServiceClassName,
                NetVersion             = netVersion,
                ServiceName            = serviceName,
                Host      = host,
                Port      = port,
                NugetPush = isPush
            };

            return(info);
        }
 public GenerateProjectNetCore(ThriftServiceInfo info, string tempDir)
 {
     _info     = info;
     _tempPath = Path.Combine(tempDir, "netcore");
 }