Skip to content

Commit e27dec1

Browse files
Massive improvements.
1 parent 8ded56a commit e27dec1

File tree

11 files changed

+39
-65
lines changed

11 files changed

+39
-65
lines changed

sdk/Notifo.SDK.FirebasePlugin/Notifo.SDK.FirebasePlugin.csproj

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,13 @@
77
<RootNamespace>Notifo.SDK.FirebasePlugin</RootNamespace>
88
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
10-
</PropertyGroup>
11-
12-
<ItemGroup>
13-
<None Include="logo-squared.png" Pack="true" PackagePath="\" />
14-
</ItemGroup>
15-
16-
<PropertyGroup>
17-
<CodeAnalysisRuleSet>..\..\Notifo.ruleset</CodeAnalysisRuleSet>
1810
<AssemblyName>Notifo.Xamarin.FirebasePlugin</AssemblyName>
19-
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
11+
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
12+
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
2013
</PropertyGroup>
2114

2215
<ItemGroup>
23-
<AdditionalFiles Include="..\..\stylecop.json" Link="stylecop.json" />
16+
<None Include="logo-squared.png" Pack="true" PackagePath="\" />
2417
</ItemGroup>
2518

2619
<ItemGroup>
@@ -46,15 +39,8 @@
4639
</ItemGroup>
4740

4841
<ItemGroup>
42+
<PackageReference Include="Notifo.SDK" Version="1.0.0" />
4943
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
50-
<PackageReference Include="RefactoringEssentials" Version="5.6.0">
51-
<PrivateAssets>all</PrivateAssets>
52-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
53-
</PackageReference>
54-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
55-
<PrivateAssets>all</PrivateAssets>
56-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
57-
</PackageReference>
5844
<PackageReference Include="Xamarin.Firebase.iOS.CloudMessaging" Version="8.10.0.1" />
5945
<PackageReference Include="Xamarin.Firebase.iOS.Core" Version="8.10.0.1" />
6046
<PackageReference Include="Xamarin.Firebase.iOS.Installations" Version="8.10.0.1" />

sdk/Notifo.SDK.FirebasePlugin/NotifoPushNotificationHandler.android.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override void OnReceived(IDictionary<string, object> parameters)
2929
{
3030
Log.Debug(Strings.ReceivedNotification, parameters);
3131

32-
var notification = new NotificationDto()
32+
var notification = new UserNotificationDto()
3333
.FromDictionary(new Dictionary<string, object>(parameters));
3434

3535
if (notification.Silent)
@@ -48,7 +48,7 @@ public override void OnReceived(IDictionary<string, object> parameters)
4848

4949
public override void OnBuildNotification(NotificationCompat.Builder notificationBuilder, IDictionary<string, object> parameters)
5050
{
51-
var notification = new NotificationDto()
51+
var notification = new UserNotificationDto()
5252
.FromDictionary(new Dictionary<string, object>(parameters));
5353

5454
notifoMobilePush.OnBuildNotification(notificationBuilder, notification);

sdk/Notifo.SDK.FirebasePlugin/PluginEventsProvider.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
using System;
99
using System.Collections.Generic;
10+
using Notifo.SDK;
11+
using Notifo.SDK.Extensions;
1012
using Notifo.SDK.PushEventProvider;
1113
using Plugin.FirebasePushNotification;
1214

@@ -45,7 +47,9 @@ private void FirebasePushNotification_OnNotificationReceived(object source, Fire
4547
return;
4648
}
4749

48-
var args = new NotificationEventArgs(new Dictionary<string, object>(e.Data));
50+
var args = new NotificationEventArgs(
51+
new UserNotificationDto().FromDictionary(new Dictionary<string, object>(e.Data)));
52+
4953
OnNotificationReceivedEvent(args);
5054
}
5155

@@ -61,7 +65,9 @@ private void FirebasePushNotification_OnNotificationOpened(object source, Fireba
6165
return;
6266
}
6367

64-
var args = new NotificationEventArgs(new Dictionary<string, object>(e.Data));
68+
var args = new NotificationEventArgs(
69+
new UserNotificationDto().FromDictionary(new Dictionary<string, object>(e.Data)));
70+
6571
OnNotificationOpenedEvent(args);
6672
}
6773

sdk/Notifo.SDK/CommandQueue/DefaultCommandQueue.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Collections.Concurrent;
1010
using System.Collections.Generic;
1111
using System.Linq;
12+
using System.Threading;
1213
using System.Threading.Tasks;
1314

1415
namespace Notifo.SDK.CommandQueue
@@ -18,19 +19,21 @@ internal sealed class DefaultCommandQueue : ICommandQueue
1819
private readonly ICommandStore commandStore;
1920
private readonly ICommandTrigger[] commandTriggers;
2021
private readonly int maxRetries;
22+
private readonly TimeSpan timeout;
2123
private readonly Task task;
2224
private readonly BlockingCollection<QueuedCommand> queue = new BlockingCollection<QueuedCommand>();
2325
private readonly Queue<QueuedCommand> retryQueue = new Queue<QueuedCommand>();
2426

2527
public DefaultCommandQueue(
2628
ICommandStore commandStore,
2729
ICommandTrigger[] commandTriggers,
28-
int maxRetries)
30+
int maxRetries,
31+
TimeSpan timeout)
2932
{
3033
this.commandStore = commandStore;
3134
this.commandTriggers = commandTriggers;
3235
this.maxRetries = maxRetries;
33-
36+
this.timeout = timeout;
3437
foreach (var trigger in commandTriggers)
3538
{
3639
trigger.Start(this);
@@ -105,7 +108,10 @@ private async Task RunAsync()
105108
{
106109
try
107110
{
108-
await enqueued.Command.ExecuteAsync();
111+
using (var cts = new CancellationTokenSource(timeout))
112+
{
113+
await enqueued.Command.ExecuteAsync(cts.Token);
114+
}
109115

110116
// We have completed the command successfully, so we can remove it here.
111117
await commandStore.RemoveAsync(enqueued.CommandId);

sdk/Notifo.SDK/CommandQueue/ICommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
// All rights reserved. Licensed under the MIT license.
66
// ==========================================================================
77

8+
using System.Threading;
89
using System.Threading.Tasks;
910

1011
namespace Notifo.SDK.CommandQueue
1112
{
1213
internal interface ICommand
1314
{
14-
ValueTask ExecuteAsync();
15+
ValueTask ExecuteAsync(
16+
CancellationToken ct);
1517

1618
bool Merge(ICommand other);
1719
}

sdk/Notifo.SDK/INotifoStartup.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// All rights reserved. Licensed under the MIT license.
66
// ==========================================================================
77

8-
using Notifo.SDK.NotifoMobilePush;
9-
108
namespace Notifo.SDK
119
{
1210
/// <summary>

sdk/Notifo.SDK/NotifoIO.shared.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static INotifoMobilePush SetupNotifoMobilePush()
4141
new TriggerPeriodically(TimeSpan.FromMinutes(10), CrossConnectivity.Current),
4242
new TriggerWhenConnected(CrossConnectivity.Current)
4343
},
44-
10);
44+
10, TimeSpan.FromSeconds(5));
4545

4646
return new NotifoMobilePushImplementation(HttpClientFactory, settings, commandQueue);
4747
}

sdk/Notifo.SDK/NotifoMobilePush/TokenRegisterCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// ==========================================================================
77

88
using System;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011
using Notifo.SDK.CommandQueue;
1112
using Notifo.SDK.Resources;
@@ -20,7 +21,8 @@ internal sealed class TokenRegisterCommand : ICommand
2021

2122
public string Token { get; set; }
2223

23-
public async ValueTask ExecuteAsync()
24+
public async ValueTask ExecuteAsync(
25+
CancellationToken ct)
2426
{
2527
refreshCount++;
2628

@@ -45,7 +47,7 @@ public async ValueTask ExecuteAsync()
4547
request.DeviceType = MobileDeviceType.IOS;
4648
}
4749

48-
await NotifoIO.Current.MobilePush.PostMyTokenAsync(request);
50+
await NotifoIO.Current.MobilePush.PostMyTokenAsync(request, ct);
4951
}
5052
catch (Exception ex)
5153
{

sdk/Notifo.SDK/NotifoMobilePush/TokenUnregisterCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// All rights reserved. Licensed under the MIT license.
66
// ==========================================================================
77

8+
using System.Threading;
89
using System.Threading.Tasks;
910
using Notifo.SDK.CommandQueue;
1011

@@ -14,9 +15,10 @@ internal sealed class TokenUnregisterCommand : ICommand
1415
{
1516
public string Token { get; set; }
1617

17-
public async ValueTask ExecuteAsync()
18+
public async ValueTask ExecuteAsync(
19+
CancellationToken ct)
1820
{
19-
await NotifoIO.Current.MobilePush.DeleteMyTokenAsync(Token);
21+
await NotifoIO.Current.MobilePush.DeleteMyTokenAsync(Token, ct);
2022
}
2123

2224
public bool Merge(ICommand other)

sdk/Notifo.SDK/NotifoMobilePush/TrackSeenCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using System;
99
using System.Collections.Generic;
10+
using System.Threading;
1011
using System.Threading.Tasks;
1112
using Notifo.SDK.CommandQueue;
1213
using Notifo.SDK.Resources;
@@ -20,7 +21,8 @@ internal sealed class TrackSeenCommand : ICommand
2021

2122
public string Token { get; set; }
2223

23-
public async ValueTask ExecuteAsync()
24+
public async ValueTask ExecuteAsync(
25+
CancellationToken ct)
2426
{
2527
try
2628
{
@@ -30,7 +32,7 @@ public async ValueTask ExecuteAsync()
3032
DeviceIdentifier = Token
3133
};
3234

33-
await NotifoIO.Current.Notifications.ConfirmMeAsync(trackUserNotificationDto);
35+
await NotifoIO.Current.Notifications.ConfirmMeAsync(trackUserNotificationDto, ct);
3436
}
3537
catch (Exception ex)
3638
{

0 commit comments

Comments
 (0)