Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
Kivii.Client.ServerEvents.Test
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
示例代码
Kivii.Client.ServerEvents.Test
Commits
f55475c6
Commit
f55475c6
authored
Jul 18, 2019
by
施晓雨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add remark
parent
b24a59d7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
FrmMain.cs
FrmMain.cs
+10
-6
No files found.
FrmMain.cs
View file @
f55475c6
...
@@ -29,12 +29,14 @@ namespace Test
...
@@ -29,12 +29,14 @@ namespace Test
btnConnect
.
Text
=
"连接"
;
btnConnect
.
Text
=
"连接"
;
return
;
return
;
}
}
//连接操作
btnConnect
.
Enabled
=
false
;
btnConnect
.
Enabled
=
false
;
_client
=
new
ServerEventsClient
(
tbxServiceUrl
.
Text
,
"home"
);
_client
=
new
ServerEventsClient
(
tbxServiceUrl
.
Text
,
"home"
);
var
auth
=
new
Authenticate
{
UserName
=
tbxUserName
.
Text
,
Password
=
tbxPassword
.
Text
,
provider
=
"kivii"
};
var
auth
=
new
Authenticate
{
UserName
=
tbxUserName
.
Text
,
Password
=
tbxPassword
.
Text
,
provider
=
"kivii"
};
var
task
=
_client
.
ServiceClient
.
PostAsync
(
auth
);
var
task
=
_client
.
ServiceClient
.
PostAsync
(
auth
);
task
.
Success
(()=>{
task
.
Success
(()=>{
_client
.
OnConnect
=
onConnect
;
//登陆成功后连接ServerEvents,设置事件
_client
.
OnConnect
=
onConnected
;
_client
.
OnCommand
=
onCommand
;
_client
.
OnCommand
=
onCommand
;
_client
.
OnMessage
=
onMessage
;
_client
.
OnMessage
=
onMessage
;
_client
.
OnException
=
onException
;
_client
.
OnException
=
onException
;
...
@@ -49,11 +51,12 @@ namespace Test
...
@@ -49,11 +51,12 @@ namespace Test
},
true
);
},
true
);
}
}
private
void
onConnect
(
ServerEventConnect
connection
)
//连接成功,得到连接相应的信息
private
void
onConnected
(
ServerEventConnect
connection
)
{
{
if
(
InvokeRequired
)
if
(
InvokeRequired
)
{
{
Invoke
(
new
Action
(()
=>
onConnect
(
connection
)));
Invoke
(
new
Action
(()
=>
onConnect
ed
(
connection
)));
return
;
return
;
}
}
btnConnect
.
Enabled
=
true
;
btnConnect
.
Enabled
=
true
;
...
@@ -67,6 +70,7 @@ namespace Test
...
@@ -67,6 +70,7 @@ namespace Test
rtbMessage
.
AppendText
(
$"
{
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
)}
:onConnect
{
connection
.
Json
}{
Environment
.
NewLine
}{
Environment
.
NewLine
}
"
);
rtbMessage
.
AppendText
(
$"
{
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
)}
:onConnect
{
connection
.
Json
}{
Environment
.
NewLine
}{
Environment
.
NewLine
}
"
);
}
}
//得到心跳包
private
void
onHeartbeat
()
private
void
onHeartbeat
()
{
{
if
(
InvokeRequired
)
if
(
InvokeRequired
)
...
@@ -77,7 +81,7 @@ namespace Test
...
@@ -77,7 +81,7 @@ namespace Test
tbxHeartBeatTime
.
BackColor
=
tbxHeartBeatTime
.
BackColor
!=
Color
.
MistyRose
?
Color
.
MistyRose
:
Color
.
YellowGreen
;
tbxHeartBeatTime
.
BackColor
=
tbxHeartBeatTime
.
BackColor
!=
Color
.
MistyRose
?
Color
.
MistyRose
:
Color
.
YellowGreen
;
tbxHeartBeatTime
.
Text
=
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
);
tbxHeartBeatTime
.
Text
=
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
);
}
}
//出现异常
private
void
onException
(
Exception
ex
)
private
void
onException
(
Exception
ex
)
{
{
if
(
InvokeRequired
)
if
(
InvokeRequired
)
...
@@ -87,7 +91,7 @@ namespace Test
...
@@ -87,7 +91,7 @@ namespace Test
}
}
rtbMessage
.
AppendText
(
$"
{
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
)}
:onException
{
ex
.
Message
}{
Environment
.
NewLine
}{
Environment
.
NewLine
}
"
);
rtbMessage
.
AppendText
(
$"
{
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
)}
:onException
{
ex
.
Message
}{
Environment
.
NewLine
}{
Environment
.
NewLine
}
"
);
}
}
//得到消息
private
void
onMessage
(
ServerEventMessage
message
)
private
void
onMessage
(
ServerEventMessage
message
)
{
{
if
(
InvokeRequired
)
if
(
InvokeRequired
)
...
@@ -97,7 +101,7 @@ namespace Test
...
@@ -97,7 +101,7 @@ namespace Test
}
}
rtbMessage
.
AppendText
(
$"
{
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
)}
:onMessage
{
message
.
Json
}{
Environment
.
NewLine
}{
Environment
.
NewLine
}
"
);
rtbMessage
.
AppendText
(
$"
{
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
)}
:onMessage
{
message
.
Json
}{
Environment
.
NewLine
}{
Environment
.
NewLine
}
"
);
}
}
//得到命令
private
void
onCommand
(
ServerEventMessage
command
)
private
void
onCommand
(
ServerEventMessage
command
)
{
{
if
(
InvokeRequired
)
if
(
InvokeRequired
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment