using RestSharp;
using System;
using System.Collections.Generic;
namespace UptimeSharp.Models
{
///
/// All parameters which can be passed for monitor modifications
///
internal class MonitorParameters
{
///
/// Gets or sets the name.
///
///
/// The name.
///
public string Name { get; set; }
///
/// Gets or sets the URI.
///
///
/// The URI.
///
public string Uri { get; set; }
///
/// Gets or sets the port.
/// Only for port monitoring.
///
///
/// The port.
///
public int? Port { get; set; }
///
/// Gets or sets the HTTP password.
///
///
/// The HTTP password.
///
public string HTTPPassword { get; set; }
///
/// Gets or sets the HTTP username.
///
///
/// The HTTP username.
///
public string HTTPUsername { get; set; }
///
/// Gets or sets the type of the keyword.
///
///
/// The type of the keyword.
///
public KeywordType KeywordType { get; set; }
///
/// Gets or sets the keyword value.
///
///
/// The keyword value.
///
public string KeywordValue { get; set; }
///
/// Gets or sets the type.
///
///
/// The type.
///
public Type Type { get; set; }
///
/// Gets or sets the subtype.
///
///
/// The subtype.
///
public Subtype Subtype { get; set; }
///
/// Gets or sets the alerts.
///
///
/// The alert contacts.
///
public string[] Alerts { get; set; }
///
/// Converts this instance to a parameter list.
///
/// Parameter list
public List Convert()
{
List parameters = new List();
parameters.Add(UptimeClient.Parameter("monitorFriendlyName", Name));
parameters.Add(UptimeClient.Parameter("monitorURL", Uri));
if ((int)Type != 0)
{
parameters.Add(UptimeClient.Parameter("monitorType", (int)Type));
}
// special params for port listener
if (Type == Type.Port && Subtype != Subtype.Unknown)
{
parameters.Add(UptimeClient.Parameter("monitorSubType", (int)Subtype));
if (Subtype == Subtype.Custom && Port.HasValue)
{
parameters.Add(UptimeClient.Parameter("monitorPort", Port));
}
}
// keyword listener
if (Type == Type.Keyword && !string.IsNullOrEmpty(KeywordValue))
{
parameters.Add(UptimeClient.Parameter("monitorKeywordType", (int)KeywordType));
parameters.Add(UptimeClient.Parameter("monitorKeywordValue", KeywordValue));
}
// HTTP basic auth credentials
parameters.Add(UptimeClient.Parameter("monitorHTTPUsername", HTTPUsername));
parameters.Add(UptimeClient.Parameter("monitorHTTPPassword", HTTPPassword));
// alert notifications
if (Alerts != null && Alerts.Length > 0)
{
parameters.Add(UptimeClient.Parameter("monitorAlertContacts", string.Join("-", Alerts)));
}
return parameters;
}
}
}