Procházet zdrojové kódy

Z991239-5298 #comment feat: spgen get entity lists from centerConfig server

chenliangyu před 1 rokem
rodič
revize
c3e9fc47bb
3 změnil soubory, kde provedl 122 přidání a 6 odebrání
  1. 86 5
      Tool/spgen/Program.cs
  2. 1 1
      Tool/spgen/app.config
  3. 35 0
      Tool/spgen/spgen.csproj

+ 86 - 5
Tool/spgen/Program.cs

@@ -5,6 +5,9 @@ using System.Text;
 using System.Xml;
 using System.IO;
 using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Net.Http;
+using Newtonsoft.Json;
 
 namespace spgen
 {
@@ -186,6 +189,19 @@ namespace spgen
                 }
             }
         }
+        
+        public static void ReadEntityInfoFromServer(List<String> InfoArr)
+        {
+            entityDic.Clear();
+
+            Regex reg = new Regex("^(.+)=.+0x(.+)$");
+            foreach (string line in InfoArr)
+            {
+                Match match = reg.Match(line);
+                if (match.Success && !entityDic.ContainsKey(match.Groups[1].Value))
+                    entityDic.Add(match.Groups[1].Value, match.Groups[2].Value);
+            }
+        }
 
         public static Entity Load(string xmlfile)
         {
@@ -530,8 +546,76 @@ namespace spgen
             Console.WriteLine("\tUsage: spgen.exe <entity>.xml\n");
         }
 
+        public class ShellInfo
+        {
+            public string module { get; set; }
+            public string name { get; set; }
+
+            public string value { get; set; }
+        }
+
+        static async Task PostRequestAsync()
+        {
+            try
+            {
+                // 构造请求数据
+                var requestData = "{\"terminal_no\": \"7555980178\"}";
+                var content = new StringContent(requestData, Encoding.UTF8, "application/json");
+
+                // 创建 HttpClient 实例
+                using (var httpClient = new HttpClient())
+                {
+                    // 设置请求的 URL
+                    var requestUrl = "http://centerconfig.paasst.cmbchina.cn/api/unify/config/query";
+
+                    // 发送 POST 请求
+                    var response = await httpClient.PostAsync(requestUrl, content);
+
+                    // 检查响应是否成功
+                    if (response.IsSuccessStatusCode)
+                    {
+                        // 读取响应内容
+                        var responseContent = await response.Content.ReadAsStringAsync();
+                        
+                        dynamic jsonObject = JsonConvert.DeserializeObject(responseContent);
+
+                        dynamic dataObj = JsonConvert.DeserializeObject(jsonObject.data.ToString());
+
+                        dynamic shellObj = JsonConvert.DeserializeObject(dataObj.shell_config_dto.ToString());
+
+
+                        List<ShellInfo> infos = JsonConvert.DeserializeObject<List<ShellInfo>>(shellObj.config.ToString());
+
+
+                        List<String> entityArr = new List<string>();
+
+                        foreach (var it in infos)
+                        {
+                            if (it.module == "Entity")
+                            {
+                                String cur = it.name + "=" + it.value;
+                                entityArr.Insert(0, cur);
+                            }
+                                
+                        }
+                        entityArr.Insert(0, "VtmLoader=1,mod_VtmLoader,0x10F");
+                        Entity.ReadEntityInfoFromServer(entityArr);
+                        
+                    }
+                    else
+                    {
+                        Console.WriteLine($"Error: {response.StatusCode}");
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine($"Exception: {ex.ToString()}");
+            }
+        }
+
         // spgen.exe print_entity.xml
-        static void Main(string[] args)
+        static async Task Main(string[] args)
         {
             if (args.Length != 1 && args.Length != 2)
             {
@@ -539,12 +623,9 @@ namespace spgen
                 return;
             }
 
-            String shellIniPath = "shell.ini";
-            if (args.Length == 2)
-                shellIniPath = args[1];
             try
             {
-                Entity.ReadEntityInfoFromShellIni(shellIniPath);
+                await PostRequestAsync();
                 string xmlfile = System.IO.Path.Combine(Environment.CurrentDirectory, args[0]);
                 Entity entity = Entity.Load(xmlfile);
 

+ 1 - 1
Tool/spgen/app.config

@@ -1,3 +1,3 @@
 <?xml version="1.0" encoding="utf-8"?>
 <configuration>
-<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>

+ 35 - 0
Tool/spgen/spgen.csproj

@@ -55,10 +55,44 @@
     <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
+    <Reference Include="System.ComponentModel.Composition" />
     <Reference Include="System.Core">
       <RequiredTargetFramework>3.5</RequiredTargetFramework>
     </Reference>
+    <Reference Include="System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath>
+      <Private>True</Private>
+      <Private>True</Private>
+    </Reference>
+    <Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath>
+      <Private>True</Private>
+      <Private>True</Private>
+    </Reference>
+    <Reference Include="System.Security.Cryptography.Algorithms, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net463\System.Security.Cryptography.Algorithms.dll</HintPath>
+      <Private>True</Private>
+      <Private>True</Private>
+    </Reference>
+    <Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
+      <Private>True</Private>
+      <Private>True</Private>
+    </Reference>
     <Reference Include="System.Xml.Linq">
       <RequiredTargetFramework>3.5</RequiredTargetFramework>
     </Reference>
@@ -93,6 +127,7 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
+    <None Include="packages.config" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it.