Skip to content

Commit 7efbbbb

Browse files
authored
Merge pull request #91 from LM-Development/dev/fix-code-smells
Fixing a bunch of code smells
2 parents 19f5948 + f05d518 commit 7efbbbb

File tree

21 files changed

+61
-52
lines changed

21 files changed

+61
-52
lines changed

Samples/PublicSamples/RecordingBot/deploy/teams-recording-bot/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ type: application
1616
# This is the chart version. This version number should be incremented each time you make changes
1717
# to the chart and its templates, including the app version.
1818
# Versions are expected to follow Semantic Versioning (https://semver.org/)
19-
version: 1.4.5
19+
version: 1.4.6
2020

2121
# This is the version number of the application being deployed. This version number should be
2222
# incremented each time you make changes to the application. Versions are not expected to
2323
# follow Semantic Versioning. They should reflect the version the application is using.
24-
appVersion: 1.3.4
24+
appVersion: 1.3.5
2525

2626
dependencies:
2727
- name: ingress-nginx

Samples/PublicSamples/RecordingBot/src/RecordingBot.Model/Extension/HttpRequestExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public static class HttpRequestExtensions
1212

1313
public static Uri GetUri(this HttpRequest request)
1414
{
15-
ArgumentNullException.ThrowIfNull(request, nameof(request));
16-
ArgumentException.ThrowIfNullOrWhiteSpace(request.Scheme, nameof(request.Scheme));
15+
ArgumentNullException.ThrowIfNull(request);
16+
ArgumentException.ThrowIfNullOrWhiteSpace(request.Scheme);
1717

1818
return new Uri(GetUrl(request));
1919
}

Samples/PublicSamples/RecordingBot/src/RecordingBot.Model/Models/JoinURLResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace RecordingBot.Model.Models
55
{
6-
public partial class JoinURLResponse
6+
public partial class JoinUrlResponse
77
{
88
[JsonProperty("callId")]
99
public object CallId { get; set; }

Samples/PublicSamples/RecordingBot/src/RecordingBot.Services/Authentication/AuthenticationProvider.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,6 @@ public async Task<RequestValidationResult> ValidateInboundRequestAsync(HttpReque
129129
JwtSecurityTokenHandler handler = new();
130130
claimsPrincipal = handler.ValidateToken(token, validationParameters, out _);
131131
}
132-
133-
// Token expired... should somehow return 401 (Unauthorized)
134-
// catch (SecurityTokenExpiredException ex)
135-
// Tampered token
136-
// catch (SecurityTokenInvalidSignatureException ex)
137-
// Some other validation error
138-
// catch (SecurityTokenValidationException ex)
139132
catch (Exception ex)
140133
{
141134
// Some other error

Samples/PublicSamples/RecordingBot/src/RecordingBot.Services/Authentication/UserPasswordAuthenticationProvider.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@
66
using System.Diagnostics;
77
using System.Net.Http;
88
using System.Net.Http.Headers;
9+
using System.Security.Authentication;
910
using System.Threading.Tasks;
1011

1112
namespace RecordingBot.Services.Authentication
1213
{
1314
public class UserPasswordAuthenticationProvider : ObjectRoot, IRequestAuthenticationProvider
1415
{
15-
private readonly string _appName;
1616
private readonly string _appId;
1717
private readonly string _appSecret;
1818
private readonly string _userName;
1919
private readonly string _password;
2020

21-
public UserPasswordAuthenticationProvider(string appName, string appId, string appSecret, string userName, string password, IGraphLogger logger)
21+
public UserPasswordAuthenticationProvider(string appId, string appSecret, string userName, string password, IGraphLogger logger)
2222
: base(logger.NotNull(nameof(logger)).CreateShim(nameof(UserPasswordAuthenticationProvider)))
2323
{
24-
_appName = appName.NotNullOrWhitespace(nameof(appName));
2524
_appId = appId.NotNullOrWhitespace(nameof(appId));
2625
_appSecret = appSecret.NotNullOrWhitespace(nameof(appSecret));
2726

@@ -30,16 +29,16 @@ public UserPasswordAuthenticationProvider(string appName, string appId, string a
3029
}
3130

3231
/// <inheritdoc />
33-
public async Task AuthenticateOutboundRequestAsync(HttpRequestMessage request, string tenantId)
32+
public async Task AuthenticateOutboundRequestAsync(HttpRequestMessage request, string tenant)
3433
{
35-
Debug.Assert(!string.IsNullOrWhiteSpace(tenantId), $"Invalid {nameof(tenantId)}.");
34+
Debug.Assert(!string.IsNullOrWhiteSpace(tenant), $"Invalid {nameof(tenant)}.");
3635

3736
const string BearerPrefix = "Bearer";
3837
const string ReplaceString = "{tenant}";
3938
const string TokenAuthorityMicrosoft = "https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token";
4039
const string Resource = @"https://graph.microsoft.com/.default";
4140

42-
var tokenLink = TokenAuthorityMicrosoft.Replace(ReplaceString, tenantId);
41+
var tokenLink = TokenAuthorityMicrosoft.Replace(ReplaceString, tenant);
4342
OAuthResponse authResult = null;
4443

4544
try
@@ -57,7 +56,7 @@ public async Task AuthenticateOutboundRequestAsync(HttpRequestMessage request, s
5756

5857
if (!result.IsSuccessStatusCode)
5958
{
60-
throw new Exception("Failed to generate user token.");
59+
throw new AuthenticationException("Failed to generate user token.");
6160
}
6261

6362
var content = await result.Content.ReadAsStringAsync().ConfigureAwait(false);
@@ -81,10 +80,11 @@ public Task<RequestValidationResult> ValidateInboundRequestAsync(HttpRequestMess
8180
throw new NotImplementedException();
8281
}
8382

84-
private class OAuthResponse
83+
[Serializable]
84+
private sealed class OAuthResponse
8585
{
86-
public string Access_Token { get; set; }
87-
public int Expires_In { get; set; }
86+
public string Access_Token { get; }
87+
public int Expires_In { get; }
8888
}
8989
}
9090
}

Samples/PublicSamples/RecordingBot/src/RecordingBot.Services/Bot/CallHandler.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,10 @@ private async void CallOnUpdated(ICall sender, ResourceEventArgs<Call> e)
115115
// Event - Recording update e.g established/updated/start/ended
116116
_eventPublisher.Publish($"Call{e.NewResource.State}", $"Call.ID {Call.Id} Sender.Id {sender.Id} status updated to {e.NewResource.State} - {e.NewResource.ResultInfo?.Message}");
117117

118-
if (e.OldResource.State != e.NewResource.State && e.NewResource.State == CallState.Established)
118+
if (e.OldResource.State != e.NewResource.State && e.NewResource.State == CallState.Established && !_isDisposed)
119119
{
120-
if (!_isDisposed)
121-
{
122-
// Call is established. We should start receiving Audio, we can inform clients that we have started recording.
123-
OnRecordingStatusFlip(sender);
124-
}
120+
// Call is established. We should start receiving Audio, we can inform clients that we have started recording.
121+
OnRecordingStatusFlip(sender);
125122
}
126123

127124
if ((e.OldResource.State == CallState.Established) && (e.NewResource.State == CallState.Terminated))
@@ -184,12 +181,9 @@ private void UpdateParticipants(ICollection<IParticipant> eventArgs, bool added
184181
{
185182
json = UpdateParticipant(BotMediaStream.participants, participant, added, participantDetails.DisplayName);
186183
}
187-
else if (participant.Resource.Info.Identity.AdditionalData?.Count > 0)
184+
else if (participant.Resource.Info.Identity.AdditionalData?.Count > 0 && CheckParticipantIsUsable(participant))
188185
{
189-
if (CheckParticipantIsUsable(participant))
190-
{
191-
json = UpdateParticipant(BotMediaStream.participants, participant, added);
192-
}
186+
json = UpdateParticipant(BotMediaStream.participants, participant, added);
193187
}
194188

195189
if (json.Length > 0)

Samples/PublicSamples/RecordingBot/src/RecordingBot.Services/Bot/HeartbeatHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public abstract class HeartbeatHandler : ObjectRootDisposable
1010
{
1111
private readonly Timer _heartbeatTimer;
1212

13-
public HeartbeatHandler(TimeSpan frequency, IGraphLogger logger)
13+
protected HeartbeatHandler(TimeSpan frequency, IGraphLogger logger)
1414
: base(logger)
1515
{
1616
// initialize the timer

Samples/PublicSamples/RecordingBot/src/RecordingBot.Services/Contract/IEventPublisher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ namespace RecordingBot.Services.Contract
22
{
33
public interface IEventPublisher
44
{
5-
void Publish(string Subject, string Message, string TopicName = "");
5+
void Publish(string subject, string message, string topicName = "");
66
}
77
}

Samples/PublicSamples/RecordingBot/src/RecordingBot.Services/Contract/IMediaStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace RecordingBot.Services.Contract
77
{
88
public interface IMediaStream
99
{
10-
Task AppendAudioBuffer(AudioMediaBuffer buffer, List<IParticipant> participant);
10+
Task AppendAudioBuffer(AudioMediaBuffer buffer, List<IParticipant> participants);
1111
Task End();
1212
}
1313
}

Samples/PublicSamples/RecordingBot/src/RecordingBot.Services/Http/Controllers/DemoController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using RecordingBot.Services.ServiceSetup;
66
using System;
77
using System.Collections.Generic;
8+
using System.Linq;
89
using System.Threading.Tasks;
910

1011
namespace RecordingBot.Services.Http.Controllers
@@ -37,9 +38,8 @@ public IActionResult OnGetCalls()
3738
_eventPublisher.Publish("GetCalls", "Getting calls");
3839

3940
List<Dictionary<string, string>> calls = [];
40-
foreach (var callHandler in _botService.CallHandlers.Values)
41+
foreach (var call in _botService.CallHandlers.Values.Select(handler => handler.Call))
4142
{
42-
var call = callHandler.Call;
4343
var callPath = "/" + HttpRouteConstants.CALL_ROUTE.Replace("{callLegId}", call.Id);
4444
var callUri = new Uri(_settings.CallControlBaseUrl, callPath).AbsoluteUri;
4545
var values = new Dictionary<string, string>

0 commit comments

Comments
 (0)