Skip to content

Commit

Permalink
Merge branch 'bitfoundation:develop' into 7761-dotnet9-rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi authored Oct 29, 2024
2 parents c2d275a + ede39a2 commit 7a5e83d
Show file tree
Hide file tree
Showing 30 changed files with 165 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class AppComponentBase : ComponentBase, IAsyncDisposable
/// <summary>
/// <inheritdoc cref="IPubSubService"/>
/// </summary>
[AutoInject] protected IPubSubService PubSubService = default!;
[AutoInject] protected PubSubService PubSubService = default!;

[AutoInject] protected IConfiguration Configuration = default!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ public partial class AppInitializer : AppComponentBase
//#if (notification == true)
[AutoInject] private IPushNotificationService pushNotificationService = default!;
//#endif
[AutoInject] private SnackBarService snackBarService = default!;
[AutoInject] private AuthenticationManager authManager = default!;
[AutoInject] private IJSRuntime jsRuntime = default!;
[AutoInject] private IBitDeviceCoordinator bitDeviceCoordinator = default!;
[AutoInject] private Bit.Butil.Console console = default!;
[AutoInject] private IStorageService storageService = default!;
[AutoInject] private CultureInfoManager cultureInfoManager = default!;
[AutoInject] private SnackBarService snackBarService = default!;
[AutoInject] private AuthenticationManager authManager = default!;
[AutoInject] private ITelemetryContext telemetryContext = default!;
[AutoInject] private NavigationManager navigationManager = default!;
[AutoInject] private Bit.Butil.Console console = default!;
[AutoInject] private CultureInfoManager cultureInfoManager = default!;
[AutoInject] private IBitDeviceCoordinator bitDeviceCoordinator = default!;

protected async override Task OnInitAsync()
{
Expand Down Expand Up @@ -52,14 +53,18 @@ protected override async Task OnAfterFirstRenderAsync()

if (AppPlatform.IsBlazorHybrid is false)
{
AppPlatform.OSDescription = await jsRuntime.GetBrowserPlatform();
telemetryContext.OS = await jsRuntime.GetBrowserPlatform();
}
}

private async void AuthenticationStateChanged(Task<AuthenticationState> task)
{
try
{
var user = (await task).User;
telemetryContext.UserId = user.IsAuthenticated() ? user.GetUserId() : null;
telemetryContext.UserSessionId = user.IsAuthenticated() ? user.GetSessionId() : null;

//#if (signalr == true)
if (InPrerenderSession is false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public partial class IdentityHeader : AppComponentBase, IDisposable
private Action unsubscribeUpdateBackLink = default!;


[AutoInject] private IThemeService themeService = default!;
[AutoInject] private ICultureService cultureService = default!;
[AutoInject] private ThemeService themeService = default!;
[AutoInject] private CultureService cultureService = default!;


[CascadingParameter] private BitDir? currentDir { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public partial class RootLayout : IDisposable
private Action unsubscribeRouteDataUpdated = default!;


[AutoInject] private IThemeService themeService = default!;
[AutoInject] private IPubSubService pubSubService = default!;
[AutoInject] private ThemeService themeService = default!;
[AutoInject] private PubSubService pubSubService = default!;
[AutoInject] private AuthenticationManager authManager = default!;
[AutoInject] private IExceptionHandler exceptionHandler = default!;
[AutoInject] private NavigationManager navigationManager = default!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public partial class UserMenu

[AutoInject] private Cookie cookie = default!;
[AutoInject] private CultureInfoManager cultureInfoManager = default!;
[AutoInject] private IThemeService themeService { get; set; } = default!;
[AutoInject] private ICultureService cultureService { get; set; } = default!;
[AutoInject] private ThemeService themeService { get; set; } = default!;
[AutoInject] private CultureService cultureService { get; set; } = default!;


[CascadingParameter] private BitDir? currentDir { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public partial class SignInPage : IDisposable


[AutoInject] private ILocalHttpServer localHttpServer = default!;
[AutoInject] private ITelemetryContext telemetryContext = default!;
[AutoInject] private IIdentityController identityController = default!;
[AutoInject] private IExternalNavigationService externalNavigationService = default!;

Expand All @@ -48,7 +49,7 @@ protected override async Task OnInitAsync()
model.UserName = UserNameQueryString;
model.Email = EmailQueryString;
model.PhoneNumber = PhoneNumberQueryString;
model.DeviceInfo = AppPlatform.OSDescription;
model.DeviceInfo = telemetryContext.OS;

if (string.IsNullOrEmpty(OtpQueryString) is false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ public static IServiceCollection AddClientCoreProjectServices(this IServiceColle

services.AddSingleton(sp => configuration.Get<ClientCoreSettings>()!);

services.AddSessioned<IPubSubService, PubSubService>();
services.AddSessioned<ILocalHttpServer, NoopLocalHttpServer>();
services.AddSessioned<PubSubService>();
services.AddSessioned<HttpClientHandler>();
services.AddSessioned<ILocalHttpServer, NoopLocalHttpServer>();
services.AddSessioned<ITelemetryContext, AppTelemetryContext>();

services.AddTransient<IPrerenderStateService, NoopPrerenderStateService>();
services.AddTransient<ICultureService, CultureService>();
services.AddTransient<IThemeService, ThemeService>();
services.AddTransient<ThemeService>();
services.AddTransient<CultureService>();
services.AddTransient<IAuthTokenProvider, ClientSideAuthTokenProvider>();
services.AddTransient<IPrerenderStateService, NoopPrerenderStateService>();
services.AddTransient<IExternalNavigationService, DefaultExternalNavigationService>();

services.AddTransient<RequestHeadersDelegationHandler>();
services.AddTransient<AuthDelegatingHandler>();
services.AddTransient<RetryDelegatingHandler>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Runtime.Versioning;
using System.Runtime.InteropServices;

namespace Boilerplate.Client.Core.Services;

Expand Down Expand Up @@ -29,6 +28,4 @@ public static partial class AppPlatform

[SupportedOSPlatformGuard("ios")]
public static bool IsIosOnMacOS { get; set; }

public static string OSDescription { get; set; } = RuntimeInformation.OSDescription;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Runtime.InteropServices;

namespace Boilerplate.Client.Core.Services;

public class AppTelemetryContext : ITelemetryContext
{
public virtual Guid? UserId { get; set; }

public virtual Guid? UserSessionId { get; set; }

public Guid AppSessionId { get; set; } = Guid.NewGuid();

public virtual string? OS { get; set; } = RuntimeInformation.OSDescription;

public virtual string? AppVersion { get; set; } = typeof(AppTelemetryContext).Assembly.GetName().Version?.ToString();

public virtual string? WebView { get; set; }
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Boilerplate.Client.Core.Services.Contracts;

public interface ITelemetryContext
{
private static ITelemetryContext? _current;

public static ITelemetryContext? Current
{
get
{
if (AppPlatform.IsBlazorHybridOrBrowser is false)
throw new InvalidOperationException("ITelemetryContext.Current is only available in Blazor Hybrid or web assembly apps.");

return _current;
}
set
{
if (AppPlatform.IsBlazorHybridOrBrowser is false)
throw new InvalidOperationException("ITelemetryContext.Current is only available in Blazor Hybrid or web assembly apps.");

_current = value;
}
}

public Guid? UserId { get; set; }

/// <summary>
/// Stored in Users table's Sessions column and is identified after the user sign-in.
/// </summary>
public Guid? UserSessionId { get; set; }

public Guid AppSessionId { get; set; }

public string? OS { get; set; }

public string? AppVersion { get; set; }

public string? WebView { get; set; }
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Boilerplate.Client.Core.Services;

public partial class CultureService : ICultureService
public partial class CultureService
{
[AutoInject] private Cookie cookie = default!;
[AutoInject] private IPubSubService pubSubService = default!;
[AutoInject] private PubSubService pubSubService = default!;
[AutoInject] private IStorageService storageService = default!;
[AutoInject] private NavigationManager navigationManager = default!;
[AutoInject] private CultureInfoManager cultureInfoManager = default!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ namespace Boilerplate.Client.Core.Services;

public abstract partial class ExceptionHandlerBase : IExceptionHandler
{
[AutoInject] protected readonly IStringLocalizer<AppStrings> Localizer = default!;
[AutoInject] protected readonly MessageBoxService MessageBoxService = default!;
[AutoInject] protected Bit.Butil.Console Console = default!;
[AutoInject] protected ITelemetryContext TelemetryContext = default!;
[AutoInject] protected ILogger<ExceptionHandlerBase> Logger = default!;
[AutoInject] protected readonly MessageBoxService MessageBoxService = default!;
[AutoInject] protected readonly IStringLocalizer<AppStrings> Localizer = default!;

public void Handle(Exception exp,
Dictionary<string, object?>? parameters = null,
Expand All @@ -26,6 +27,15 @@ public void Handle(Exception exp,
parameters[nameof(filePath)] = filePath;
parameters[nameof(memberName)] = memberName;
parameters[nameof(lineNumber)] = lineNumber;
parameters[nameof(TelemetryContext.UserId)] = TelemetryContext.UserId;
parameters[nameof(TelemetryContext.UserSessionId)] = TelemetryContext.UserSessionId;
parameters[nameof(TelemetryContext.AppSessionId)] = TelemetryContext.AppSessionId;
parameters[nameof(TelemetryContext.AppVersion)] = TelemetryContext.AppVersion;
parameters[nameof(TelemetryContext.OS)] = TelemetryContext.OS;
if (AppPlatform.IsBlazorHybrid)
{
parameters[nameof(TelemetryContext.WebView)] = TelemetryContext.WebView;
}

Handle(exp, parameters.ToDictionary(i => i.Key, i => i.Value ?? string.Empty));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public partial class MessageBoxService
private readonly ConcurrentQueue<MessageBoxData> queue = new();


[AutoInject] private readonly IPubSubService pubSubService = default!;
[AutoInject] private readonly PubSubService pubSubService = default!;


public Task<bool> Show(string message, string title = "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Boilerplate.Client.Core.Services;

/// <summary>
/// For more information <see cref="IPubSubService"/> docs.
/// Service for Publish/Subscribe pattern.
/// </summary>
public partial class PubSubService : IPubSubService
public partial class PubSubService
{
private readonly ConcurrentDictionary<string, List<Func<object?, Task>>> handlers = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public partial class SnackBarService
{
[AutoInject] private readonly IPubSubService pubSubService = default!;
[AutoInject] private readonly PubSubService pubSubService = default!;


public void Show(string title, string body = "", BitColor color = BitColor.Info)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Boilerplate.Client.Core.Services;

public partial class ThemeService : IThemeService
public partial class ThemeService
{
[AutoInject] private Cookie cookie = default!;
[AutoInject] private IPubSubService pubSubService = default!;
[AutoInject] private PubSubService pubSubService = default!;
[AutoInject] private BitThemeManager bitThemeManager = default!;
[AutoInject] private IBitDeviceCoordinator bitDeviceCoordinator = default!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Boilerplate.Client.Maui.Components.Pages;

public partial class AboutPage
{
[AutoInject] private ITelemetryContext telemetryContext = default!;

protected override string? Title => Localizer[nameof(AppStrings.AboutTitle)];
protected override string? Subtitle => string.Empty;

Expand All @@ -16,18 +18,13 @@ public partial class AboutPage

protected async override Task OnInitAsync()
{
appName = AppInfo.Name;
appVersion = AppInfo.Version.ToString();
processId = Environment.ProcessId.ToString();
os = $"{DeviceInfo.Current.Platform} {DeviceInfo.Current.VersionString}";
#if Android
// You have direct access to the Android, iOS, macOS, and Windows SDK features along with the ability to
// call third-party Java, Kotlin, Swift, and Objective-C libraries.
// https://stackoverflow.com/a/2941199/2720104
os += $" {Android.Webkit.WebView.CurrentWebViewPackage?.PackageName}: {Android.Webkit.WebView.CurrentWebViewPackage?.VersionName}";
#elif Windows
os += $" EdgeWebView2: {Microsoft.Web.WebView2.Core.CoreWebView2Environment.GetAvailableBrowserVersionString()}";
#endif
appName = AppInfo.Name;
appVersion = telemetryContext.AppVersion!;
os = $"{telemetryContext.OS} {telemetryContext.WebView}";
processId = Environment.ProcessId.ToString();
oem = DeviceInfo.Current.Manufacturer;

await base.OnInitAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static void ConfigureServices(this MauiAppBuilder builder)
//-:cnd:noEmit

services.AddTransient<MainPage>();
services.AddSingleton(ITelemetryContext.Current = new MauiTelemetryContext());
services.AddTransient<IStorageService, MauiStorageService>();
services.AddTransient<IBitDeviceCoordinator, MauiDeviceCoordinator>();
services.AddTransient<IExceptionHandler, MauiExceptionHandler>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//#endif
//-:cnd:noEmit
using Boilerplate.Client.Core.Styles;
using Boilerplate.Client.Maui.Services;
#if iOS || Mac
using UIKit;
using WebKit;
Expand All @@ -33,9 +34,6 @@ public static MauiApp CreateMauiApp()
#if iOS
AppPlatform.IsIosOnMacOS = NSProcessInfo.ProcessInfo.IsiOSApplicationOnMac;
#endif

AppPlatform.OSDescription = $"{DeviceInfo.Current.Manufacturer} {(AppPlatform.IsIosOnMacOS ? DevicePlatform.macOS : DeviceInfo.Current.Platform)} {DeviceInfo.Current.Version}";

var builder = MauiApp.CreateBuilder();

builder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Boilerplate.Client.Maui.Services;

public class MauiTelemetryContext : AppTelemetryContext
{
public override string? OS { get; set; } = $"{DeviceInfo.Current.Manufacturer} {(AppPlatform.IsIosOnMacOS ? DevicePlatform.macOS : DeviceInfo.Current.Platform)} {DeviceInfo.Current.Version}";

public override string? AppVersion { get; set; } = VersionTracking.CurrentVersion;

//-:cnd:noEmit
public override string? WebView { get; set; } =
#if Android
$"{Android.Webkit.WebView.CurrentWebViewPackage?.PackageName} {Android.Webkit.WebView.CurrentWebViewPackage?.VersionName}";
#elif Windows
$"EdgeWebView2 {Microsoft.Web.WebView2.Core.CoreWebView2Environment.GetAvailableBrowserVersionString()}";
#else
null;
#endif
}
Loading

0 comments on commit 7a5e83d

Please sign in to comment.