Skip to content

Commit

Permalink
chore: fix event aggregator
Browse files Browse the repository at this point in the history
- Add LoginView notification on logout(Session ended)

Signed-off-by: Russell Camo <[email protected]>
  • Loading branch information
russkyc committed Aug 28, 2023
1 parent c8235d1 commit f9f366f
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// Copyright (C) 2023 Russell Camo (Russkyc).- All Rights Reserved
//
//
// Unauthorized copying or redistribution of all files, in source and binary forms via any medium
// without written, signed consent from the author is strictly prohibited.

using Injectio.Attributes;
using MvvmGen.Events;
namespace GroomWise.Application.Events;

namespace GroomWise.Infrastructure.Messaging;

[RegisterSingleton<IEventAggregator, MessageAggregator>]
public class MessageAggregator : EventAggregator { }
public record LogoutEvent();
18 changes: 18 additions & 0 deletions GroomWise.Application/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2023 Russell Camo (Russkyc).- All Rights Reserved
//
// Unauthorized copying or redistribution of all files, in source and binary forms via any medium
// without written, signed consent from the author is strictly prohibited.

using Microsoft.Extensions.DependencyInjection;
using MvvmGen.Events;

namespace GroomWise.Application.Extensions;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddEventAggregator(this IServiceCollection collection)
{
collection.AddSingleton<IEventAggregator, EventAggregator>();
return collection;
}
}
4 changes: 4 additions & 0 deletions GroomWise.Application/GroomWise.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@







</ItemGroup>


Expand Down
4 changes: 4 additions & 0 deletions GroomWise.Application/ViewModels/AppViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// without written, signed consent from the author is strictly prohibited.

using GroomWise.Application.Enums;
using GroomWise.Application.Events;
using GroomWise.Domain.Enums;
using GroomWise.Infrastructure.Authentication.Enums;
using GroomWise.Infrastructure.Authentication.Interfaces;
Expand All @@ -13,6 +14,7 @@
using GroomWise.Infrastructure.Theming.Interfaces;
using Injectio.Attributes;
using MvvmGen;
using MvvmGen.Events;
using MvvmGen.ViewModels;

namespace GroomWise.Application.ViewModels;
Expand All @@ -23,6 +25,7 @@ namespace GroomWise.Application.ViewModels;
[Inject(typeof(IAppServicesContainer))]
[Inject(typeof(IConfigurationService))]
[Inject(typeof(IThemeManagerService))]
[Inject(typeof(IEventAggregator))]
[Inject(typeof(DashboardViewModel))]
[ViewModel]
[RegisterSingleton]
Expand Down Expand Up @@ -63,6 +66,7 @@ private async Task Logout()
if (result.Equals(AuthenticationStatus.NotAuthenticated))
{
NavigationService.Navigate(AppViews.Login);
EventAggregator.Publish(new LogoutEvent());
}
}
});
Expand Down
20 changes: 19 additions & 1 deletion GroomWise.Application/ViewModels/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
// without written, signed consent from the author is strictly prohibited.

using GroomWise.Application.Enums;
using GroomWise.Application.Events;
using GroomWise.Application.Observables;
using GroomWise.Domain.Enums;
using GroomWise.Infrastructure.Authentication.Enums;
using GroomWise.Infrastructure.Authentication.Interfaces;
using GroomWise.Infrastructure.Navigation.Interfaces;
using Injectio.Attributes;
using MvvmGen;
using MvvmGen.Events;
using Swordfish.NET.Collections;

namespace GroomWise.Application.ViewModels;
Expand All @@ -20,7 +22,7 @@ namespace GroomWise.Application.ViewModels;
[Inject(typeof(INavigationService))]
[Inject(typeof(IAuthenticationService))]
[RegisterSingleton]
public partial class LoginViewModel
public partial class LoginViewModel : IEventSubscriber<LogoutEvent>
{
[Property]
private string _username;
Expand Down Expand Up @@ -104,4 +106,20 @@ private async Task RemoveNotification(object param)
}
});
}

public void OnEvent(LogoutEvent eventData)
{
Task.Run(async () =>
{
await Task.Delay(200);
Notifications.RemoveLast();
Notifications.Add(
new ObservableNotification
{
Type = NotificationType.Danger,
Description = "Session Ended."
}
);
});
}
}
4 changes: 4 additions & 0 deletions GroomWise.Infrastructure/GroomWise.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@







</ItemGroup>


Expand Down
2 changes: 2 additions & 0 deletions GroomWise.WPF/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System.Threading;
using GroomWise.Application.Enums;
using GroomWise.Application.Extensions;
using GroomWise.Infrastructure.Configuration.Interfaces;
using GroomWise.Infrastructure.IoC.Interfaces;
using GroomWise.Infrastructure.Navigation.Interfaces;
Expand All @@ -31,6 +32,7 @@ public App()
.AddGroomWiseInfrastructure()
.AddGroomWiseApplication()
.AddGroomWise()
.AddEventAggregator()
.BuildServiceProvider();

var scope = container.GetService<IAppServicesContainer>();
Expand Down
1 change: 0 additions & 1 deletion GroomWise.WPF/GroomWise.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<PackageReference Include="Bindables.Wpf" Version="1.4.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="CredentialManagement" Version="1.0.2" />
<PackageReference Include="ini.net" Version="1.1.0" />
<PackageReference Include="Lombok.NET" Version="2.1.3" />
<PackageReference Include="Material.Icons.WPF" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
Expand Down
2 changes: 0 additions & 2 deletions GroomWise.WPF/Views/Dialogs/LoginView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
x:Class="GroomWise.Views.Dialogs.LoginView"
xmlns="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:GroomWise.Converters"
xmlns:d="http:https://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="clr-namespace:org.russkyc.moderncontrols.Helpers;assembly=Russkyc.ModernControls.WPF"
xmlns:icons="clr-namespace:Material.Icons.WPF;assembly=Material.Icons.WPF"
xmlns:mc="http:https://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:russkyc="clr-namespace:org.russkyc.moderncontrols;assembly=Russkyc.ModernControls.WPF"
Expand Down

0 comments on commit f9f366f

Please sign in to comment.