17 using System.Collections.Generic;
19 using System.Text.RegularExpressions;
20 using Newtonsoft.Json;
49 [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
50 public Dictionary<string, string>
Headers {
get;
set; }
60 [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
61 public object Data {
get;
set; }
69 public NotificationWeb(
string address,
object data =
null, Dictionary<string, string> headers =
null)
90 [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
113 [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
114 public Dictionary<string, string>
Headers {
get;
set; }
129 [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
135 [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
136 public string Data {
get;
set; }
147 public NotificationEmail(
string address,
string subject =
"",
string message =
"",
string data =
"", Dictionary<string, string> headers =
null)
155 Data = data ??
string.Empty;
156 Message = message ??
string.Empty;
157 Subject = subject ??
string.Empty;
171 public string Id {
get;
set; }
176 [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
182 [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
207 private static readonly Regex HostnameProtocolRegex =
new(
@"^[s]?ftp\:\/\/", RegexOptions.IgnoreCase | RegexOptions.Compiled);
209 private const int DefaultPort = 21;
214 [JsonProperty(
"secure")]
220 [JsonProperty(
"host")]
226 [JsonProperty(
"port")]
232 [JsonProperty(
"username")]
238 [JsonProperty(
"password", DefaultValueHandling = DefaultValueHandling.Ignore)]
244 [JsonProperty(
"fileDestinationPath")]
250 [JsonProperty(
"fileContent")]
256 [JsonProperty(
"privateKey", DefaultValueHandling = DefaultValueHandling.Ignore)]
262 [JsonProperty(
"passphrase", DefaultValueHandling = DefaultValueHandling.Ignore)]
265 private NotificationFtp(
string hostname,
string username,
string filePath,
byte[] fileContent,
bool secure,
int? port)
267 Hostname = NormalizeHostname(hostname);
268 Port = port ?? DefaultPort;
285 public NotificationFtp(
string hostname,
string username,
string password,
string filePath,
byte[] fileContent,
286 bool secure =
true,
int? port =
null)
287 : this(hostname, username, filePath, fileContent, secure, port)
289 if (
string.IsNullOrEmpty(password))
308 public NotificationFtp(
string hostname,
string username,
string privateKey,
string privateKeyPassphrase,
309 string filePath,
byte[] fileContent,
int? port =
null)
310 : this(hostname, username, filePath, fileContent, true, port)
312 if (
string.IsNullOrEmpty(privateKey))
331 public NotificationFtp(
string hostname,
string username,
string password,
string filePath,
string fileContent,
332 bool secure =
true,
int? port =
null)
333 : this(hostname, username, password, filePath, Encoding.ASCII.GetBytes(fileContent), secure, port)
348 public NotificationFtp(
string hostname,
string username,
string privateKey,
string privateKeyPassphrase,
349 string filePath,
string fileContent,
int? port =
null)
350 : this(hostname, username, privateKey, privateKeyPassphrase, filePath, Encoding.ASCII.GetBytes(fileContent), port)
354 private static string NormalizeHostname(
string hostname)
357 hostname = hostname.Trim().TrimEnd(
'/');
359 return HostnameProtocolRegex.Replace(hostname,
"");
365 internal static NotificationFtp FromEncodedData(
string hostname,
string username,
string password,
string filePath,
string encodedFileContent,
366 bool secure,
int? port)
368 var notification =
new NotificationFtp(hostname, username, password, filePath, Array.Empty<
byte>(), secure, port);
369 notification.FileContent = encodedFileContent;
376 internal static NotificationFtp FromEncodedData(
string hostname,
string username,
string privateKey,
string privateKeyPassphrase,
377 string filePath,
string encodedFileContent,
int? port)
379 var notification =
new NotificationFtp(hostname, username, privateKey, privateKeyPassphrase, filePath, Array.Empty<
byte>(), port);
380 notification.FileContent = encodedFileContent;
397 if (notification ==
null)
402 var type = notification.GetType();