-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
126 lines (108 loc) · 4.46 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using Shared;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using SpecificEngines;
using Helpers;
using ProgramRunners;
using ProgramRunners.PuzzleTestRunners;
namespace CodinGameExperiments
{
public class RunAction
{
public string Name { get; set; }
public string Description { get;set; }
public Action Action { get; set; }
}
class Program
{
private const string PuzzlePath = "Puzzles/";
private const string ChallengePath = "Challenges/";
private const string SharedPath = "Shared/";
private const string FrameworkPath = "Framework/";
private const string MergePath = "Merged/";
static void Main(string[] args)
{
Console.WriteLine("Puzzle solution");
if(!args.Any())
{
LogOptions();
Console.WriteLine("Select option:");
var res = Console.ReadLine();
args = new string[] { res };
}
var action = GetRunAction(args.FirstOrDefault());
if(action != null)
{
System.Console.WriteLine($"Running action: {action.Name} ({action.Description})");
action.Action();
return;
}
LogOptions();
}
private static void LogOptions()
{
GetActions().ToList().ForEach(a =>
{
System.Console.WriteLine($"{a.Name}\t\t{a.Description}");
});
System.Console.WriteLine("Parameters:");
System.Console.WriteLine($"Basepath \t\t {GetCleanRunPath(AppContext.BaseDirectory)}");
System.Console.WriteLine($"PuzzlePath \t\t {PuzzlePath}");
System.Console.WriteLine($"SharedPath\t\t {SharedPath}");
System.Console.WriteLine($"MergePath\t\t {MergePath}");
}
private static RunAction GetRunAction(string action)
{
if(action == null) { return null; }
return GetActions().FirstOrDefault(a => string.Equals(a.Name, action, StringComparison.OrdinalIgnoreCase));
}
private static IEnumerable<RunAction> GetActions()
{
yield return new RunAction() { Name = "merge", Description = "Merge the files", Action = RunMerge };
yield return new RunAction() { Name = "watch", Description = "Watch a file for changes and merge", Action = RunWatch };
yield return new RunAction() { Name = "test-batman", Description = "Run batman test-case", Action = new Batman().RunBatman }; //TODO: Batman should also go in some kind of base testing thingy (taking a custom engine)
yield return new RunAction() { Name = "test-spoon", Description = "Run spoon test-case", Action = new Spoon().RunPuzzleTests };
yield return new RunAction() { Name = "test-defib", Description = "Run defib test-case", Action = new Defibrillators().RunPuzzleTests };
yield return new RunAction() { Name = "test-warcards", Description = "Run warcards test-case", Action = new WarCards().RunPuzzleTests };
yield return new RunAction() { Name = "test-helpers", Description = "Run test cases for helpers", Action = new SharedElementTestRunner().RunHelperTests };
yield return new RunAction() { Name = "test-routes", Description = "Run test cases for routes", Action = new RouteTestRunner().RunRouteTests };
}
private static void RunMerge()
{
System.Console.WriteLine("Running the merger");
var merger = GetFileMerger();
merger.MergePuzzleFiles();
}
private static void RunWatch()
{
var merger = GetFileMergeWatcher();
System.Console.WriteLine($"Starting puzzle file watcher");
merger.WatchFolders();
}
private static FileMerger GetFileMerger()
{
return new FileMerger(GetCleanRunPath(AppContext.BaseDirectory), PuzzlePath, ChallengePath, SharedPath, FrameworkPath, MergePath);
}
private static FileMergeWatcher GetFileMergeWatcher()
{
return new FileMergeWatcher(GetCleanRunPath(AppContext.BaseDirectory), PuzzlePath, ChallengePath, SharedPath, FrameworkPath, MergePath);
}
private static string GetCleanRunPath(string fullPath)
{
return fullPath.IndexOf("\\") > -1 ? GetCleanPathBackSlash(fullPath) : GetCleanPathForwardSlash(fullPath);
}
private static string GetCleanPathBackSlash(string path)
{
int idx = path.IndexOf("bin\\debug", StringComparison.OrdinalIgnoreCase);
return idx > -1 ? path.Substring(0, idx) : path;
}
private static string GetCleanPathForwardSlash(string path)
{
int idx = path.IndexOf("bin/debug", StringComparison.OrdinalIgnoreCase);
return idx > -1 ? path.Substring(0, idx) : path;
}
//TODO: Createa logic to run multiple testcases and process the results
}
}