forked from acken/AutoTest.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
96 lines (87 loc) · 3.21 KB
/
Copy pathProgram.cs
File metadata and controls
96 lines (87 loc) · 3.21 KB
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
using AutoTest.Core.Configuration;
using System.Reflection;
using Castle.Core.Logging;
namespace AutoTest.Console
{
internal class Program
{
private static ILogger _logger = null;
private static void Main(string[] args)
{
if (userWantedCommandLineHelpPrinted(args))
return;
ConsoleConfiguration.Configure();
_logger = BootStrapper.Services.Locate<ILogger>();
_logger.Info("Starting up AutoTester");
var directory = getWatchDirectory(args);
BootStrapper.InitializeCache(directory);
var application = BootStrapper.Services.Locate<IConsoleApplication>();
application.Start(directory);
BootStrapper.ShutDown();
}
private static bool userWantedCommandLineHelpPrinted(string[] args)
{
if (args.Length != 1)
return false;
if (args[0] != "--help" && args[0] != "-help" && args[0] != "/help" &&
args[0] != "--?" && args[0] != "-?" && args[0] != "/?")
return false;
writeConsoleUsage();
return true;
}
private static void writeConsoleUsage()
{
System.Console.WriteLine("AutoTest.Console.exe command line arguments");
System.Console.WriteLine("");
System.Console.WriteLine("To specify watch directory on startup you can type:");
System.Console.WriteLine("\tAutoTest.Console.exe \"Path to the directory you want\"");
}
private static string getWatchDirectory(string[] args)
{
string directory;
if ((directory = getPossibleCommandArgs(args)) != null)
return directory;
if ((directory = pickFromConfiguration()) != null)
return directory;
return "";
}
private static string pickFromConfiguration()
{
var configuration = BootStrapper.Services.Locate<IConfiguration>();
if (configuration.WatchDirectores.Length == 0)
return null;
_logger.Info("Pick a directory to watch. Type the number of your choice");
for (int i = 0; i < configuration.WatchDirectores.Length; i++)
_logger.InfoFormat("{1}. {0}", configuration.WatchDirectores[i], i+1);
return pickDirectory(configuration);
}
private static string pickDirectory(IConfiguration configuration)
{
var numberOfDirectories = configuration.WatchDirectores.Length;
var directory = "";
while (true)
{
int number;
var numberString = System.Console.ReadLine();
if (int.TryParse(numberString, out number))
{
if (number > 0 && number <= numberOfDirectories)
{
directory = configuration.WatchDirectores[number-1];
break;
}
}
_logger.Info("Invalid number");
}
return directory;
}
private static string getPossibleCommandArgs(string[] args)
{
if (args == null)
return null;
if (args.Length != 1)
return null;
return args[0];
}
}
}