forked from InEngine-NET/InEngine.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
86 lines (82 loc) · 3.11 KB
/
Program.cs
File metadata and controls
86 lines (82 loc) · 3.11 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
using CommandLine;
using CommandLine.Text;
using IntegrationEngine.Client;
using IntegrationEngine.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IntegrationEngine.ConsoleClient
{
class Program
{
static void Main(string[] args)
{
var options = new Options();
var invokedVerb = "";
var invokedVerbInstance = new object();
if (args == null ||
args.Length == 0 ||
!CommandLine.Parser.Default.ParseArguments(args, options, (verb, subOptions) => {
invokedVerb = verb;
invokedVerbInstance = subOptions;
}))
{
Console.WriteLine(options.GetUsage());
Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
}
var client = !string.IsNullOrWhiteSpace(options.WebApiUrl) ?
new InEngineClient(options.WebApiUrl) :
new InEngineClient();
if (invokedVerb == "get") {
var getSubOptions = (GetSubOptions)invokedVerbInstance;
if (getSubOptions.Id != null)
switch (getSubOptions.Resource)
{
case Endpoint.CronTrigger:
ResolveResult(client.Get<CronTrigger>(getSubOptions.Id));
break;
case Endpoint.SimpleTrigger:
ResolveResult(client.Get<SimpleTrigger>(getSubOptions.Id));
break;
}
else
switch (getSubOptions.Resource)
{
case Endpoint.CronTrigger:
ResolveResult(client.GetCollection<CronTrigger>());
break;
case Endpoint.SimpleTrigger:
ResolveResult(client.GetCollection<SimpleTrigger>());
break;
case Endpoint.JobType:
ResolveResult(client.GetCollection<JobType>());
break;
case Endpoint.LogEvent:
ResolveResult(client.GetCollection<LogEvent>());
break;
case Endpoint.HealthStatus:
ResolveResult(client.GetHealthStatus());
break;
}
}
if (invokedVerb == "ping") {
Console.WriteLine(client.Ping());
}
}
public static void ResolveResult(dynamic result)
{
if (result == null)
Console.WriteLine("The web API did not return a result. Is the URL correct and the server online? Try -mPing.");
else if (result is IEnumerable)
{
Console.WriteLine("Number of items: {0}", result.Count);
foreach (var item in result)
Console.WriteLine(item);
}
else
Console.WriteLine(result);
}
}
}