Browse Source

winform debugger

0x0001F36D 5 năm trước cách đây
mục cha
commit
04094527e1

+ 40 - 0
src/Yuuna.Interaction.WinForms.Test/Form1.Designer.cs

@@ -0,0 +1,40 @@
+namespace Yuuna.Interaction.WinForms.Test
+{
+    partial class Form1
+    {
+        /// <summary>
+        ///  Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        ///  Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        ///  Required method for Designer support - do not modify
+        ///  the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(800, 450);
+            this.Text = "Form1";
+        }
+
+        #endregion
+    }
+}
+

+ 88 - 0
src/Yuuna.Interaction.WinForms.Test/Form1.cs

@@ -0,0 +1,88 @@
+
+namespace Yuuna.Interaction.WinForms.Test
+{
+    using Newtonsoft.Json;
+    using RestSharp;
+    using System;
+    using System.Collections.Generic;
+    using System.ComponentModel;
+    using System.Data;
+    using System.Diagnostics;
+    using System.Drawing;
+    using System.Linq;
+    using System.Text;
+    using System.Threading.Tasks;
+    using System.Windows.Forms;
+
+    public partial class Form1 : Form
+    {
+        private readonly ListBox _history;
+        private readonly TextBox _input;
+        public Form1()
+        {
+            this.InitializeComponent();
+            this.Text = "Yuuna's Debugger Form";
+            this.MaximizeBox = false;
+            this.MinimizeBox = false;
+            this.MaximumSize = new Size( 320, 640);
+            this.Opacity = 0.8;
+            this.DoubleBuffered = true;
+            this.BackColor = Color.White;
+
+            var rx = Screen.PrimaryScreen.WorkingArea; 
+            this.Location = new Point(rx.Width - this.Size.Width, rx.Height - this.Size.Height); 
+            this.StartPosition = FormStartPosition.Manual;
+
+            this.Move += delegate
+            {
+                this.Visible = false;
+                this.Location = new Point(rx.Width - this.Size.Width, rx.Height - this.Size.Height);
+                this.Visible = true;
+            };
+
+
+            _history = new ListBox();
+            _history.Dock = DockStyle.Fill;
+            _history.Enabled = false;
+            _history.BorderStyle = BorderStyle.None;
+            this.Controls.Add(_history);
+
+            _input = new TextBox();
+            _input.Dock = DockStyle.Bottom;
+            _input.KeyDown += (sender, e) => 
+            {
+                if (e.KeyCode == Keys.Enter)
+                {
+                    var req = this._input.Text; 
+                    this._input.Clear();
+
+                    if (string.IsNullOrWhiteSpace(req))
+                        return;
+
+                    this._history.Items.Add("我:  " + req);
+                    var resp = Send(req);
+                    this._history.Items.Add("Bot: " + resp.message);
+                }
+            }; 
+            this.Controls.Add(_input);
+        }
+
+        private static (string mood, string message) Send(string text)
+        {
+            var client = new RestClient("http://localhost:5000/");
+            client.Timeout = 3000;
+            var request = new RestRequest(Method.POST);
+            request.AddHeader("Content-Type", "application/json");
+            request.AddParameter("application/json", "{\n    \"text\": \"" + text + "\"\n}", ParameterType.RequestBody);
+            var response = client.Execute(request);
+            var result = JsonConvert.DeserializeAnonymousType(response.Content, new
+            {
+                Success = default(bool),
+                Message = default(string),
+                Mood = default(string),
+                Text = default(string),
+            });
+            return (result.Mood, result.Message); 
+        }
+    }
+}

+ 23 - 0
src/Yuuna.Interaction.WinForms.Test/Program.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Yuuna.Interaction.WinForms.Test
+{
+    static class Program
+    {
+        /// <summary>
+        ///  The main entry point for the application.
+        /// </summary>
+        [STAThread]
+        static void Main()
+        {
+            Application.SetHighDpiMode(HighDpiMode.SystemAware);
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+            Application.Run(new Form1());
+        }
+    }
+}

+ 14 - 0
src/Yuuna.Interaction.WinForms.Test/Yuuna.Interaction.WinForms.Test.csproj

@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
+
+  <PropertyGroup>
+    <OutputType>WinExe</OutputType>
+    <TargetFramework>netcoreapp3.0</TargetFramework>
+    <UseWindowsForms>true</UseWindowsForms>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
+    <PackageReference Include="RestSharp" Version="106.10.0" />
+  </ItemGroup>
+
+</Project>

+ 25 - 0
src/Yuuna.Interaction.WinForms.Test/Yuuna.Interaction.WinForms.Test.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29503.13
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yuuna.Interaction.WinForms.Test", "Yuuna.Interaction.WinForms.Test.csproj", "{DB5EC76F-8B69-40FC-A15A-4C855F6EA0F7}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{DB5EC76F-8B69-40FC-A15A-4C855F6EA0F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{DB5EC76F-8B69-40FC-A15A-4C855F6EA0F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{DB5EC76F-8B69-40FC-A15A-4C855F6EA0F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{DB5EC76F-8B69-40FC-A15A-4C855F6EA0F7}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {FE45CD9C-618D-4BCC-9F66-7C0B7F214D62}
+	EndGlobalSection
+EndGlobal

+ 28 - 27
src/Yuuna/EntryPoint.cs

@@ -24,35 +24,36 @@ namespace Yuuna
         public static async Task Main(string[] args)
         {
 
-            var canResponses = new Response[]
-            {
-                    (Moods.Sad, "我不清楚你想做什麼 OvQ"),
-                    (Moods.Sad, "我不懂你想幹嘛 QAQ"),
-                    (Moods.Sad, "我不知道你想幹嘛 OHQ"),
-            };
-            var r = new Actor(new JiebaTextSegmenter(), canResponses, default, ModuleManager.Instance.Modules);
+            //var canResponses = new Response[]
+            //{
+            //        (Moods.Sad, "我不清楚你想做什麼 OvQ"),
+            //        (Moods.Sad, "我不懂你想幹嘛 QAQ"),
+            //        (Moods.Sad, "我不知道你想幹嘛 OHQ"),
+            //};
+            //var r = new Actor(new JiebaTextSegmenter(), canResponses, default, ModuleManager.Instance.Modules);
 
-            while (true)
-            {
-                var x = Console.ReadLine();
+            //while (true)
+            //{
+            //    var x = Console.ReadLine();
 
-                if (x.Equals("unload-all"))
-                {
-                    ModuleManager.Instance.UnloadAll();
-                    foreach (var m in ModuleManager.Instance.Modules)
-                        Console.WriteLine(m.Metadata.Name);
-                }
-                else if (x.Equals("reload-all"))
-                {
-                    ModuleManager.Instance.ReloadAll();
-                    foreach (var m in ModuleManager.Instance.Modules)
-                        Console.WriteLine(m.Metadata.Name);
-                }
-                else if (r.Accept(x, out var rx))
-                    Console.WriteLine(rx.Message);
-            }
-            //var k = WebHost.RunAsync(); 
-            //await k;
+            //    if (x.Equals("unload-all"))
+            //    {
+            //        ModuleManager.Instance.UnloadAll();
+            //        foreach (var m in ModuleManager.Instance.Modules)
+            //            Console.WriteLine(m.Metadata.Name);
+            //    }
+            //    else if (x.Equals("reload-all"))
+            //    {
+            //        ModuleManager.Instance.ReloadAll();
+            //        foreach (var m in ModuleManager.Instance.Modules)
+            //            Console.WriteLine(m.Metadata.Name);
+            //    }
+            //    else if (r.Accept(x, out var rx))
+            //        Console.WriteLine(rx.Message);
+            //}
+
+            var k = WebHost.RunAsync();
+            await k;
         }
     }
 }

+ 1 - 2
src/Yuuna/Actor.cs → src/Yuuna/Interaction/Actor.cs

@@ -201,8 +201,7 @@ namespace Yuuna
                     case AlternativeStatus.Optimal:
                         {
                             var single = alternative.Matches[0];
-                            this._moduleProxies.First(x=>x.Id.Equals(single.Pattern.Owner))
-                           .Patterns.TryGet(single.Pattern, out var bag);
+                            this._moduleProxies.First(x=>x.Id.Equals(single.Pattern.Owner)).Patterns.TryGet(single.Pattern, out var bag);
                             var r = bag.Invoke(single);
                             return r;
                         }

+ 3 - 0
src/Yuuna/Yuuna.csproj

@@ -3,6 +3,8 @@
   <PropertyGroup>
     <OutputType>Exe</OutputType>
     <TargetFramework>netcoreapp3.0</TargetFramework>
+    <ApplicationIcon />
+    <StartupObject />
   </PropertyGroup>
 
   <ItemGroup>
@@ -11,6 +13,7 @@
 
   <ItemGroup>
     <Folder Include="Interaction\AspNetCore\Mvc\Views\" />
+    <Folder Include="Interaction\NewFolder\" />
     <Folder Include="Properties\" />
   </ItemGroup>