Infra: Separação de classes e responsabilidades.
This commit is contained in:
parent
771de2de33
commit
1e814e9c34
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
Program.cs
36
Program.cs
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user