-
Notifications
You must be signed in to change notification settings - Fork 28
/
Program.cs
110 lines (84 loc) · 3.48 KB
/
Program.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
using System;
using Giles.Core.Configuration;
using Giles.Core.Watchers;
using Ninject;
namespace Giles
{
class Program
{
static SourceWatcher sourceWatcher;
static GilesConfig config;
static void Main(string[] args)
{
Console.Clear();
Console.CancelKeyPress += Console_CancelKeyPress;
Console.WriteLine("Giles - your own personal watcher");
var solutionPath = args[0];
var testAssemblyPath = args[1];
var projectRoot = args[2];
//solutionPath = @"D:\Dev\Prototypes\TestableTestStuff\TestableTestStuff.sln";
//testAssemblyPath = @"D:\Dev\Prototypes\TestableTestStuff\ClassThatDoesShit.Tests\bin\Debug\Teh.Tests.dll";
var kernel = new StandardKernel(new SlayerModule(solutionPath, testAssemblyPath, projectRoot));
var configFactory = kernel.Get<GilesConfigFactory>();
config = configFactory.Build();
sourceWatcher = kernel.Get<SourceWatcher>();
sourceWatcher.Watch(solutionPath, @"*.cs");
DisplayOptions();
MainFeedbackLoop();
Console.WriteLine("See you next time...");
}
static void MainFeedbackLoop()
{
while (true)
{
var key = Console.ReadKey(true);
var keyValue = key.KeyChar.ToString().ToLower();
if (keyValue == "?")
DisplayOptions();
if (keyValue == "i")
DisplayConfig();
if (keyValue == "c")
Console.Clear();
if (keyValue == "r")
sourceWatcher.RunNow();
if (keyValue == "b")
config.BuildDelay = GetUserValue(config.BuildDelay);
if (keyValue == "q")
break;
}
}
static T GetUserValue<T>(T defaultValue)
{
Console.Write("Enter new value ({0}): ", defaultValue);
var newValue = Console.ReadLine();
if (string.IsNullOrWhiteSpace(newValue))
return defaultValue;
return (T)Convert.ChangeType(newValue, typeof(T));
}
static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
// eating the ctrl-c for breakfast...
e.Cancel = true;
}
static void DisplayConfig()
{
Console.WriteLine("\nCurrent Configuration");
Console.WriteLine(" Build Delay: " + config.BuildDelay);
Console.WriteLine(" Solution: " + config.SolutionPath);
Console.WriteLine(" Project Root: " + config.ProjectRoot);
Console.WriteLine(" Test Assembly: " + config.TestAssemblyPath);
Console.WriteLine();
}
static void DisplayOptions()
{
Console.WriteLine("Interactive Console Options:");
Console.WriteLine(" ? = Display options");
Console.WriteLine(" C = Clear the window");
Console.WriteLine(" I = Show current configuration");
Console.WriteLine(" R = Run build & tests now");
Console.WriteLine(" B = Set Build Delay");
Console.WriteLine(" Q = Quit");
Console.WriteLine();
}
}
}