/// <summary>
        /// Try to parse the given text representation of a Heartbeat request.
        /// </summary>
        /// <param name="Text">The text to be parsed.</param>
        /// <param name="RequestId">The request identification.</param>
        /// <param name="ChargeBoxId">The charge box identification.</param>
        /// <param name="HeartbeatRequest">The parsed heartbeat request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(String Text,
                                       Request_Id RequestId,
                                       ChargeBox_Id ChargeBoxId,
                                       out HeartbeatRequest HeartbeatRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                Text = Text?.Trim();

                if (Text.IsNotNullOrEmpty())
                {
                    if (Text.StartsWith("{") &&
                        TryParse(JObject.Parse(Text),
                                 RequestId,
                                 ChargeBoxId,
                                 out HeartbeatRequest,
                                 out String ErrorResponse))
                    {
                        return(true);
                    }

                    if (TryParse(XDocument.Parse(Text).Root,
                                 RequestId,
                                 ChargeBoxId,
                                 out HeartbeatRequest,
                                 OnException))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                OnException?.Invoke(Timestamp.Now, Text, e);
            }

            HeartbeatRequest = null;
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Try to parse the given text representation of a FirmwareStatusNotification request.
        /// </summary>
        /// <param name="Text">The text to be parsed.</param>
        /// <param name="RequestId">The request identification.</param>
        /// <param name="ChargeBoxId">The charge box identification.</param>
        /// <param name="FirmwareStatusNotificationRequest">The parsed FirmwareStatusNotification request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(String Text,
                                       Request_Id RequestId,
                                       ChargeBox_Id ChargeBoxId,
                                       out FirmwareStatusNotificationRequest FirmwareStatusNotificationRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                Text = Text?.Trim();

                if (Text.IsNotNullOrEmpty())
                {
                    if (Text.StartsWith("{") &&
                        TryParse(JObject.Parse(Text),
                                 RequestId,
                                 ChargeBoxId,
                                 out FirmwareStatusNotificationRequest,
                                 out String ErrorResponse))
                    {
                        return(true);
                    }

                    if (TryParse(XDocument.Parse(Text).Root,//.Element(SOAPNS.v1_2.NS.SOAPEnvelope + "Body"),
                                 RequestId,
                                 ChargeBoxId,
                                 out FirmwareStatusNotificationRequest,
                                 OnException))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, Text, e);
            }

            FirmwareStatusNotificationRequest = null;
            return(false);
        }
        /// <summary>
        /// Try to parse the given text-representation of an OICP push authentication data request.
        /// </summary>
        /// <param name="PushAuthenticationDataRequestText">The text to parse.</param>
        /// <param name="PushAuthenticationDataRequest">The parsed push authentication data request.</param>
        /// <param name="CustomPushAuthenticationDataRequestParser">A delegate to parse custom PushAuthenticationData requests.</param>
        /// <param name="CustomProviderAuthenticationDataParser">A delegate to parse custom ProviderAuthenticationData XML elements.</param>
        /// <param name="CustomIdentificationParser">A delegate to parse custom Identification XML elements.</param>
        /// <param name="CustomRFIDIdentificationParser">A delegate to parse custom RFID identification XML elements.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        ///
        /// <param name="Timestamp">The optional timestamp of the request.</param>
        /// <param name="CancellationToken">An optional token to cancel this request.</param>
        /// <param name="EventTrackingId">An optional event tracking identification for correlating this request with other events.</param>
        /// <param name="RequestTimeout">An optional timeout for this request.</param>
        public static Boolean TryParse(String PushAuthenticationDataRequestText,
                                       out PushAuthenticationDataRequest PushAuthenticationDataRequest,
                                       CustomXMLParserDelegate <PushAuthenticationDataRequest> CustomPushAuthenticationDataRequestParser = null,
                                       CustomXMLParserDelegate <ProviderAuthenticationData> CustomProviderAuthenticationDataParser       = null,
                                       CustomXMLParserDelegate <Identification> CustomIdentificationParser         = null,
                                       CustomXMLParserDelegate <RFIDIdentification> CustomRFIDIdentificationParser = null,
                                       OnExceptionDelegate OnException = null,

                                       DateTime?Timestamp = null,
                                       CancellationToken?CancellationToken = null,
                                       EventTracking_Id EventTrackingId    = null,
                                       TimeSpan?RequestTimeout             = null)

        {
            try
            {
                if (TryParse(XDocument.Parse(PushAuthenticationDataRequestText).Root,
                             out PushAuthenticationDataRequest,
                             CustomPushAuthenticationDataRequestParser,
                             CustomProviderAuthenticationDataParser,
                             CustomIdentificationParser,
                             CustomRFIDIdentificationParser,
                             OnException,

                             Timestamp,
                             CancellationToken,
                             EventTrackingId,
                             RequestTimeout))
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, PushAuthenticationDataRequestText, e);
            }

            PushAuthenticationDataRequest = null;
            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Try to parse the given XML representation of an OICP EVSE status record.
        /// </summary>
        /// <param name="EVSEStatusRecordXML">The XML to parse.</param>
        /// <param name="EVSEStatusRecord">The parsed EVSE status record.</param>
        /// <param name="CustomEVSEStatusRecordParser">A delegate to parse custom XML elements.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement EVSEStatusRecordXML,
                                       out EVSEStatusRecord EVSEStatusRecord,
                                       CustomXMLParserDelegate <EVSEStatusRecord> CustomEVSEStatusRecordParser = null,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                if (EVSEStatusRecordXML.Name != OICPNS.EVSEStatus + "EvseStatusRecord")
                {
                    EVSEStatusRecord = null;
                    return(false);
                }

                EVSEStatusRecord = new EVSEStatusRecord(

                    EVSEStatusRecordXML.MapValueOrFail(OICPNS.EVSEStatus + "EvseID",
                                                       EVSE_Id.Parse),

                    EVSEStatusRecordXML.MapValueOrFail(OICPNS.EVSEStatus + "EvseStatus",
                                                       EVSEStatusTypesExtentions.Parse)

                    );


                if (CustomEVSEStatusRecordParser != null)
                {
                    EVSEStatusRecord = CustomEVSEStatusRecordParser(EVSEStatusRecordXML, EVSEStatusRecord);
                }

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, EVSEStatusRecordXML, e);

                EVSEStatusRecord = null;
                return(false);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Try to parse the given XML representation of an OCPP authorize response.
        /// </summary>
        /// <param name="AuthorizeResponseXML">The XML to parse.</param>
        /// <param name="AuthorizeResponse">The parsed authorize response.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(CP.AuthorizeRequest Request,
                                       XElement AuthorizeResponseXML,
                                       out AuthorizeResponse AuthorizeResponse,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                var IdTagInfoXML = AuthorizeResponseXML.ElementOrFail(OCPPNS.OCPPv1_6_CS + "idTagInfo");


                AuthorizeResponse = new AuthorizeResponse(

                    Request,

                    new IdTagInfo(

                        IdTagInfoXML.MapEnumValues(OCPPNS.OCPPv1_6_CS + "status",
                                                   XML_IO.AsAuthorizationStatus),

                        IdTagInfoXML.MapValueOrNullable(OCPPNS.OCPPv1_6_CS + "expiryDate",
                                                        DateTime.Parse),

                        IdTagInfoXML.MapValueOrNull(OCPPNS.OCPPv1_6_CS + "parentIdTag",
                                                    IdToken.Parse)

                        )

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.Now, AuthorizeResponseXML, e);

                AuthorizeResponse = null;
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Try to parse the given JSON representation of a status notification response.
        /// </summary>
        /// <param name="Request">The status notification request leading to this response.</param>
        /// <param name="JSON">The JSON to be parsed.</param>
        /// <param name="StatusNotificationResponse">The parsed status notification response.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(CP.StatusNotificationRequest Request,
                                       JObject JSON,
                                       out StatusNotificationResponse StatusNotificationResponse,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                StatusNotificationResponse = null;

                #region CustomData

                if (JSON.ParseOptionalJSON("customData",
                                           "custom data",
                                           OCPPv2_0.CustomData.TryParse,
                                           out CustomData CustomData,
                                           out String ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion


                StatusNotificationResponse = new StatusNotificationResponse(Request,
                                                                            CustomData);

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, JSON, e);

                StatusNotificationResponse = null;
                return(false);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Try to parse the given text representation of an eMIP heartbeat request.
        /// </summary>
        /// <param name="SetChargeDetailRecordRequestText">The text to parse.</param>
        /// <param name="SetChargeDetailRecordRequest">The parsed heartbeat request.</param>
        /// <param name="CustomSendSetChargeDetailRecordRequestParser">An optional delegate to parse custom SetChargeDetailRecordRequest XML elements.</param>
        /// <param name="CustomChargeDetailRecordParser">An optional delegate to parse custom ChargeDetailRecord XML elements.</param>
        /// <param name="CustomMeterReportParser">An optional delegate to parse custom MeterReport XML elements.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        ///
        /// <param name="HTTPRequest">The correlated HTTP request of this eMIP request.</param>
        /// <param name="Timestamp">The optional timestamp of the request.</param>
        /// <param name="CancellationToken">An optional token to cancel this request.</param>
        /// <param name="EventTrackingId">An optional event tracking identification for correlating this request with other events.</param>
        /// <param name="RequestTimeout">An optional timeout for this request.</param>
        public static Boolean TryParse(String SetChargeDetailRecordRequestText,
                                       out SetChargeDetailRecordRequest SetChargeDetailRecordRequest,
                                       CustomXMLParserDelegate <SetChargeDetailRecordRequest> CustomSendSetChargeDetailRecordRequestParser = null,
                                       CustomXMLParserDelegate <ChargeDetailRecord> CustomChargeDetailRecordParser = null,
                                       CustomXMLParserDelegate <MeterReport> CustomMeterReportParser = null,
                                       OnExceptionDelegate OnException = null,

                                       HTTPRequest HTTPRequest             = null,
                                       DateTime?Timestamp                  = null,
                                       CancellationToken?CancellationToken = null,
                                       EventTracking_Id EventTrackingId    = null,
                                       TimeSpan?RequestTimeout             = null)
        {
            try
            {
                if (TryParse(XDocument.Parse(SetChargeDetailRecordRequestText).Root,
                             out SetChargeDetailRecordRequest,
                             CustomSendSetChargeDetailRecordRequestParser,
                             CustomChargeDetailRecordParser,
                             CustomMeterReportParser,
                             OnException,

                             HTTPRequest,
                             Timestamp,
                             CancellationToken,
                             EventTrackingId,
                             RequestTimeout))
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, SetChargeDetailRecordRequestText, e);
            }

            SetChargeDetailRecordRequest = null;
            return(false);
        }
        /// <summary>
        /// Try to parse the given text representation of an OIOI charge detail record.
        /// </summary>
        /// <param name="ChargeDetailRecordText">The text to parse.</param>
        /// <param name="ChargeDetailRecord">The parsed charge detail record.</param>
        /// <param name="CustomChargeDetailRecordParser">An optional delegate to parse custom ChargeDetailRecord XML elements.</param>
        /// <param name="CustomMeterReportParser">An optional delegate to parse custom MeterReport XML elements.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(String ChargeDetailRecordText,
                                       out ChargeDetailRecord ChargeDetailRecord,
                                       CustomXMLParserDelegate <ChargeDetailRecord> CustomChargeDetailRecordParser = null,
                                       CustomXMLParserDelegate <MeterReport> CustomMeterReportParser = null,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                return(TryParse(XElement.Parse(ChargeDetailRecordText),
                                out ChargeDetailRecord,
                                CustomChargeDetailRecordParser,
                                CustomMeterReportParser,
                                OnException));
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, ChargeDetailRecordText, e);

                ChargeDetailRecord = null;
                return(false);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Try to parse the given XML representation of an OCPP get configuration request.
        /// </summary>
        /// <param name="GetConfigurationRequestXML">The XML to parse.</param>
        /// <param name="GetConfigurationRequest">The parsed get configuration request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement GetConfigurationRequestXML,
                                       out GetConfigurationRequest GetConfigurationRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                GetConfigurationRequest = new GetConfigurationRequest(

                    GetConfigurationRequestXML.ElementValues(OCPPNS.OCPPv1_6_CP + "key")

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.Now, GetConfigurationRequestXML, e);

                GetConfigurationRequest = null;
                return(false);
            }
        }
        /// <summary>
        /// Try to parse the given XML representation of a SetServiceAuthorisation response.
        /// </summary>
        /// <param name="Request">The SetServiceAuthorisation request leading to this response.</param>
        /// <param name="SetServiceAuthorisationResponseXML">The XML to parse.</param>
        /// <param name="SetServiceAuthorisationResponse">The parsed SetServiceAuthorisation response.</param>
        /// <param name="CustomSendSetServiceAuthorisationResponseParser">An optional delegate to parse custom SetServiceAuthorisationResponse XML elements.</param>
        /// <param name="HTTPResponse">The correlated HTTP response of this eMIP response.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(SetServiceAuthorisationRequest Request,
                                       XElement SetServiceAuthorisationResponseXML,
                                       out SetServiceAuthorisationResponse SetServiceAuthorisationResponse,
                                       CustomXMLParserDelegate <SetServiceAuthorisationResponse> CustomSendSetServiceAuthorisationResponseParser = null,
                                       HTTPResponse HTTPResponse       = null,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                SetServiceAuthorisationResponse = new SetServiceAuthorisationResponse(

                    Request,

                    SetServiceAuthorisationResponseXML.MapValueOrFail("transactionId", Transaction_Id.Parse),
                    SetServiceAuthorisationResponseXML.MapValueOrFail("requestStatus", RequestStatus.Parse),
                    SetServiceAuthorisationResponseXML.MapValueOrFail("serviceSessionId", ServiceSession_Id.Parse),
                    SetServiceAuthorisationResponseXML.MapValueOrNullable("execPartnerOperatorId", Operator_Id.Parse),

                    HTTPResponse

                    );


                if (CustomSendSetServiceAuthorisationResponseParser != null)
                {
                    SetServiceAuthorisationResponse = CustomSendSetServiceAuthorisationResponseParser(SetServiceAuthorisationResponseXML,
                                                                                                      SetServiceAuthorisationResponse);
                }

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, SetServiceAuthorisationResponseXML, e);

                SetServiceAuthorisationResponse = null;
                return(false);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Try to parse the given XML representation of an OCPP get diagnostics response.
        /// </summary>
        /// <param name="GetDiagnosticsResponseXML">The XML to parse.</param>
        /// <param name="GetDiagnosticsResponse">The parsed get diagnostics response.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement GetDiagnosticsResponseXML,
                                       out GetDiagnosticsResponse GetDiagnosticsResponse,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                GetDiagnosticsResponse = new GetDiagnosticsResponse(

                    GetDiagnosticsResponseXML.ElementValueOrDefault(OCPPNS.OCPPv1_6_CP + "fileName")

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.Now, GetDiagnosticsResponseXML, e);

                GetDiagnosticsResponse = null;
                return(false);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Try to parse the given XML representation of a status notification request.
        /// </summary>
        /// <param name="StatusNotificationRequestXML">The XML to be parsed.</param>
        /// <param name="StatusNotificationRequest">The parsed status notification request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement StatusNotificationRequestXML,
                                       out StatusNotificationRequest StatusNotificationRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                StatusNotificationRequest = new StatusNotificationRequest(

                    StatusNotificationRequestXML.MapValueOrFail(OCPPNS.OCPPv1_6_CS + "connectorId",
                                                                Connector_Id.Parse),

                    StatusNotificationRequestXML.MapEnumValuesOrFail(OCPPNS.OCPPv1_6_CS + "status",
                                                                     ChargePointStatusExtentions.Parse),

                    StatusNotificationRequestXML.MapEnumValuesOrFail(OCPPNS.OCPPv1_6_CS + "errorCode",
                                                                     ChargePointErrorCodeExtentions.Parse),

                    StatusNotificationRequestXML.ElementValueOrDefault(OCPPNS.OCPPv1_6_CS + "info"),

                    StatusNotificationRequestXML.MapValueOrNullable(OCPPNS.OCPPv1_6_CS + "timestamp",
                                                                    DateTime.Parse),

                    StatusNotificationRequestXML.ElementValueOrDefault(OCPPNS.OCPPv1_6_CS + "vendorId"),

                    StatusNotificationRequestXML.ElementValueOrDefault(OCPPNS.OCPPv1_6_CS + "vendorErrorCode")

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, StatusNotificationRequestXML, e);

                StatusNotificationRequest = null;
                return(false);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Try to parse the given JSON representation of a heartbeat request.
        /// </summary>
        /// <param name="HeartbeatRequestJSON">The JSON to be parsed.</param>
        /// <param name="HeartbeatRequest">The parsed heartbeat request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(JObject HeartbeatRequestJSON,
                                       out HeartbeatRequest HeartbeatRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                HeartbeatRequest = null;

                #region CustomData

                if (HeartbeatRequestJSON.ParseOptionalJSON("customData",
                                                           "custom data",
                                                           OCPPv2_0.CustomData.TryParse,
                                                           out CustomData CustomData,
                                                           out String ErrorResponse,
                                                           OnException))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion


                HeartbeatRequest = new HeartbeatRequest(CustomData);

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, HeartbeatRequestJSON, e);

                HeartbeatRequest = null;
                return(false);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Try to parse the given XML representation of a ClearChargingProfile request.
        /// </summary>
        /// <param name="XML">The XML to be parsed.</param>
        /// <param name="RequestId">The request identification.</param>
        /// <param name="ChargeBoxId">The charge box identification.</param>
        /// <param name="ClearChargingProfileRequest">The parsed ClearChargingProfile request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement XML,
                                       Request_Id RequestId,
                                       ChargeBox_Id ChargeBoxId,
                                       out ClearChargingProfileRequest ClearChargingProfileRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                ClearChargingProfileRequest = new ClearChargingProfileRequest(

                    ChargeBoxId,

                    XML.MapValueOrNull(OCPPNS.OCPPv1_6_CP + "id",
                                       ChargingProfile_Id.Parse),

                    XML.MapValueOrNull(OCPPNS.OCPPv1_6_CP + "connectorId",
                                       Connector_Id.Parse),

                    XML.MapValueOrNullable(OCPPNS.OCPPv1_6_CP + "chargingProfilePurpose",
                                           ChargingProfilePurposesExtentions.Parse),

                    XML.MapValueOrNullable(OCPPNS.OCPPv1_6_CP + "stackLevel",
                                           UInt32.Parse),

                    RequestId

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, XML, e);

                ClearChargingProfileRequest = null;
                return(false);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Try to parse the given XML representation of an OICP send charge detail record request.
        /// </summary>
        /// <param name="SendChargeDetailRecordXML">The XML to parse.</param>
        /// <param name="SendChargeDetailRecord">The parsed send charge detail record request.</param>
        /// <param name="CustomChargeDetailRecordParser">A delegate to parse custom CustomChargeDetailRecord XML elements.</param>
        /// <param name="CustomIdentificationParser">A delegate to parse custom Identification XML elements.</param>
        /// <param name="CustomRFIDIdentificationParser">A delegate to parse custom RFID identification XML elements.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        ///
        /// <param name="Timestamp">The optional timestamp of the request.</param>
        /// <param name="CancellationToken">An optional token to cancel this request.</param>
        /// <param name="EventTrackingId">An optional event tracking identification for correlating this request with other events.</param>
        /// <param name="RequestTimeout">An optional timeout for this request.</param>
        public static Boolean TryParse(XElement SendChargeDetailRecordXML,
                                       out SendChargeDetailRecordRequest SendChargeDetailRecord,
                                       CustomXMLParserDelegate <ChargeDetailRecord> CustomChargeDetailRecordParser = null,
                                       CustomXMLParserDelegate <Identification> CustomIdentificationParser         = null,
                                       CustomXMLParserDelegate <RFIDIdentification> CustomRFIDIdentificationParser = null,
                                       OnExceptionDelegate OnException = null,

                                       DateTime?Timestamp = null,
                                       CancellationToken?CancellationToken = null,
                                       EventTracking_Id EventTrackingId    = null,
                                       TimeSpan?RequestTimeout             = null)

        {
            try
            {
                SendChargeDetailRecord = new SendChargeDetailRecordRequest(
                    ChargeDetailRecord.Parse(SendChargeDetailRecordXML,
                                             CustomChargeDetailRecordParser,
                                             CustomIdentificationParser,
                                             CustomRFIDIdentificationParser,
                                             OnException),

                    Timestamp,
                    CancellationToken,
                    EventTrackingId,
                    RequestTimeout
                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, SendChargeDetailRecordXML, e);

                SendChargeDetailRecord = null;
                return(false);
            }
        }
        /// <summary>
        /// Try to parse the given text-representation of an OICP authorize stop request.
        /// </summary>
        /// <param name="AuthorizeStopText">The text to parse.</param>
        /// <param name="AuthorizeStop">The parsed authorize stop request.</param>
        /// <param name="CustomAuthorizeStopRequestParser">A delegate to customize the deserialization of AuthorizeStop requests.</param>
        /// <param name="CustomIdentificationParser">A delegate to parse custom Identification XML elements.</param>
        /// <param name="CustomRFIDIdentificationParser">A delegate to parse custom RFID identification XML elements.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        ///
        /// <param name="Timestamp">The optional timestamp of the request.</param>
        /// <param name="CancellationToken">An optional token to cancel this request.</param>
        /// <param name="EventTrackingId">An optional event tracking identification for correlating this request with other events.</param>
        /// <param name="RequestTimeout">An optional timeout for this request.</param>
        public static Boolean TryParse(String AuthorizeStopText,
                                       out AuthorizeStopRequest AuthorizeStop,
                                       CustomXMLParserDelegate <AuthorizeStopRequest> CustomAuthorizeStopRequestParser = null,
                                       CustomXMLParserDelegate <Identification> CustomIdentificationParser             = null,
                                       CustomXMLParserDelegate <RFIDIdentification> CustomRFIDIdentificationParser     = null,
                                       OnExceptionDelegate OnException = null,

                                       DateTime?Timestamp = null,
                                       CancellationToken?CancellationToken = null,
                                       EventTracking_Id EventTrackingId    = null,
                                       TimeSpan?RequestTimeout             = null)

        {
            try
            {
                if (TryParse(XDocument.Parse(AuthorizeStopText).Root,
                             out AuthorizeStop,
                             CustomAuthorizeStopRequestParser,
                             CustomIdentificationParser,
                             CustomRFIDIdentificationParser,
                             OnException,

                             Timestamp,
                             CancellationToken,
                             EventTrackingId,
                             RequestTimeout))
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, AuthorizeStopText, e);
            }

            AuthorizeStop = null;
            return(false);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Try to parse the given XML representation of an OCPP stop transaction request.
        /// </summary>
        /// <param name="StopTransactionRequestXML">The XML to parse.</param>
        /// <param name="StopTransactionRequest">The parsed stop transaction request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement StopTransactionRequestXML,
                                       out StopTransactionRequest StopTransactionRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                StopTransactionRequest = new StopTransactionRequest(

                    StopTransactionRequestXML.MapValueOrFail(OCPPNS.OCPPv1_6_CS + "transactionId",
                                                             Transaction_Id.Parse),

                    StopTransactionRequestXML.MapValueOrFail(OCPPNS.OCPPv1_6_CS + "idTag",
                                                             DateTime.Parse),

                    StopTransactionRequestXML.MapValueOrFail(OCPPNS.OCPPv1_6_CS + "meterStop",
                                                             UInt64.Parse),

                    StopTransactionRequestXML.MapValueOrNullable(OCPPNS.OCPPv1_6_CS + "idTag",
                                                                 IdToken.Parse),

                    StopTransactionRequestXML.MapEnumValues(OCPPNS.OCPPv1_6_CS + "reason",
                                                            XML_IO.AsReasons),

                    StopTransactionRequestXML.MapElements(OCPPNS.OCPPv1_6_CS + "transactionData",
                                                          MeterValue.Parse)

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.Now, StopTransactionRequestXML, e);

                StopTransactionRequest = null;
                return(false);
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Try to parse the given XML representation of an OCPP trigger message response.
        /// </summary>
        /// <param name="TriggerMessageResponseXML">The XML to parse.</param>
        /// <param name="TriggerMessageResponse">The parsed trigger message response.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement TriggerMessageResponseXML,
                                       out TriggerMessageResponse TriggerMessageResponse,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                TriggerMessageResponse = new TriggerMessageResponse(

                    TriggerMessageResponseXML.MapValueOrFail(OCPPNS.OCPPv1_6_CP + "status",
                                                             XML_IO.AsTriggerMessageStatus)

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.Now, TriggerMessageResponseXML, e);

                TriggerMessageResponse = null;
                return(false);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Try to parse the given text representation of a stop transaction response.
        /// </summary>
        /// <param name="Request">The stop transaction request leading to this response.</param>
        /// <param name="StopTransactionResponseText">The text to be parsed.</param>
        /// <param name="StopTransactionResponse">The parsed stop transaction response.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(CP.StopTransactionRequest Request,
                                       String StopTransactionResponseText,
                                       out StopTransactionResponse StopTransactionResponse,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                if (TryParse(Request,
                             XDocument.Parse(StopTransactionResponseText).Root,
                             out StopTransactionResponse,
                             OnException))
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, StopTransactionResponseText, e);
            }

            StopTransactionResponse = null;
            return(false);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Try to parse the given XML representation of an authorize request.
        /// </summary>
        /// <param name="AuthorizeRequestXML">The XML to be parsed.</param>
        /// <param name="AuthorizeRequest">The parsed authorize request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement AuthorizeRequestXML,
                                       out AuthorizeRequest AuthorizeRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                AuthorizeRequest = new AuthorizeRequest(

                    AuthorizeRequestXML.MapValueOrFail(OCPPNS.OCPPv1_6_CS + "idTag",
                                                       IdToken.Parse)

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, AuthorizeRequestXML, e);

                AuthorizeRequest = null;
                return(false);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Try to parse the given text representation of an eMIP SessionAction object.
        /// </summary>
        /// <param name="SessionActionText">The text to parse.</param>
        /// <param name="CustomSessionActionParser">An optional delegate to parse custom SessionAction XML elements.</param>
        /// <param name="SessionAction">The parsed SessionAction object.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(String SessionActionText,
                                       CustomXMLParserDelegate <SessionAction> CustomSessionActionParser,
                                       out SessionAction SessionAction,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                if (TryParse(XDocument.Parse(SessionActionText).Root,
                             CustomSessionActionParser,
                             out SessionAction,
                             OnException))
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, SessionActionText, e);
            }

            SessionAction = null;
            return(false);
        }
        /// <summary>
        /// Try to parse the given XML representation of an OCPP change configuration response.
        /// </summary>
        /// <param name="ChangeConfigurationResponseXML">The XML to parse.</param>
        /// <param name="ChangeConfigurationResponse">The parsed change configuration response.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement ChangeConfigurationResponseXML,
                                       out ChangeConfigurationResponse ChangeConfigurationResponse,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                ChangeConfigurationResponse = new ChangeConfigurationResponse(

                    ChangeConfigurationResponseXML.MapValueOrFail(OCPPNS.OCPPv1_6_CP + "status",
                                                                  XML_IO.AsConfigurationStatus)

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.Now, ChangeConfigurationResponseXML, e);

                ChangeConfigurationResponse = null;
                return(false);
            }
        }
        /// <summary>
        /// Try to parse the given XML representation of an OCPP remote stop transaction request.
        /// </summary>
        /// <param name="RemoteStopTransactionRequestXML">The XML to parse.</param>
        /// <param name="RemoteStopTransactionRequest">The parsed remote stop transaction request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement RemoteStopTransactionRequestXML,
                                       out RemoteStopTransactionRequest RemoteStopTransactionRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                RemoteStopTransactionRequest = new RemoteStopTransactionRequest(

                    RemoteStopTransactionRequestXML.MapValueOrFail(OCPPNS.OCPPv1_6_CP + "transactionId",
                                                                   Transaction_Id.Parse)

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.Now, RemoteStopTransactionRequestXML, e);

                RemoteStopTransactionRequest = null;
                return(false);
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Try to parse the given XML representation of a unlock connector request.
        /// </summary>
        /// <param name="UnlockConnectorRequestXML">The XML to be parsed.</param>
        /// <param name="UnlockConnectorRequest">The parsed unlock connector request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement UnlockConnectorRequestXML,
                                       out UnlockConnectorRequest UnlockConnectorRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                UnlockConnectorRequest = new UnlockConnectorRequest(

                    UnlockConnectorRequestXML.MapValueOrFail(OCPPNS.OCPPv1_6_CP + "connectorId",
                                                             Connector_Id.Parse)

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, UnlockConnectorRequestXML, e);

                UnlockConnectorRequest = null;
                return(false);
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Try to parse the given XML representation of an OCPP stop transaction response.
        /// </summary>
        /// <param name="StopTransactionResponseXML">The XML to parse.</param>
        /// <param name="StopTransactionResponse">The parsed stop transaction response.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement StopTransactionResponseXML,
                                       out StopTransactionResponse StopTransactionResponse,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                StopTransactionResponse = new StopTransactionResponse(

                    StopTransactionResponseXML.MapElementOrNullable(OCPPNS.OCPPv1_6_CS + "idTagInfo",
                                                                    OCPPv1_6.IdTagInfo.Parse)

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.Now, StopTransactionResponseXML, e);

                StopTransactionResponse = null;
                return(false);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Try to parse the given XML representation of a change configuration request.
        /// </summary>
        /// <param name="ChangeConfigurationRequestXML">The XML to be parsed.</param>
        /// <param name="ChangeConfigurationRequest">The parsed change configuration request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement ChangeConfigurationRequestXML,
                                       out ChangeConfigurationRequest ChangeConfigurationRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                ChangeConfigurationRequest = new ChangeConfigurationRequest(

                    ChangeConfigurationRequestXML.ElementValueOrFail(OCPPNS.OCPPv1_6_CP + "key"),
                    ChangeConfigurationRequestXML.ElementValueOrFail(OCPPNS.OCPPv1_6_CP + "value")

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, ChangeConfigurationRequestXML, e);

                ChangeConfigurationRequest = null;
                return(false);
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Try to parse the given XML representation of a firmware status notification request.
        /// </summary>
        /// <param name="FirmwareStatusNotificationRequestXML">The XML to be parsed.</param>
        /// <param name="FirmwareStatusNotificationRequest">The parsed firmware status notification request.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement FirmwareStatusNotificationRequestXML,
                                       out FirmwareStatusNotificationRequest FirmwareStatusNotificationRequest,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                FirmwareStatusNotificationRequest = new FirmwareStatusNotificationRequest(

                    FirmwareStatusNotificationRequestXML.MapValueOrFail(OCPPNS.OCPPv1_6_CS + "status",
                                                                        FirmwareStatusExtentions.Parse)

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, FirmwareStatusNotificationRequestXML, e);

                FirmwareStatusNotificationRequest = null;
                return(false);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Try to parse the given text-representation of an OICP EVSE status record.
        /// </summary>
        /// <param name="EVSEStatusRecordText">The text to parse.</param>
        /// <param name="EVSEStatusRecord">The parsed EVSE status record.</param>
        /// <param name="CustomEVSEStatusRecordParser">A delegate to parse custom XML elements.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(String EVSEStatusRecordText,
                                       out EVSEStatusRecord EVSEStatusRecord,
                                       CustomXMLParserDelegate <EVSEStatusRecord> CustomEVSEStatusRecordParser = null,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                if (TryParse(XDocument.Parse(EVSEStatusRecordText).Root,
                             out EVSEStatusRecord,
                             CustomEVSEStatusRecordParser,
                             OnException))
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.UtcNow, EVSEStatusRecordText, e);
            }

            EVSEStatusRecord = null;
            return(false);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Try to parse the given text representation of an OCPP authorize response.
        /// </summary>
        /// <param name="AuthorizeResponseText">The text to parse.</param>
        /// <param name="AuthorizeResponse">The parsed authorize response.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(CP.AuthorizeRequest Request,
                                       String AuthorizeResponseText,
                                       out AuthorizeResponse AuthorizeResponse,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                if (TryParse(Request,
                             XDocument.Parse(AuthorizeResponseText).Root,
                             out AuthorizeResponse,
                             OnException))
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.Now, AuthorizeResponseText, e);
            }

            AuthorizeResponse = null;
            return(false);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Try to parse the given XML representation of an OCPP heartbeat response.
        /// </summary>
        /// <param name="HeartbeatResponseXML">The XML to parse.</param>
        /// <param name="HeartbeatResponse">The parsed heartbeat response.</param>
        /// <param name="OnException">An optional delegate called whenever an exception occured.</param>
        public static Boolean TryParse(XElement HeartbeatResponseXML,
                                       out HeartbeatResponse HeartbeatResponse,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                HeartbeatResponse = new HeartbeatResponse(

                    HeartbeatResponseXML.MapValueOrFail(OCPPNS.OCPPv1_6_CS + "currentTime",
                                                        DateTime.Parse)

                    );

                return(true);
            }
            catch (Exception e)
            {
                OnException?.Invoke(DateTime.Now, HeartbeatResponseXML, e);

                HeartbeatResponse = null;
                return(false);
            }
        }