add JsonExtensions and Models

This commit is contained in:
2013-10-28 21:14:23 +01:00
parent c1cb0cb505
commit 9bbaafb528
12 changed files with 750 additions and 9 deletions
+6
View File
@@ -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
+96
View File
@@ -0,0 +1,96 @@
using Newtonsoft.Json;
namespace UptimeSharp.Models
{
/// <summary>
/// The Alert Model
/// </summary>
[JsonObject]
public class Alert
{
/// <summary>
/// Gets or sets the ID.
/// </summary>
/// <value>
/// The ID.
/// </value>
[JsonProperty("id")]
public string ID { get; set; }
/// <summary>
/// Gets or sets the alert type.
/// </summary>
/// <value>
/// The name.
/// </value>
[JsonProperty("type")]
public AlertType Type { get; set; }
/// <summary>
/// Gets or sets the alert status.
/// </summary>
/// <value>
/// The status.
/// </value>
[JsonProperty("status")]
public AlertStatus Status { get; set; }
/// <summary>
/// Gets or sets the alert value.
/// </summary>
/// <value>
/// The value - Phone Number / E-Mail / Account
/// </value>
[JsonProperty("value")]
public string Value { get; set; }
}
/// <summary>
/// The type of the alert contact notified.
/// </summary>
public enum AlertType
{
/// <summary>
/// SMS
/// </summary>
SMS = 1,
/// <summary>
/// E-Mail
/// </summary>
Email = 2,
/// <summary>
/// Twitter DM
/// </summary>
Twitter = 3,
/// <summary>
/// Boxcar
/// </summary>
Boxcar = 4
}
/// <summary>
/// The status of the alert contact.
/// </summary>
public enum AlertStatus
{
/// <summary>
/// Unknown
/// </summary>
Unknown,
/// <summary>
/// Not activated
/// </summary>
NotActicated = 0,
/// <summary>
/// Paused
/// </summary>
Paused = 1,
/// <summary>
/// Active
/// </summary>
Active = 2
}
}
+65
View File
@@ -0,0 +1,65 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using System;
namespace UptimeSharp.Models
{
/// <summary>
/// The Log Model
/// </summary>
[JsonObject]
public class Log
{
/// <summary>
/// Gets or sets the log type.
/// </summary>
/// <value>
/// The type.
/// </value>
[JsonProperty("type")]
public LogType Type { get; set; }
/// <summary>
/// Gets or sets the date time, when the log action appeared.
/// </summary>
/// <value>
/// The date.
/// </value>
[JsonProperty("datetime")]
public DateTime Date { get; set; }
/// <summary>
/// Gets or sets the alerts, which were notified when the log action appeared.
/// </summary>
/// <value>
/// The alert contacts.
/// </value>
[JsonProperty("alertcontact")]
public List<Alert> Alerts { get; set; }
}
/// <summary>
/// The type of the log entry.
/// </summary>
public enum LogType
{
/// <summary>
/// Down
/// </summary>
Down = 1,
/// <summary>
/// Up
/// </summary>
Up = 2,
/// <summary>
/// Started
/// </summary>
Started = 98,
/// <summary>
/// Paused
/// </summary>
Paused = 99
}
}
+287
View File
@@ -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
{
/// <summary>
/// The Monitor Model implementation
/// </summary>
[JsonObject]
public class Monitor
{
/// <summary>
/// Gets or sets the ID.
/// </summary>
/// <value>
/// The ID.
/// </value>
[JsonProperty("id")]
public int ID { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>
/// The name.
/// </value>
[JsonProperty("friendlyname")]
public string Name { get; set; }
/// <summary>
/// Gets or sets the URI.
/// </summary>
/// <value>
/// The URI.
/// </value>
[JsonProperty("url")]
public string UriString { get; set; }
/// <summary>
/// Gets the URI.
/// </summary>
/// <value>
/// The URI.
/// </value>
[JsonIgnore]
public Uri Uri
{
get
{
Uri uri;
try
{
uri = new Uri(UriString);
}
catch
{
uri = null;
}
return uri;
}
}
/// <summary>
/// Gets or sets the port.
/// Only for port monitoring.
/// </summary>
/// <value>
/// The port.
/// </value>
[JsonProperty("port")]
public int? Port { get; set; }
/// <summary>
/// Gets or sets the uptime.
/// </summary>
/// <value>
/// Uptime ratio of the monitor calculated since the monitor is created.
/// </value>
[JsonProperty("alltimeuptimeratio")]
public float Uptime { get; set; }
/// <summary>
/// Gets or sets the uptime custom.
/// </summary>
/// <value>
/// The uptime ratio of the monitor for the given periods
/// </value>
[JsonProperty("customuptimeratio")]
public float? UptimeCustom { get; set; }
/// <summary>
/// Gets or sets the HTTP password.
/// </summary>
/// <value>
/// The HTTP password.
/// </value>
[JsonProperty("httppassword")]
public string HTTPPassword { get; set; }
/// <summary>
/// Gets or sets the HTTP username.
/// </summary>
/// <value>
/// The HTTP username.
/// </value>
[JsonProperty("httpusername")]
public string HTTPUsername { get; set; }
/// <summary>
/// Gets or sets the type of the keyword.
/// </summary>
/// <value>
/// The type of the keyword.
/// </value>
[JsonProperty("keywordtype")]
public KeywordType KeywordType { get; set; }
/// <summary>
/// Gets or sets the keyword value.
/// </summary>
/// <value>
/// The keyword value.
/// </value>
[JsonProperty("keywordvalue")]
public string KeywordValue { get; set; }
/// <summary>
/// Gets or sets the status.
/// </summary>
/// <value>
/// The status.
/// </value>
[JsonProperty("status")]
public Status Status { get; set; }
/// <summary>
/// Gets or sets the type.
/// </summary>
/// <value>
/// The type.
/// </value>
[JsonProperty("type")]
public Type Type { get; set; }
/// <summary>
/// Gets or sets the subtype.
/// </summary>
/// <value>
/// The subtype.
/// </value>
[JsonProperty("subtype")]
public Subtype Subtype { get; set; }
/// <summary>
/// Gets or sets the alerts.
/// </summary>
/// <value>
/// The alert contacts.
/// </value>
[JsonProperty("alertcontact")]
public List<Alert> Alerts { get; set; }
/// <summary>
/// Gets or sets the log.
/// </summary>
/// <value>
/// The log with dates and associated alert contacts.
/// </value>
[JsonProperty("log")]
public List<Log> Log { get; set; }
}
/// <summary>
/// The status of the monitor
/// </summary>
public enum Status
{
/// <summary>
/// Paused
/// </summary>
Pause = 0,
/// <summary>
/// Not checked yet
/// </summary>
NotChecked = 1,
/// <summary>
/// Up
/// </summary>
Up = 2,
/// <summary>
/// Seems down
/// </summary>
SeemsDown = 8,
/// <summary>
/// Down
/// </summary>
Down = 9
}
/// <summary>
/// The type of the monitor
/// </summary>
public enum Type
{
/// <summary>
/// HTTP
/// </summary>
HTTP = 1,
/// <summary>
/// Keyword
/// </summary>
Keyword = 2,
/// <summary>
/// Ping
/// </summary>
Ping = 3,
/// <summary>
/// Port
/// </summary>
Port = 4
}
/// <summary>
/// Shows which pre-defined port/service is monitored or if a custom port is monitored.
/// </summary>
public enum Subtype
{
/// <summary>
/// Unknown
/// </summary>
Unknown,
/// <summary>
/// HTTP
/// </summary>
HTTP = 1,
/// <summary>
/// HTTPS
/// </summary>
HTTPS = 2,
/// <summary>
/// FTP
/// </summary>
FTP = 3,
/// <summary>
/// SMTP
/// </summary>
SMTP = 4,
/// <summary>
/// POP3
/// </summary>
POP3 = 5,
/// <summary>
/// IMAP
/// </summary>
IMAP = 6,
/// <summary>
/// Custom Port
/// </summary>
Custom = 99
}
/// <summary>
/// Shows if the monitor will be flagged as down when the keyword exists or not exists
/// </summary>
public enum KeywordType
{
/// <summary>
/// Unknown
/// </summary>
Unknown,
/// <summary>
/// Exists
/// </summary>
Exists = 1,
/// <summary>
/// Exists not
/// </summary>
NotExists = 2
}
}
@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
namespace UptimeSharp.Models
{
/// <summary>
/// All parameters which can be passed for monitor modifications
/// </summary>
internal class MonitorParameters
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>
/// The name.
/// </value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the URI.
/// </summary>
/// <value>
/// The URI.
/// </value>
public string Uri { get; set; }
/// <summary>
/// Gets or sets the port.
/// Only for port monitoring.
/// </summary>
/// <value>
/// The port.
/// </value>
public int? Port { get; set; }
/// <summary>
/// Gets or sets the HTTP password.
/// </summary>
/// <value>
/// The HTTP password.
/// </value>
public string HTTPPassword { get; set; }
/// <summary>
/// Gets or sets the HTTP username.
/// </summary>
/// <value>
/// The HTTP username.
/// </value>
public string HTTPUsername { get; set; }
/// <summary>
/// Gets or sets the type of the keyword.
/// </summary>
/// <value>
/// The type of the keyword.
/// </value>
public KeywordType KeywordType { get; set; }
/// <summary>
/// Gets or sets the keyword value.
/// </summary>
/// <value>
/// The keyword value.
/// </value>
public string KeywordValue { get; set; }
/// <summary>
/// Gets or sets the type.
/// </summary>
/// <value>
/// The type.
/// </value>
public Type Type { get; set; }
/// <summary>
/// Gets or sets the subtype.
/// </summary>
/// <value>
/// The subtype.
/// </value>
public Subtype Subtype { get; set; }
/// <summary>
/// Gets or sets the alerts.
/// </summary>
/// <value>
/// The alert contacts.
/// </value>
public string[] Alerts { get; set; }
}
}
@@ -0,0 +1,41 @@
namespace UptimeSharp.Models
{
/// <summary>
/// All parameters which can be passed for monitor retrieval
/// </summary>
internal class RetrieveParameters
{
/// <summary>
/// List of monitor ids
/// </summary>
/// <value>
/// The monitors.
/// </value>
public int[] Monitors { get; set; }
/// <summary>
/// Defines the number of days to calculate the uptime ratio
/// </summary>
/// <value>
/// The custom uptime ratio.
/// </value>
public float[] CustomUptimeRatio { get; set; }
/// <summary>
/// Defines if the logs of each monitor will be returned
/// </summary>
/// <value>
/// The log bool.
/// </value>
public bool? ShowLog { get; set; }
/// <summary>
/// Defines if the alert contacts set for the monitor to be returned
/// </summary>
/// <value>
/// The alert contacts bool.
/// </value>
public bool? ShowAlerts { get; set; }
}
}
@@ -0,0 +1,37 @@
using Newtonsoft.Json;
using System.Collections.Generic;
namespace UptimeSharp.Models
{
/// <summary>
/// Alert Response
/// </summary>
[JsonObject]
internal class AlertResponse : ResponseBase
{
/// <summary>
/// Gets or sets the item dictionary.
/// The list is 2 layers deep, so this one is necessary :-/
/// </summary>
/// <value>
/// The item dictionary.
/// </value>
[JsonProperty("alertcontacts")]
public Dictionary<string, List<Alert>> ItemDictionary { get; set; }
/// <summary>
/// Gets the items.
/// </summary>
/// <value>
/// The items.
/// </value>
[JsonIgnore]
public List<Alert> Items
{
get
{
return ItemDictionary["alertcontact"];
}
}
}
}
@@ -0,0 +1,10 @@
using Newtonsoft.Json;
namespace UptimeSharp.Models
{
/// <summary>
/// Default Response
/// </summary>
[JsonObject]
internal class DefaultResponse : ResponseBase {}
}
@@ -0,0 +1,51 @@
using Newtonsoft.Json;
namespace UptimeSharp.Models
{
/// <summary>
/// Base for Responses
/// </summary>
[JsonObject]
internal class ResponseBase
{
/// <summary>
/// Gets or sets the error code.
/// </summary>
/// <value>
/// The error code.
/// </value>
[JsonProperty("id")]
public string ErrorCode { get; set; }
/// <summary>
/// Gets or sets the error message.
/// </summary>
/// <value>
/// The error message.
/// </value>
[JsonProperty("message")]
public string ErrorMessage { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="ResponseBase"/> is status.
/// </summary>
/// <value>
/// "ok" or "fail"
/// </value>
[JsonProperty("stat")]
public string RawStatus { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="ResponseBase"/> is status.
/// </summary>
/// <value>
/// <c>true</c> if status is OK; otherwise, <c>false</c>.
/// </value>
[JsonIgnore]
public bool Status
{
get { return RawStatus == "ok"; }
}
}
}
@@ -0,0 +1,37 @@
using System.Collections.Generic;
using Newtonsoft.Json;
namespace UptimeSharp.Models
{
/// <summary>
/// Monitor Response
/// </summary>
[JsonObject]
internal class RetrieveResponse : ResponseBase
{
/// <summary>
/// Gets or sets the item dictionary.
/// The list is 2 layers deep, so this one is necessary :-/
/// </summary>
/// <value>
/// The item dictionary.
/// </value>
[JsonProperty("monitors")]
public Dictionary<string, List<Monitor>> ItemDictionary { get; set; }
/// <summary>
/// Gets the items.
/// </summary>
/// <value>
/// The items.
/// </value>
[JsonIgnore]
public List<Monitor> Items
{
get
{
return ItemDictionary != null ? ItemDictionary["monitor"] : null;
}
}
}
}
+5 -6
View File
@@ -7,14 +7,13 @@ using System.Runtime.InteropServices;
// 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:
//
@@ -26,5 +25,5 @@ using System.Runtime.InteropServices;
// 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")]
+20
View File
@@ -39,7 +39,20 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="IUptimeClient.cs" />
<Compile Include="Models\Alert.cs" />
<Compile Include="Models\Log.cs" />
<Compile Include="Models\Monitor.cs" />
<Compile Include="Models\Parameters\MonitorParameters.cs" />
<Compile Include="Models\Parameters\RetrieveParameters.cs" />
<Compile Include="Models\Response\AlertResponse.cs" />
<Compile Include="Models\Response\DefaultResponse.cs" />
<Compile Include="Models\Response\ResponseBase.cs" />
<Compile Include="Models\Response\RetrieveResponse.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UptimeClient.cs" />
<Compile Include="Utilities\JsonExtensions.cs" />
<Compile Include="Utilities\UptimeSharpException.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Threading.Tasks">
@@ -48,6 +61,13 @@
<Reference Include="Microsoft.Threading.Tasks.Extensions">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.16\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\portable-net40+sl4+wp7+win8\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PropertyChanged">
<HintPath>..\packages\PropertyChanged.Fody.1.41.0.0\Lib\portable-net4+sl4+wp7+win8+MonoAndroid16+MonoTouch40\PropertyChanged.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.IO">
<HintPath>..\packages\Microsoft.Bcl.1.1.3\lib\portable-net40+sl4+win8+wp71\System.IO.dll</HintPath>
</Reference>