-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from bnotech/feature/net8.0
Feature/net8.0
- Loading branch information
Showing
24 changed files
with
505 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Matomo.Maui.Services.Core; | ||
using Matomo.Maui.Services.Shell; | ||
using Matomo.Maui.Services.Storage; | ||
|
||
namespace Matomo.Maui; | ||
|
||
/// <summary> | ||
/// <see cref="MauiAppBuilder"/> Extensions | ||
/// </summary> | ||
public static class AppBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Initializes the Matomo Analytics Client | ||
/// </summary> | ||
/// <param name="builder"><see cref="MauiAppBuilder"/> generated by <see cref="MauiApp"/> </param> | ||
/// <returns><see cref="MauiAppBuilder"/> initialized for <see cref="Matomo.Maui"/></returns> | ||
public static MauiAppBuilder UseMatomo(this MauiAppBuilder builder) | ||
{ | ||
builder | ||
.Services | ||
.AddTransient<IShellHelper, ShellHelper>() | ||
.AddSingleton<ISimpleStorage, SimpleStorage>() | ||
.AddSingleton<IMatomoAnalytics, MatomoAnalytics>(); | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System.Collections.Specialized; | ||
using Newtonsoft.Json; | ||
using Matomo.Maui.Services.Storage; | ||
|
||
namespace Matomo.Maui.Buffers; | ||
|
||
public class ActionBuffer | ||
{ | ||
private readonly string _baseParameters; | ||
private readonly List<string> _inbox; | ||
private readonly List<string> _outbox; | ||
private readonly ISimpleStorage _storage; | ||
|
||
public ActionBuffer(NameValueCollection baseParameters, ISimpleStorage storage) | ||
{ | ||
_baseParameters = $"?rec=1&apiv=1&{baseParameters}&"; | ||
_inbox = []; | ||
_outbox = []; | ||
_storage = storage; | ||
|
||
_inbox = storage.Get("actions_inbox", new List<string>()); | ||
_outbox = storage.Get("actions_outbox", new List<string>()); | ||
} | ||
|
||
public int Count | ||
{ | ||
get | ||
{ | ||
if (_inbox != null && _outbox != null) return _inbox.Count + _outbox.Count; | ||
return 0; | ||
} | ||
} | ||
|
||
public void Add(NameValueCollection parameters) | ||
{ | ||
if (OptOut) | ||
return; | ||
|
||
lock (_inbox) | ||
{ | ||
_inbox.Add(_baseParameters + parameters); | ||
_storage.Put("actions_inbox", _inbox); | ||
} | ||
} | ||
|
||
public string CreateOutbox() | ||
{ | ||
lock (_outbox) lock (_inbox) | ||
{ | ||
_outbox.AddRange(_inbox); | ||
if (_outbox.Count == 0) | ||
return ""; | ||
|
||
_inbox.Clear(); | ||
_storage.Put("actions_inbox", _inbox); | ||
_storage.Put("actions_outbox", _outbox); | ||
} | ||
|
||
var data = new Dictionary<string, object>(); | ||
data["requests"] = _outbox; | ||
return JsonConvert.SerializeObject(data); | ||
} | ||
|
||
public void ClearOutbox() | ||
{ | ||
lock (_outbox) | ||
{ | ||
_outbox.Clear(); | ||
_storage.Put("actions_outbox", _outbox); | ||
} | ||
} | ||
|
||
public void Clear() | ||
{ | ||
lock (_outbox) // NOTE we atain a lock for both objects before clearing. | ||
lock (_inbox) | ||
{ | ||
_inbox.Clear(); | ||
_outbox.Clear(); | ||
_storage.Put("actions_inbox", _inbox); | ||
_storage.Put("actions_outbox", _outbox); | ||
} | ||
} | ||
|
||
public bool OptOut | ||
{ | ||
get => _storage.Get("opt_out", false); | ||
set => _storage.Put("opt_out", value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using System; | ||
namespace Matomo.Maui; | ||
namespace Matomo.Maui.Models; | ||
|
||
public class Dimension | ||
{ | ||
|
Oops, something went wrong.