forked from ProVal-Tech/SimpleNotification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
89 lines (80 loc) · 2.85 KB
/
Program.cs
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
using CommandLine;
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Windows.Forms;
using Tomlyn;
namespace SimpleNotification {
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
public class Options {
[Option(
'm',
"message",
Required = true,
HelpText = "The message to display to the end user.",
SetName = "direct"
)]
public string Message { get; set; }
[Option(
'i',
"imageurl",
Required = false,
Default = "",
HelpText = "The URL for the image to display instead of the default.",
SetName = "direct"
)]
public string ImageUrl { get; set; }
[Option(
'e',
"email",
Required = false,
Default = "",
HelpText = "The support e-mail address to display to the user.",
SetName = "direct"
)]
public string Email { get; set; }
[Option(
'p',
"phone",
Required = false,
Default = "",
HelpText = "The support phone number to display to the user.",
SetName = "direct"
)]
public string Phone { get; set; }
[Option(
'c',
"configfile",
Required = true,
Default = "",
HelpText = "The path to the TOML config file.",
SetName = "toml"
)]
[IgnoreDataMember]
public string TomlPath { get; set; }
}
private static Options clArguments = new Options();
[STAThread]
static void Main(string[] args) {
Parser parser = new Parser(settings => { settings.CaseSensitive = false; });
parser.ParseArguments<Options>(args)
.WithParsed((opts) => clArguments = opts)
.WithNotParsed((errs) => Environment.Exit(1));
if (!string.IsNullOrWhiteSpace(clArguments.TomlPath)) {
try {
string toml = File.ReadAllText(clArguments.TomlPath);
clArguments = Toml.ToModel<Options>(toml);
} catch {
Console.WriteLine("Error reading TOML file.");
Environment.Exit(1);
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1(clArguments.Message, clArguments.ImageUrl, clArguments.Email, clArguments.Phone));
}
}
}