From 80437a5f56fe2d5a5a11c8cc75d151d69ddc6596 Mon Sep 17 00:00:00 2001 From: ceee Date: Sun, 18 Aug 2013 11:07:51 +0200 Subject: [PATCH] add Monitor Model/POCO --- UptimeSharp/JsonDeserializer.cs | 20 ++- UptimeSharp/Models/Monitor.cs | 239 ++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+), 2 deletions(-) diff --git a/UptimeSharp/JsonDeserializer.cs b/UptimeSharp/JsonDeserializer.cs index 2f00805..e4c453a 100644 --- a/UptimeSharp/JsonDeserializer.cs +++ b/UptimeSharp/JsonDeserializer.cs @@ -2,6 +2,7 @@ using RestSharp.Deserializers; using ServiceStack.Text; using System; +using System.Net; namespace UptimeSharp { @@ -30,12 +31,27 @@ namespace UptimeSharp public static void AddCustomDeserialization() { // generate correct Uri format - JsConfig.DeSerializeFn = value => new Uri(value); + JsConfig.DeSerializeFn = value => + { + Uri uri; + try + { + uri = new Uri(value); + } + catch + { + uri = null; + } + return uri; + }; // create DateTime from UNIX timestamp input JsConfig.DeSerializeFn = value => { - if (value == "0") return null; + if (value == "0") + { + return null; + } return new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(Convert.ToDouble(value)).ToLocalTime(); }; } diff --git a/UptimeSharp/Models/Monitor.cs b/UptimeSharp/Models/Monitor.cs index 58a4c39..54b44b1 100644 --- a/UptimeSharp/Models/Monitor.cs +++ b/UptimeSharp/Models/Monitor.cs @@ -3,9 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; +using System.Net; +using ServiceStack.Text; namespace UptimeSharp.Models { + /// + /// The Monitor Model implementation + /// [DataContract] public class Monitor { @@ -26,5 +31,239 @@ namespace UptimeSharp.Models /// [DataMember(Name = "friendlyname")] public string Name { get; set; } + + /// + /// Gets or sets the URI. + /// + /// + /// The URI. + /// + [DataMember(Name = "url")] + public string UriString { get; set; } + + /// + /// Gets the URI. + /// + /// + /// The URI. + /// + [IgnoreDataMember] + public Uri Uri + { + get + { + Uri uri; + try + { + uri = new Uri(UriString); + } + catch + { + uri = null; + } + return uri; + } + } + + /// + /// Gets or sets the port. + /// Only for port monitoring. + /// + /// + /// The port. + /// + [DataMember(Name = "port")] + public int? Port { get; set; } + + /// + /// Gets or sets the uptime. + /// + /// + /// Uptime ratio of the monitor calculated since the monitor is created. + /// + [DataMember(Name = "alltimeuptimeratio")] + public float Uptime { get; set; } + + /// + /// Gets or sets the uptime custom. + /// + /// + /// The uptime ratio of the monitor for the given periods + /// + [DataMember(Name = "customuptimeratio")] + public float? UptimeCustom { get; set; } + + /// + /// Gets or sets the HTTP password. + /// + /// + /// The HTTP password. + /// + [DataMember(Name = "httppassword")] + public string HTTPPassword { get; set; } + + /// + /// Gets or sets the HTTP username. + /// + /// + /// The HTTP username. + /// + [DataMember(Name = "httpusername")] + public string HTTPUsername { get; set; } + + /// + /// Gets or sets the type of the keyword. + /// + /// + /// The type of the keyword. + /// + [DataMember(Name = "keywordtype")] + public KeywordType KeywordType { get; set; } + + /// + /// Gets or sets the keyword value. + /// + /// + /// The keyword value. + /// + [DataMember(Name = "keywordvalue")] + public string KeywordValue { get; set; } + + /// + /// Gets or sets the status. + /// + /// + /// The status. + /// + [DataMember(Name = "status")] + public Status Status { get; set; } + + /// + /// Gets or sets the type. + /// + /// + /// The type. + /// + [DataMember(Name = "type")] + public Type Type { get; set; } + + /// + /// Gets or sets the subtype. + /// + /// + /// The subtype. + /// + [DataMember(Name = "subtype")] + public Subtype Subtype { get; set; } + } + + + + /// + /// The status of the monitor + /// + public enum Status + { + /// + /// Paused + /// + Pause = 0, + /// + /// Not checked yet + /// + NotChecked = 1, + /// + /// Up + /// + Up = 2, + /// + /// Seems down + /// + SeemsDown = 8, + /// + /// Down + /// + Down = 9 + } + + /// + /// The type of the monitor + /// + public enum Type + { + /// + /// HTTP + /// + HTTP = 1, + /// + /// Keyword + /// + Keyword = 2, + /// + /// Ping + /// + Ping = 3, + /// + /// Port + /// + Port = 4 + } + + /// + /// Shows which pre-defined port/service is monitored or if a custom port is monitored. + /// + public enum Subtype + { + /// + /// Unknown + /// + Unknown, + /// + /// HTTP + /// + HTTP = 1, + /// + /// HTTPS + /// + HTTPS = 2, + /// + /// FTP + /// + FTP = 3, + /// + /// SMTP + /// + SMTP = 4, + /// + /// POP3 + /// + POP3 = 5, + /// + /// IMAP + /// + IMAP = 6, + /// + /// Custom Port + /// + Custom = 99 + } + + /// + /// Shows if the monitor will be flagged as down when the keyword exists or not exists + /// + public enum KeywordType + { + /// + /// Unknown + /// + Unknown, + /// + /// Exists + /// + Exists = 1, + /// + /// Exists not + /// + NotExists = 2 } }