/// <summary> /// Try to parse the given XML representation of an OCPP SOAP header. /// </summary> /// <param name="SOAPHeaderXML">The XML to parse.</param> /// <param name="SOAPHeader">The parsed connector type.</param> /// <param name="OnException">An optional delegate called whenever an exception occured.</param> public static Boolean TryParse(XElement SOAPHeaderXML, out SOAPHeader SOAPHeader, OnExceptionDelegate OnException = null) { try { SOAPHeader = new SOAPHeader( SOAPHeaderXML.MapValueOrFail(OCPPNS.OCPPv1_6_CS + "chargeBoxIdentity", ChargeBox_Id.Parse), SOAPHeaderXML.ElementValueOrFail(OCPPNS.OCPPv1_6_CS + "Action"), SOAPHeaderXML.ElementValueOrFail(OCPPNS.OCPPv1_6_CS + "MessageID"), SOAPHeaderXML.ElementValueOrDefault(OCPPNS.OCPPv1_6_CS + "RelatesTo"), SOAPHeaderXML.ElementValueOrFail(OCPPNS.OCPPv1_6_CS + "From"), SOAPHeaderXML.ElementValueOrFail(OCPPNS.OCPPv1_6_CS + "To") ); return(true); } catch (Exception e) { OnException?.Invoke(DateTime.Now, SOAPHeaderXML, e); SOAPHeader = null; return(false); } }
/// <summary> /// Encapsulate the given XML within an OCPP XML SOAP frame. /// </summary> /// <param name="SOAPHeader">An OCPP SOAP header.</param> /// <param name="SOAPBody">The internal XML for the SOAP body.</param> /// <param name="XMLNamespaces">An optional delegate to process the XML namespaces.</param> public static XElement Encapsulation(SOAPHeader SOAPHeader, XElement SOAPBody, XMLNamespacesDelegate XMLNamespaces = null) => Encapsulation(SOAPHeader.ChargeBoxIdentity, SOAPHeader.Action, SOAPHeader.MessageId, SOAPHeader.RelatesTo, SOAPHeader.From, SOAPHeader.To, SOAPBody, XMLNamespaces);
/// <summary> /// Compares two id tag infos for equality. /// </summary> /// <param name="SOAPHeader">An id tag info to compare with.</param> /// <returns>True if both match; False otherwise.</returns> public Boolean Equals(SOAPHeader SOAPHeader) { if ((Object)SOAPHeader == null) { return(false); } return(ChargeBoxIdentity.Equals(SOAPHeader.ChargeBoxIdentity) && Action.Equals(SOAPHeader.Action) && MessageId.Equals(SOAPHeader.MessageId) && ((RelatesTo == null && SOAPHeader.RelatesTo == null) || (RelatesTo != null && SOAPHeader.RelatesTo != null && RelatesTo.Equals(SOAPHeader.RelatesTo))) && From.Equals(SOAPHeader.From) && To.Equals(SOAPHeader.To)); }
/// <summary> /// Try to parse the given text representation of an OCPP SOAP header. /// </summary> /// <param name="SOAPHeaderText">The text to parse.</param> /// <param name="SOAPHeader">The parsed connector type.</param> /// <param name="OnException">An optional delegate called whenever an exception occured.</param> public static Boolean TryParse(String SOAPHeaderText, out SOAPHeader SOAPHeader, OnExceptionDelegate OnException = null) { try { if (TryParse(XDocument.Parse(SOAPHeaderText).Root, out SOAPHeader, OnException)) { return(true); } } catch (Exception e) { OnException?.Invoke(DateTime.Now, SOAPHeaderText, e); } SOAPHeader = null; return(false); }