-
Notifications
You must be signed in to change notification settings - Fork 7
/
AprsConfig.cs
125 lines (104 loc) · 4.19 KB
/
AprsConfig.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
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
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.Extensions.Configuration;
namespace Skyhop.Aprs.Client
{
public static class AprsConfig
{
public static IConfigurationRoot Configuration { get; set; }
static AprsConfig() {
Configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true).Build();
}
public static string Uri => Configuration["aprsClient:uri"] ?? "noam.aprs2.net";
public static int Port => Convert.ToInt32(Configuration["aprsClient:port"] ?? "14580");
public static string Callsign => Configuration["aprsClient:callsign"] ?? "0";
public static string Password => Configuration["aprsClient:password"] ?? "-1";
public static string SoftwareName => Configuration["aprsClient:softwareName"] ?? "bocobrew";
public static string SoftwareVersion => Configuration["aprsClient:softwareVersion"] ?? "0.0";
public static string Filter => Configuration["aprsClient:filter"] ?? "t/poimqstunw";
public static bool UseOgnAdditives => Convert.ToBoolean(Configuration["aprsClient:useOgnAdditives"] ?? "true");
}
public class Config
{
string uri;
int? port;
string callsign;
string password;
string softwareName;
string softwareVersion;
string filter;
bool? useOgnAdditives;
// ToDo: Check whether the URI can be used to connect with an IP address.
public string Uri
{
get { return uri ?? AprsConfig.Uri; }
set { uri = value; }
}
public int Port
{
get { return port ?? AprsConfig.Port; }
set { port = value; }
}
public string Callsign
{
get { return callsign ?? AprsConfig.Callsign; }
set { callsign = value; }
}
public string Password
{
get { return password ?? AprsConfig.Password; }
set { password = value; }
}
public string SoftwareName
{
get { return softwareName ?? AprsConfig.SoftwareName; }
set { softwareName = value; }
}
public string SoftwareVersion
{
get { return softwareVersion ?? AprsConfig.SoftwareVersion; }
set { softwareVersion = value; }
}
public string Filter
{
get { return filter ?? AprsConfig.Filter; }
set { filter = value; }
}
public bool UseOgnAdditives
{
get { return useOgnAdditives ?? AprsConfig.UseOgnAdditives; }
set { useOgnAdditives = value; }
}
public bool ValidateConfiguration()
{
bool callsignValidity = Callsign.VerifyCallsign();
bool passwordValidity = Helpers.VerifyPassword(Callsign, Password);
bool checkSoftwareName = SoftwareName.IndexOf(' ') > -1;
bool checkSoftwareVersion = SoftwareVersion.IndexOf(' ') > -1;
if (!callsignValidity)
{
Trace.TraceWarning($"{nameof(Callsign)} could not be validated, see http://www.aprs-is.net/Connecting.aspx for more information");
}
if (!passwordValidity)
{
Trace.TraceWarning($"{nameof(Password)} is not valid for given callsign. Please request a valid password with the software vendor in case you need write access to the APRS server.");
}
if (Password == "-1")
{
Trace.TraceWarning("APRS client is in readonly mode. Request a valid password in case you need write access to the APRS server");
}
if (!checkSoftwareName)
{
Trace.TraceWarning($"{nameof(SoftwareName)} contains a space.Spaces are illegal. Your mileage may vary now.");
}
if (!checkSoftwareVersion)
{
Trace.TraceWarning($"{nameof(SoftwareVersion)} contains a space. Spaces are illegal. Your mileage may vary now.");
}
return callsignValidity && passwordValidity && checkSoftwareName && checkSoftwareVersion;
}
}
}