Skip to content

Commit 7428cd4

Browse files
committed
refactor: shortened some console-outputs and made config local for where it's needed
1 parent 739077a commit 7428cd4

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

AdventOfCode/Infrastructure/Helpers/FormatHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ static class FormatHelper
1010

1111
public static string FormatTitle(int day, string title) => $"Day {day}: {title}";
1212

13-
public static string FormatDebug(string debugInput) => string.IsNullOrEmpty(debugInput)
14-
? "!! Debug mode active, but no DebugInput defined"
15-
: "!! Debug mode active, using DebugInput";
13+
public static string FormatDebug(string debugInput) => "!! Debug mode active, using DebugInput";
1614

1715
public static string FormatPart(int part, SolutionResult result)
1816
=> $" - Part{part} => " + (string.IsNullOrEmpty(result.Answer) ? "Unsolved" : $"{result.Answer} ({result.Time.TotalMilliseconds}ms)");

AdventOfCode/Infrastructure/Helpers/InputHelper.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using System;
22
using System.IO;
33
using System.Net;
4+
using AdventOfCode.Infrastructure.Models;
45

56
namespace AdventOfCode.Infrastructure.Helpers
67
{
78
static class InputHelper
89
{
10+
readonly static string cookie = Config.Get("config.json").Cookie;
11+
912
public static string LoadInput(int day, int year)
1013
{
1114
string INPUT_FILEPATH = GetDayPath(day, year) + "/input";
@@ -25,7 +28,7 @@ public static string LoadInput(int day, int year)
2528

2629
using (var client = new WebClient())
2730
{
28-
client.Headers.Add(HttpRequestHeader.Cookie, Program.Config.Cookie);
31+
client.Headers.Add(HttpRequestHeader.Cookie, cookie);
2932
input = client.DownloadString(INPUT_URL).Trim();
3033
File.WriteAllText(INPUT_FILEPATH, input);
3134
}
@@ -37,12 +40,12 @@ public static string LoadInput(int day, int year)
3740
Console.ForegroundColor = ConsoleColor.DarkRed;
3841
if (statusCode == HttpStatusCode.BadRequest)
3942
{
40-
Console.WriteLine($"Day {day}: Error code 400 when attempting to retrieve puzzle input through the web client. Your session cookie is probably not recognized.");
43+
Console.WriteLine($"Day {day}: Received 400 when attempting to retrieve puzzle input. Your session cookie is probably not recognized.");
4144

4245
}
4346
else if (statusCode == HttpStatusCode.NotFound)
4447
{
45-
Console.WriteLine($"Day {day}: Error code 404 when attempting to retrieve puzzle input through the web client. The puzzle is probably not available yet.");
48+
Console.WriteLine($"Day {day}: Received 404 when attempting to retrieve puzzle input. The puzzle is probably not available yet.");
4649
}
4750
else
4851
{

AdventOfCode/Infrastructure/Models/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private IEnumerable<int> ParseString(string str)
114114
{
115115
return new int[] { day };
116116
}
117-
117+
118118
return new int[0];
119119
});
120120
}

AdventOfCode/Infrastructure/SolutionCollector.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using AdventOfCode.Infrastructure.Models;
56
using AdventOfCode.Solutions;
67

78
namespace AdventOfCode.Infrastructure
89
{
910
class SolutionCollector : IEnumerable<ASolution>
1011
{
12+
readonly static Config config = Config.Get("config.json");
13+
1114
IEnumerable<ASolution> Solutions;
1215

16+
public SolutionCollector() => Solutions = LoadSolutions(config.Year, config.Days).ToArray();
1317
public SolutionCollector(int year, int[] days) => Solutions = LoadSolutions(year, days).ToArray();
1418

1519
public ASolution GetSolution(int day)
@@ -26,7 +30,6 @@ public ASolution GetSolution(int day)
2630

2731
public IEnumerator<ASolution> GetEnumerator() => Solutions.GetEnumerator();
2832

29-
3033
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
3134

3235
IEnumerable<ASolution> LoadSolutions(int year, int[] days)

AdventOfCode/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ namespace AdventOfCode
88
{
99
class Program
1010
{
11-
public static Config Config = Config.Get("config.json");
12-
static SolutionCollector Solutions = new SolutionCollector(Config.Year, Config.Days);
11+
static SolutionCollector Solutions = new SolutionCollector();
1312

1413
static void Main(string[] args)
1514
{

0 commit comments

Comments
 (0)