Infra: Separação de classes e responsabilidades.

This commit is contained in:
Adriano Serighelli 2025-09-30 15:46:09 -03:00
parent 771de2de33
commit 1e814e9c34
3 changed files with 38 additions and 38 deletions

View File

@ -3,10 +3,26 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Infra;
namespace Infra namespace Infra
{ {
internal class SoapFaultException public class SoapFaultException : Exception
{ {
public string FaultCode { get; }
public string FaultString { get; }
public string ErrorCode { get; }
public string ErrorMessage { get; }
public SoapFaultException(string faultCode, string faultString, string errorCode, string errorMessage)
: base($"{faultString} (Code: {errorCode})")
{
FaultCode = faultCode;
FaultString = faultString;
ErrorCode = errorCode;
ErrorMessage = errorMessage;
}
} }
} }

View File

@ -3,10 +3,30 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
namespace Infra namespace Infra
{ {
internal class SoapHelper public static class SoapHelper
{ {
public static void VerificarRespostaSOAP(string responseXml)
{
var doc = XDocument.Parse(responseXml);
XNamespace env = "http://schemas.xmlsoap.org/soap/envelope/";
XNamespace tns = "http://xmlns.energia.org.br/FM/v2";
var fault = doc.Descendants(env + "Fault").FirstOrDefault();
if (fault != null)
{
string faultCode = fault.Element("faultcode")?.Value ?? "";
string faultString = fault.Element("faultstring")?.Value ?? "";
var detail = fault.Element("detail")?.Descendants().First();
string errorCode = detail?.Element(tns + "errorCode")?.Value ?? "";
string message = detail?.Element(tns + "message")?.Value ?? "";
throw new SoapFaultException(faultCode, faultString, errorCode, message);
}
}
} }
} }

View File

@ -383,42 +383,6 @@ internal class Plat_integ
} }
return; return;
} }
public class SoapFaultException : Exception
{
public string FaultCode { get; }
public string FaultString { get; }
public string ErrorCode { get; }
public string ErrorMessage { get; }
public SoapFaultException(string faultCode, string faultString, string errorCode, string errorMessage)
: base($"{faultString} (Code: {errorCode})")
{
FaultCode = faultCode;
FaultString = faultString;
ErrorCode = errorCode;
ErrorMessage = errorMessage;
}
}
public static void VerificarRespostaSOAP(string responseXml)
{
var doc = XDocument.Parse(responseXml);
XNamespace env = "http://schemas.xmlsoap.org/soap/envelope/";
XNamespace tns = "http://xmlns.energia.org.br/FM/v2";
var fault = doc.Descendants(env + "Fault").FirstOrDefault();
if (fault != null)
{
string faultCode = fault.Element("faultcode")?.Value ?? "";
string faultString = fault.Element("faultstring")?.Value ?? "";
var detail = fault.Element("detail")?.Descendants().First();
string errorCode = detail?.Element(tns + "errorCode")?.Value ?? "";
string message = detail?.Element(tns + "message")?.Value ?? "";
throw new SoapFaultException(faultCode, faultString, errorCode, message);
}
}
} }
public class perfil public class perfil