Skip to content

Commit 079df04

Browse files
committed
Full refactor:
* Rethinking application separation (see new folder and namespace structure). * Splitting commands into Partial Views, so the ViewModels will not be very long due to the many commands. * Complete rewriting and improvement of command and input data logic processing for better transparency and readability. * Defined are enums, static classes. * Removed previously created Handlers and their associated interfaces. * The individual elements have been removed from the global resource because they are not global but static, so they have been associated with the corresponding Views. * Removing individual behaviors because can be made these functions also with Commands. * Defined AppCacheStorage on client side. * The storage uses the Default Memory Cache. * Some data is stored in a cache for easier data processing on the client side. * Defined AppUserService on client side. * This service manages the signed in user on the client side. * Defined ViewNavigator on client side. * The ViewNavigator implements which view is visible in Main Window. * The SignalR management has been outsourced to a separate service on the client side. * The full Hub management for ChatHub has been added to the SignalRChatHub service and removed from the MainWindowViewModel. * The Hubs will be those Singleton instances. * Defined the AsynObservableCollection - ObservableCollection Extension into the Client Project. * Defined Log4Net into Client and Server Side. * Configured the application that the app run in a Dev or Prod environment. * Created of the corresponding Environment Service. * Replaced the ServiceLocator. * Defined a Dependency Injector that allows you to register Sigelton and Transient dependencies. * Created a bootstrapper whose Init method registers all dependency connections into the Container. * Overrided OnStartup() method, that is, this is where the dependencies are registered into the Container. * Managed globally unhandled exceptions. * Unhandled exceptions appear in an ErrorWindow. * The text that is displayed depends on whether the application is running in a Dev or Prod environment. * Defined custom exceptions. * On the Client and Server side, the Send Unicast Notification and Send Broadcast Notification operations have been removed as they do not belong to a basic chat application. * On the Client and Server side, the configuration settings that have been burned into code so far have been outsourced to the app.config file. * Unity DI Container has also been implemented on the server side. * A repository has been created on the server side to manage participants (this will be a singelton instance).
1 parent 34177f8 commit 079df04

File tree

166 files changed

+3668
-2327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+3668
-2327
lines changed

Application.Client/App.config

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<configSections>
4+
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, Log4net" />
5+
<section name="SignalRConfiguration" type="Application.Client.Core.AppConfigurations.SignalR.ConfigurationSections.SignalRConfigurationSection, Application.Client"/>
6+
</configSections>
7+
<log4net>
8+
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
9+
<param name="File" value="logs\logs.log" />
10+
<param name="AppendToFile" value="true" />
11+
<param name="MaxSizeRollBackups" value="10" />
12+
<param name="MaximumFileSize" value="10240KB" />
13+
<param name="RollingStyle" value="Size" />
14+
<param name="StaticLogFileName" value="true" />
15+
<layout type="log4net.Layout.PatternLayout,log4net">
16+
<param name="ConversionPattern" value="[%level] - %date - %type.%method, row: %line - %message%n" />
17+
</layout>
18+
</appender>
19+
<root>
20+
<level value="ALL" />
21+
<appender-ref ref="RollingLogFileAppender" />
22+
</root>
23+
</log4net>
24+
<SignalRConfiguration>
25+
<HubConnectionConfiguration Url="http://localhost:8080/signalchat" />
26+
<ChatHubConfiguration HubName="ChatHub" ReconnectTimeInterval="1000" />
27+
</SignalRConfiguration>
28+
<appSettings>
29+
<add key="ENVIRONMENT_TYPE" value="0"/>
30+
</appSettings>
31+
<startup>
32+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
33+
</startup>
34+
<system.net>
35+
<connectionManagement>
36+
<add address="*" maxconnection="1" />
37+
</connectionManagement>
38+
</system.net>
39+
<runtime>
40+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
41+
<dependentAssembly>
42+
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
43+
<bindingRedirect oldVersion="0.0.0.0-2.0.12.0" newVersion="2.0.12.0" />
44+
</dependentAssembly>
45+
</assemblyBinding>
46+
</runtime>
47+
</configuration>

Application.Client/App.xaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Application x:Class="Application.Client.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:chatView="clr-namespace:Application.Client.Views.Chat"
5+
xmlns:chatViewModels="clr-namespace:Application.Client.Views.Chat.ViewModels"
6+
xmlns:signInView="clr-namespace:Application.Client.Views.SignIn"
7+
xmlns:signInViewModels="clr-namespace:Application.Client.Views.SignIn.ViewModels"
8+
Startup="App_OnStartup">
9+
<Application.Resources>
10+
<ResourceDictionary>
11+
<ResourceDictionary.MergedDictionaries>
12+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
13+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
14+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
15+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
16+
</ResourceDictionary.MergedDictionaries>
17+
18+
<DataTemplate DataType="{x:Type signInViewModels:SignInViewModel}">
19+
<signInView:SignInView/>
20+
</DataTemplate>
21+
<DataTemplate DataType="{x:Type chatViewModels:ChatViewModel}">
22+
<chatView:ChatView/>
23+
</DataTemplate>
24+
</ResourceDictionary>
25+
</Application.Resources>
26+
</Application>

Application.Client/App.xaml.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Windows;
2+
using System.Windows.Threading;
3+
using Application.Client.Container;
4+
using Application.Client.Container.Unity;
5+
using Application.Client.Core.Environment.Enums;
6+
using Application.Client.Core.Environment.Services.Interfaces;
7+
using Application.Client.Core.Exceptions.Models;
8+
using Application.Client.Windows.Main;
9+
10+
namespace Application.Client
11+
{
12+
public partial class App
13+
{
14+
private IEnvironmentService _environmentService;
15+
16+
protected override void OnStartup(StartupEventArgs e)
17+
{
18+
base.OnStartup(e);
19+
20+
log4net.Config.XmlConfigurator.Configure();
21+
22+
Bootstrapper.Init();
23+
24+
_environmentService = DependencyInjector.Retrieve<IEnvironmentService>();
25+
26+
DependencyInjector.Retrieve<MainWindow>().Show();
27+
}
28+
29+
private void App_OnStartup(object sender, StartupEventArgs e)
30+
{
31+
Current.DispatcherUnhandledException += AppDispatcherUnhandledException;
32+
}
33+
34+
private void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
35+
{
36+
EnvironmentType environmentType = _environmentService.GetEnvironmentType();
37+
ErrorModel errorModel = new ErrorModel(environmentType, e.Exception);
38+
39+
ShowUnhandledException(errorModel);
40+
41+
e.Handled = true;
42+
}
43+
44+
private static void ShowUnhandledException(ErrorModel errorModel)
45+
{
46+
string errorMessage = $"An application error occured.\n\n{errorModel.Message}.\n\n{errorModel.Exception}";
47+
48+
if (MessageBox.Show(errorMessage, "Application Error", MessageBoxButton.OK, MessageBoxImage.Error) == MessageBoxResult.OK)
49+
{
50+
Current.Shutdown();
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)