-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
121 lines (101 loc) · 2.63 KB
/
Copy pathProgram.cs
File metadata and controls
121 lines (101 loc) · 2.63 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
using System;
using Nancy.Hosting.Self;
using System.Threading;
using CommandLine;
using HyperOffice.App.Providers;
using HyperOffice.App.Actions;
/**
* https://github.com/commandlineparser/commandline
*
* Show more options:
* HyperOffice.exe --help
*/
namespace HyperOffice
{
class Program
{
[Verb("up",
isDefault: true,
HelpText = "Start the Http server"
)]
class UpOptions
{
[Option('d',
Required = false,
HelpText = "Detached mode. Run application in the background"
)]
public bool Detached { get; set; }
[Option('q', "quiet",
Required = false,
HelpText = "Quiet mode"
)]
public bool Quiet { get; set; }
[Option('p', "port",
Required = false,
Default = 8080,
HelpText = "Port of listen server"
)]
public int Port { get; set; }
[Option('t', "threads",
Required = false,
Default = 1,
HelpText = "Numbers worker threads of Queue. Limited by the number of CPU cores"
)]
public int Threads { get; set; }
}
[Verb("snapshot",
HelpText = "Make screenshot in MS Office document"
)]
class SnapshotOptions
{
[Option("url",
Required = false,
HelpText = "Url for return result"
)]
public string Url { get; set; }
[Option("input",
HelpText = "Microsoft Word document file"
)]
public string Input { get; set; }
}
static void Main(string[] args)
{
Parser.Default.ParseArguments<UpOptions, SnapshotOptions>(args)
.WithParsed<UpOptions>(opts => HttpServer(opts))
.WithParsed<SnapshotOptions>(opts => Snapshot(opts));
}
static void HttpServer(UpOptions opts)
{
if (opts.Port < 1024 || opts.Port > 49151)
{
throw new Exception("Expected User Ports (1024-49151)");
}
State.Queue = new QueueProvider(opts.Threads);
var origin = string.Format(@"http://localhost:{0}",
opts.Port
);
var listen = new Uri(origin);
var server = new NancyHost(listen);
server.Start();
if (opts.Detached)
{
Thread.Sleep(Timeout.Infinite);
}
else
{
Console.WriteLine(@"Server started on {0}",
origin
);
Console.WriteLine("Press esc to exit the application");
while (Console.ReadKey().Key != ConsoleKey.Escape) { }
}
server.Stop();
}
static void Snapshot(SnapshotOptions opts)
{
var hyperDocument = new HyperDocument();
var uri = new Uri(opts.Url);
hyperDocument.Snapshot(uri, opts.Input);
}
}
}