/
MainWindow.xaml.cs
151 lines (147 loc) · 4.79 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace Advent2020
{
public partial class MainWindow : Window
{
int LastDay = 20;
public int ChoosenDay;
private readonly MainView _mainView;
public MainWindow()
{
InitializeComponent();
_mainView = DataContext as MainView;
InputBox.Focus();
ChoosenDay = LastDay;
DayBox.Text = ChoosenDay.ToString();
}
private void DayBoxKeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
try
{
int DayToChoose = 0;
DayToChoose = Int32.Parse(DayBox.Text);
if (DayToChoose > 0 && DayToChoose <= 25)
ChoosenDay = DayToChoose;
DayBox.Text = ChoosenDay.ToString();
}
catch
{
DayBox.Text = ChoosenDay.ToString();
}
}
}
private async void InputBoxKeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Day d = CanIHasDay(ChoosenDay, InputBox.Text);
d.SetMainView(_mainView);
Tuple<string, string> OutputTuple;
await Task.Run(() =>
{
OutputTuple = d.getResult();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
_mainView.OutText = "Del 1: " + OutputTuple.Item1 + " och del 2: " + OutputTuple.Item2 + " Executed in " + ts.TotalMilliseconds.ToString() + " ms";
});
}
else
_mainView.KeyPresses += e.Key;
}
private Day CanIHasDay(int _day, string _input)
{
Day ReturnDay;
switch (_day)
{
case 1:
ReturnDay = new Day01(_input);
break;
case 2:
ReturnDay = new Day02(_input);
break;
case 3:
ReturnDay = new Day03(_input);
break;
case 4:
ReturnDay = new Day04(_input);
break;
case 5:
ReturnDay = new Day05(_input);
break;
case 6:
ReturnDay = new Day06(_input);
break;
case 7:
ReturnDay = new Day07(_input);
break;
case 8:
ReturnDay = new Day08(_input);
break;
case 9:
ReturnDay = new Day09(_input);
break;
case 10:
ReturnDay = new Day10(_input);
break;
case 11:
ReturnDay = new Day11(_input);
break;
case 12:
ReturnDay = new Day12(_input);
break;
case 13:
ReturnDay = new Day13(_input);
ReturnDay.SetMainView(_mainView);
break;
case 14:
ReturnDay = new Day14(_input);
break;
case 15:
ReturnDay = new Day15(_input);
break;
case 16:
ReturnDay = new Day16(_input);
break;
case 17:
ReturnDay = new Day17(_input);
break;
case 18:
ReturnDay = new Day18(_input);
break;
case 19:
ReturnDay = new Day19(_input);
break;
case 20:
ReturnDay = new Day20(_input);
break;
case 21:
ReturnDay = new Day21(_input);
break;
case 22:
ReturnDay = new Day22(_input);
break;
case 23:
ReturnDay = new Day23(_input);
break;
case 24:
ReturnDay = new Day24(_input);
break;
case 25:
ReturnDay = new Day25(_input);
break;
default:
ReturnDay = new Day01(_input);
break;
}
return ReturnDay;
}
}
}