/// <summary> /// Handles an Ensurance failure for the given constraint. Implementors /// should always call /// <code> /// if( successor != null) { /// successor.Handle( constraint, message, args ); /// } /// </code> /// So that the downstream handler can have a chance to process the /// failure. /// </summary> /// <param name="constraint">The constraint.</param> /// <param name="message">The message.</param> /// <param name="args">The args.</param> public override void Handle(Constraint constraint, string message, params object[] args) { TextWriter.Write(ToString()); IEnsuranceResponsibilityChainLink handler = Successor; if (handler != null) { handler.Handle(constraint, message, args); } }
/// <summary> /// Handles an Ensurance failure for the given constraint. Implementors /// should always call /// <code> /// IEnsuranceResponsibilityChainLink handler = successor; /// if( successor != null) { /// successor.Handle( constraint, message, args ); /// } /// </code> /// So that the downstream handler can have a chance to process the /// failure. /// </summary> /// <exception cref="EnsuranceException">Always</exception> /// <param name="constraint">The constraint.</param> /// <param name="message">The message.</param> /// <param name="args">The args.</param> public override void Handle(Constraint constraint, string message, params object[] args) { try { MessageWriter messageWriter = new TextMessageWriter(new StringWriter(CultureInfo.CurrentCulture)); constraint.WriteMessageTo(messageWriter); throw new EnsuranceException(messageWriter.ToString()); } finally { IEnsuranceResponsibilityChainLink handler = Successor; if (handler != null) { handler.Handle(constraint, message, args); } } }
/// <summary> /// Handles an Ensurance failure for the given constraint. Implementors /// should always call /// <code> /// IEnsuranceResponsibilityChainLink handler = successor; /// if( successor != null) { /// successor.Handle( constraint, message, args ); /// } /// </code> /// So that the downstream handler can have a chance to process the /// failure. /// </summary> /// <param name="constraint">The constraint.</param> /// <param name="message">The message.</param> /// <param name="args">The args.</param> public void Handle(Constraint constraint, string message, params object[] args) { try { if (Debugger.IsAttached) { Debugger.Break(); } } finally { IEnsuranceResponsibilityChainLink handler = _successor; if (handler != null) { handler.Handle(constraint, message, args); } } }
/// <summary> /// Handles an Ensurance failure for the given constraint. Implementors /// should always call /// <code> /// IEnsuranceResponsibilityChainLink handler = successor; /// if( handler != null ) { /// handler.Handle( constraint, message, args ); /// } /// </code> /// So that the downstream handler can have a chance to process the /// failure. /// </summary> /// <param name="constraint">The constraint.</param> /// <param name="message">The message.</param> /// <param name="args">The args.</param> public void Handle(Constraint constraint, string message, params object[] args) { try { MessageWriter messagewriter = new TextMessageWriter(); messagewriter.WriteLine(); constraint.WriteMessageTo(messagewriter); messagewriter.Write(new StackTraceWriter().ToString()); string tmpMessage = String.Format(CultureInfo.CurrentCulture, "{0}{1}", message, messagewriter); switch (_logger.DefaultLogSeverity) { case LogSeverity.Debug: _logger.Debug(tmpMessage, args); break; case LogSeverity.Info: _logger.Info(tmpMessage, args); break; case LogSeverity.Warn: _logger.Warn(tmpMessage, args); break; case LogSeverity.Error: _logger.Error(tmpMessage, args); break; case LogSeverity.Fatal: _logger.Fatal(tmpMessage, args); break; } } finally { IEnsuranceResponsibilityChainLink handler = _successor; if (handler != null) { handler.Handle(constraint, message, args); } } }
/// <summary> /// Handles an Ensurance failure for the given constraint. Implementors /// should always call /// <code> /// if( successor != null ) { /// successor.Handle( constraint, message, args ); /// } /// </code> /// So that the downstream handler can have a chance to process the /// failure. /// </summary> /// <param name="constraint">The constraint.</param> /// <param name="message">The message.</param> /// <param name="args">The args.</param> public override void Handle(Constraint constraint, string message, params object[] args) { try { if (!string.IsNullOrEmpty(message)) { WriteMessageLine(message, args); } constraint.WriteMessageTo(this); } finally { IEnsuranceResponsibilityChainLink handler = Successor; if (handler != null) { handler.Handle(constraint, message, args); } } }
// 5. Implement the interface explicitly. void IEnsuranceHandler.Handle(Constraint constraint, string message, params object[] args) { // 5. Do your logging. try { if (_log.IsErrorEnabled) { _log.Error(constraint.ToString()); _log.WarnFormat(message, args); } } finally { // 6. ALWAYS pass the call onto your successor. IEnsuranceResponsibilityChainLink handler = _successor; if (handler != null) { handler.Handle(constraint, message, args); } } }
// 8. 'Implement' the interface with a private static version with which you // will do all of your work. private static void Handle(Constraint constraint, string message, params object[] args) { // 9. Process your handler chain _handler.Handle(constraint, message, args); }