-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d26e16
commit 9caccae
Showing
16 changed files
with
990 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace PetStore.Core.DomainObjects.Log | ||
{ | ||
/// <summary> | ||
/// Error of application domain | ||
/// </summary> | ||
public class DomainError : Error | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace PetStore.Core.DomainObjects.Log | ||
{ | ||
/// <summary> | ||
/// Represents an error | ||
/// </summary> | ||
public abstract class Error : IValidatable<Error> | ||
{ | ||
#region Properties | ||
|
||
/// <summary> | ||
/// Error ID | ||
/// </summary> | ||
public virtual int Id { get; set; } | ||
|
||
/// <summary> | ||
/// When the error occurred | ||
/// </summary> | ||
public virtual DateTime GeneratedAt { get; set; } | ||
|
||
/// <summary> | ||
/// Error Type (represents the exception Type) | ||
/// </summary> | ||
public virtual string Type { get; set; } | ||
|
||
/// <summary> | ||
/// Error message | ||
/// </summary> | ||
public virtual string Message { get; set; } | ||
|
||
/// <summary> | ||
/// Error details | ||
/// </summary> | ||
public virtual string Details { get; set; } | ||
|
||
/// <summary> | ||
/// Error additional information | ||
/// </summary> | ||
public virtual string AdditionalInformation { get; set; } | ||
|
||
/// <summary> | ||
/// Informs whether the error was handled (true) or not (false). | ||
/// </summary> | ||
public virtual bool Handled { get; set; } | ||
|
||
#endregion | ||
|
||
#region IValidatable Members | ||
|
||
bool IValidatable<Error>.Validate(IValidator<Error> validator, out IList<string> brokenRules) | ||
{ | ||
brokenRules = validator.BrokenRules(this); | ||
return brokenRules.Count() == 0; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace PetStore.Core.DomainObjects.Log | ||
{ | ||
/// <summary> | ||
/// Generic Error - not an error of application domain. | ||
/// </summary> | ||
public class GenericError : Error | ||
{ | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/PetStore.Core/DomainObjects/Log/Validation/ErrorValidationException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using PetStore.Resources.DomainObjects.Log; | ||
|
||
namespace PetStore.Core.DomainObjects.Log.Validation | ||
{ | ||
public class ErrorValidationException : ValidationException | ||
{ | ||
#region Constructors | ||
|
||
public ErrorValidationException(IList<string> brokenRules) | ||
: base(GetMainMessage(), brokenRules) | ||
{ | ||
} | ||
|
||
#endregion | ||
|
||
#region Static Methods | ||
|
||
private static string GetMainMessage() | ||
{ | ||
return ErrorResources.ErrorValidationExceptionMainMessage; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/PetStore.Core/DomainObjects/Log/Validation/ErrorValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using PetStore.Core.Extension; | ||
using PetStore.Resources.DomainObjects.Log; | ||
|
||
namespace PetStore.Core.DomainObjects.Log.Validation | ||
{ | ||
/// <summary> | ||
/// Validates an error object | ||
/// </summary> | ||
public class ErrorValidator : IValidator<Error> | ||
{ | ||
#region Constants | ||
|
||
public const int TypeMaxSize = 500; | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
public IList<string> BrokenRules(Error obj) | ||
{ | ||
IList<string> brokenRules = new List<string>(); | ||
|
||
if (String.IsNullOrWhiteSpace(obj.Type)) | ||
brokenRules.Add(ErrorResources.ErrorTypeIsRequired); | ||
else if (obj.Type.Length > TypeMaxSize) | ||
brokenRules.Add(ErrorResources.ErrorTypeTooBig.FormatWith(TypeMaxSize)); | ||
|
||
if (String.IsNullOrWhiteSpace(obj.Message)) | ||
brokenRules.Add(ErrorResources.ErrorMessageIsRequired); | ||
|
||
return brokenRules; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using PetStore.Core.Infrastructure.InversionOfControl; | ||
using PetStore.Core.Services.Log; | ||
|
||
namespace PetStore.Core.Helper | ||
{ | ||
/// <summary> | ||
/// Responsible for registering exception information | ||
/// </summary> | ||
public static class ExceptionManager | ||
{ | ||
#region Public Methods | ||
|
||
/// <summary> | ||
/// Logs an exception | ||
/// </summary> | ||
/// <param name="exception">Exception</param> | ||
public static void LogException(Exception exception) | ||
{ | ||
Check.Argument.IsNotNull(exception, "exception"); | ||
|
||
LogException(exception, true, string.Empty); | ||
} | ||
|
||
/// <summary> | ||
/// Logs an Exception | ||
/// </summary> | ||
/// <param name="exception">Excetion</param> | ||
/// <param name="handled">Informs whether the exception was handled.</param> | ||
/// <param name="additionalInformation">Additional information about the error.</param> | ||
public static void LogException(Exception exception, bool handled, string additionalInformation) | ||
{ | ||
Check.Argument.IsNotNull(exception, "exception"); | ||
|
||
GetErrorService().RegisterException(exception, handled, additionalInformation); | ||
} | ||
|
||
/// <summary> | ||
/// Gets an excetpion as a string. Includes all inner exception details in the string | ||
/// </summary> | ||
/// <param name="ex">Exception.</param> | ||
/// <returns>String with all information about the exception.</returns> | ||
public static string GetExceptionAsString(Exception ex) | ||
{ | ||
Check.Argument.IsNotNull(ex, "exception"); | ||
|
||
try | ||
{ | ||
StringBuilder sbMessage = new StringBuilder(); | ||
sbMessage.Append("EXCEPTION\n"); | ||
|
||
sbMessage.AppendLine("Type:"); | ||
sbMessage.AppendLine(ex.GetType().FullName); | ||
sbMessage.AppendLine(); | ||
|
||
if (!String.IsNullOrEmpty(ex.Message)) | ||
{ | ||
sbMessage.AppendLine("Message:"); | ||
sbMessage.AppendLine(ex.Message); | ||
sbMessage.AppendLine(); | ||
} | ||
|
||
if (!String.IsNullOrEmpty(ex.StackTrace)) | ||
{ | ||
sbMessage.AppendLine("Stack Trace:"); | ||
sbMessage.AppendLine(ex.StackTrace); | ||
sbMessage.AppendLine(); | ||
} | ||
|
||
if (ex.InnerException != null) | ||
{ | ||
sbMessage.AppendLine(); | ||
sbMessage.AppendLine(); | ||
sbMessage.Append(GetMessageFromInnerException(ex.InnerException, 1)); | ||
} | ||
|
||
return sbMessage.ToString(); | ||
} | ||
catch (Exception) | ||
{ | ||
return string.Empty; | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region Private Methods | ||
|
||
private static string GetMessageFromInnerException(Exception ex, int number) | ||
{ | ||
StringBuilder sbMessage = new StringBuilder(); | ||
sbMessage.Append(String.Format("INNER EXCEPTION {0}\n", number)); | ||
|
||
sbMessage.AppendLine("Type:"); | ||
sbMessage.AppendLine(ex.GetType().FullName); | ||
sbMessage.AppendLine(); | ||
|
||
if (!String.IsNullOrEmpty(ex.Message)) | ||
{ | ||
sbMessage.AppendLine("Message:"); | ||
sbMessage.AppendLine(ex.Message); | ||
sbMessage.AppendLine(); | ||
} | ||
|
||
if (!String.IsNullOrEmpty(ex.StackTrace)) | ||
{ | ||
sbMessage.AppendLine("Stack Trace:"); | ||
sbMessage.AppendLine(ex.StackTrace); | ||
sbMessage.AppendLine(); | ||
} | ||
|
||
if (ex.InnerException != null) | ||
{ | ||
sbMessage.AppendLine(); | ||
sbMessage.Append(GetMessageFromInnerException(ex.InnerException, number + 1)); | ||
} | ||
|
||
return sbMessage.ToString(); | ||
} | ||
|
||
[DebuggerStepThrough] | ||
private static ErrorService GetErrorService() | ||
{ | ||
return IoC.Resolve<ErrorService>(); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.