From 35e986a077df52ec485a4e8a858fb542105546bf Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 26 Feb 2019 08:15:56 -0500 Subject: [PATCH] update libs and remove old code/workarounds --- src/Core/Core.csproj | 6 ++--- .../NotificationHubPushNotificationService.cs | 21 ++++----------- .../NotificationHubPushRegistrationService.cs | 27 +++++-------------- src/Icons/Icons.csproj | 2 +- src/Icons/Services/IconFetchingService.cs | 4 +-- src/Notifications/Notifications.csproj | 2 +- 6 files changed, 19 insertions(+), 43 deletions(-) diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index e3df1ade5..a556c8fed 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -14,14 +14,14 @@ - + - + @@ -39,7 +39,7 @@ - + diff --git a/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs b/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs index 0b3355bde..c4e3ffe5f 100644 --- a/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs +++ b/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs @@ -16,7 +16,6 @@ namespace Bit.Core.Services private readonly IHttpContextAccessor _httpContextAccessor; private NotificationHubClient _client = null; - private DateTime? _clientExpires = null; public NotificationHubPushNotificationService( GlobalSettings globalSettings, @@ -24,6 +23,9 @@ namespace Bit.Core.Services { _globalSettings = globalSettings; _httpContextAccessor = httpContextAccessor; + _client = NotificationHubClient.CreateClientFromConnectionString( + _globalSettings.NotificationHub.ConnectionString, + _globalSettings.NotificationHub.HubName); } public async Task PushSyncCipherCreateAsync(Cipher cipher, IEnumerable collectionIds) @@ -175,25 +177,12 @@ namespace Bit.Core.Services private async Task SendPayloadAsync(string tag, PushType type, object payload) { - await RenewClientAndExecuteAsync(async client => await client.SendTemplateNotificationAsync( + await _client.SendTemplateNotificationAsync( new Dictionary { { "type", ((byte)type).ToString() }, { "payload", JsonConvert.SerializeObject(payload) } - }, tag)); - } - - private async Task RenewClientAndExecuteAsync(Func task) - { - var now = DateTime.UtcNow; - if(_client == null || !_clientExpires.HasValue || _clientExpires.Value < now) - { - _clientExpires = now.Add(TimeSpan.FromMinutes(30)); - _client = NotificationHubClient.CreateClientFromConnectionString( - _globalSettings.NotificationHub.ConnectionString, - _globalSettings.NotificationHub.HubName); - } - await task(_client); + }, tag); } } } diff --git a/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs b/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs index f13220764..65a5405a3 100644 --- a/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs +++ b/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs @@ -12,12 +12,14 @@ namespace Bit.Core.Services private readonly GlobalSettings _globalSettings; private NotificationHubClient _client = null; - private DateTime? _clientExpires = null; public NotificationHubPushRegistrationService( GlobalSettings globalSettings) { _globalSettings = globalSettings; + _client = NotificationHubClient.CreateClientFromConnectionString( + _globalSettings.NotificationHub.ConnectionString, + _globalSettings.NotificationHub.HubName); } public async Task CreateOrUpdateRegistrationAsync(string pushToken, string deviceId, string userId, @@ -53,7 +55,7 @@ namespace Bit.Core.Services messageTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\"}," + "\"notification\":{\"title\":\"$(title)\",\"body\":\"$(message)\"}}}"; - installation.Platform = NotificationPlatform.Gcm; + installation.Platform = NotificationPlatform.Fcm; break; case DeviceType.iOS: payloadTemplate = "{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}," + @@ -80,8 +82,7 @@ namespace Bit.Core.Services BuildInstallationTemplate(installation, "badgeMessage", badgeMessageTemplate ?? messageTemplate, userId, identifier); - await RenewClientAndExecuteAsync(async client => - await client.CreateOrUpdateInstallationAsync(installation)); + await _client.CreateOrUpdateInstallationAsync(installation); } private void BuildInstallationTemplate(Installation installation, string templateId, string templateBody, @@ -116,7 +117,7 @@ namespace Bit.Core.Services { try { - await RenewClientAndExecuteAsync(async client => await client.DeleteInstallationAsync(deviceId)); + await _client.DeleteInstallationAsync(deviceId); } catch(Exception e) { @@ -165,8 +166,7 @@ namespace Bit.Core.Services { try { - await RenewClientAndExecuteAsync(async client => - await client.PatchInstallationAsync(id, new List { operation })); + await _client.PatchInstallationAsync(id, new List { operation }); } catch(Exception e) { @@ -177,18 +177,5 @@ namespace Bit.Core.Services } } } - - private async Task RenewClientAndExecuteAsync(Func task) - { - var now = DateTime.UtcNow; - if(_client == null || !_clientExpires.HasValue || _clientExpires.Value < now) - { - _clientExpires = now.Add(TimeSpan.FromMinutes(30)); - _client = NotificationHubClient.CreateClientFromConnectionString( - _globalSettings.NotificationHub.ConnectionString, - _globalSettings.NotificationHub.HubName); - } - await task(_client); - } } } diff --git a/src/Icons/Icons.csproj b/src/Icons/Icons.csproj index 19e226d3b..1d26846fb 100644 --- a/src/Icons/Icons.csproj +++ b/src/Icons/Icons.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/Icons/Services/IconFetchingService.cs b/src/Icons/Services/IconFetchingService.cs index c23407903..3edda71e1 100644 --- a/src/Icons/Services/IconFetchingService.cs +++ b/src/Icons/Services/IconFetchingService.cs @@ -6,10 +6,10 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Bit.Icons.Models; -using AngleSharp.Parser.Html; using Microsoft.Extensions.Logging; using System.Text.RegularExpressions; using System.Text; +using AngleSharp.Html.Parser; namespace Bit.Icons.Services { @@ -116,7 +116,7 @@ namespace Bit.Icons.Services var parser = new HtmlParser(); using(response) using(var htmlStream = await response.Content.ReadAsStreamAsync()) - using(var document = await parser.ParseAsync(htmlStream)) + using(var document = await parser.ParseDocumentAsync(htmlStream)) { uri = response.RequestMessage.RequestUri; if(document.DocumentElement == null) diff --git a/src/Notifications/Notifications.csproj b/src/Notifications/Notifications.csproj index b6b404607..af89f0a47 100644 --- a/src/Notifications/Notifications.csproj +++ b/src/Notifications/Notifications.csproj @@ -10,7 +10,7 @@ - +