Skip to content

Commit

Permalink
- latest c# lang features
Browse files Browse the repository at this point in the history
- fix warnings
  • Loading branch information
pjmagee committed Nov 30, 2024
1 parent ba611df commit 51d92dc
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 269 deletions.
24 changes: 11 additions & 13 deletions dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type GitVersion struct {
// Build the project
func (m *Dota2Helper) Build(
ctx context.Context,
// +defaultPath="."
// +defaultPath="."
git *dagger.Directory) (string, error) {

cache := dag.CacheVolume("nuget-cache")
Expand All @@ -59,36 +59,34 @@ func (m *Dota2Helper) Build(
// Get a dotnet container with the required tools
func (m *Dota2Helper) Dotnet() *dagger.Container {
return dag.Container().
From("mcr.microsoft.com/dotnet/sdk:8.0").
From("mcr.microsoft.com/dotnet/sdk:9.0").
WithExec([]string{"dotnet", "tool", "install", "--global", "nuget-license"}).
WithExec([]string{"dotnet", "tool", "install", "--global", "GitVersion.Tool"})
WithExec([]string{"dotnet", "tool", "install", "--global", "GitVersion.Tool"}).
WithExec([]string{"sh", "-c", "export PATH=\"$PATH:/root/.dotnet/tools\""})
}

func (m *Dota2Helper) GetPackages(
ctx context.Context,
// +defaultPath="."
// +defaultPath="."
git *dagger.Directory) (string, error) {

return m.Dotnet().
WithDirectory("/repo", git).
WithWorkdir("/repo/src").
WithExec([]string{
"sh",
"-c",
"~/.dotnet/tools/nuget-license -i Dota2Helper.sln -o JsonPretty || true"}).
WithExec([]string{"sh", "-c", "~/.dotnet/tools/nuget-license -i Dota2Helper.sln -o JsonPretty || true"}).
Stdout(ctx)
}

// Get the semver details of the current git repository
func (m *Dota2Helper) GitVersion(
ctx context.Context,
// +defaultPath="."
// +defaultPath="."
git *dagger.Directory) (GitVersion, error) {

version, err := m.Dotnet().
WithDirectory("/repo", git).
WithWorkdir("/repo").
WithExec([]string{"sh", "-c", "$HOME/.dotnet/tools/dotnet-gitversion"}).
WithExec([]string{"sh", "-c", "~/.dotnet/tools/dotnet-gitversion"}).
Stdout(ctx)

if err != nil {
Expand All @@ -108,7 +106,7 @@ func (m *Dota2Helper) GitVersion(
// Publish the project in release mode
func (m *Dota2Helper) PublishWindows(
ctx context.Context,
// +defaultPath="."
// +defaultPath="."
git *dagger.Directory,
version string) *dagger.Container {

Expand Down Expand Up @@ -144,7 +142,7 @@ func (m *Dota2Helper) PublishWindows(
// Zip the published files
func (m *Dota2Helper) Zip(
ctx context.Context,
// +defaultPath="."
// +defaultPath="."
git *dagger.Directory) (*dagger.File, error) {

gitVersion, err := m.GitVersion(ctx, git)
Expand All @@ -168,7 +166,7 @@ func (m *Dota2Helper) Zip(
// Create a release on github
func (m *Dota2Helper) Release(
ctx context.Context,
// +defaultPath="/"
// +defaultPath="/"
git *dagger.Directory,
token *dagger.Secret) error {

Expand Down
5 changes: 3 additions & 2 deletions src/Dota2Helper.Desktop/Dota2Helper.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -21,11 +22,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="11.2.1" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.2" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="6.0.0">
<PackageReference Include="GitVersion.MsBuild" Version="6.0.5">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Dota2Helper.Desktop/appsettings.timers.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"AudioFile": "./audio/Neutrals.mp3",
"Time": "00:17:00",
"RemindAt": "00:00:10",
"StopAfter": "00:17:00",
"StopAfter": "00:18:00",
"StartAfter": "00:16:00"
},
{
Expand All @@ -154,8 +154,8 @@
"AudioFile": "./audio/Neutrals.mp3",
"Time": "00:27:00",
"RemindAt": "00:00:10",
"StopAfter": "00:27:10",
"StartAfter": "00:26:30"
"StopAfter": "00:28:00",
"StartAfter": "00:26:00"
},
{
"Name": "Tier 4 Neutrals",
Expand All @@ -166,7 +166,7 @@
"AudioFile": "./audio/Neutrals.mp3",
"Time": "00:37:00",
"RemindAt": "00:00:30",
"StopAfter": "00:36:40",
"StopAfter": "00:38:00",
"StartAfter": "00:35:00"
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/Dota2Helper.Desktop/timer.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@
"AudioFile",
"Time"
],
"additionalProperties": false
"additionalProperties": false,
"additionalItems": false
}
4 changes: 2 additions & 2 deletions src/Dota2Helper.Tests/Dota2Helper.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<IsTestProject>true</IsTestProject>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
</ItemGroup>
Expand Down
99 changes: 52 additions & 47 deletions src/Dota2Helper/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,53 +39,8 @@ public override async void OnFrameworkInitializationCompleted()
if (IsDesignMode)
{
services
.Configure<Settings>(o =>
{
o.Mode = TimeMode.Auto;
o.Volume = 50;
o.Theme = "Light";
o.DemoMuted = true;
o.SelectedProfileIdx = 0;
o.Profiles = new List<Profile>
{
new Profile
{
Name = "Default",
Timers = new List<DotaTimer>
{
new DotaTimer
{
Name = "Roshan",
Time = TimeSpan.FromMinutes(8),
IsInterval = false,
IsManualReset = true,
IsEnabled = true,
IsMuted = false,
RemindAt = TimeSpan.FromMinutes(1),
StopAfter = TimeSpan.FromMinutes(1),
StartAfter = TimeSpan.FromMinutes(1),
AudioFile = null,
}
}
}
};
})
.Configure<List<DotaTimer>>(o =>
{
o.Add(new DotaTimer
{
Name = "Roshan",
Time = TimeSpan.FromMinutes(8),
IsInterval = false,
IsManualReset = true,
IsEnabled = true,
IsMuted = false,
RemindAt = TimeSpan.FromMinutes(1),
StopAfter = TimeSpan.FromMinutes(1),
StartAfter = TimeSpan.FromMinutes(1),
AudioFile = null,
});
});
.Configure<Settings>(ConfigureDesignSettings)
.Configure<List<DotaTimer>>(ConfigureDesignDefaultTimers);
}
else
{
Expand Down Expand Up @@ -163,4 +118,54 @@ await Task.WhenAny(

base.OnFrameworkInitializationCompleted();
}

void ConfigureDesignDefaultTimers(List<DotaTimer> o)
{
o.Add(new DotaTimer
{
Name = "Roshan",
Time = TimeSpan.FromMinutes(8),
IsInterval = false,
IsManualReset = true,
IsEnabled = true,
IsMuted = false,
RemindAt = TimeSpan.FromMinutes(1),
StopAfter = TimeSpan.FromMinutes(1),
StartAfter = TimeSpan.FromMinutes(1),
AudioFile = null,
}
);
}

void ConfigureDesignSettings(Settings o)
{
o.Mode = TimeMode.Auto;
o.Volume = 50;
o.Theme = "Light";
o.DemoMuted = true;
o.SelectedProfileIdx = 0;
o.Profiles = new List<Profile>
{
new Profile
{
Name = "Default",
Timers = new List<DotaTimer>
{
new DotaTimer
{
Name = "Roshan",
Time = TimeSpan.FromMinutes(8),
IsInterval = false,
IsManualReset = true,
IsEnabled = true,
IsMuted = false,
RemindAt = TimeSpan.FromMinutes(1),
StopAfter = TimeSpan.FromMinutes(1),
StartAfter = TimeSpan.FromMinutes(1),
AudioFile = null,
}
}
}
};
}
}
2 changes: 1 addition & 1 deletion src/Dota2Helper/Controls/AboutTabContent.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
x:DataType="viewModels:SettingsViewModel"
x:Class="Dota2Helper.Controls.AboutTabContent" Margin="5">

<StackPanel Orientation="Vertical" Spacing="5" HorizontalAlignment="Left" Width="750">
<StackPanel Orientation="Vertical" Spacing="5" HorizontalAlignment="Left">
<TextBlock Margin="5" HorizontalAlignment="Left">
All 3rd party packages used in this project.
</TextBlock>
Expand Down
14 changes: 7 additions & 7 deletions src/Dota2Helper/Dota2Helper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.1" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.2.1" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.1" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.1" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.2.1" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="Avalonia" Version="11.2.2" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.2.2" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.2" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.2" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.2.2" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="Avalonia.Xaml.Interactions" Version="11.2.0.1" />
<PackageReference Include="Avalonia.Xaml.Interactions.Events" Version="11.2.0.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="FluentIcons.Avalonia" Version="1.1.265" />
<PackageReference Include="FluentIcons.Avalonia" Version="1.1.266" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
Expand All @@ -35,7 +35,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="6.0.0">
<PackageReference Include="GitVersion.MsBuild" Version="6.0.5">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
28 changes: 21 additions & 7 deletions src/Dota2Helper/Features/About/AboutItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
using Dota2Helper.Features.Settings;

namespace Dota2Helper.Features.About;

Expand All @@ -10,25 +13,36 @@ public int CompareTo(PackageItem? other)
return string.Compare(PackageId, other?.PackageId, StringComparison.Ordinal);
}

[SetsRequiredMembers]
public PackageItem(string packageId, string packageVersion, string packageProjectUrl, string copyright, string authors, string license, string licenseUrl)
{
PackageId = packageId;
PackageVersion = packageVersion;
PackageProjectUrl = packageProjectUrl;
Copyright = copyright;
Authors = authors;
License = license;
LicenseUrl = licenseUrl;
}

[JsonPropertyName("PackageId")]
public string PackageId { get; set; }
public required string PackageId { get; set; }

[JsonPropertyName("PackageVersion")]
public string PackageVersion { get; set; }
public required string PackageVersion { get; set; }

[JsonPropertyName("PackageProjectUrl")]
public string PackageProjectUrl { get; set; }
public required string PackageProjectUrl { get; set; }

[JsonPropertyName("Copyright")]
public string Copyright { get; set; }
public required string Copyright { get; set; }

[JsonPropertyName("Authors")]
public string Authors { get; set; }
public required string Authors { get; set; }

[JsonPropertyName("License")]
public string License { get; set; }
public required string License { get; set; }

[JsonPropertyName("LicenseUrl")]
public string LicenseUrl { get; set; }
public required string LicenseUrl { get; set; }
}
4 changes: 2 additions & 2 deletions src/Dota2Helper/Features/About/AboutTableData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public AboutTableData()
}
}

IEnumerable<PackageItem>? GetPackageItems()
IEnumerable<PackageItem> GetPackageItems()
{
try
{
var dir = Directory.GetCurrentDirectory();
var json = File.ReadAllText(Path.Combine(dir, "packages.json"));
return System.Text.Json.JsonSerializer.Deserialize<List<PackageItem>>(json);
return System.Text.Json.JsonSerializer.Deserialize<List<PackageItem>>(json)!;
}
catch(Exception e)
{
Expand Down
Loading

0 comments on commit 51d92dc

Please sign in to comment.