Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit fad3361

Browse files
committed
Code quality review (Codacy)
1 parent 0beb1aa commit fad3361

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

Toastify/src/Core/Broadcaster/ToastifyBroadcaster.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public async Task StopAsync()
122122

123123
private async Task SendCommand(string command, params string[] args)
124124
{
125-
if (await this.EnsureConnection())
125+
if (await this.EnsureConnection().ConfigureAwait(false))
126126
{
127127
string argsString = string.Empty;
128128
if (args != null && args.Length > 0)
@@ -131,14 +131,14 @@ private async Task SendCommand(string command, params string[] args)
131131
byte[] bytes = Encoding.UTF8.GetBytes($"{command}{argsString}");
132132

133133
// Wait until the previous message has been sent: only one outstanding send operation is allowed!
134-
await this.SendChannelAvailable();
134+
await this.SendChannelAvailable().ConfigureAwait(false);
135135

136136
if (this.socket != null && this.socket.State == WebSocketState.Open)
137137
{
138138
try
139139
{
140140
this.isSending = true;
141-
await this.socket.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Text, true, CancellationToken.None);
141+
await this.socket.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Text, true, CancellationToken.None).ConfigureAwait(false);
142142
}
143143
finally
144144
{
@@ -152,22 +152,22 @@ private async void ReceiveMessageLoop()
152152
{
153153
try
154154
{
155-
if (!await this.EnsureConnection())
155+
if (!await this.EnsureConnection().ConfigureAwait(false))
156156
{
157157
logger.Error("Couldn't establish a connection to the local WebSocket.");
158158
return;
159159
}
160160

161161
// Wait until the previous message has been received: only one outstanding receive operation is allowed!
162-
await this.ReceiveChannelAvailable();
162+
await this.ReceiveChannelAvailable().ConfigureAwait(false);
163163

164164
this.isReceiving = true;
165165
var buffer = new byte[4 * 1024];
166-
WebSocketReceiveResult receiveResult = await this.socket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
166+
WebSocketReceiveResult receiveResult = await this.socket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None).ConfigureAwait(false);
167167
this.isReceiving = false;
168168

169169
string message = string.Empty;
170-
while (!receiveResult.CloseStatus.HasValue && await this.EnsureConnection())
170+
while (!receiveResult.CloseStatus.HasValue && await this.EnsureConnection().ConfigureAwait(false))
171171
{
172172
if (receiveResult.MessageType == WebSocketMessageType.Text)
173173
{
@@ -181,16 +181,16 @@ private async void ReceiveMessageLoop()
181181
else
182182
message = string.Empty;
183183

184-
if (await this.EnsureConnection())
184+
if (await this.EnsureConnection().ConfigureAwait(false))
185185
{
186-
await this.ReceiveChannelAvailable();
186+
await this.ReceiveChannelAvailable().ConfigureAwait(false);
187187
this.isReceiving = true;
188-
receiveResult = await this.socket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
188+
receiveResult = await this.socket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None).ConfigureAwait(false);
189189
this.isReceiving = false;
190190
}
191191
}
192192

193-
await this.socket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None);
193+
await this.socket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).ConfigureAwait(false);
194194
}
195195
catch (Exception e)
196196
{

Toastify/src/Core/Broadcaster/ToastifyWebSocketHostStartup.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,18 @@ private async Task HandleClients(string message, WebSocket clientWebSocket)
133133

134134
public override void ConfigureServices(IServiceCollection services)
135135
{
136+
// Nothing to configure
136137
}
137138

138139
protected override async Task ConfigureWebSocketRequestPipeline(HttpContext context, Func<Task> next, WebSocket webSocket)
139140
{
140141
switch (context.Request.Path)
141142
{
142-
case InternalPath:
143+
case var s when s == InternalPath:
143144
await this.WebSocketLoop(context, webSocket, this.HandleInternal).ConfigureAwait(false);
144145
break;
145146

146-
case ClientsPath:
147+
case var s when s == ClientsPath:
147148
await this.WebSocketLoop(context, webSocket, this.HandleClients).ConfigureAwait(false);
148149
break;
149150

@@ -160,10 +161,10 @@ protected override bool ShouldAcceptConnection(HttpContext context, WebSocket we
160161

161162
switch (context.Request.Path)
162163
{
163-
case InternalPath:
164+
case var s when s == InternalPath:
164165
return this.toastifyBroadcasterSocket == null || this.toastifyBroadcasterSocket == webSocket;
165166

166-
case ClientsPath:
167+
case var s when s == ClientsPath:
167168
return true;
168169

169170
default:
@@ -177,11 +178,11 @@ protected override void OnWebSocketConnected(HttpContext context, WebSocket webS
177178

178179
switch (context.Request.Path)
179180
{
180-
case InternalPath:
181+
case var s when s == InternalPath:
181182
this.toastifyBroadcasterSocket = webSocket;
182183
break;
183184

184-
case ClientsPath:
185+
case var s when s == ClientsPath:
185186
int i = Array.FindIndex(this.clients.ToArray(), w => w == webSocket);
186187
if (i < 0)
187188
{
@@ -210,12 +211,12 @@ protected override void OnWebSocketClosed(HttpContext context, WebSocket webSock
210211

211212
switch (context.Request.Path)
212213
{
213-
case InternalPath:
214+
case var s when s == InternalPath:
214215
if (this.toastifyBroadcasterSocket == webSocket)
215216
this.toastifyBroadcasterSocket = null;
216217
break;
217218

218-
case ClientsPath:
219+
case var s when s == ClientsPath:
219220
int i = Array.FindIndex(this.clients.ToArray(), w => w == webSocket);
220221
if (i >= 0)
221222
this.clients.RemoveAt(i);

ToastifyAPI.Tests/Logic/MouseHookHotkeyVisitorTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public IAction Action
128128
public MouseAction? MouseButton
129129
{
130130
get { return MouseAction.XButton1; }
131-
set { }
131+
set { var _ = value; }
132132
}
133133

134134
#endregion

0 commit comments

Comments
 (0)