-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an action to Server to list all the projects (ListProjects). Modified the command line app so it can be an interaction console for executing commands against a server.
- Loading branch information
Showing
10 changed files
with
240 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace CruiseControl.Command | ||
{ | ||
public class Command | ||
{ | ||
#region Public properties | ||
#region Name | ||
public string Name { get; set; } | ||
#endregion | ||
|
||
#region Arguments | ||
public string[] Arguments { get; set; } | ||
#endregion | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,122 @@ | ||
namespace CruiseControl.Command | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using CruiseControl.Common; | ||
|
||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var connection = new ServerConnection(args[0]); | ||
connection.Ping(); | ||
var exit = false; | ||
WriteToConsole(ConsoleColor.White, "CruiseControl.NET: Interactive Console"); | ||
WriteToConsole(ConsoleColor.White, new string('=', 40)); | ||
WriteToConsole(ConsoleColor.Yellow, "Retrieving server name..."); | ||
var fullUrn = connection.RetrieveServerName(); | ||
WriteToConsole(ConsoleColor.Yellow, "...server name is '{0}'", fullUrn); | ||
var shortUrn = fullUrn.Substring(10); | ||
while (!exit) | ||
{ | ||
Console.Write(shortUrn + ">"); | ||
var command = ReadFromConsole(); | ||
switch (command.Name) | ||
{ | ||
case "exit": | ||
exit = true; | ||
break; | ||
|
||
case "ping": | ||
RunPingCommand(connection); | ||
break; | ||
|
||
case "query": | ||
RunQueryCommand(connection, fullUrn); | ||
break; | ||
|
||
case "invoke": | ||
RunInvokeCommand(connection, fullUrn, command.Arguments); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private static Command ReadFromConsole() | ||
{ | ||
var input = Console.ReadLine(); | ||
var parts = input.Split(' '); | ||
var command = new Command(); | ||
if (parts.Length > 0) | ||
{ | ||
command.Name = parts[0].ToLowerInvariant(); | ||
command.Arguments = parts.Skip(1).ToArray(); | ||
} | ||
|
||
return command; | ||
} | ||
|
||
private static void WriteToConsole(ConsoleColor colour, string message, params object[] args) | ||
{ | ||
var oldColour = Console.ForegroundColor; | ||
try | ||
{ | ||
Console.ForegroundColor = colour; | ||
Console.WriteLine(message, args); | ||
} | ||
finally | ||
{ | ||
Console.ForegroundColor = oldColour; | ||
} | ||
} | ||
|
||
private static void RunPingCommand(ServerConnection connection) | ||
{ | ||
WriteToConsole(ConsoleColor.Yellow, "Sending ping..."); | ||
var stopwatch = new Stopwatch(); | ||
stopwatch.Start(); | ||
var result = connection.Ping(); | ||
stopwatch.Stop(); | ||
if (result) | ||
{ | ||
WriteToConsole(ConsoleColor.Yellow, "...ping received in {0}ms", stopwatch.ElapsedMilliseconds); | ||
} | ||
else | ||
{ | ||
WriteToConsole(ConsoleColor.Red, "...ping failed!", stopwatch.ElapsedMilliseconds); | ||
} | ||
} | ||
|
||
private static void RunQueryCommand(ServerConnection connection, string fullUrn) | ||
{ | ||
WriteToConsole(ConsoleColor.Yellow, "Querying '{0}'...", fullUrn); | ||
try | ||
{ | ||
var result = connection.Query(fullUrn); | ||
WriteToConsole(ConsoleColor.Yellow, "...{0} action(s) retrieved", result.Length); | ||
foreach (var action in result) | ||
{ | ||
WriteToConsole(ConsoleColor.White, "\t{0}", action.Name); | ||
} | ||
} | ||
catch (Exception error) | ||
{ | ||
WriteToConsole(ConsoleColor.Red, "...failed: " + error.Message); | ||
} | ||
} | ||
|
||
private static void RunInvokeCommand(ServerConnection connection, string fullUrn, string[] arguments) | ||
{ | ||
WriteToConsole(ConsoleColor.Yellow, "Invoking '{1}' on '{0}'...", fullUrn, arguments[0]); | ||
try | ||
{ | ||
var result = connection.Invoke(fullUrn, arguments[0], arguments.Skip(1).ToArray()); | ||
WriteToConsole(ConsoleColor.Yellow, "...completed"); | ||
} | ||
catch (Exception error) | ||
{ | ||
WriteToConsole(ConsoleColor.Red, "...failed: " + error.Message); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace CruiseControl.Common.Messages | ||
{ | ||
/// <summary> | ||
/// An item on the server. | ||
/// </summary> | ||
public class ServerItem | ||
{ | ||
#region Public properties | ||
#region DisplayName | ||
/// <summary> | ||
/// Gets or sets the display name. | ||
/// </summary> | ||
/// <value> | ||
/// The display name. | ||
/// </value> | ||
public string DisplayName { get; set; } | ||
#endregion | ||
|
||
#region Urn | ||
/// <summary> | ||
/// Gets or sets the URN. | ||
/// </summary> | ||
/// <value> | ||
/// The URN of the item. | ||
/// </value> | ||
public string Urn { get; set; } | ||
#endregion | ||
|
||
#region Description | ||
/// <summary> | ||
/// Gets or sets the description. | ||
/// </summary> | ||
/// <value> | ||
/// The description. | ||
/// </value> | ||
public string Description { get; set; } | ||
#endregion | ||
#endregion | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Playground/CruiseControl.Common/Messages/ServerItemList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace CruiseControl.Common.Messages | ||
{ | ||
/// <summary> | ||
/// A blank message. | ||
/// </summary> | ||
public class ServerItemList | ||
{ | ||
#region Public properties | ||
#region Children | ||
/// <summary> | ||
/// Gets or sets the children. | ||
/// </summary> | ||
/// <value> | ||
/// The children. | ||
/// </value> | ||
public ServerItem[] Children { get; set; } | ||
#endregion | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters