10
10
11
11
namespace Microsoft . Azure . SignalR . Samples . Management
12
12
{
13
- class Program
13
+ public class Program
14
14
{
15
- static void Main ( string [ ] args )
15
+ public static void Main ( string [ ] args )
16
16
{
17
- var app = new CommandLineApplication ( ) ;
18
- app . FullName = "Azure SignalR Management Sample: Message Publisher" ;
17
+ var app = new CommandLineApplication
18
+ {
19
+ FullName = "Azure SignalR Management Sample: Message Publisher"
20
+ } ;
19
21
app . HelpOption ( "--help" ) ;
20
22
app . Description = "Message publisher using Azure SignalR Service Management SDK." ;
21
23
@@ -28,7 +30,7 @@ static void Main(string[] args)
28
30
. Build ( ) ;
29
31
30
32
31
- app . OnExecute ( async ( ) =>
33
+ app . OnExecute ( async ( ) =>
32
34
{
33
35
var connectionString = connectionStringOption . Value ( ) ?? configuration [ "Azure:SignalR:ConnectionString" ] ;
34
36
@@ -82,8 +84,8 @@ private static async Task StartAsync(MessagePublisher publisher)
82
84
83
85
if ( args . Length == 2 && args [ 0 ] . Equals ( "broadcast" ) )
84
86
{
85
- Console . WriteLine ( $ "broadcast message '{ args [ 1 ] } '") ;
86
87
await publisher . SendMessages ( args [ 0 ] , null , args [ 1 ] ) ;
88
+ Console . WriteLine ( $ "broadcast message '{ args [ 1 ] } '") ;
87
89
}
88
90
else if ( args . Length == 4 && args [ 0 ] . Equals ( "send" ) )
89
91
{
@@ -96,10 +98,21 @@ private static async Task StartAsync(MessagePublisher publisher)
96
98
var preposition = args [ 1 ] == "add" ? "to" : "from" ;
97
99
Console . WriteLine ( $ "{ args [ 1 ] } user '{ args [ 2 ] } ' { preposition } group '{ args [ 3 ] } '") ;
98
100
}
101
+ else if ( args . Length == 3 && args [ 0 ] == "close" )
102
+ {
103
+ await publisher . CloseConnection ( args [ 1 ] , args [ 2 ] ) ;
104
+ Console . WriteLine ( $ "Close connection '{ args [ 1 ] } ' because '{ args [ 2 ] } '") ;
105
+ }
106
+ else if ( args . Length == 3 && args [ 0 ] == "checkexist" )
107
+ {
108
+ var exist = await publisher . CheckExist ( args [ 1 ] . ToLowerInvariant ( ) , args [ 2 ] ) ;
109
+ Console . WriteLine ( exist ? $ "{ args [ 1 ] } '{ args [ 2 ] } ' exists." : $ "{ args [ 1 ] } '{ args [ 2 ] } ' does not exist.") ;
110
+ }
99
111
else
100
112
{
101
113
Console . WriteLine ( $ "Can't recognize command { argLine } ") ;
102
114
}
115
+ Console . Write ( "> " ) ;
103
116
}
104
117
}
105
118
finally
@@ -110,16 +123,21 @@ private static async Task StartAsync(MessagePublisher publisher)
110
123
111
124
private static void ShowHelp ( )
112
125
{
113
- Console . WriteLine (
114
- "*********Usage*********\n " +
115
- "send user <User Id> <Message>\n " +
116
- "send users <User Id List (Seperated by ',')> <Message>\n " +
117
- "send group <Group Name> <Message>\n " +
118
- "send groups <Group List (Seperated by ',')> <Message>\n " +
119
- "usergroup add <User Id> <Group Name>\n " +
120
- "usergroup remove <User Id> <Group Name>\n " +
121
- "broadcast <Message>\n " +
122
- "***********************" ) ;
126
+ Console . Write (
127
+ @"*********Usage*********
128
+ send user <User Id> <Message>
129
+ send users <User Id List (Seperated by ',')> <Message>
130
+ send group <Group Name> <Message>
131
+ send groups <Group List (Seperated by ',')> <Message>
132
+ usergroup add <User Id> <Group Name>
133
+ usergroup remove <User Id> <Group Name>
134
+ broadcast <Message>
135
+ close <Connection ID> <Reason>
136
+ checkexist connection <Connection ID>
137
+ checkexist user <User ID>
138
+ checkexist group <Group Name>
139
+ ***********************
140
+ > " ) ;
123
141
}
124
142
125
143
private static void MissOptions ( )
0 commit comments