Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Extensions / ExceptionChaining / EmailHandler.cs
blobeff9e9845b27796f7660cff96422f84779834600
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Extensions.ExceptionChaining
17 using System;
18 using System.Configuration;
19 using Castle.Components.Common.EmailSender;
20 using Castle.Core.Configuration;
22 /// <summary>
23 /// A handle that sends the exception by email
24 /// </summary>
25 public class EmailHandler : AbstractExceptionHandler, IConfigurableHandler
27 private String mailTo;
28 private String mailFrom = "donotreply@castleproject.org";
30 /// <summary>
31 /// Implementors should check for known attributes and child nodes
32 /// within the <c>exceptionHandlerNode</c>
33 /// </summary>
34 /// <param name="exceptionHandlerNode">The Xml node
35 /// that represents this handler on the configuration file</param>
36 public void Configure(IConfiguration exceptionHandlerNode)
38 string mailToAtt = exceptionHandlerNode.Attributes["mailTo"];
40 if (mailToAtt == null)
42 String message = "'mailTo' is a required attribute " +
43 "for EmailHandler (part of ExceptionChaining extension)";
44 throw new ConfigurationErrorsException(message);
47 mailTo = mailToAtt;
49 string mailFromAtt = exceptionHandlerNode.Attributes["mailFrom"];
51 if (mailFromAtt != null)
53 mailFrom = mailFromAtt;
57 /// <summary>
58 /// Implementors should perform the action
59 /// on the exception. Note that the exception
60 /// is available in <see cref="IEngineContext.LastException"/>
61 /// </summary>
62 /// <param name="context"></param>
63 public override void Process(IEngineContext context)
65 IEmailSender emailSender = (IEmailSender) context.GetService(typeof(IEmailSender));
67 String message = BuildStandardMessage(context);
69 try
71 emailSender.Send(mailFrom, mailTo,
72 "MonoRail Exception: " + context.LastException.GetType().Name, message);
74 catch(Exception)
76 // We ignore errors during send
79 InvokeNext(context);