Skip to content

Commit

Permalink
Merge pull request #23 from modularity
Browse files Browse the repository at this point in the history
Split and organize the extension classes into module project based
  • Loading branch information
kevinboon3288 committed Apr 12, 2024
2 parents a87c864 + cdf382a commit 49752bd
Show file tree
Hide file tree
Showing 42 changed files with 608 additions and 582 deletions.
6 changes: 1 addition & 5 deletions App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VersionController"
xmlns:prism="http://prismlibrary.com/">
<Application.Resources>

</Application.Resources>
</prism:PrismApplication>
xmlns:prism="http://prismlibrary.com/"/>
8 changes: 4 additions & 4 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Prism.Events;
using CommonModule.Core;
using PackageModule.Core;
using Prism.Events;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Regions;
Expand All @@ -7,8 +9,6 @@
using Serilog.Core;
using System.Windows;
using Unity;
using VersionController.Services;
using VersionController.Core;

namespace VersionController
{
Expand Down Expand Up @@ -52,7 +52,7 @@ protected override void ConfigureViewModelLocator()

protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
moduleCatalog.AddModule<Main.MainModule>();
moduleCatalog.AddModule<MainModule.MainModule>();
moduleCatalog.AddModule<PackageModule.PackageModule>();
}

Expand Down
13 changes: 13 additions & 0 deletions Common/CommonModule/CommonModule.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Prism.Core" Version="8.1.97" />
<PackageReference Include="Serilog" Version="3.1.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace VersionController.Controls.Converter
namespace CommonModule.Converters
{
public class VisibilityConverter : IValueConverter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace VersionController.Core
namespace CommonModule.Core
{
public class ConstantFilePaths
{
Expand Down
23 changes: 23 additions & 0 deletions Common/CommonModule/Core/LogSink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace CommonModule.Core;

public class LogSink : ILogEventSink
{
private readonly IEventAggregator _eventAggregator;

public LogSink(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
}

public void Emit(LogEvent logEvent)
{
ArgumentNullException.ThrowIfNull(logEvent);

StringWriter strWriter = new();

MessageTemplateTextFormatter textFormatter = new MessageTemplateTextFormatter("{Timestamp:yyyy/MM/dd HH:mm:ss} [{Level:u3}]: {Message}{Exception}");
textFormatter.Format(logEvent, strWriter);

_eventAggregator.GetEvent<Events.LogEvent>().Publish(strWriter.ToString());
}
}
5 changes: 5 additions & 0 deletions Common/CommonModule/Events/LogEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace CommonModule.Events;

public class LogEvent : PubSubEvent<string>
{
}
6 changes: 6 additions & 0 deletions Common/CommonModule/Events/LogEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CommonModule.Events;

public class LogEventArgs: EventArgs
{
public required string LogMessage { get; set; }
}
8 changes: 8 additions & 0 deletions Common/CommonModule/Using.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global using System.IO;
global using System.Globalization;
global using System.Windows;
global using System.Windows.Data;
global using Serilog.Core;
global using Serilog.Events;
global using Serilog.Formatting.Display;
global using Prism.Events;
8 changes: 0 additions & 8 deletions LoggerService/Events/LogEvent.cs

This file was deleted.

9 changes: 0 additions & 9 deletions LoggerService/Events/LogEventArgs.cs

This file was deleted.

31 changes: 0 additions & 31 deletions LoggerService/LogSink.cs

This file was deleted.

10 changes: 1 addition & 9 deletions Main/MainModule.cs → Modules/MainModule/MainModule.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
using Prism.Ioc;
using Prism.Modularity;
using Prism.Mvvm;
using Prism.Regions;
using Serilog;
using VersionController.Main.ViewModels;
using VersionController.Main.Views;

namespace VersionController.Main
namespace MainModule
{
public class MainModule : IModule
{
Expand Down
18 changes: 18 additions & 0 deletions Modules/MainModule/MainModule.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Prism.Logging.Serilog" Version="7.2.0.1423" />
<PackageReference Include="Prism.Unity" Version="8.1.97" />
<PackageReference Include="Serilog" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\CommonModule\CommonModule.csproj" />
<ProjectReference Include="..\..\Resource\Resource.csproj" />
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions Modules/MainModule/Using.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
global using Prism.Ioc;
global using Prism.Modularity;
global using Prism.Mvvm;
global using Prism.Regions;
global using Prism.Events;
global using Serilog;
global using MainModule.ViewModels;
global using MainModule.Views;
global using CommonModule.Events;
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using Serilog;
using System;
using VersionController.PackageModule.ViewModels;
using VersionController.Services.Events;

namespace VersionController.Main.ViewModels
namespace MainModule.ViewModels
{
public class MainViewModel : BindableBase, INavigationAware
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<UserControl x:Class="VersionController.Main.Views.MainView"
<UserControl x:Class="MainModule.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:VersionController.Main.Views"
xmlns:local="clr-namespace:MainModule.Views"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VersionController.Main.ViewModels;
using VersionController.Services.Events;

namespace VersionController.Main.Views
namespace MainModule.Views
{
/// <summary>
/// Interaction logic for MainView.xaml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
using Serilog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace VersionController.Core
namespace PackageModule.Core
{
public class DirectoryUtils : IDirectoryUtils
{
private readonly ILogger _logger;
private const string _folderPattern = @"(?<=\..*)\.";

public DirectoryUtils(ILogger logger)
{
Expand All @@ -37,10 +27,18 @@ public List<(string, string?)> GetDotNugetPackages()
return dotNugetPackages;
}

public List<(string, string?)> GetFilterPackages(string filterFileNames)
public List<(string, string?)> GetDotNugetFilterPackages(string filterFileNames)
{
List<(string fileName, string? version)> packages = ReadPackages(Directory.GetDirectories(ConstantFilePaths.DotNugetFilePath));
return packages.FindAll(x => x.fileName.Contains(filterFileNames.ToUpper())).ToList();

return packages.Where(x => x.fileName.Contains(filterFileNames) || (!string.IsNullOrEmpty(x.version) && x.version.Contains(filterFileNames))).ToList();
}

public List<(string, string?)> GetNugetFilterPackages(string filterFileNames)
{
List<(string fileName, string? version)> packages = ReadPackages(Directory.GetDirectories(ConstantFilePaths.NugetX86FilePath));

return packages.Where(x => x.fileName.Contains(filterFileNames) || (!string.IsNullOrEmpty(x.version) && x.version.Contains(filterFileNames))).ToList();
}

private List<(string, string?)> ReadPackages(string[] filterFolderPaths)
Expand All @@ -51,11 +49,7 @@ private List<(string, string?)> ReadPackages(string[] filterFolderPaths)
{
string? version = Path.GetFileName(Directory.GetDirectories(folder, "*", SearchOption.TopDirectoryOnly).FirstOrDefault());

Match match = Regex.Match(folder, _folderPattern);
if (match.Success)
{
folders.Add((Path.GetFileName(folder), version));
}
folders.Add((Path.GetFileName(folder), version));
}

return folders;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System.Collections.Generic;

namespace VersionController.Core
namespace PackageModule.Core
{
public interface IDirectoryUtils
{
List<(string, string?)> GetNugetPackages();
List<(string, string?)> GetDotNugetPackages();
List<(string, string?)> GetFilterPackages(string filterFileNames);
List<(string, string?)> GetNugetFilterPackages(string filterFileNames);
List<(string, string?)> GetDotNugetFilterPackages(string filterFileNames);
void Delete(List<string> filterFileNames, string filePath);
void Publish(string directory, string fileName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Prism.Mvvm;
using System.Xml.Linq;

namespace VersionController.PackageModule.Models
namespace PackageModule.Models
{
public class Package : BindableBase
{
Expand Down
35 changes: 35 additions & 0 deletions Modules/PackageModule/PackageModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace PackageModule;

public class PackageModule : IModule
{
private readonly ILogger _logger;
private readonly IRegionManager _regionManager;

public PackageModule(ILogger logger, IRegionManager regionManager)
{
_logger = logger;
_regionManager = regionManager;
}

public void OnInitialized(IContainerProvider containerProvider)
{
_regionManager.RegisterViewWithRegion("PackageContentRegion", typeof(PackageView));
_regionManager.RegisterViewWithRegion("DotNugetPackageContentRegion", typeof(DotNugetPackageListView));
_regionManager.RegisterViewWithRegion("PackageListContentRegion", typeof(PackageListView));

//TODO: Update this implementation if there is a better way for first navigation
IRegion region = _regionManager.Regions["PackageContentRegion"];
region.RequestNavigate(nameof(PackageView));
}

public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<PackageView>();
containerRegistry.RegisterForNavigation<DotNugetPackageListView>();
containerRegistry.RegisterForNavigation<PackageListView>();

ViewModelLocationProvider.Register<PackageView, PackageViewModel>();
ViewModelLocationProvider.Register<DotNugetPackageListView, DotNugetPackageListViewModel>();
ViewModelLocationProvider.Register<PackageListView, PackageListViewModel>();
}
}
18 changes: 18 additions & 0 deletions Modules/PackageModule/PackageModule.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Prism.Logging.Serilog" Version="7.2.0.1423" />
<PackageReference Include="Prism.Unity" Version="8.1.97" />
<PackageReference Include="Serilog" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\CommonModule\CommonModule.csproj" />
<ProjectReference Include="..\..\Resource\Resource.csproj" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions Modules/PackageModule/Using.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
global using System.IO;
global using System.Diagnostics;
global using System.Text.RegularExpressions;
global using System.Collections.ObjectModel;
global using Serilog;
global using Prism.Ioc;
global using Prism.Modularity;
global using Prism.Mvvm;
global using Prism.Commands;
global using Prism.Regions;
global using CommonModule.Core;
global using PackageModule.Core;
global using PackageModule.Models;
global using PackageModule.Views;
global using PackageModule.ViewModels;
Loading

0 comments on commit 49752bd

Please sign in to comment.