Add project files.

This commit is contained in:
2022-11-28 22:54:49 -05:00
parent dd97a677bb
commit c0c9e45e49
20 changed files with 417 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>AOC.Runner</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

30
AOC Runner/AOCRunner.cs Normal file
View File

@@ -0,0 +1,30 @@
using AOC.Runner;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode;
public class AOCRunner
{
public AOCRunner()
{
FindProblemClasses();
}
private void FindProblemClasses()
{
var types = Assembly.GetExecutingAssembly()?.DefinedTypes.Where(t => t.IsAssignableTo(typeof(IProblemBase)));
if (types == null)
return;
foreach (var type in types)
{
Console.WriteLine(type.Name);
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AOC.Runner;
public interface IProblemBase
{
void LoadInput();
void CalculatePart1();
void PrintPart1();
void CalculatePart2();
void PrintPart2();
}

View File

@@ -0,0 +1,13 @@
namespace AOC.Runner;
public class ProblemInfoAttribute : Attribute
{
public int Day { get; init; }
public string Year { get; init; }
public string Name { get; init; }
public ProblemInfoAttribute(string year, int day, string name)
{
Year = year;
Day = day;
Name = name;
}
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>2a85c7ef-9de8-4c58-b15c-4d4393590b3f</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>AOC.Shared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)AOCAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ProblemBase.cs" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>2a85c7ef-9de8-4c58-b15c-4d4393590b3f</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="AOC.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace AOC.Shared
{
public class ProblemInfoAttribute : Attribute
{
public int Day { get; init; }
public string Year { get; init; }
public string Name { get; init; }
public ProblemInfoAttribute(string year, int day, string name) {
Year = year;
Day = day;
Name = name;
}
}
}

14
AOC.Shared/ProblemBase.cs Normal file
View File

@@ -0,0 +1,14 @@
namespace AOC.Shared
{
public interface IProblemBase
{
void LoadInput();
void CalculatePart1();
void PrintPart1();
void CalculatePart2();
void PrintPart2();
}
}

13
AOC2022/AOC2022.csproj Normal file
View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AOC Runner\AOC Runner.csproj" />
</ItemGroup>
</Project>

32
AOC2022/TestProblem.cs Normal file
View File

@@ -0,0 +1,32 @@
using AOC.Runner;
namespace AOC2022;
[ProblemInfo("2022", 0, "Test")]
public class TestProblem : IProblemBase
{
public void LoadInput()
{
Thread.Sleep(1000);
}
public void CalculatePart1()
{
Thread.Sleep(1000);
}
public void CalculatePart2()
{
Thread.Sleep(1000);
}
public void PrintPart1()
{
Console.WriteLine("Result");
}
public void PrintPart2()
{
Console.WriteLine("Result 2");
}
}

13
AOC2023/AOC2023.csproj Normal file
View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AOC Runner\AOC Runner.csproj" />
</ItemGroup>
</Project>

32
AOC2023/TestProblem.cs Normal file
View File

@@ -0,0 +1,32 @@
using AOC.Runner;
namespace AOC2023;
[ProblemInfo("2023", 0, "Test")]
public class TestProblem : IProblemBase
{
public void LoadInput()
{
Thread.Sleep(1000);
}
public void CalculatePart1()
{
Thread.Sleep(1000);
}
public void CalculatePart2()
{
Thread.Sleep(1000);
}
public void PrintPart1()
{
Console.WriteLine("Result");
}
public void PrintPart2()
{
Console.WriteLine("Result 2");
}
}

25
AdventOfCode.sln Normal file
View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33110.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode", "AdventOfCode\AdventOfCode.csproj", "{CAAB9EC2-0787-4CBC-87E3-4529BFB56B3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CAAB9EC2-0787-4CBC-87E3-4529BFB56B3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CAAB9EC2-0787-4CBC-87E3-4529BFB56B3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CAAB9EC2-0787-4CBC-87E3-4529BFB56B3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CAAB9EC2-0787-4CBC-87E3-4529BFB56B3F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1FDE3D49-4BB6-48E2-B2CE-617A7B97684B}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,33 @@
using AdventOfCode.Runner;
using AdventOfCode.Runner.Attributes;
namespace AdventOfCode.Problems.AOC2022.Day0;
[ProblemInfo("2022", 0, "Fancy Test")]
public class TestProblem : IProblemBase
{
public void LoadInput()
{
Thread.Sleep(1000);
}
public void CalculatePart1()
{
Thread.Sleep(1000);
}
public void CalculatePart2()
{
Thread.Sleep(1000);
}
public void PrintPart1()
{
Console.WriteLine("Result");
}
public void PrintPart2()
{
Console.WriteLine("Result 2");
}
}

View File

@@ -0,0 +1,33 @@
using AdventOfCode.Runner;
using AdventOfCode.Runner.Attributes;
namespace AdventOfCode.Problems.AOC2023.Day0;
[ProblemInfo("2023", 0, "Test")]
public class TestProblem : IProblemBase
{
public void LoadInput()
{
Thread.Sleep(1000);
}
public void CalculatePart1()
{
Thread.Sleep(1000);
}
public void CalculatePart2()
{
Thread.Sleep(1000);
}
public void PrintPart1()
{
Console.WriteLine("Result");
}
public void PrintPart2()
{
Console.WriteLine("Result 2");
}
}

12
AdventOfCode/Program.cs Normal file
View File

@@ -0,0 +1,12 @@
using AdventOfCode.Runner;
namespace AdventOfCode;
internal class Program
{
static void Main(string[] args)
{
var runner = new AOCRunner();
runner.RenderMenu();
}
}

View File

@@ -0,0 +1,52 @@
using AdventOfCode.Runner.Attributes;
using System.Reflection;
namespace AdventOfCode.Runner;
public class AOCRunner
{
private Dictionary<string, List<(ProblemInfoAttribute info, Type type)>> _loadedProblems;
public AOCRunner()
{
_loadedProblems = new();
FindProblemClasses();
}
private void FindProblemClasses()
{
var types = Assembly.GetExecutingAssembly().DefinedTypes.Where(t => t.IsAssignableTo(typeof(IProblemBase)) && !t.IsInterface);
if (types == null)
return;
foreach (var type in types)
{
var info = type.GetCustomAttribute<ProblemInfoAttribute>();
if (info == null)
continue;
if (_loadedProblems.ContainsKey(info.Year))
_loadedProblems[info.Year].Add((info, type));
else
_loadedProblems.Add(info.Year, new() { (info, type) });
}
}
public void RenderMenu()
{
var years = _loadedProblems.Keys.OrderByDescending(k => k);
Console.WriteLine("Available Problems:");
foreach (var year in years)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"{year}:");
Console.ForegroundColor = ConsoleColor.Gray;
var days = _loadedProblems[year];
for (int i = 0; i < days.Count; i++)
{
var day = days[i];
Console.WriteLine($"\tDay {day.info.Day} - {day.info.Name}");
}
}
}
}

View File

@@ -0,0 +1,13 @@
namespace AdventOfCode.Runner.Attributes;
public class ProblemInfoAttribute : Attribute
{
public int Day { get; init; }
public string Year { get; init; }
public string Name { get; init; }
public ProblemInfoAttribute(string year, int day, string name)
{
Year = year;
Day = day;
Name = name;
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode.Runner;
public interface IProblemBase
{
void LoadInput();
void CalculatePart1();
void PrintPart1();
void CalculatePart2();
void PrintPart2();
}