diff --git a/UptimeSharp.sln b/UptimeSharp.sln index 8a9d74f..280df16 100644 --- a/UptimeSharp.sln +++ b/UptimeSharp.sln @@ -5,6 +5,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UptimeSharp.OldClassLib", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UptimeSharp.Tests", "UptimeSharp.Tests\UptimeSharp.Tests.csproj", "{7AB536B7-1A99-44A7-B5AA-E36E9C7F09F4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UptimeSharp", "UptimeSharp\UptimeSharp.csproj", "{EC1E656D-4966-499A-9EDD-9DB56137BF62}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -19,6 +21,10 @@ Global {7AB536B7-1A99-44A7-B5AA-E36E9C7F09F4}.Debug|Any CPU.Build.0 = Debug|Any CPU {7AB536B7-1A99-44A7-B5AA-E36E9C7F09F4}.Release|Any CPU.ActiveCfg = Release|Any CPU {7AB536B7-1A99-44A7-B5AA-E36E9C7F09F4}.Release|Any CPU.Build.0 = Release|Any CPU + {EC1E656D-4966-499A-9EDD-9DB56137BF62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EC1E656D-4966-499A-9EDD-9DB56137BF62}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EC1E656D-4966-499A-9EDD-9DB56137BF62}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EC1E656D-4966-499A-9EDD-9DB56137BF62}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/UptimeSharp/Models/Alert.cs b/UptimeSharp/Models/Alert.cs new file mode 100644 index 0000000..01fdf02 --- /dev/null +++ b/UptimeSharp/Models/Alert.cs @@ -0,0 +1,96 @@ +using Newtonsoft.Json; + +namespace UptimeSharp.Models +{ + /// + /// The Alert Model + /// + [JsonObject] + public class Alert + { + /// + /// Gets or sets the ID. + /// + /// + /// The ID. + /// + [JsonProperty("id")] + public string ID { get; set; } + + /// + /// Gets or sets the alert type. + /// + /// + /// The name. + /// + [JsonProperty("type")] + public AlertType Type { get; set; } + + /// + /// Gets or sets the alert status. + /// + /// + /// The status. + /// + [JsonProperty("status")] + public AlertStatus Status { get; set; } + + /// + /// Gets or sets the alert value. + /// + /// + /// The value - Phone Number / E-Mail / Account + /// + [JsonProperty("value")] + public string Value { get; set; } + } + + + + /// + /// The type of the alert contact notified. + /// + public enum AlertType + { + /// + /// SMS + /// + SMS = 1, + /// + /// E-Mail + /// + Email = 2, + /// + /// Twitter DM + /// + Twitter = 3, + /// + /// Boxcar + /// + Boxcar = 4 + } + + + /// + /// The status of the alert contact. + /// + public enum AlertStatus + { + /// + /// Unknown + /// + Unknown, + /// + /// Not activated + /// + NotActicated = 0, + /// + /// Paused + /// + Paused = 1, + /// + /// Active + /// + Active = 2 + } +} diff --git a/UptimeSharp/Models/Log.cs b/UptimeSharp/Models/Log.cs new file mode 100644 index 0000000..9156749 --- /dev/null +++ b/UptimeSharp/Models/Log.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using System; + +namespace UptimeSharp.Models +{ + /// + /// The Log Model + /// + [JsonObject] + public class Log + { + /// + /// Gets or sets the log type. + /// + /// + /// The type. + /// + [JsonProperty("type")] + public LogType Type { get; set; } + + /// + /// Gets or sets the date time, when the log action appeared. + /// + /// + /// The date. + /// + [JsonProperty("datetime")] + public DateTime Date { get; set; } + + /// + /// Gets or sets the alerts, which were notified when the log action appeared. + /// + /// + /// The alert contacts. + /// + [JsonProperty("alertcontact")] + public List Alerts { get; set; } + } + + + + /// + /// The type of the log entry. + /// + public enum LogType + { + /// + /// Down + /// + Down = 1, + /// + /// Up + /// + Up = 2, + /// + /// Started + /// + Started = 98, + /// + /// Paused + /// + Paused = 99 + } +} diff --git a/UptimeSharp/Models/Monitor.cs b/UptimeSharp/Models/Monitor.cs new file mode 100644 index 0000000..189b440 --- /dev/null +++ b/UptimeSharp/Models/Monitor.cs @@ -0,0 +1,287 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.Serialization; +using System.Net; +using Newtonsoft.Json; + +namespace UptimeSharp.Models +{ + /// + /// The Monitor Model implementation + /// + [JsonObject] + public class Monitor + { + /// + /// Gets or sets the ID. + /// + /// + /// The ID. + /// + [JsonProperty("id")] + public int ID { get; set; } + + /// + /// Gets or sets the name. + /// + /// + /// The name. + /// + [JsonProperty("friendlyname")] + public string Name { get; set; } + + /// + /// Gets or sets the URI. + /// + /// + /// The URI. + /// + [JsonProperty("url")] + public string UriString { get; set; } + + /// + /// Gets the URI. + /// + /// + /// The URI. + /// + [JsonIgnore] + 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. + /// + [JsonProperty("port")] + public int? Port { get; set; } + + /// + /// Gets or sets the uptime. + /// + /// + /// Uptime ratio of the monitor calculated since the monitor is created. + /// + [JsonProperty("alltimeuptimeratio")] + public float Uptime { get; set; } + + /// + /// Gets or sets the uptime custom. + /// + /// + /// The uptime ratio of the monitor for the given periods + /// + [JsonProperty("customuptimeratio")] + public float? UptimeCustom { get; set; } + + /// + /// Gets or sets the HTTP password. + /// + /// + /// The HTTP password. + /// + [JsonProperty("httppassword")] + public string HTTPPassword { get; set; } + + /// + /// Gets or sets the HTTP username. + /// + /// + /// The HTTP username. + /// + [JsonProperty("httpusername")] + public string HTTPUsername { get; set; } + + /// + /// Gets or sets the type of the keyword. + /// + /// + /// The type of the keyword. + /// + [JsonProperty("keywordtype")] + public KeywordType KeywordType { get; set; } + + /// + /// Gets or sets the keyword value. + /// + /// + /// The keyword value. + /// + [JsonProperty("keywordvalue")] + public string KeywordValue { get; set; } + + /// + /// Gets or sets the status. + /// + /// + /// The status. + /// + [JsonProperty("status")] + public Status Status { get; set; } + + /// + /// Gets or sets the type. + /// + /// + /// The type. + /// + [JsonProperty("type")] + public Type Type { get; set; } + + /// + /// Gets or sets the subtype. + /// + /// + /// The subtype. + /// + [JsonProperty("subtype")] + public Subtype Subtype { get; set; } + + /// + /// Gets or sets the alerts. + /// + /// + /// The alert contacts. + /// + [JsonProperty("alertcontact")] + public List Alerts { get; set; } + + /// + /// Gets or sets the log. + /// + /// + /// The log with dates and associated alert contacts. + /// + [JsonProperty("log")] + public List Log { 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 + } +} diff --git a/UptimeSharp/Models/Parameters/MonitorParameters.cs b/UptimeSharp/Models/Parameters/MonitorParameters.cs new file mode 100644 index 0000000..9ac1185 --- /dev/null +++ b/UptimeSharp/Models/Parameters/MonitorParameters.cs @@ -0,0 +1,92 @@ +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; } + } +} diff --git a/UptimeSharp/Models/Parameters/RetrieveParameters.cs b/UptimeSharp/Models/Parameters/RetrieveParameters.cs new file mode 100644 index 0000000..4aea8b1 --- /dev/null +++ b/UptimeSharp/Models/Parameters/RetrieveParameters.cs @@ -0,0 +1,41 @@ + +namespace UptimeSharp.Models +{ + /// + /// All parameters which can be passed for monitor retrieval + /// + internal class RetrieveParameters + { + /// + /// List of monitor ids + /// + /// + /// The monitors. + /// + public int[] Monitors { get; set; } + + /// + /// Defines the number of days to calculate the uptime ratio + /// + /// + /// The custom uptime ratio. + /// + public float[] CustomUptimeRatio { get; set; } + + /// + /// Defines if the logs of each monitor will be returned + /// + /// + /// The log bool. + /// + public bool? ShowLog { get; set; } + + /// + /// Defines if the alert contacts set for the monitor to be returned + /// + /// + /// The alert contacts bool. + /// + public bool? ShowAlerts { get; set; } + } +} diff --git a/UptimeSharp/Models/Response/AlertResponse.cs b/UptimeSharp/Models/Response/AlertResponse.cs new file mode 100644 index 0000000..094b723 --- /dev/null +++ b/UptimeSharp/Models/Response/AlertResponse.cs @@ -0,0 +1,37 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace UptimeSharp.Models +{ + /// + /// Alert Response + /// + [JsonObject] + internal class AlertResponse : ResponseBase + { + /// + /// Gets or sets the item dictionary. + /// The list is 2 layers deep, so this one is necessary :-/ + /// + /// + /// The item dictionary. + /// + [JsonProperty("alertcontacts")] + public Dictionary> ItemDictionary { get; set; } + + /// + /// Gets the items. + /// + /// + /// The items. + /// + [JsonIgnore] + public List Items + { + get + { + return ItemDictionary["alertcontact"]; + } + } + } +} diff --git a/UptimeSharp/Models/Response/DefaultResponse.cs b/UptimeSharp/Models/Response/DefaultResponse.cs new file mode 100644 index 0000000..208422c --- /dev/null +++ b/UptimeSharp/Models/Response/DefaultResponse.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace UptimeSharp.Models +{ + /// + /// Default Response + /// + [JsonObject] + internal class DefaultResponse : ResponseBase {} +} diff --git a/UptimeSharp/Models/Response/ResponseBase.cs b/UptimeSharp/Models/Response/ResponseBase.cs new file mode 100644 index 0000000..0473c9a --- /dev/null +++ b/UptimeSharp/Models/Response/ResponseBase.cs @@ -0,0 +1,51 @@ +using Newtonsoft.Json; + +namespace UptimeSharp.Models +{ + /// + /// Base for Responses + /// + [JsonObject] + internal class ResponseBase + { + + /// + /// Gets or sets the error code. + /// + /// + /// The error code. + /// + [JsonProperty("id")] + public string ErrorCode { get; set; } + + /// + /// Gets or sets the error message. + /// + /// + /// The error message. + /// + [JsonProperty("message")] + public string ErrorMessage { get; set; } + + /// + /// Gets or sets a value indicating whether this is status. + /// + /// + /// "ok" or "fail" + /// + [JsonProperty("stat")] + public string RawStatus { get; set; } + + /// + /// Gets or sets a value indicating whether this is status. + /// + /// + /// true if status is OK; otherwise, false. + /// + [JsonIgnore] + public bool Status + { + get { return RawStatus == "ok"; } + } + } +} diff --git a/UptimeSharp/Models/Response/RetrieveResponse.cs b/UptimeSharp/Models/Response/RetrieveResponse.cs new file mode 100644 index 0000000..25573dc --- /dev/null +++ b/UptimeSharp/Models/Response/RetrieveResponse.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace UptimeSharp.Models +{ + /// + /// Monitor Response + /// + [JsonObject] + internal class RetrieveResponse : ResponseBase + { + /// + /// Gets or sets the item dictionary. + /// The list is 2 layers deep, so this one is necessary :-/ + /// + /// + /// The item dictionary. + /// + [JsonProperty("monitors")] + public Dictionary> ItemDictionary { get; set; } + + /// + /// Gets the items. + /// + /// + /// The items. + /// + [JsonIgnore] + public List Items + { + get + { + return ItemDictionary != null ? ItemDictionary["monitor"] : null; + } + } + } +} diff --git a/UptimeSharp/Properties/AssemblyInfo.cs b/UptimeSharp/Properties/AssemblyInfo.cs index d71da8c..29662d6 100644 --- a/UptimeSharp/Properties/AssemblyInfo.cs +++ b/UptimeSharp/Properties/AssemblyInfo.cs @@ -3,28 +3,27 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("UptimeSharp")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyDescription("UptimeSharp is a .NET class library that integrates the UptimeRobot API")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("cee")] [assembly: AssemblyProduct("UptimeSharp")] -[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyCopyright("Copyright © cee 2013")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.0")] +[assembly: AssemblyFileVersion("1.0.0")] \ No newline at end of file diff --git a/UptimeSharp/UptimeSharp.csproj b/UptimeSharp/UptimeSharp.csproj index 41f97dc..308c93c 100644 --- a/UptimeSharp/UptimeSharp.csproj +++ b/UptimeSharp/UptimeSharp.csproj @@ -39,7 +39,20 @@ + + + + + + + + + + + + + @@ -48,6 +61,13 @@ ..\packages\Microsoft.Bcl.Async.1.0.16\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.Extensions.dll + + ..\packages\Newtonsoft.Json.5.0.8\lib\portable-net40+sl4+wp7+win8\Newtonsoft.Json.dll + + + ..\packages\PropertyChanged.Fody.1.41.0.0\Lib\portable-net4+sl4+wp7+win8+MonoAndroid16+MonoTouch40\PropertyChanged.dll + False + ..\packages\Microsoft.Bcl.1.1.3\lib\portable-net40+sl4+win8+wp71\System.IO.dll