Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
guo450212436
et
提交
13556c20
E
et
项目概览
guo450212436
/
et
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
et
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
13556c20
编写于
3月 23, 2018
作者:
T
tanghai
提交者:
GitHub
3月 23, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #50 from Yinmany/master
1. 让Http处理方法,支持async。
上级
0a6ff515
0144740d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
74 addition
and
39 deletion
+74
-39
Server/App/Program.cs
Server/App/Program.cs
+1
-1
Server/Hotfix/Module/Http/HttpTest.cs
Server/Hotfix/Module/Http/HttpTest.cs
+20
-12
Server/Model/Entity/Http.cs
Server/Model/Entity/Http.cs
+6
-4
Server/Model/Module/Http/HttpComponent.cs
Server/Model/Module/Http/HttpComponent.cs
+23
-18
Server/Model/Module/Http/HttpHandlerAttribute.cs
Server/Model/Module/Http/HttpHandlerAttribute.cs
+3
-3
Server/Model/Module/Http/IHttpHandler.cs
Server/Model/Module/Http/IHttpHandler.cs
+21
-1
未找到文件。
Server/App/Program.cs
浏览文件 @
13556c20
...
...
@@ -105,7 +105,7 @@ namespace App
Game
.
Scene
.
AddComponent
<
ConfigComponent
>();
Game
.
Scene
.
AddComponent
<
ServerFrameComponent
>();
Game
.
Scene
.
AddComponent
<
ActorManagerComponent
>();
//Game.Scene.AddComponent<HttpComponent>();
//
Game.Scene.AddComponent<HttpComponent>();
break
;
case
AppType
.
Benchmark
:
Game
.
Scene
.
AddComponent
<
NetOuterComponent
>();
...
...
Server/Hotfix/Module/Http/HttpTest.cs
浏览文件 @
13556c20
using
System.Net
;
using
ETModel
;
using
System.Threading.Tasks
;
namespace
ETHotfix
{
public
class
AccountInfo
{
public
string
name
;
public
string
pwd
;
}
[
HttpHandler
(
AppType
.
Gate
,
"/"
)]
public
class
HttpTest
:
AHttpHandler
public
class
HttpTest
:
AHttpHandler
{
[
Get
]
// url-> /Login?name=11&age=1111
public
string
Login
(
string
name
,
int
age
,
HttpListenerRequest
req
,
HttpListenerResponse
resp
)
...
...
@@ -23,6 +18,7 @@ namespace ETHotfix
[
Get
(
"t"
)]
// url-> /t
public
int
Test
()
{
System
.
Console
.
WriteLine
(
""
);
return
1
;
}
...
...
@@ -38,12 +34,24 @@ namespace ETHotfix
return
1
;
}
[
Post
]
public
object
Test3
(
HttpListenerResponse
resp
,
HttpListenerRequest
req
,
string
postBody
,
AccountInfo
accountInfo
)
[
Get
]
// url-> /GetRechargeRecord
public
async
Task
<
HttpResult
>
GetRechargeRecord
(
long
id
)
{
Log
.
Info
(
postBody
);
Log
.
Info
(
JsonHelper
.
ToJson
(
accountInfo
));
return
new
{
name
=
"1111"
};
// var db = Game.Scene.GetComponent<DBProxyComponent>();
// var info = await db.Query<RechargeRecord>(id);
await
Task
.
Delay
(
1000
);
// 用于测试
object
info
=
null
;
if
(
info
!=
null
)
{
return
Ok
(
data
:
info
);
}
else
{
return
Error
(
"ID不存在!"
);
}
}
}
}
\ No newline at end of file
Server/Model/Entity/Http.cs
浏览文件 @
13556c20
...
...
@@ -8,11 +8,11 @@
// 充值数量
public
int
CardNumber
{
get
;
set
;
}
// 充值时间
public
long
Time
{
get
;
set
;
}
public
RechargeRecord
(
long
id
):
base
(
id
)
public
RechargeRecord
(
long
id
)
:
base
(
id
)
{
}
}
...
...
@@ -21,10 +21,10 @@
public
sealed
class
Recharge
:
Entity
{
public
int
CardNumber
{
get
;
set
;
}
public
long
UpdateTime
{
get
;
set
;
}
public
Recharge
(
long
id
):
base
(
id
)
public
Recharge
(
long
id
)
:
base
(
id
)
{
}
}
...
...
@@ -34,6 +34,8 @@
public
int
code
;
public
bool
status
;
public
string
msg
=
""
;
[
MongoDB
.
Bson
.
Serialization
.
Attributes
.
BsonIgnoreIfNull
]
public
object
data
;
}
public
static
class
HttpErrorCode
...
...
Server/Model/Module/Http/HttpComponent.cs
浏览文件 @
13556c20
...
...
@@ -3,11 +3,12 @@ using System.Collections.Generic;
using
System.IO
;
using
System.Net
;
using
System.Reflection
;
using
System.Threading.Tasks
;
namespace
ETModel
{
[
ObjectSystem
]
public
class
HttpComponentComponentAwakeSystem
:
AwakeSystem
<
HttpComponent
>
public
class
HttpComponentComponentAwakeSystem
:
AwakeSystem
<
HttpComponent
>
{
public
override
void
Awake
(
HttpComponent
self
)
{
...
...
@@ -16,7 +17,7 @@ namespace ETModel
}
[
ObjectSystem
]
public
class
HttpComponentComponentLoadSystem
:
LoadSystem
<
HttpComponent
>
public
class
HttpComponentComponentLoadSystem
:
LoadSystem
<
HttpComponent
>
{
public
override
void
Load
(
HttpComponent
self
)
{
...
...
@@ -36,7 +37,7 @@ namespace ETModel
/// <summary>
/// http请求分发器
/// </summary>
public
class
HttpComponent
:
Component
public
class
HttpComponent
:
Component
{
public
AppType
appType
;
public
HttpListener
listener
;
...
...
@@ -76,7 +77,7 @@ namespace ETModel
continue
;
}
HttpHandlerAttribute
httpHandlerAttribute
=
(
HttpHandlerAttribute
)
attrs
[
0
];
HttpHandlerAttribute
httpHandlerAttribute
=
(
HttpHandlerAttribute
)
attrs
[
0
];
if
(!
httpHandlerAttribute
.
AppType
.
Is
(
this
.
appType
))
{
continue
;
...
...
@@ -136,7 +137,7 @@ namespace ETModel
object
[]
getAttrs
=
method
.
GetCustomAttributes
(
typeof
(
GetAttribute
),
false
);
if
(
getAttrs
.
Length
!=
0
)
{
GetAttribute
get
=
(
GetAttribute
)
getAttrs
[
0
];
GetAttribute
get
=
(
GetAttribute
)
getAttrs
[
0
];
string
path
=
method
.
Name
;
if
(!
string
.
IsNullOrEmpty
(
get
.
Path
))
...
...
@@ -152,7 +153,7 @@ namespace ETModel
if
(
postAttrs
.
Length
!=
0
)
{
// Post处理方法
PostAttribute
post
=
(
PostAttribute
)
postAttrs
[
0
];
PostAttribute
post
=
(
PostAttribute
)
postAttrs
[
0
];
string
path
=
method
.
Name
;
if
(!
string
.
IsNullOrEmpty
(
post
.
Path
))
...
...
@@ -183,7 +184,7 @@ namespace ETModel
}
HttpListenerContext
context
=
await
this
.
listener
.
GetContextAsync
();
InvokeHandler
(
context
);
await
InvokeHandler
(
context
);
context
.
Response
.
Close
();
}
}
...
...
@@ -192,7 +193,7 @@ namespace ETModel
/// 调用处理方法
/// </summary>
/// <param name="context"></param>
private
void
InvokeHandler
(
HttpListenerContext
context
)
private
async
Task
InvokeHandler
(
HttpListenerContext
context
)
{
context
.
Response
.
StatusCode
=
404
;
...
...
@@ -231,21 +232,25 @@ namespace ETModel
// 自动把返回值,以json方式响应。
object
resp
=
methodInfo
.
Invoke
(
httpHandler
,
args
);
if
(
resp
==
null
)
object
result
=
resp
;
if
(
resp
is
Task
t
)
{
return
;
await
t
;
result
=
t
.
GetType
().
GetProperty
(
"Result"
).
GetValue
(
t
,
null
);
}
using
(
StreamWriter
sw
=
new
StreamWriter
(
context
.
Response
.
OutputStream
)
)
if
(
result
!=
null
)
{
if
(
resp
is
string
)
{
sw
.
Write
(
resp
.
ToString
());
}
else
using
(
StreamWriter
sw
=
new
StreamWriter
(
context
.
Response
.
OutputStream
))
{
sw
.
Write
(
JsonHelper
.
ToJson
(
resp
));
if
(
result
.
GetType
()
==
typeof
(
string
))
{
sw
.
Write
(
result
.
ToString
());
}
else
{
sw
.
Write
(
JsonHelper
.
ToJson
(
result
));
}
}
}
}
...
...
Server/Model/Module/Http/HttpHandlerAttribute.cs
浏览文件 @
13556c20
...
...
@@ -2,7 +2,7 @@
namespace
ETModel
{
public
class
HttpHandlerAttribute
:
Attribute
public
class
HttpHandlerAttribute
:
Attribute
{
public
AppType
AppType
{
get
;
}
...
...
@@ -16,7 +16,7 @@ namespace ETModel
}
[
AttributeUsage
(
AttributeTargets
.
Method
,
AllowMultiple
=
true
,
Inherited
=
false
)]
public
class
GetAttribute
:
Attribute
public
class
GetAttribute
:
Attribute
{
public
string
Path
{
get
;
}
...
...
@@ -31,7 +31,7 @@ namespace ETModel
}
[
AttributeUsage
(
AttributeTargets
.
Method
,
AllowMultiple
=
true
,
Inherited
=
false
)]
public
class
PostAttribute
:
Attribute
public
class
PostAttribute
:
Attribute
{
public
string
Path
{
get
;
}
...
...
Server/Model/Module/Http/IHttpHandler.cs
浏览文件 @
13556c20
...
...
@@ -7,10 +7,30 @@ namespace ETModel
void
Handle
(
HttpListenerContext
context
);
}
public
abstract
class
AHttpHandler
:
IHttpHandler
public
abstract
class
AHttpHandler
:
IHttpHandler
{
public
virtual
void
Handle
(
HttpListenerContext
context
)
{
}
public
virtual
HttpResult
Ok
(
string
msg
=
""
,
object
data
=
null
)
{
return
new
HttpResult
{
code
=
HttpErrorCode
.
Success
,
msg
=
msg
,
status
=
true
,
data
=
data
};
}
public
virtual
HttpResult
Error
(
string
msg
=
""
)
{
return
new
HttpResult
{
code
=
HttpErrorCode
.
Exception
,
msg
=
msg
,
status
=
false
};
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录