From 0e0d6f38f46b37007dcdc27f3e23557a1a2afe63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=9A=93=E6=9C=88?= <353374337@qq.com>
Date: Thu, 11 Oct 2018 20:44:17 +0800
Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?=
=?UTF-8?q?=20=E5=A4=87=E4=BB=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitattributes | 63 ++++
Sin365AIProject.sln | 22 ++
Sin365AIProject_01/Function/B_Test1.cs | 28 ++
Sin365AIProject_01/Function/Weather.cs | 35 ++
.../Function/haoyue_Training.cs | 23 ++
Sin365AIProject_01/Program.cs | 338 ++++++++++++++++++
Sin365AIProject_01/Properties/AssemblyInfo.cs | 36 ++
Sin365AIProject_01/Sin365AIProject_01.csproj | 61 ++++
Sin365AIProject_01/Sin365_Attribute.cs | 13 +
Sin365AIProject_01/Speak.cs | 28 ++
10 files changed, 647 insertions(+)
create mode 100644 .gitattributes
create mode 100644 Sin365AIProject.sln
create mode 100644 Sin365AIProject_01/Function/B_Test1.cs
create mode 100644 Sin365AIProject_01/Function/Weather.cs
create mode 100644 Sin365AIProject_01/Function/haoyue_Training.cs
create mode 100644 Sin365AIProject_01/Program.cs
create mode 100644 Sin365AIProject_01/Properties/AssemblyInfo.cs
create mode 100644 Sin365AIProject_01/Sin365AIProject_01.csproj
create mode 100644 Sin365AIProject_01/Sin365_Attribute.cs
create mode 100644 Sin365AIProject_01/Speak.cs
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..1ff0c42
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,63 @@
+###############################################################################
+# Set default behavior to automatically normalize line endings.
+###############################################################################
+* text=auto
+
+###############################################################################
+# Set default behavior for command prompt diff.
+#
+# This is need for earlier builds of msysgit that does not have it on by
+# default for csharp files.
+# Note: This is only used by command line
+###############################################################################
+#*.cs diff=csharp
+
+###############################################################################
+# Set the merge driver for project and solution files
+#
+# Merging from the command prompt will add diff markers to the files if there
+# are conflicts (Merging from VS is not affected by the settings below, in VS
+# the diff markers are never inserted). Diff markers may cause the following
+# file extensions to fail to load in VS. An alternative would be to treat
+# these files as binary and thus will always conflict and require user
+# intervention with every merge. To do so, just uncomment the entries below
+###############################################################################
+#*.sln merge=binary
+#*.csproj merge=binary
+#*.vbproj merge=binary
+#*.vcxproj merge=binary
+#*.vcproj merge=binary
+#*.dbproj merge=binary
+#*.fsproj merge=binary
+#*.lsproj merge=binary
+#*.wixproj merge=binary
+#*.modelproj merge=binary
+#*.sqlproj merge=binary
+#*.wwaproj merge=binary
+
+###############################################################################
+# behavior for image files
+#
+# image files are treated as binary by default.
+###############################################################################
+#*.jpg binary
+#*.png binary
+#*.gif binary
+
+###############################################################################
+# diff behavior for common document formats
+#
+# Convert binary document formats to text before diffing them. This feature
+# is only available from the command line. Turn it on by uncommenting the
+# entries below.
+###############################################################################
+#*.doc diff=astextplain
+#*.DOC diff=astextplain
+#*.docx diff=astextplain
+#*.DOCX diff=astextplain
+#*.dot diff=astextplain
+#*.DOT diff=astextplain
+#*.pdf diff=astextplain
+#*.PDF diff=astextplain
+#*.rtf diff=astextplain
+#*.RTF diff=astextplain
diff --git a/Sin365AIProject.sln b/Sin365AIProject.sln
new file mode 100644
index 0000000..b47fdc1
--- /dev/null
+++ b/Sin365AIProject.sln
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26403.3
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sin365AIProject_01", "Sin365AIProject_01\Sin365AIProject_01.csproj", "{D3DD7363-7667-4183-8C27-4FEDB95757E7}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {D3DD7363-7667-4183-8C27-4FEDB95757E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D3DD7363-7667-4183-8C27-4FEDB95757E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D3DD7363-7667-4183-8C27-4FEDB95757E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D3DD7363-7667-4183-8C27-4FEDB95757E7}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/Sin365AIProject_01/Function/B_Test1.cs b/Sin365AIProject_01/Function/B_Test1.cs
new file mode 100644
index 0000000..38437a9
--- /dev/null
+++ b/Sin365AIProject_01/Function/B_Test1.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Sin365AIProject_01.Function
+{
+ public class B_Test1
+ {
+ //标记类可以被加载
+ public static int HaoYueAI_Class = 1;
+ //static string HaoYueAI_ClassName = "测试类1";
+
+ //可添加任意自己的扩展方法
+ public static string HaoYueAI_FuncName_GetT1 = "简易名称1";
+ public void GetT1()
+ {
+ Console.WriteLine("T1方法调用成功");
+ }
+
+ public static string HaoYueAI_FuncName_GetT2 = "简易名称2";
+ public void GetT2()
+ {
+ Console.WriteLine("T2方法调用成功");
+ }
+
+ }
+}
diff --git a/Sin365AIProject_01/Function/Weather.cs b/Sin365AIProject_01/Function/Weather.cs
new file mode 100644
index 0000000..664a2f1
--- /dev/null
+++ b/Sin365AIProject_01/Function/Weather.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+
+namespace Sin365AIProject_01.Function
+{
+ public class Weather
+ {
+ public static int HaoYueAI_Class = 1;
+
+ //可添加任意自己的扩展方法
+ public static string HaoYueAI_FuncName_GetWeatherForCity = "查询天气,天气";
+ public void GetWeatherForCity(string cityMsg)
+ {
+ Console.WriteLine("天气查询中……");
+
+ //根据根据城市中文名获取天气
+ //string url = "http://apistore.baidu.com/microservice/weather?cityname=北京";
+ string url = "http://apistore.baidu.com/microservice/weather?cityname="+cityMsg;
+ WebRequest wRequest = WebRequest.Create(url);
+ wRequest.Method = "GET";
+ wRequest.ContentType = "text/html;charset=UTF-8";
+ WebResponse wResponse = wRequest.GetResponse();
+ Stream stream = wResponse.GetResponseStream();
+ StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default);
+ string str = reader.ReadToEnd(); //url返回的值
+ reader.Close();
+ wResponse.Close();
+
+ }
+ }
+}
diff --git a/Sin365AIProject_01/Function/haoyue_Training.cs b/Sin365AIProject_01/Function/haoyue_Training.cs
new file mode 100644
index 0000000..5d1aa2e
--- /dev/null
+++ b/Sin365AIProject_01/Function/haoyue_Training.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Sin365AIProject_01.Function
+{
+ public class haoyue_Training
+ {
+ //标记类可以被加载
+ public static int HaoYueAI_Class = 1;
+ //static string HaoYueAI_ClassName = "测试类1";
+
+ //可添加任意自己的扩展方法
+ public static string HaoYueAI_FuncName_GetT1 = "简易名称1";
+
+ //数据增加
+ public void AddDialog(string fristchat,string tochat)
+ {
+
+ }
+ }
+}
diff --git a/Sin365AIProject_01/Program.cs b/Sin365AIProject_01/Program.cs
new file mode 100644
index 0000000..beab4d1
--- /dev/null
+++ b/Sin365AIProject_01/Program.cs
@@ -0,0 +1,338 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using System.Reflection;
+using System.Speech.Synthesis;
+using System.Threading;
+
+namespace Sin365AIProject_01
+{
+ class Program
+ {
+ ///
+ /// 模式
+ ///
+ static AIMode Mode = AIMode.NormalServiceMode;
+
+ static List list = new List();
+ class MyBLL
+ {
+ public string AssemblyName { get; set; }
+ public string ClassFullName { get; set; }
+ public string Method { get; set; }
+ public string SortName { get; set; }
+ public List ParamList { get; set; }
+ }
+
+ class MyParam
+ {
+ //参数的名称
+ public string ParamName { get; set; }
+ //参数的类型
+ public Type ParamType { get; set; }
+ //参数备注
+ public string ParamNote { get; set; }
+ }
+
+ ///
+ ///
+ ///
+ public enum AIMode
+ {
+ NormalServiceMode = 0,
+ CommanderMode = 1
+ };
+
+ static void Main(string[] args)
+ {
+ StartServer();
+ }
+
+ ///
+ /// 启动
+ ///
+ public static void StartServer()
+ {
+ Haoyue_Write("---------------------------");
+ Haoyue_Write("皓月简易智能交互系统");
+ Haoyue_Write("Ver 0.0.1 ");
+ Haoyue_Write("---------------------------");
+ Haoyue_Write("启动中……");
+ Haoyue_Write("功能类库,装载中……");
+ LoadAssembly("Sin365AIProject_01");
+ Haoyue_Write("功能类库装载完毕!");
+ Haoyue_Write("启动完毕!");
+ Haoyue_Write("皓月AI , Online ",true);
+
+ do
+ {
+ //模式选择
+ switch (Mode)
+ {
+ case AIMode.NormalServiceMode:
+ Haoyue_Write("进入-服务模式:");
+ NormalMode();
+ break;
+ case AIMode.CommanderMode:
+ Haoyue_Write("进入-命令行服务模式:");
+ CommanderMode();
+ break;
+ default://如果没有可用状态直接退出
+ return;
+ }
+ } while (true);
+ }
+
+ ///
+ /// 普通模式
+ ///
+ public static void NormalMode()
+ {
+ do
+ {
+ Haoyue_Write("请输入模糊查询的方法名:");
+ var Msg = Console.ReadLine();
+
+ var thisselect = list.Where(w => w.SortName.Contains(Msg)).ToList();
+ if (thisselect.Count < 1)
+ {
+ Haoyue_Write("未知命令!");
+ }
+ else if (thisselect.Count > 1)
+ {
+ Haoyue_Write("您具体要的是哪个功能呢");
+ int index = 1;
+ foreach (var t in thisselect)
+ {
+ Haoyue_Write("[" + index + "]" + t.SortName);
+ index++;
+ }
+ index = GetaInt() - 1;
+ if (index <= thisselect.Count)
+ {
+ RefMainSet(thisselect[index].AssemblyName, thisselect[index].ClassFullName, thisselect[index].Method, new object[] { });
+ }
+ else
+ {
+ Haoyue_Write("错误输入");
+ }
+ }
+ else if (thisselect.Count == 1)
+ {
+ RefMainSet(thisselect[0].AssemblyName, thisselect[0].ClassFullName, thisselect[0].Method, new object[] { });
+ }
+ else
+ {
+ Haoyue_Write("出错");
+ }
+ } while (true);
+ }
+
+ ///
+ /// 命令行模式
+ ///
+ public static void CommanderMode()
+ {
+ do
+ {
+ var Msg = Console.ReadLine();
+ switch (Msg)
+ {
+ case "help":
+ Haoyue_Write("帮助:");
+ break;
+ case "quit":
+ Haoyue_Write("退出命令行模式");
+ break;
+ }
+ } while (true);
+ }
+
+ #region 输入标准化处理
+ public static int GetaInt()
+ {
+ do
+ {
+ Haoyue_Write("请输入数字格式:");
+ var IndexMsg = Console.ReadLine();
+ try
+ {
+ return Convert.ToInt32(IndexMsg);
+ }
+ catch
+ {
+ Haoyue_Write("请确保输入的是数字格式");
+ }
+ } while (true);
+ }
+
+ public static DateTime GetaDate()
+ {
+ do
+ {
+ Haoyue_Write("请输入日期格式格式:如 “2018-08-08” 或者 “2018-08-08 10:10:10”");
+ var IndexMsg = Console.ReadLine();
+ try
+ {
+ return Convert.ToDateTime(IndexMsg);
+ }
+ catch
+ {
+ Haoyue_Write("请确保输入的是日期格式");
+ }
+ } while (true);
+ }
+ #endregion
+
+ public static void Haoyue_Write(string Msg)
+ {
+ string ShowStr = DateTime.Now.ToString("> hh:mm:ss") + " " + Msg;
+ Console.WriteLine(ShowStr, ConsoleColor.DarkGreen);
+ }
+
+ public static void Haoyue_Write(string Msg,bool IsSpeak)
+ {
+ Haoyue_Write(Msg);
+ if (IsSpeak)
+ {
+ Haoyue_WriteWithSpeek(Msg);
+ }
+ }
+
+ //public static void SpeekMsg(string Msg)
+ //{
+ // SpeechSynthesizer sp = new SpeechSynthesizer();
+ // sp.Speak(Msg);
+ //}
+
+ public static void Haoyue_WriteWithSpeek(string Msg)
+ {
+ SpeechSynthesizer sp = new SpeechSynthesizer();
+ sp.SpeakAsync(Msg);
+ }
+
+
+ public static void LoadAssembly(string AssemblyName)
+ {
+ Haoyue_Write("反射扫描-遍历程序集 ["+ AssemblyName+"]");
+ foreach (var i in Assembly.Load(AssemblyName).GetTypes())
+ {
+ Type itype = Assembly.Load(AssemblyName).GetType(i.FullName);
+
+ //实例这个类
+ var iInstance = Assembly.Load(AssemblyName).CreateInstance(i.FullName);
+
+ var pitem = itype.GetMembers();
+ Haoyue_Write("检查 [" + i.FullName + "]");
+ //判断方法下是否有我们约定好的 HaoYueAI_Class 属性
+ MemberInfo[] HaoYueAI_Class = itype.GetMember("HaoYueAI_Class");
+ if (HaoYueAI_Class.Count() > 0)
+ {
+ Haoyue_Write("确认类库 [" + i.FullName + "] 为皓月AI标准类库");
+ //如果有 则装载
+ //MethodInfo[] MethodItem = itype.GetMethods();
+
+
+ //不考虑父级成员
+ MethodInfo[] MethodItem = itype.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
+
+ foreach (var m in MethodItem)
+ {
+ var mtype = itype.GetMember("HaoYueAI_FuncName_" + m.Name);
+ if (mtype.Count() > 0)
+ {
+ Haoyue_Write("确认方法/接口/函数 [" + m.Name + "] 为皓月AI标准功能方法");
+ MyBLL mb = new MyBLL();
+ mb.AssemblyName = AssemblyName;
+ mb.ClassFullName = i.FullName;
+ mb.Method = m.Name;
+ //实例化参数类型存储列表
+ List plist = new List();
+ Haoyue_Write("获取 [" + m.Name + "] 参数");
+ var getplist = m.GetParameters();
+ Haoyue_Write("参数数量:"+getplist.Count());
+ //方法数量标记
+ int pindex = 0;
+ foreach (var gp in getplist)
+ {
+ pindex++;
+ Haoyue_Write("方法 ["+ m.Name+"] 第"+pindex+"个参数");
+ Haoyue_Write("--参数名:" + gp.Name);
+ MyParam p = new MyParam();
+ p.ParamName = gp.Name;
+ Haoyue_Write("--参数类型:" + gp.ParameterType.Name);
+ p.ParamType = gp.ParameterType;
+ Haoyue_Write("--参数说明:" + "");
+ p.ParamNote = "";
+ p.ParamType = gp.ParameterType;
+ plist.Add(p);
+ }
+ mb.ParamList = plist;//参数列表
+ //获取常量
+ var mfield = itype.GetField("HaoYueAI_FuncName_" + m.Name);
+ mb.SortName = mfield.GetValue(iInstance).ToString();
+ Haoyue_Write("并标记 [" + m.Name + "] 的交互简易名称词汇为:"+ mb.SortName);
+ list.Add(mb);
+ }
+ }
+ }
+ }
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ static void RefMainSet(string AssemblyName, string ClassFullName, string MethodName, object[] parameters)
+ {
+ //指定程序集、类名 获取类
+ Type type = Assembly.Load(AssemblyName).GetType(ClassFullName);
+
+ //需要调用的方法名
+ MethodInfo meth = type.GetMethod(MethodName);
+
+ //判断是否是静态方法
+ if (!meth.IsStatic)
+ {//如果不是静态方法
+ RefMainSetUnStatic(meth, type, parameters);
+ }
+ else
+ {//如果是静态方法
+ RefMainSetStatic(meth, type, parameters);
+ }
+ }
+
+ ///
+ /// 调用非静态方法
+ ///
+ ///
+ ///
+ ///
+ static void RefMainSetUnStatic(MethodInfo meth, Type type, object[] parameters)
+ {
+ //调用非静态方法
+ object obj = Activator.CreateInstance(type);
+ //调用参数
+ meth.Invoke(obj, parameters);
+ }
+
+ ///
+ /// 调用静态方法静态方法
+ ///
+ ///
+ ///
+ ///
+ static void RefMainSetStatic(MethodInfo meth, Type type, object[] parameters)
+ {
+ //调用参数
+ meth.Invoke(null, parameters);
+ }
+
+
+ }
+}
diff --git a/Sin365AIProject_01/Properties/AssemblyInfo.cs b/Sin365AIProject_01/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..ab7cc1f
--- /dev/null
+++ b/Sin365AIProject_01/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("Sin365AIProject_01")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Sin365AIProject_01")]
+[assembly: AssemblyCopyright("Copyright © 2017")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+//将 ComVisible 设置为 false 将使此程序集中的类型
+//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("d3dd7363-7667-4183-8c27-4fedb95757e7")]
+
+// 程序集的版本信息由下列四个值组成:
+//
+// 主版本
+// 次版本
+// 生成号
+// 修订号
+//
+//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Sin365AIProject_01/Sin365AIProject_01.csproj b/Sin365AIProject_01/Sin365AIProject_01.csproj
new file mode 100644
index 0000000..c9be536
--- /dev/null
+++ b/Sin365AIProject_01/Sin365AIProject_01.csproj
@@ -0,0 +1,61 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {D3DD7363-7667-4183-8C27-4FEDB95757E7}
+ Exe
+ Properties
+ Sin365AIProject_01
+ Sin365AIProject_01
+ v4.0
+ 512
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Sin365AIProject_01/Sin365_Attribute.cs b/Sin365AIProject_01/Sin365_Attribute.cs
new file mode 100644
index 0000000..03c87a9
--- /dev/null
+++ b/Sin365AIProject_01/Sin365_Attribute.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Sin365AIProject_01
+{
+ class Sin365_Attribute :Attribute
+ {
+ public string my_ClassName { get; set; }
+ public string my_FunctionName { get; set; }
+ }
+}
diff --git a/Sin365AIProject_01/Speak.cs b/Sin365AIProject_01/Speak.cs
new file mode 100644
index 0000000..e4844e6
--- /dev/null
+++ b/Sin365AIProject_01/Speak.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Speech.Synthesis;
+
+namespace Sin365AIProject_01
+{
+ //public class SpeakChatMsgList
+ //{
+ // public string ID { get; set; }
+ // public string ChatMsg { get; set; }
+ //}
+ //public static class Speak
+ //{
+ // public static List SpeakList = new List();
+ // public static void InSpeak()
+ // {
+ // SpeechSynthesizer sp = new SpeechSynthesizer();
+ // while (SpeakList.Count > 0)
+ // {
+ // var one = Speak.SpeakList.FirstOrDefault();
+ // sp.Speak(one.ChatMsg);
+ // SpeakList.Remove(one);
+ // }
+ // }
+ //}
+}