forked from ccnet/CruiseControl.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunner.cs
More file actions
128 lines (115 loc) · 2.46 KB
/
Copy pathRunner.cs
File metadata and controls
128 lines (115 loc) · 2.46 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
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
using System;
using System.Net.Sockets;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Activation;
using System.Configuration;
using System.Text.RegularExpressions;
using tw.ccnet.remote;
namespace CCNet.CCRunner
{
public class Runner
{
private string url;
public const string URL_CONFIG = "cc.net.url";
public const string NULL_PROJECT_MSG = "Please specify the name of the CruiseControl.NET project to run";
public const string HELP =
@"usage: ccnet.runner.exe [options] projectName
options:
-url:<url> Location of server. If omitted this will be loaded from 'ccnet.runner.exe.config'.
-help Display command-line help and options.";
public Runner()
{
Url = LoadURLFromConfig();
}
public string Url
{
get { return url; }
set { url = value; }
}
public void Run(string projectName)
{
if (projectName == null) throw new ArgumentNullException("projectName", NULL_PROJECT_MSG);
try
{
GetRemoteManager().Run(projectName, new Schedule());
}
catch (SocketException ex)
{
throw new ServerConnectionException(Url, ex);
}
catch (RemotingException ex)
{
throw new ServerConnectionException(Url, ex);
}
}
private ICruiseManager GetRemoteManager()
{
return (ICruiseManager) RemotingServices.Connect(typeof(ICruiseManager), Url);
}
private string LoadURLFromConfig()
{
return ConfigurationSettings.AppSettings[URL_CONFIG];
}
public static System.IO.TextWriter Out = Console.Out;
[STAThread]
public static void Main(string[] args)
{
if (HasHelp(args))
{
ShowHelp();
return;
}
Runner runner = new Runner();
runner.Url = ParseUrl(args);
try
{
runner.Run(ParseProject(args));
}
catch (Exception ex)
{
Out.WriteLine(ex.Message);
Out.WriteLine();
ShowHelp();
}
}
private static bool HasHelp(string[] args)
{
foreach (string arg in args)
{
if (arg == "-help")
{
return true;
}
}
return false;
}
private static void ShowHelp()
{
Out.WriteLine(HELP);
Environment.ExitCode = 1;
}
public static string ParseUrl(string[] args)
{
foreach (string arg in args)
{
if (arg.StartsWith("-url:"))
{
return arg.Substring(5);
}
}
return null;
}
public static string ParseProject(string[] args)
{
foreach (string arg in args)
{
if (! arg.StartsWith("-"))
{
return arg;
}
}
return null;
}
}
}