Skip to content

Commit 1f985a2

Browse files
committed
2.0.0B4
文档和小bug
1 parent 22d65cb commit 1f985a2

33 files changed

Lines changed: 747 additions & 369 deletions

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
![ico](./ColoryrWork.png)
33

44
2.0.0版本正在进行中
5-
2.0.0B2已完成
65

76
一个多功能服务器/应用框架
87

@@ -27,9 +26,7 @@
2726

2827
[部署&启动](./doc/run.md)
2928

30-
[目录文件说明](./doc/dir.md)
31-
32-
[配置文件说明](./doc/config.md)
29+
[目录结构与文件信息](./doc/config.md)
3330

3431
[业务代码编写](./doc/code.md)
3532
```

doc/builder.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77

88
连接服务器后得到下面的窗口,在这里可以进行服务器业务代码的编写
99

10-
![图片](pic_code/builder.png)
10+
![图片](pic/pic1.png)
1111

12-
在编辑器选择接口选项卡,右键添加一个接口(在文档里面我用test为UUID)
12+
在编辑器选择接口选项卡,右键添加一个接口
13+
内容是软路由地址
1314

14-
![图片](pic_code/builder1.png)
15+
![图片](pic/pic2.png)
1516

1617
右键接口编辑即可修改代码
1718

18-
![图片](pic_code/builder2.png)
19+
![图片](pic/pic7.png)
1920

20-
其他都相同
21+
其他类型基本都相同
22+
`网页``class`类型在修改代码后需要点击更新才能保存代码更改
2123

2224
如果你不想用自带的代码编辑器,可以用其他编辑器打开`CodeTemp`文件夹

doc/code.md

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,69 @@
11
# ColoryrServer
2-
32
## 业务代码编写
43
[返回](../README.md)
54

6-
默认的账户密码均为`Admin`
5+
**默认的账户密码均为`Admin`**
6+
7+
[接口代码编写](./code/http.md)
8+
9+
[类代码编写](./code/class.md)
10+
11+
[Socket代码编写](./code/socket.md)
12+
13+
[机器人代码编写](./code/robot.md)
14+
15+
[WebSocket代码编写](./code/websocket.md)
16+
17+
[Mqtt代码编写](./code/mqtt.md)
18+
19+
[Task代码编写](./code/task.md)
20+
21+
[网页代码编写](./code/web.md)
22+
23+
## 软路由
24+
25+
`接口``网页`类型需要注意软路由路径
26+
例如你的UUID设置为`WebApi/test`,则访问地址为
27+
```
28+
{服务器基地址}/WebApi/test
29+
```
30+
31+
## 服务器SDK
32+
33+
服务器提供了一些重复使用的方法[ColoryrSDK](../src/ColoryrServer/Core/SDK/ColoryrSDK.cs)
34+
35+
数据库包装方法[DatabaseSDK](../src/ColoryrServer/Core/SDK/DatabaseSDK.cs)
36+
37+
HttpClient包装方法[HtmlSDK](../src/ColoryrServer/Core/SDK/HtmlSDK.cs)
38+
39+
Mqtt包装方法[MqttSDK](../src/ColoryrServer/Core/SDK/MqttSDK.cs)
40+
41+
机器人数据包[RobotSDK](../src/ColoryrServer/Core/SDK/RobotSDK.cs)
42+
43+
任务包装方法[TaskSDK](../src/ColoryrServer/Core/SDK/TaskSDK.cs)
44+
45+
Web资源包装方法[WebHtmlSDK](../src/ColoryrServer/Core/SDK/WebHtmlSDK.cs)
46+
47+
## Vue项目构建
48+
Vue项目构建会执行指令
49+
```
50+
$ npm run build
51+
```
52+
因此需要nodejs运行环境,并且配置好环境变量才能正常编译
53+
54+
`node_modules`需要手动准备
55+
在文件夹`ColoryrServer/Codes/Static`下有一个`node_modules`文件夹,里面装的是Vue编译需要的库
56+
57+
如果你只使用框架自带的Vue项目
58+
按照下面步骤做即可
59+
1. 安装nodejs配置环境变量
60+
2. 新建一个Vue项目
61+
3. 在Vue项目文件夹下打开命令行输入
62+
```
63+
$ npm i
64+
```
65+
4. 结束后剪切`node_modules`文件夹到`ColoryrServer/Codes/Static`中去
766

8-
## [接口代码编写](http.md)
67+
注意:如果你使用自己的Vue项目要配置好路径
68+
例如你的`网页项目`的UUID为`Web/test`,则需要在`vite.config.ts`或其他配置文件设置输出路径为`./Web/test/`
69+
如果不设置会无法正确找到文件

doc/code/class.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ColoryrServer
2+
3+
## 类代码编写
4+
[返回](code.md)
5+
6+
默认的类代码
7+
8+
```C#
9+
using ColoryrServer.SDK;
10+
11+
[DLLIN]
12+
public class test
13+
{
14+
public test()
15+
{
16+
17+
}
18+
19+
public string getString(string data)
20+
{
21+
return data + "test";
22+
}
23+
}
24+
```
25+
26+
每个类代码**至少有一个类必须**带有[ColoryrServer.SDK.DLLIN](../../src/ColoryrServer/Core/SDK/NotesSDK.cs#L21)的属性
27+
28+
类代码没有太多限制,也支持多文件
29+
只要注意类名不要冲突即可

doc/code/http.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# ColoryrServer
2+
3+
## 接口代码编写
4+
[返回](code.md)
5+
6+
默认的接口代码
7+
```C#
8+
using ColoryrServer.SDK;
9+
10+
[DLLIN(true)]//true则报错输出至网页
11+
public class app_FD578CDE687FD183ED8E321C7A1ACEC25BDAF9CF
12+
{
13+
[NotesSDK("一个接口", new string[1]{ "输入" }, new string[1]{ "输出" })]
14+
public dynamic Main(HttpDllRequest http)
15+
{
16+
return "true";
17+
}
18+
}
19+
```
20+
21+
该代码中包含一个[接口类](#接口类)和一个[接口函数](#接口函数)
22+
23+
## 接口函数
24+
一个标准的接口函数
25+
[接口类](#接口类)中,所有的`public`函数都为接口函数
26+
```C#
27+
[NotesSDK("一个接口", new string[1]{ "输入" }, new string[1]{ "输出" })]
28+
public dynamic Main(HttpDllRequest http)
29+
{
30+
return "true";
31+
}
32+
```
33+
接口函数输入的参数**必须**[ColoryrServer.SDK.HttpDllRequest](../../src/ColoryrServer/Core/SDK/WebApiSDK.cs#L8)
34+
并且**必须**带有[ColoryrServer.SDK.NotesSDK](../../src/ColoryrServer/Core/SDK/NotesSDK.cs#L6)的属性
35+
36+
## 接口类
37+
**必须**带有[ColoryrServer.SDK.DLLIN](../../src/ColoryrServer/Core/SDK/NotesSDK.cs#L21)的属性
38+
`DLLIN`中可以设置报错是否输出到网页中去
39+
40+
一个接口类**必须**包含名字为`Main`[接口函数](#接口函数)
41+
不是叫`Main`[接口函数](#接口函数)都为识别为[子接口](#子接口)
42+
43+
接口类**必须**`public`否则将无法调用
44+
45+
接口类的请求地址为
46+
```
47+
http://{服务器基地址}/{UUID}
48+
```
49+
例如你的接口UUID为`WebApi/test`,默认配置文件的情况下,则默认的URL地址为
50+
```
51+
http://127.0.0.1/WebApi/test
52+
```
53+
54+
## 子接口
55+
一个接口类里面可以有多个子接口
56+
子接口的请求地址为
57+
```
58+
http://{服务器基地址}/{UUID}/{name}
59+
```
60+
例如下面的代码
61+
```C#
62+
using ColoryrServer.SDK;
63+
64+
[DLLIN(true)]
65+
public class app_FD578CDE687FD183ED8E321C7A1ACEC25BDAF9CF
66+
{
67+
[NotesSDK("主接口", new string[1]{ "输入" }, new string[1]{ "输出" })]
68+
public dynamic Main(HttpDllRequest http)
69+
{
70+
return "true";
71+
}
72+
[NotesSDK("子接口", new string[1]{ "输入" }, new string[1]{ "输出" })]
73+
public dynamic push(HttpDllRequest http)
74+
{
75+
return "ok";
76+
}
77+
}
78+
```
79+
请求
80+
```
81+
http://127.0.0.1:25555/WebApi/test
82+
```
83+
后返回的数据为
84+
```
85+
test
86+
```
87+
请求
88+
```
89+
http://127.0.0.1:25555/WebApi/test/push
90+
```
91+
后返回的数据为
92+
```
93+
ok
94+
```
95+
96+
### 接口请求参数
97+
接口函数传入的对象为[ColoryrServer.SDK.HttpDllRequest](../../src/ColoryrServer/Core/SDK/WebApiSDK.cs#L8)
98+
```C#
99+
public class HttpDllRequest
100+
{
101+
/// <summary>
102+
/// 请求参数
103+
/// </summary>
104+
public Dictionary<string, dynamic> Parameter { get; init; }
105+
/// <summary>
106+
/// 请求头
107+
/// </summary>
108+
public NameValueCollection RowRequest { get; init; }
109+
/// <summary>
110+
/// Cookie
111+
/// </summary>
112+
public Dictionary<string, List<string>> Cookie { get; init; }
113+
/// <summary>
114+
/// 请求体类型
115+
/// </summary>
116+
public MyContentType ContentType { get; init; }
117+
/// <summary>
118+
/// 请求体流
119+
/// </summary>
120+
public Stream Stream { get; init; }
121+
/// <summary>
122+
/// 请求方法
123+
/// </summary>
124+
public string Method { get; init; }
125+
126+
/// <summary>
127+
/// 获取请求数据
128+
/// </summary>
129+
/// <param name="arg">参数名</param>
130+
/// <returns>返回</returns>
131+
public dynamic Get(string arg)
132+
=> Parameter.ContainsKey(arg) ? Parameter[arg] : null;
133+
}
134+
```
135+
### 接口返回类型
136+
接口可以返回的类型可以是
137+
- string
138+
- Dictionary<string, object>
139+
- [ColoryrServer.SDK.HttpResponseString](../../src/ColoryrServer/Core/SDK/WebApiSDK.cs#L68)
140+
- [ColoryrServer.SDK.HttpResponseDictionary](../../src/ColoryrServer/Core/SDK/WebApiSDK.cs#L90)
141+
- [ColoryrServer.SDK.HttpResponseStream](../../src/ColoryrServer/Core/SDK/WebApiSDK.cs#L123)
142+
- [ColoryrServer.SDK.HttpResponseBytes](../../src/ColoryrServer/Core/SDK/WebApiSDK.cs#L139)
143+
144+
其他返回类型均会报错
145+

doc/code/mqtt.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ColoryrServer
2+
3+
## Mqtt代码编写
4+
[返回](code.md)
5+
6+
默认的Mqtt代码
7+
8+
```C#
9+
using ColoryrServer.SDK;
10+
11+
[DLLIN]
12+
public class test
13+
{
14+
public bool OnMessage(DllMqttMessage head)
15+
{
16+
return false; //true表示事件已处理完毕
17+
}
18+
public bool OnMessageLoading(DllMqttLoadingRetainedMessages head)
19+
{
20+
return false;
21+
}
22+
public bool OnValidator(DllMqttConnectionValidator head)
23+
{
24+
return false;
25+
}
26+
public bool OnSubscription(DllMqttSubscription head)
27+
{
28+
return false;
29+
}
30+
public bool OnUnsubscription(DllMqttUnsubscription head)
31+
{
32+
return false;
33+
}
34+
}
35+
```
36+
37+
**必须**带有[ColoryrServer.SDK.DLLIN](../../src/ColoryrServer/Core/SDK/NotesSDK.cs#L21)的属性
38+
39+
- `OnMessage`表示收到消息
40+
- `OnMessageLoading`表示消息正在加载
41+
- `OnValidator`表示有客户端正在验证链接
42+
- `OnSubscription`表示有客户端正在订阅频道
43+
- `OnUnsubscription`表示有客户端正在取消订阅频道
44+
45+
返回如果为true,则这个事件不会传到下个Dll中去

doc/code/robot.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ColoryrServer
2+
3+
## 机器人代码编写
4+
[返回](code.md)
5+
6+
默认的机器人代码
7+
8+
```C#
9+
using ColoryrServer.SDK;
10+
11+
[DLLIN]
12+
public class test
13+
{
14+
public bool OnMessage(RobotMessage head)
15+
{
16+
return false; //true表示事件已处理完毕
17+
}
18+
public bool OnMessagSend(RobotSend head)
19+
{
20+
return false;
21+
}
22+
public bool OnRobotEvent(RobotEvent head)
23+
{
24+
return false;
25+
}
26+
}
27+
```
28+
29+
**必须**带有[ColoryrServer.SDK.DLLIN](../../src/ColoryrServer/Core/SDK/NotesSDK.cs#L21)的属性
30+
31+
- `OnMessage`表示收到消息
32+
- `OnMessagSend`表示机器人发送消息后
33+
- `OnRobotEvent`表示收到其他事件后,需要在服务器配置中添加
34+
35+
返回如果为true,则这个事件不会传到下个Dll中去

0 commit comments

Comments
 (0)