KeplerExceptionMapper
Maps Kepler ServiceException to SoapException which is handled by RDC and IAPI code.
using Microsoft.VisualBasic.CompilerServices;
using Relativity.DataExchange.Logger;
using Relativity.Logging;
using Relativity.Services.Exceptions;
using System;
using System.IO;
using System.Web.Services.Protocols;
using System.Xml;
using System.Xml.Serialization;
namespace kCura.WinEDDS.Mapping
{
public class KeplerExceptionMapper : IServiceExceptionMapper
{
private readonly ILog _logger;
public KeplerExceptionMapper()
{
_logger = RelativityLogger.Instance;
}
public SoapException Map(ServiceException serviceException)
{
return Soapify((Exception)serviceException);
}
SoapException IServiceExceptionMapper.Map(ServiceException serviceException)
{
return this.Map(serviceException);
}
private SoapException Soapify(Exception exception)
{
try {
KeplerExceptionDetail o = new KeplerExceptionDetail(exception);
XmlDocument xmlDocument = new XmlDocument();
XmlSerializer xmlSerializer = new XmlSerializer(typeof(KeplerExceptionDetail));
XmlSerializerNamespaces xmlSerializerNamespaces = new XmlSerializerNamespaces();
xmlSerializerNamespaces.Add(string.Empty, string.Empty);
using (StringWriter stringWriter = new StringWriter()) {
xmlSerializer.Serialize(stringWriter, o, xmlSerializerNamespaces);
xmlDocument.LoadXml(stringWriter.ToString());
}
return new SoapException(exception.Message, SoapException.ServerFaultCode, string.Empty, xmlDocument.ChildNodes[1], exception);
} catch (Exception ex) {
ProjectData.SetProjectError(ex);
Exception ex2 = ex;
_logger.LogError(ex2, "Error when mapping Kepler exception - {ExceptionMessage}. Kepler exception: {KeplerExceptionMessage}", new object[2] {
ex2.Message,
exception.Message
});
SoapException result = new SoapException(exception.Message, SoapException.ServerFaultCode, string.Empty, (XmlNode)null, ex2);
ProjectData.ClearProjectError();
return result;
}
}
}
}