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
6019ca53
Commit
6019ca53
authored
Jan 14, 2024
by
施晓雨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
up
parent
59547644
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
13 deletions
+17
-13
FrmMain.Designer.cs
FrmMain.Designer.cs
+0
-0
FrmMain.cs
FrmMain.cs
+12
-10
Kivii.Client.ServerEvent.Test.csproj
Kivii.Client.ServerEvent.Test.csproj
+3
-2
packages.config
packages.config
+2
-1
No files found.
FrmMain.Designer.cs
View file @
6019ca53
This diff is collapsed.
Click to expand it.
FrmMain.cs
View file @
6019ca53
...
@@ -32,23 +32,23 @@ namespace Test
...
@@ -32,23 +32,23 @@ namespace Test
//连接操作
//连接操作
btnConnect
.
Enabled
=
false
;
btnConnect
.
Enabled
=
false
;
_client
=
new
ServerEventsClient
(
tbxServiceUrl
.
Text
);
_client
=
new
ServerEventsClient
(
tbxServiceUrl
.
Text
);
_client
.
OnConnect
=
onConnected
;
_client
.
OnConnect
=
onConnected
;
//连接成功
_client
.
OnCommand
=
onCommand
;
_client
.
OnCommand
=
onCommand
;
//收到命令
_client
.
OnMessage
=
onMessage
;
_client
.
OnMessage
=
onMessage
;
//收到消息
_client
.
OnException
=
onException
;
_client
.
OnException
=
onException
;
//发生异常
_client
.
OnHeartbeat
=
onHeartbeat
;
_client
.
OnHeartbeat
=
onHeartbeat
;
//心跳
_client
.
Handlers
[
"test"
]
=
testHandler
;
_client
.
Handlers
[
"test"
]
=
testHandler
;
_client
.
Channels
=
tbxConnectChannels
.
Text
.
Split
(
new
char
[
1
]
{
','
},
StringSplitOptions
.
RemoveEmptyEntries
);
//如果用户名为空,匿名连接
//如果用户名为空,匿名连接
if
(
tbxUserName
.
Text
.
IsNullOrEmpty
())
if
(
tbxUserName
.
Text
.
IsNullOrEmpty
())
{
{
_client
.
Connect
();
_client
.
Connect
();
return
;
return
;
}
}
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
);
//_client.ServiceClient.PostAsync(auth);
var
task
=
_client
.
AuthenticateAsync
(
auth
);
//等同于_client.ServiceClient.PostAsync
task
.
Success
((
res
)=>{
task
.
Success
((
res
)=>{
tbxAuthSessionId
.
Text
=
res
.
SessionId
;
//登陆成功后连接ServerEvents,设置事件
//登陆成功后连接ServerEvents,设置事件
_client
.
Connect
();
_client
.
Connect
();
},
true
);
},
true
);
...
@@ -83,7 +83,7 @@ namespace Test
...
@@ -83,7 +83,7 @@ namespace Test
tbxSubscriptionId
.
Text
=
connection
.
SubscriptionId
;
tbxSubscriptionId
.
Text
=
connection
.
SubscriptionId
;
tbxSessionId
.
Text
=
connection
.
SessionId
;
tbxSessionId
.
Text
=
connection
.
SessionId
;
tbxChannels
.
Text
=
connection
.
Channels
?.
Join
(
","
);
tbxChannels
.
Text
=
connection
.
Channels
?.
Join
(
","
);
tbxUserId
.
Text
=
connection
.
UserId
;
tbxConnectedTime
.
Text
=
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
);
tbxConnectedTime
.
Text
=
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
);
tbxConnectedTime
.
BackColor
=
tbxConnectedTime
.
BackColor
!=
Color
.
MistyRose
?
Color
.
MistyRose
:
Color
.
YellowGreen
;
tbxConnectedTime
.
BackColor
=
tbxConnectedTime
.
BackColor
!=
Color
.
MistyRose
?
Color
.
MistyRose
:
Color
.
YellowGreen
;
...
@@ -157,6 +157,7 @@ namespace Test
...
@@ -157,6 +157,7 @@ namespace Test
btnRemoveChannel
.
Enabled
=
false
;
btnRemoveChannel
.
Enabled
=
false
;
var
task
=
_client
.
UnsubscribeFromChannelsAsync
(
tbxUpdateChannel
.
Text
.
Split
(
new
char
[
1
]
{
','
},
StringSplitOptions
.
RemoveEmptyEntries
));
var
task
=
_client
.
UnsubscribeFromChannelsAsync
(
tbxUpdateChannel
.
Text
.
Split
(
new
char
[
1
]
{
','
},
StringSplitOptions
.
RemoveEmptyEntries
));
task
.
Success
(()=>{
task
.
Success
(()=>{
tbxChannels
.
Text
=
_client
.
Channels
.
Join
(
","
);
btnRemoveChannel
.
Enabled
=
true
;
btnRemoveChannel
.
Enabled
=
true
;
});
});
task
.
Error
((
ex
)=>
{
task
.
Error
((
ex
)=>
{
...
@@ -172,6 +173,7 @@ namespace Test
...
@@ -172,6 +173,7 @@ namespace Test
btnAddChannel
.
Enabled
=
false
;
btnAddChannel
.
Enabled
=
false
;
var
task
=
_client
.
SubscribeToChannelsAsync
(
tbxUpdateChannel
.
Text
.
Split
(
new
char
[
1
]
{
','
},
StringSplitOptions
.
RemoveEmptyEntries
));
var
task
=
_client
.
SubscribeToChannelsAsync
(
tbxUpdateChannel
.
Text
.
Split
(
new
char
[
1
]
{
','
},
StringSplitOptions
.
RemoveEmptyEntries
));
task
.
Success
(()
=>
{
task
.
Success
(()
=>
{
tbxChannels
.
Text
=
_client
.
Channels
.
Join
(
","
);
btnAddChannel
.
Enabled
=
true
;
btnAddChannel
.
Enabled
=
true
;
});
});
task
.
Error
((
ex
)
=>
{
task
.
Error
((
ex
)
=>
{
...
...
Kivii.Client.ServerEvent.Test.csproj
View file @
6019ca53
...
@@ -32,8 +32,9 @@
...
@@ -32,8 +32,9 @@
<WarningLevel>
4
</WarningLevel>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<Reference
Include=
"Kivii.Common.V4.5, Version=5.6.2022.8200, Culture=neutral, processorArchitecture=MSIL"
>
<Reference
Include=
"Kivii.Common.V4.5, Version=5.6.2024.1140, Culture=neutral, processorArchitecture=MSIL"
>
<HintPath>
packages\Kivii.Common.5.6.2022.8200\lib\net45\Kivii.Common.V4.5.dll
</HintPath>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
..\..\localhost\net45\app\Kivii.Common.V4.5.dll
</HintPath>
</Reference>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Core"
/>
...
...
packages.config
View file @
6019ca53
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
packages
>
<
package
id
=
"Kivii.Common"
version
=
"5.6.202
2.820
0"
targetFramework
=
"net45"
/>
<
package
id
=
"Kivii.Common"
version
=
"5.6.202
4.114
0"
targetFramework
=
"net45"
/>
</
packages
>
</
packages
>
\ No newline at end of file
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