|
|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|