From 8951857c44eb6e143705df6a99395d18b50b41f2 Mon Sep 17 00:00:00 2001 From: zhaoyushun1999 <1306383139@qq.com> Date: Sat, 31 May 2025 16:51:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...crosoft.Extension.Net.ApiCommunication.sln | 25 ++++ ...soft.Extension.Net.ApiCommunication.csproj | 16 +++ .../Form1.Designer.cs | 85 +++++++++++++ .../Form1.cs | 42 ++++++ .../Form1.resx | 120 ++++++++++++++++++ .../Person.cs | 14 ++ .../Program.cs | 17 +++ 7 files changed, 319 insertions(+) create mode 100644 Demo.Microsoft.Extension.Net.ApiCommunication.sln create mode 100644 Demo.Microsoft.Extension.Net.ApiCommunication/Demo.Microsoft.Extension.Net.ApiCommunication.csproj create mode 100644 Demo.Microsoft.Extension.Net.ApiCommunication/Form1.Designer.cs create mode 100644 Demo.Microsoft.Extension.Net.ApiCommunication/Form1.cs create mode 100644 Demo.Microsoft.Extension.Net.ApiCommunication/Form1.resx create mode 100644 Demo.Microsoft.Extension.Net.ApiCommunication/Person.cs create mode 100644 Demo.Microsoft.Extension.Net.ApiCommunication/Program.cs diff --git a/Demo.Microsoft.Extension.Net.ApiCommunication.sln b/Demo.Microsoft.Extension.Net.ApiCommunication.sln new file mode 100644 index 0000000..70b09ae --- /dev/null +++ b/Demo.Microsoft.Extension.Net.ApiCommunication.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36121.58 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo.Microsoft.Extension.Net.ApiCommunication", "Demo.Microsoft.Extension.Net.ApiCommunication\Demo.Microsoft.Extension.Net.ApiCommunication.csproj", "{172F7E98-C6FE-4CB0-90E5-901B6296879E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {172F7E98-C6FE-4CB0-90E5-901B6296879E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {172F7E98-C6FE-4CB0-90E5-901B6296879E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {172F7E98-C6FE-4CB0-90E5-901B6296879E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {172F7E98-C6FE-4CB0-90E5-901B6296879E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D8628FB3-0E35-4D7D-A577-A24B323410D3} + EndGlobalSection +EndGlobal diff --git a/Demo.Microsoft.Extension.Net.ApiCommunication/Demo.Microsoft.Extension.Net.ApiCommunication.csproj b/Demo.Microsoft.Extension.Net.ApiCommunication/Demo.Microsoft.Extension.Net.ApiCommunication.csproj new file mode 100644 index 0000000..23bb94c --- /dev/null +++ b/Demo.Microsoft.Extension.Net.ApiCommunication/Demo.Microsoft.Extension.Net.ApiCommunication.csproj @@ -0,0 +1,16 @@ + + + + WinExe + net8.0-windows + enable + true + enable + Demo + + + + + + + \ No newline at end of file diff --git a/Demo.Microsoft.Extension.Net.ApiCommunication/Form1.Designer.cs b/Demo.Microsoft.Extension.Net.ApiCommunication/Form1.Designer.cs new file mode 100644 index 0000000..b53e46a --- /dev/null +++ b/Demo.Microsoft.Extension.Net.ApiCommunication/Form1.Designer.cs @@ -0,0 +1,85 @@ +namespace Demo +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + button1 = new Button(); + groupBox1 = new GroupBox(); + richTextBox1 = new RichTextBox(); + groupBox1.SuspendLayout(); + SuspendLayout(); + // + // button1 + // + button1.Location = new Point(451, 105); + button1.Name = "button1"; + button1.Size = new Size(75, 23); + button1.TabIndex = 0; + button1.Text = "Send"; + button1.UseVisualStyleBackColor = true; + button1.Click += button1_Click; + // + // groupBox1 + // + groupBox1.Controls.Add(richTextBox1); + groupBox1.Location = new Point(174, 105); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(254, 165); + groupBox1.TabIndex = 1; + groupBox1.TabStop = false; + groupBox1.Text = "Result"; + // + // richTextBox1 + // + richTextBox1.Dock = DockStyle.Fill; + richTextBox1.Location = new Point(3, 19); + richTextBox1.Name = "richTextBox1"; + richTextBox1.Size = new Size(248, 143); + richTextBox1.TabIndex = 0; + richTextBox1.Text = ""; + // + // Form1 + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(groupBox1); + Controls.Add(button1); + Name = "Form1"; + Text = "Form1"; + groupBox1.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private Button button1; + private GroupBox groupBox1; + private RichTextBox richTextBox1; + } +} diff --git a/Demo.Microsoft.Extension.Net.ApiCommunication/Form1.cs b/Demo.Microsoft.Extension.Net.ApiCommunication/Form1.cs new file mode 100644 index 0000000..f7b36f6 --- /dev/null +++ b/Demo.Microsoft.Extension.Net.ApiCommunication/Form1.cs @@ -0,0 +1,42 @@ +using Microsoft.Extension.Core; +using Microsoft.Extension.Net.ApiCommunication; + +namespace Demo +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + ApiCommunicationManager.RunServer((ApiRequest data) => { + ApiRespond apiRespond = new ApiRespond(); + apiRespond.IsSucess = true; + apiRespond.Msg = "OK"; + apiRespond.Datas.Add("intval",99); + apiRespond.Datas.Add("floatval", 99.9f); + apiRespond.Datas.Add("person",new Person() { + Name = data.StationID,//ÇëÇóÊý¾Ý´¦Àí + Age = 18 + }); + return apiRespond; + }); + } + + private async void button1_Click(object sender, EventArgs e) + { + this.richTextBox1.Text = ""; + await Task.Delay(500); + var ret = ApiCommunicationManager.Request(new ApiRequest() { + StationID = "zys" + }); + if (ret.IsSucess) + { + this.richTextBox1.Text = ret.Content.GetJsonString(); + } + else + { + MessageBox.Show(ret.Message, "fail"); + } + } + } +} diff --git a/Demo.Microsoft.Extension.Net.ApiCommunication/Form1.resx b/Demo.Microsoft.Extension.Net.ApiCommunication/Form1.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Demo.Microsoft.Extension.Net.ApiCommunication/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Demo.Microsoft.Extension.Net.ApiCommunication/Person.cs b/Demo.Microsoft.Extension.Net.ApiCommunication/Person.cs new file mode 100644 index 0000000..09252bc --- /dev/null +++ b/Demo.Microsoft.Extension.Net.ApiCommunication/Person.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo +{ + public class Person + { + public string Name { get; set; } + public int Age { get; set; } + } +} diff --git a/Demo.Microsoft.Extension.Net.ApiCommunication/Program.cs b/Demo.Microsoft.Extension.Net.ApiCommunication/Program.cs new file mode 100644 index 0000000..11da63c --- /dev/null +++ b/Demo.Microsoft.Extension.Net.ApiCommunication/Program.cs @@ -0,0 +1,17 @@ +namespace Demo +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file