Skip to content

Commit

Permalink
feat: update to bit 9.1.0 #61 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi authored Dec 15, 2024
1 parent 839c810 commit ae58e3e
Show file tree
Hide file tree
Showing 207 changed files with 2,701 additions and 1,495 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
}
},
"forwardPorts": [
4052,
4269,
5000,
5054
5291
],
"features": {
"ghcr.io/devcontainers/features/node": {},
Expand Down
17 changes: 7 additions & 10 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Bit.TemplatePlayground CD
name: Bit.TemplatePlayground CD

# https://bitplatform.dev/templates/dev-ops

Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:

- name: Build migrations bundle
run: |
cd src/Server/Bit.TemplatePlayground.Server.Api/ && dotnet tool restore && dotnet ef migrations bundle --self-contained -r linux-x64 --project Bit.TemplatePlayground.Server.Api.csproj
cd src/Server/Bit.TemplatePlayground.Server.Api/ && dotnet tool restore && dotnet ef migrations bundle --self-contained -r linux-x64 --project Bit.TemplatePlayground.Server.Api.csproj --verbose
- name: Upload ef migrations bundle
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -154,9 +154,9 @@ jobs:
- name: Publish
run: |
cd src\Client\Bit.TemplatePlayground.Client.Windows\
dotnet publish Bit.TemplatePlayground.Client.Windows.csproj -c Release -o .\publish-result -r win-x86 -p:Version="${{ vars.APPLICATION_DISPLAY_VERSION}}"
dotnet publish Bit.TemplatePlayground.Client.Windows.csproj -c Release -o .\publish-result -r win-x86 -p:Version="${{ vars.APPLICATION_DISPLAY_VERSION}}" --self-contained
dotnet tool restore
dotnet vpk pack -u Bit.TemplatePlayground.Client.Windows -v "${{ vars.APPLICATION_DISPLAY_VERSION }}" -p .\publish-result -e Bit.TemplatePlayground.Client.Windows.exe -r win-x86 --framework net9.0-x86-desktop,webview2 --icon .\wwwroot\favicon.ico --packTitle 'Bit.TemplatePlayground'
dotnet vpk pack -u Bit.TemplatePlayground.Client.Windows -v "${{ vars.APPLICATION_DISPLAY_VERSION }}" -p .\publish-result -e Bit.TemplatePlayground.Client.Windows.exe -r win-x86 --framework webview2 --icon .\wwwroot\favicon.ico --packTitle 'Bit.TemplatePlayground'
- name: Upload artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -207,11 +207,8 @@ jobs:
dotnet build src/Client/Bit.TemplatePlayground.Client.Core/Bit.TemplatePlayground.Client.Core.csproj -t:BeforeBuildTasks --no-restore -c Release
dotnet build src/Client/Bit.TemplatePlayground.Client.Maui/Bit.TemplatePlayground.Client.Maui.csproj -t:BeforeBuildTasks --no-restore -c Release
- name: Build aab
run: dotnet build src/Client/Bit.TemplatePlayground.Client.Maui/Bit.TemplatePlayground.Client.Maui.csproj -c Release -p:AndroidPackageFormat=aab -p:AndroidKeyStore=true -p:AndroidSigningKeyStore="Bit.TemplatePlayground.keystore" -p:AndroidSigningKeyAlias=Bit.TemplatePlayground -p:AndroidSigningKeyPass="${{ secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD }}" -p:AndroidSigningStorePass="${{ secrets.ANDROID_RELEASE_SIGNING_PASSWORD }}" -f net9.0-android

- name: Build apk
run: dotnet build src/Client/Bit.TemplatePlayground.Client.Maui/Bit.TemplatePlayground.Client.Maui.csproj -c Release -p:AndroidKeyStore=true -p:AndroidSigningKeyStore="Bit.TemplatePlayground.keystore" -p:AndroidSigningKeyAlias=Bit.TemplatePlayground -p:AndroidSigningKeyPass="${{ secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD }}" -p:AndroidSigningStorePass="${{ secrets.ANDROID_RELEASE_SIGNING_PASSWORD }}" -f net9.0-android
- name: Publish aab
run: dotnet publish src/Client/Bit.TemplatePlayground.Client.Maui/Bit.TemplatePlayground.Client.Maui.csproj -c Release -p:AndroidPackageFormat=aab -p:AndroidKeyStore=true -p:AndroidSigningKeyStore="Bit.TemplatePlayground.keystore" -p:AndroidSigningKeyAlias=Bit.TemplatePlayground -p:AndroidSigningKeyPass="${{ secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD }}" -p:AndroidSigningStorePass="${{ secrets.ANDROID_RELEASE_SIGNING_PASSWORD }}" -f net9.0-android

- name: Upload artifact
uses: actions/upload-artifact@v4
Expand All @@ -235,7 +232,7 @@ jobs:

- uses: maxim-lobanov/[email protected]
with:
xcode-version: '16.0'
xcode-version: '16.2'

- uses: actions/setup-node@v4
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Bit.BlazorUI" />
<PackageReference Include="Bit.BlazorUI.Icons" />
<PackageReference Include="Bit.BlazorUI.Assets" />
<PackageReference Include="Bit.BlazorUI.Extras" />
<PackageReference Include="Bit.BlazorUI.Extras" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,24 @@ public partial class AppComponentBase : ComponentBase, IAsyncDisposable

[AutoInject] protected IExceptionHandler ExceptionHandler = default!;

[AutoInject] protected AuthenticationManager AuthenticationManager = default!;
[AutoInject] protected AuthManager AuthManager = default!;

[AutoInject] protected SnackBarService SnackBarService = default!;

[AutoInject] protected ITelemetryContext TelemetryContext = default!;

/// <summary>
/// <inheritdoc cref="ISharedServiceCollectionExtensions.ConfigureAuthorizationCore"/>
/// </summary>
[AutoInject] protected IAuthorizationService AuthorizationService = default!;

/// <summary>
/// <inheritdoc cref="AbsoluteServerAddressProvider" />
/// </summary>
[AutoInject] protected AbsoluteServerAddressProvider AbsoluteServerAddress { get; set; } = default!;


private readonly CancellationTokenSource cts = new();
private CancellationTokenSource cts = new();
protected CancellationToken CurrentCancellationToken => cts.Token;

protected bool InPrerenderSession => AppPlatform.IsBlazorHybrid is false && JSRuntime.IsInitialized() is false;
Expand Down Expand Up @@ -214,6 +219,16 @@ public virtual Func<T, Task> WrapHandled<T>(Func<T, Task> func,
};
}

/// <summary>
/// Cancells running codes inside current component.
/// </summary>
protected void Abort()
{
cts.Cancel();
cts.Dispose();
cts = new();
}

public async ValueTask DisposeAsync()
{
await DisposeAsync(true);
Expand All @@ -226,8 +241,8 @@ protected virtual async ValueTask DisposeAsync(bool disposing)
if (disposing)
{
await PrerenderStateService.DisposeAsync();
cts?.Cancel();
cts?.Dispose();
cts.Cancel();
cts.Dispose();
}
}

Expand All @@ -245,6 +260,6 @@ private void HandleException(Exception exp,
}
parameters["ComponentType"] = GetType().FullName;

ExceptionHandler.Handle(exp, parameters, lineNumber, memberName, filePath);
ExceptionHandler.Handle(exp, nonInterrupting: false, parameters, lineNumber, memberName, filePath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,40 @@ public partial class ClientAppCoordinator : AppComponentBase
[AutoInject] private Navigator navigator = default!;
[AutoInject] private IJSRuntime jsRuntime = default!;
[AutoInject] private IStorageService storageService = default!;
[AutoInject] private AuthenticationManager authManager = default!;
[AutoInject] private ILogger<AuthManager> authLogger = default!;
[AutoInject] private ILogger<Navigator> navigatorLogger = default!;
[AutoInject] private ILogger<ClientAppCoordinator> logger = default!;
[AutoInject] private CultureInfoManager cultureInfoManager = default!;
[AutoInject] private ILogger<AuthenticationManager> authLogger = default!;
[AutoInject] private IBitDeviceCoordinator bitDeviceCoordinator = default!;

private Action? unsubscribe;

protected override async Task OnInitAsync()
{
if (AppPlatform.IsBlazorHybrid)
{
if (CultureInfoManager.MultilingualEnabled)
{
cultureInfoManager.SetCurrentCulture(new Uri(NavigationManager.Uri).GetCulture() ?? // 1- Culture query string OR Route data request culture
await storageService.GetItem("Culture") ?? // 2- User settings
CultureInfo.CurrentUICulture.Name); // 3- OS settings
}

await SetupBodyClasses();
await ConfigureUISetup();
}

if (InPrerenderSession is false)
{
NavigationManager.LocationChanged += NavigationManager_LocationChanged;
AuthenticationManager.AuthenticationStateChanged += AuthenticationStateChanged;

unsubscribe = PubSubService.Subscribe(ClientPubSubMessages.NAVIGATE_TO, async (uri) =>
{
NavigationManager.NavigateTo(uri!.ToString()!);
});
TelemetryContext.UserAgent = await navigator.GetUserAgent();
TelemetryContext.TimeZone = await jsRuntime.GetTimeZone();
TelemetryContext.Culture = CultureInfo.CurrentCulture.Name;
TelemetryContext.PageUrl = NavigationManager.Uri;
if (AppPlatform.IsBlazorHybrid is false)
{
TelemetryContext.OS = await jsRuntime.GetBrowserPlatform();
TelemetryContext.Platform = await jsRuntime.GetBrowserPlatform();
}


AuthenticationStateChanged(AuthenticationManager.GetAuthenticationStateAsync());
NavigationManager.LocationChanged += NavigationManager_LocationChanged;
AuthManager.AuthenticationStateChanged += AuthenticationStateChanged;
await PropagateUserId(firstRun: true, AuthenticationStateTask);
}

await base.OnInitAsync();
Expand All @@ -56,23 +54,43 @@ await storageService.GetItem("Culture") ?? // 2- User settings
private void NavigationManager_LocationChanged(object? sender, LocationChangedEventArgs e)
{
TelemetryContext.PageUrl = e.Location;
navigatorLogger.LogInformation("Navigation's location changed to {Location}", e.Location);
navigatorLogger.LogInformation("Navigator's location changed to {Location}", e.Location);
}

private async void AuthenticationStateChanged(Task<AuthenticationState> task)
private Guid? lastPropagatedUserId = Guid.Empty;
/// <summary>
/// This code manages the association of a user with sensitive services, such as SignalR, push notifications, App Insights, and others,
/// ensuring the user is correctly set or cleared as needed.
/// </summary>
public async Task PropagateUserId(bool firstRun, Task<AuthenticationState> task)
{
try
{
var user = (await task).User;
var isAuthenticated = user.IsAuthenticated();
TelemetryContext.UserId = isAuthenticated ? user.GetUserId() : null;
var userId = isAuthenticated ? user.GetUserId() : (Guid?)null;
if (lastPropagatedUserId == userId)
return;
Abort(); // Cancels ongoing user id propagation, because the new authentication state is available.
lastPropagatedUserId = userId;
TelemetryContext.UserId = userId;
TelemetryContext.UserSessionId = isAuthenticated ? user.GetSessionId() : null;

// Typically, we use the logger directly without utilizing logger.BeginScope.
// While many loggers provide specific methods to set userId and other context-related information,
// we use this method to propagate the user ID and other telemetry contexts via Microsoft.Extensions.Logging's Scope feature.
// PropagateUserId method is invoked both during app startup and when the authentication state changes.
// Additionally, this is a convenient place to manage user-specific contexts for services like:
// - App Insights: Set or clear the user ID for tracking purposes.
// - Push Notifications: Update subscriptions to ensure user-specific notifications are routed to the correct devices.
// - SignalR: Map connection IDs to a user's group of connections for message targeting.
// By leveraging this method during authentication state changes, we streamline the propagation of user-specific contexts across these systems.


var data = TelemetryContext.ToDictionary();
using var scope = authLogger.BeginScope(data);
{
authLogger.LogInformation("Authentication state changed.");
authLogger.LogInformation("Propagating {AuthStateType} {AuthState} authentication state.", firstRun ? "Initial" : "Updated", user.IsAuthenticated() ? "Authenticated" : "Anonymous");
}


Expand All @@ -83,39 +101,36 @@ private async void AuthenticationStateChanged(Task<AuthenticationState> task)
}
}


private async Task SetupBodyClasses()
private void AuthenticationStateChanged(Task<AuthenticationState> task)
{
var cssClasses = new List<string> { };
_ = PropagateUserId(firstRun: false, task);
}

if (AppPlatform.IsWindows)
{
cssClasses.Add("bit-windows");
}
else if (AppPlatform.IsMacOS)
{
cssClasses.Add("bit-macos");
}
else if (AppPlatform.IsIOS)
{
cssClasses.Add("bit-ios");
}
else if (AppPlatform.IsAndroid)

private async Task ConfigureUISetup()
{
if (CultureInfoManager.MultilingualEnabled)
{
cssClasses.Add("bit-android");
cultureInfoManager.SetCurrentCulture(new Uri(NavigationManager.Uri).GetCulture() ?? // 1- Culture query string OR Route data request culture
await storageService.GetItem("Culture") ?? // 2- User settings
CultureInfo.CurrentUICulture.Name); // 3- OS settings
}

var cssVariables = new Dictionary<string, string>
{
};
var platformCssClass = AppPlatform.IsWindows ? "bit-windows" :
AppPlatform.IsMacOS ? "bit-macos" :
AppPlatform.IsIOS ? "bit-ios" :
AppPlatform.IsAndroid ? "bit-android" : "bit-unknown";

await jsRuntime.ApplyBodyElementClasses(cssClasses, cssVariables);
await jsRuntime.ApplyBodyElementClasses(cssClasses: [platformCssClass], cssVariables: []);
}

private List<IDisposable> signalROnDisposables = [];
protected override async ValueTask DisposeAsync(bool disposing)
{
unsubscribe?.Invoke();

NavigationManager.LocationChanged -= NavigationManager_LocationChanged;
AuthenticationManager.AuthenticationStateChanged -= AuthenticationStateChanged;
AuthManager.AuthenticationStateChanged -= AuthenticationStateChanged;


await base.DisposeAsync(disposing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ private void GoHome()
navigationManager.NavigateTo(Urls.HomePage, forceLoad: true);
}

private void ShowDiagnostic()
private async Task ShowDiagnostic()
{
Recover();
await Task.Yield();
pubSubService.Publish(ClientPubSubMessages.SHOW_DIAGNOSTIC_MODAL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
main {
width: 100%;
height: 100%;
background-color: $bit-color-background-primary
}

.exception {
Expand Down
Loading

0 comments on commit ae58e3e

Please sign in to comment.