Skip to content

Commit

Permalink
Merge branch 'main' into chore/prepare-new-release
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoBaSs84 authored Aug 26, 2024
2 parents ffa7513 + 675b61d commit 5ac6c18
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 51 deletions.
125 changes: 83 additions & 42 deletions src/QrCode.Generator/Controls/AboutControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,93 @@
d:DataContext="{d:DesignInstance Type=vm:AboutViewModel}"
d:Background="WhiteSmoke"
d:Height="400"
d:Width="700">
d:Width="600">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="12*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10" />
<RowDefinition />
<RowDefinition Height="10" />
<RowDefinition Height="1*" />
<RowDefinition Height="7*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<DockPanel LastChildFill="true"
Grid.Column="1"
Grid.Row="1">
<GroupBox Header="About">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Grid.Column="0"
Grid.ColumnSpan="2">
<Label Content="Title:" />
<Label Content="{Binding Model.Title}"
FontWeight="Bold" />
<Label Content="Version:" />
<Label Content="{Binding Model.Version}"
FontWeight="Bold" />
<Label Content="Comments:" />
<Label Content="{Binding Model.Comments}"
FontWeight="Bold" />
<Label Content="Company:" />
<Label Content="{Binding Model.Company}"
FontWeight="Bold" />
<Label Content="Copyright:" />
<Label Content="{Binding Model.Copyright}"
FontWeight="Bold" />
</StackPanel>
</Grid>
</StackPanel>
</GroupBox>
</DockPanel>
<Grid x:Name="AboutGrid"
Grid.Column="1"
Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Content="Title:"
FontSize="14"
Grid.Column="0"
Grid.Row="0" />
<Label Content="{Binding Model.Title}"
FontSize="14"
Grid.Column="1"
Grid.Row="0" />
<Label Content="Version:"
FontSize="14"
Grid.Column="0"
Grid.Row="1" />
<Label Content="{Binding Model.Version}"
FontSize="14"
Grid.Column="1"
Grid.Row="1" />
<Label Content="Description:"
FontSize="14"
Grid.Column="0"
Grid.Row="2" />
<TextBlock Text="{Binding Model.Comments}"
TextWrapping="WrapWithOverflow"
FontSize="14"
Grid.Column="1"
Grid.Row="2"
Margin="5" />
<Label Content="Company:"
FontSize="14"
Grid.Column="0"
Grid.Row="3" />
<Label Content="{Binding Model.Company}"
FontSize="14"
Grid.Column="1"
Grid.Row="3" />
<Label Content="Copyright:"
FontSize="14"
Grid.Column="0"
Grid.Row="4" />
<Label Content="{Binding Model.Copyright}"
FontSize="14"
Grid.Column="1"
Grid.Row="4" />
<Label Content="Framework:"
FontSize="14"
Grid.Column="0"
Grid.Row="5" />
<Label Content="{Binding Model.FrameworkName}"
FontSize="14"
Grid.Column="1"
Grid.Row="5" />
<Label Content="Repository:"
FontSize="14"
Grid.Column="0"
Grid.Row="6" />
<Label Content="{Binding Model.Repository}"
FontSize="14"
Grid.Column="1"
Grid.Row="6" />
</Grid>
</Grid>
</UserControl>
48 changes: 39 additions & 9 deletions src/QrCode.Generator/Models/AboutModel.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
using System.Diagnostics;
using System.Reflection;
using System.Runtime.Versioning;

using QrCode.Generator.Models.Base;

namespace QrCode.Generator.Models;

/// <summary>
/// The about model.
/// The about model class.
/// </summary>
public sealed class AboutModel : ModelBase
{
private readonly FileVersionInfo _fileVersionInfo;

/// <summary>
/// Initializes an instance of <see cref="AboutModel"/> class.
/// </summary>
public AboutModel()
{
_fileVersionInfo = FileVersionInfo.GetVersionInfo(typeof(AboutModel).Assembly.Location);
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);

Title = _fileVersionInfo.ProductName;
Version = _fileVersionInfo.FileVersion;
Comments = _fileVersionInfo.Comments;
Company = _fileVersionInfo.CompanyName;
Copyright = _fileVersionInfo.LegalCopyright;
Title = fileVersionInfo.ProductName;
Version = fileVersionInfo.FileVersion;
Comments = fileVersionInfo.Comments;
Company = fileVersionInfo.CompanyName;
Copyright = fileVersionInfo.LegalCopyright;
FrameworkName = GetFrameworkName(assembly);
Repository = GetRepositoryLocation(assembly);
}

/// <summary>
Expand All @@ -49,4 +52,31 @@ public AboutModel()
/// The copyright of the application.
/// </summary>
public string? Copyright { get; }

/// <summary>
/// The name of the .NET version with which the assembly was compiled.
/// </summary>
public string? FrameworkName { get; }

/// <summary>
/// The repository location of the application.
/// </summary>
public string? Repository { get; }

private static string? GetFrameworkName(Assembly assembly)
{
TargetFrameworkAttribute? targetFramework = assembly
.GetCustomAttributes(typeof(TargetFrameworkAttribute), false)
.SingleOrDefault() as TargetFrameworkAttribute;

return targetFramework is not null ? targetFramework.FrameworkName : default;
}

private static string? GetRepositoryLocation(Assembly assembly)
{
IEnumerable<AssemblyMetadataAttribute>? assemblyMetadata = assembly
.GetCustomAttributes(typeof(AssemblyMetadataAttribute), false) as IEnumerable<AssemblyMetadataAttribute>;

return assemblyMetadata?.Where(x => x.Key == "RepositoryUrl").Select(x => x.Value).SingleOrDefault();
}
}
2 changes: 2 additions & 0 deletions tests/QrCode.GeneratorTests/Models/AboutModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public void AboutModelTest()
Assert.IsNotNull(model.Comments);
Assert.IsNotNull(model.Title);
Assert.IsNotNull(model.Version);
Assert.IsNotNull(model.FrameworkName);
Assert.IsNotNull(model.Repository);
}
}

0 comments on commit 5ac6c18

Please sign in to comment.