diff --git a/UptimeSharp/APIException.cs b/UptimeSharp/APIException.cs new file mode 100644 index 0000000..becdccd --- /dev/null +++ b/UptimeSharp/APIException.cs @@ -0,0 +1,60 @@ +using System; +using System.Runtime.Serialization; + +namespace UptimeSharp +{ + /// + /// custom UptimeRobot API Exceptions + /// + public class APIException : Exception + { + /// + /// Gets or sets the UptimeRobot error code. + /// + /// + /// The pocket error code. + /// + public int? UptimeErrorCode { get; set; } + + /// + /// Gets or sets the UptimeRobot error. + /// + /// + /// The pocket error. + /// + public string UptimeError { get; set; } + + + /// + /// Initializes a new instance of the class. + /// + public APIException() + : base() { } + + + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public APIException(string message) + : base(message) { } + + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. + public APIException(string message, Exception innerException) + : base(message, innerException) { } + + + /// + /// Initializes a new instance of the class. + /// + /// The that holds the serialized object data about the exception being thrown. + /// The that contains contextual information about the source or destination. + protected APIException(SerializationInfo info, StreamingContext context) + : base(info, context) { } + } +} diff --git a/UptimeSharp/JsonDeserializer.cs b/UptimeSharp/JsonDeserializer.cs new file mode 100644 index 0000000..2f00805 --- /dev/null +++ b/UptimeSharp/JsonDeserializer.cs @@ -0,0 +1,79 @@ +using RestSharp; +using RestSharp.Deserializers; +using ServiceStack.Text; +using System; + +namespace UptimeSharp +{ + /// + /// Custom JSON Deserializer which implements ServiceStack.Text + /// + internal class JsonDeserializer : IDeserializer + { + public const string JsonContentType = "application/json"; + + /// + /// Deserializes the specified response. + /// + /// + /// The response. + /// + public T Deserialize(IRestResponse response) + { + return JsonSerializer.DeserializeFromString(response.Content); + } + + + /// + /// Adds custom deserialization for specific types. + /// + public static void AddCustomDeserialization() + { + // generate correct Uri format + JsConfig.DeSerializeFn = value => new Uri(value); + + // create DateTime from UNIX timestamp input + JsConfig.DeSerializeFn = value => + { + if (value == "0") return null; + return new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(Convert.ToDouble(value)).ToLocalTime(); + }; + } + + + /// + /// Gets or sets the date format. + /// + /// + /// The date format. + /// + public string DateFormat { get; set; } + + /// + /// Gets or sets the namespace. + /// + /// + /// The namespace. + /// + public string Namespace { get; set; } + + /// + /// Gets or sets the root element. + /// + /// + /// The root element. + /// + public string RootElement { get; set; } + + /// + /// Gets the type of the content. + /// + /// + /// The type of the content. + /// + public string ContentType + { + get { return JsonContentType; } + } + } +} diff --git a/UptimeSharp/Properties/AssemblyInfo.cs b/UptimeSharp/Properties/AssemblyInfo.cs index a1ecc83..a28e5ad 100644 --- a/UptimeSharp/Properties/AssemblyInfo.cs +++ b/UptimeSharp/Properties/AssemblyInfo.cs @@ -8,7 +8,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyTitle("UptimeSharp")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("cee")] [assembly: AssemblyProduct("UptimeSharp")] [assembly: AssemblyCopyright("Copyright © 2013")] [assembly: AssemblyTrademark("")] diff --git a/UptimeSharp/UptimeSharp.csproj b/UptimeSharp/UptimeSharp.csproj index 7356a21..0b4f974 100644 --- a/UptimeSharp/UptimeSharp.csproj +++ b/UptimeSharp/UptimeSharp.csproj @@ -32,6 +32,12 @@ 4 + + ..\packages\RestSharp.104.1\lib\net4\RestSharp.dll + + + ..\packages\ServiceStack.Text.3.9.56\lib\net35\ServiceStack.Text.dll + @@ -41,8 +47,14 @@ + + + + + +