Init RaspberryIO
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
namespace Unosquare.Swan.Exceptions
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// Generic Constraint Registration Exception.
|
||||
/// </summary>
|
||||
/// <seealso cref="Exception" />
|
||||
public class DependencyContainerRegistrationException : Exception
|
||||
{
|
||||
private const string ConvertErrorText = "Cannot convert current registration of {0} to {1}";
|
||||
private const string RegisterErrorText =
|
||||
"Cannot register type {0} - abstract classes or interfaces are not valid implementation types for {1}.";
|
||||
private const string ErrorText = "Duplicate implementation of type {0} found ({1}).";
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DependencyContainerRegistrationException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="registerType">Type of the register.</param>
|
||||
/// <param name="types">The types.</param>
|
||||
public DependencyContainerRegistrationException(Type registerType, IEnumerable<Type> types)
|
||||
: base(string.Format(ErrorText, registerType, GetTypesString(types)))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DependencyContainerRegistrationException" /> class.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="method">The method.</param>
|
||||
/// <param name="isTypeFactory">if set to <c>true</c> [is type factory].</param>
|
||||
public DependencyContainerRegistrationException(Type type, string method, bool isTypeFactory = false)
|
||||
: base(isTypeFactory
|
||||
? string.Format(RegisterErrorText, type.FullName, method)
|
||||
: string.Format(ConvertErrorText, type.FullName, method))
|
||||
{
|
||||
}
|
||||
|
||||
private static string GetTypesString(IEnumerable<Type> types)
|
||||
{
|
||||
return string.Join(",", types.Select(type => type.FullName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Unosquare.Swan.Exceptions
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// An exception for dependency resolutions.
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Exception" />
|
||||
public class DependencyContainerResolutionException : Exception
|
||||
{
|
||||
private const string ErrorText = "Unable to resolve type: {0}";
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DependencyContainerResolutionException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
public DependencyContainerResolutionException(Type type)
|
||||
: base(string.Format(ErrorText, type.FullName))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DependencyContainerResolutionException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="innerException">The inner exception.</param>
|
||||
public DependencyContainerResolutionException(Type type, Exception innerException)
|
||||
: base(string.Format(ErrorText, type.FullName), innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Unosquare.Swan.Exceptions
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Weak Reference Exception.
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Exception" />
|
||||
public class DependencyContainerWeakReferenceException : Exception
|
||||
{
|
||||
private const string ErrorText = "Unable to instantiate {0} - referenced object has been reclaimed";
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DependencyContainerWeakReferenceException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
public DependencyContainerWeakReferenceException(Type type)
|
||||
: base(string.Format(ErrorText, type.FullName))
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace Unosquare.Swan.Exceptions
|
||||
{
|
||||
using System;
|
||||
using Networking;
|
||||
|
||||
/// <summary>
|
||||
/// An exception thrown when the DNS query fails.
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Exception" />
|
||||
public class DnsQueryException : Exception
|
||||
{
|
||||
internal DnsQueryException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
internal DnsQueryException(string message, Exception e)
|
||||
: base(message, e)
|
||||
{
|
||||
}
|
||||
|
||||
internal DnsQueryException(DnsClient.IDnsResponse response)
|
||||
: this(response, Format(response))
|
||||
{
|
||||
}
|
||||
|
||||
internal DnsQueryException(DnsClient.IDnsResponse response, string message)
|
||||
: base(message)
|
||||
{
|
||||
Response = response;
|
||||
}
|
||||
|
||||
internal DnsClient.IDnsResponse Response { get; }
|
||||
|
||||
private static string Format(DnsClient.IDnsResponse response)
|
||||
{
|
||||
return $"Invalid response received with code {response.ResponseCode}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
namespace Unosquare.Swan.Exceptions
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Represents errors that occurs requesting a JSON file through HTTP.
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Exception" />
|
||||
#if !NETSTANDARD1_3
|
||||
[Serializable]
|
||||
#endif
|
||||
public class JsonRequestException
|
||||
: Exception
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:Unosquare.Swan.Exceptions.JsonRequestException" /> class.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
/// <param name="httpErrorCode">The HTTP error code.</param>
|
||||
/// <param name="errorContent">Content of the error.</param>
|
||||
public JsonRequestException(string message, int httpErrorCode = 500, string errorContent = null)
|
||||
: base(message)
|
||||
{
|
||||
HttpErrorCode = httpErrorCode;
|
||||
HttpErrorContent = errorContent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP error code.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The HTTP error code.
|
||||
/// </value>
|
||||
public int HttpErrorCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of the HTTP error.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The content of the HTTP error.
|
||||
/// </value>
|
||||
public string HttpErrorContent { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => string.IsNullOrEmpty(HttpErrorContent) ? $"HTTP Response Status Code {HttpErrorCode} Error Message: {HttpErrorContent}" : base.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
namespace Unosquare.Swan.Exceptions
|
||||
{
|
||||
using System;
|
||||
using Networking.Ldap;
|
||||
|
||||
/// <summary>
|
||||
/// Thrown to indicate that an Ldap exception has occurred. This is a general
|
||||
/// exception which includes a message and an Ldap result code.
|
||||
/// An LdapException can result from physical problems (such as
|
||||
/// network errors) as well as problems with Ldap operations detected
|
||||
/// by the server. For example, if an Ldap add operation fails because of a
|
||||
/// duplicate entry, the server returns a result code.
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Exception" />
|
||||
public class LdapException
|
||||
: Exception
|
||||
{
|
||||
internal const string UnexpectedEnd = "Unexpected end of filter";
|
||||
internal const string MissingLeftParen = "Unmatched parentheses, left parenthesis missing";
|
||||
internal const string MissingRightParen = "Unmatched parentheses, right parenthesis missing";
|
||||
internal const string ExpectingRightParen = "Expecting right parenthesis, found \"{0}\"";
|
||||
internal const string ExpectingLeftParen = "Expecting left parenthesis, found \"{0}\"";
|
||||
|
||||
private readonly string _serverMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LdapException" /> class.
|
||||
/// Constructs an exception with a detailed message obtained from the
|
||||
/// specified <c>MessageOrKey</c> String.
|
||||
/// Additional parameters specify the result code, the message returned
|
||||
/// from the server, and a matchedDN returned from the server.
|
||||
/// The String is used either as a message key to obtain a localized
|
||||
/// message from ExceptionMessages, or if there is no key in the
|
||||
/// resource matching the text, it is used as the detailed message itself.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
/// <param name="resultCode">The result code returned.</param>
|
||||
/// <param name="serverMsg">Error message specifying additional information
|
||||
/// from the server.</param>
|
||||
/// <param name="matchedDN">The maximal subset of a specified DN which could
|
||||
/// be matched by the server on a search operation.</param>
|
||||
/// <param name="rootException">The root exception.</param>
|
||||
public LdapException(
|
||||
string message,
|
||||
LdapStatusCode resultCode,
|
||||
string serverMsg = null,
|
||||
string matchedDN = null,
|
||||
Exception rootException = null)
|
||||
: base(message)
|
||||
{
|
||||
ResultCode = resultCode;
|
||||
Cause = rootException;
|
||||
MatchedDN = matchedDN;
|
||||
_serverMessage = serverMsg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the error message from the Ldap server, if this message is
|
||||
/// available (that is, if this message was set). If the message was not set,
|
||||
/// this method returns null.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The error message or null if the message was not set.
|
||||
/// </returns>
|
||||
public string LdapErrorMessage =>
|
||||
_serverMessage != null && _serverMessage.Length == 0 ? null : _serverMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the lower level Exception which caused the failure, if any.
|
||||
/// For example, an IOException with additional information may be returned
|
||||
/// on a CONNECT_ERROR failure.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The cause.
|
||||
/// </value>
|
||||
public Exception Cause { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the result code from the exception.
|
||||
/// The codes are defined as <c>public final static int</c> members
|
||||
/// of the Ldap Exception class. If the exception is a
|
||||
/// result of error information returned from a directory operation, the
|
||||
/// code will be one of those defined for the class. Otherwise, a local error
|
||||
/// code is returned.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The result code.
|
||||
/// </value>
|
||||
public LdapStatusCode ResultCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the part of a submitted distinguished name which could be
|
||||
/// matched by the server.
|
||||
/// If the exception was caused by a local error, such as no server
|
||||
/// available, the return value is null. If the exception resulted from
|
||||
/// an operation being executed on a server, the value is an empty string
|
||||
/// except when the result of the operation was one of the following:.
|
||||
/// <ul><li>NO_SUCH_OBJECT</li><li>ALIAS_PROBLEM</li><li>INVALID_DN_SYNTAX</li><li>ALIAS_DEREFERENCING_PROBLEM</li></ul>
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The matched dn.
|
||||
/// </value>
|
||||
public string MatchedDN { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Message => ResultCode.ToString().Humanize();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
// Craft a string from the resource file
|
||||
var msg = $"{nameof(LdapException)}: {base.Message} ({ResultCode}) {ResultCode.ToString().Humanize()}";
|
||||
|
||||
// Add server message
|
||||
if (!string.IsNullOrEmpty(_serverMessage))
|
||||
{
|
||||
msg += $"\r\nServer Message: {_serverMessage}";
|
||||
}
|
||||
|
||||
// Add Matched DN message
|
||||
if (MatchedDN != null)
|
||||
{
|
||||
msg += $"\r\nMatched DN: {MatchedDN}";
|
||||
}
|
||||
|
||||
if (Cause != null)
|
||||
{
|
||||
msg += $"\r\n{Cause}";
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#if NETSTANDARD1_3
|
||||
namespace Unosquare.Swan.Exceptions
|
||||
{
|
||||
using Networking;
|
||||
|
||||
/// <summary>
|
||||
/// Defines an SMTP Exceptions class.
|
||||
/// </summary>
|
||||
public class SmtpException : System.Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SmtpException" /> class with a message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
public SmtpException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SmtpException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="replyCode">The SmtpStatusCode reply.</param>
|
||||
/// <param name="message">The exception message.</param>
|
||||
public SmtpException(SmtpStatusCode replyCode, string message)
|
||||
: base($"{message} ReplyCode: {replyCode}")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user