internal void SendNewChargeDetailRecord(DateTime Timestamp,
                                         Object Sender,
                                         ChargeDetailRecord ChargeDetailRecord)
 {
     if (ChargeDetailRecord != null)
     {
         OnNewChargeDetailRecord?.Invoke(Timestamp, Sender, ChargeDetailRecord);
     }
 }
Example #2
0
        /// <summary>
        /// Return a JSON-representation of this object.
        /// </summary>
        /// <param name="CustomChargeDetailRecordRequestSerializer">A delegate to customize the serialization of ChargeDetailRecordRequest responses.</param>
        /// <param name="CustomChargeDetailRecordSerializer">A delegate to serialize custom ChargeDetailRecord XML elements.</param>
        /// <param name="CustomIdentificationSerializer">A delegate to serialize custom Identification JSON elements.</param>
        /// <param name="CustomSignedMeteringValueSerializer">A delegate to serialize custom time period JSON objects.</param>
        /// <param name="CustomCalibrationLawVerificationSerializer">A delegate to serialize custom calibration law verification JSON objects.</param>
        public JObject ToJSON(CustomJObjectSerializerDelegate <ChargeDetailRecordRequest> CustomChargeDetailRecordRequestSerializer = null,
                              CustomJObjectSerializerDelegate <ChargeDetailRecord> CustomChargeDetailRecordSerializer   = null,
                              CustomJObjectSerializerDelegate <Identification> CustomIdentificationSerializer           = null,
                              CustomJObjectSerializerDelegate <SignedMeteringValue> CustomSignedMeteringValueSerializer = null,
                              CustomJObjectSerializerDelegate <CalibrationLawVerification> CustomCalibrationLawVerificationSerializer = null)
        {
            var JSON = ChargeDetailRecord.ToJSON(CustomChargeDetailRecordSerializer,
                                                 CustomIdentificationSerializer,
                                                 CustomSignedMeteringValueSerializer,
                                                 CustomCalibrationLawVerificationSerializer);

            return(CustomChargeDetailRecordRequestSerializer != null
                       ? CustomChargeDetailRecordRequestSerializer(this, JSON)
                       : JSON);
        }
        SendChargeDetailRecord(this ICPOClient ICPOClient,
                               ChargeDetailRecord ChargeDetailRecord,

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


        => ICPOClient.SendChargeDetailRecord(new SendChargeDetailRecordRequest(ChargeDetailRecord,

                                                                               Timestamp,
                                                                               CancellationToken,
                                                                               EventTrackingId,
                                                                               RequestTimeout ?? ICPOClient.RequestTimeout));
        /// <summary>
        /// Try to parse the given XML representation of an OICP EVSE statuses request.
        /// </summary>
        /// <param name="Request">An PullGetChargeDetailRecordsResponse request.</param>
        /// <param name="GetChargeDetailRecordsResponseXML">The XML to parse.</param>
        /// <param name="GetChargeDetailRecordsResponse">The parsed GetChargeDetailRecordsResponse request.</param>
        /// <param name="CustomGetChargeDetailRecordsResponseParser">A delegate to parse custom GetChargeDetailRecords responses.</param>
        /// <param name="CustomChargeDetailRecordParser">A delegate to parse custom ChargeDetailRecord 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>
        public static Boolean TryParse(GetChargeDetailRecordsRequest Request,
                                       XElement GetChargeDetailRecordsResponseXML,
                                       out GetChargeDetailRecordsResponse GetChargeDetailRecordsResponse,
                                       CustomXMLParserDelegate <GetChargeDetailRecordsResponse> CustomGetChargeDetailRecordsResponseParser = null,
                                       CustomXMLParserDelegate <ChargeDetailRecord> CustomChargeDetailRecordParser = null,
                                       CustomXMLParserDelegate <Identification> CustomIdentificationParser         = null,
                                       CustomXMLParserDelegate <RFIDIdentification> CustomRFIDIdentificationParser = null,
                                       OnExceptionDelegate OnException = null)
        {
            try
            {
                if (GetChargeDetailRecordsResponseXML.Name != OICPNS.Authorization + "eRoamingChargeDetailRecords")
                {
                    GetChargeDetailRecordsResponse = null;
                    return(false);
                }

                GetChargeDetailRecordsResponse = new GetChargeDetailRecordsResponse(

                    Request,

                    GetChargeDetailRecordsResponseXML.MapElements(OICPNS.Authorization + "eRoamingChargeDetailRecord",
                                                                  (XML, e) => ChargeDetailRecord.Parse(XML,
                                                                                                       CustomChargeDetailRecordParser,
                                                                                                       CustomIdentificationParser,
                                                                                                       CustomRFIDIdentificationParser,
                                                                                                       e),
                                                                  OnException)

                    );


                if (CustomGetChargeDetailRecordsResponseParser != null)
                {
                    GetChargeDetailRecordsResponse = CustomGetChargeDetailRecordsResponseParser(GetChargeDetailRecordsResponseXML,
                                                                                                GetChargeDetailRecordsResponse);
                }

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

                GetChargeDetailRecordsResponse = null;
                return(false);
            }
        }
Example #5
0
        /// <summary>
        /// Create a new ChargeDetailRecord request.
        /// </summary>
        /// <param name="ChargeDetailRecord">A charge detail record to send.</param>
        /// <param name="OperatorId">The unqiue identification of the operator sending the given charge detail record (not the suboperator or the operator of the EVSE).</param>
        /// <param name="CustomData">Optional customer specific data, e.g. in combination with custom parsers and serializers. This means: Not the sub operator or the operator of the EVSE!</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">The timeout for this request.</param>
        public ChargeDetailRecordRequest(ChargeDetailRecord ChargeDetailRecord,
                                         Operator_Id OperatorId,
                                         JObject CustomData = null,

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

            : base(CustomData,
                   Timestamp,
                   CancellationToken,
                   EventTrackingId,
                   RequestTimeout)

        {
            this.ChargeDetailRecord = ChargeDetailRecord ?? throw new ArgumentNullException(nameof(ChargeDetailRecord), "The given charge detail record must not be null!");
            this.OperatorId         = OperatorId;
        }
        public static JProperty ToJSON(this ChargeDetailRecord ChargeDetailRecord, String JPropertyKey)
        {
            #region Initial checks

            if (ChargeDetailRecord == null)
            {
                throw new ArgumentNullException(nameof(ChargeDetailRecord), "The given charging session must not be null!");
            }

            if (JPropertyKey.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(JPropertyKey), "The given json property key must not be null or empty!");
            }

            #endregion

            return(new JProperty(JPropertyKey,
                                 ChargeDetailRecord.ToJSON()));
        }
            SendChargeDetailRecord(this ICPOClient     CPOClient,
                                   ChargeDetailRecord  ChargeDetailRecord,
                                   Operator_Id         OperatorId,
                                   JObject             CustomData         = null,

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


                => CPOClient.SendChargeDetailRecord(
                       new ChargeDetailRecordRequest(
                           ChargeDetailRecord,
                           OperatorId,
                           CustomData,

                           Timestamp,
                           CancellationToken,
                           EventTrackingId,
                           RequestTimeout ?? CPOClient.RequestTimeout));
Example #8
0
        /// <summary>
        /// Create a SetChargeDetailRecord XML/SOAP request.
        /// </summary>
        /// <param name="PartnerId">The partner identification.</param>
        /// <param name="OperatorId">The operator identification.</param>
        /// <param name="ChargeDetailRecord">The charge detail record.</param>
        /// <param name="TransactionId">An optional transaction identification.</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 SetChargeDetailRecordRequest(Partner_Id PartnerId,
                                            Operator_Id OperatorId,
                                            ChargeDetailRecord ChargeDetailRecord,
                                            Transaction_Id?TransactionId = null,

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

            : base(HTTPRequest,
                   PartnerId,
                   TransactionId,
                   Timestamp,
                   CancellationToken,
                   EventTrackingId,
                   RequestTimeout)

        {
            this.OperatorId         = OperatorId;
            this.ChargeDetailRecord = ChargeDetailRecord;
        }
Example #9
0
        SetChargeDetailRecord(this ICPOClient CPOClient,
                              Partner_Id PartnerId,
                              Operator_Id OperatorId,
                              ChargeDetailRecord ChargeDetailRecord,
                              Transaction_Id?TransactionId = null,

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


        => CPOClient.SetChargeDetailRecord(new SetChargeDetailRecordRequest(PartnerId,
                                                                            OperatorId,
                                                                            ChargeDetailRecord,
                                                                            TransactionId,

                                                                            HTTPRequest,
                                                                            Timestamp,
                                                                            CancellationToken,
                                                                            EventTrackingId,
                                                                            RequestTimeout ?? CPOClient.RequestTimeout));
Example #10
0
        /// <summary>
        /// Create an OICP SendChargeDetailRecord XML/SOAP request.
        /// </summary>
        /// <param name="ChargeDetailRecord">A charge detail record to upload.</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 SendChargeDetailRecordRequest(ChargeDetailRecord ChargeDetailRecord,

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

            : base(Timestamp,
                   CancellationToken,
                   EventTrackingId,
                   RequestTimeout)

        {
            #region Initial checks

            if (ChargeDetailRecord == null)
            {
                throw new ArgumentNullException(nameof(ChargeDetailRecord), "The given charge detail record must not be null!");
            }

            #endregion

            this.ChargeDetailRecord = ChargeDetailRecord;
        }
Example #11
0
        public static JObject ToJSON(this ChargeDetailRecord ChargeDetailRecord)

        => JSONObject.Create(

            new JProperty("SessionId", ChargeDetailRecord.SessionId.ToString()),

            ChargeDetailRecord.SessionTime.HasValue
                       ? new JProperty("SessionStart", ChargeDetailRecord.SessionTime.Value.StartTime.ToIso8601())
                       : null,

            ChargeDetailRecord.SessionTime.HasValue && ChargeDetailRecord.SessionTime.Value.EndTime.HasValue
                       ? new JProperty("SessionEnd", ChargeDetailRecord.SessionTime.Value.EndTime.Value.ToIso8601())
                       : null,

            ChargeDetailRecord.Reservation != null
                       ? new JProperty("Reservation", JSONObject.Create(
                                           new JProperty("ReservationId", ChargeDetailRecord.Reservation.Id.ToString()),
                                           new JProperty("StartTime", ChargeDetailRecord.Reservation.StartTime.ToIso8601()),
                                           new JProperty("Duration", ChargeDetailRecord.Reservation.ConsumedReservationTime.TotalSeconds)
                                           ))
                       : ChargeDetailRecord.ReservationId != null
                             ? new JProperty("ReservationId", ChargeDetailRecord.ReservationId.ToString())
                             : null,


            ChargeDetailRecord.ProviderIdStart != null
                       ? new JProperty("ProviderIdStart", ChargeDetailRecord.ProviderIdStart.ToString())
                       : null,

            ChargeDetailRecord.ProviderIdStop != null
                       ? new JProperty("ProviderIdStop", ChargeDetailRecord.ProviderIdStop.ToString())
                       : null,

            //ChargeDetailRecord.EVSEOperatorId      != null
            //    ? new JProperty("EVSEOperatorId",         ChargeDetailRecord.EVSEOperatorId.ToString())
            //    : null,

            //ChargeDetailRecord.ChargingPoolId      != null
            //    ? new JProperty("ChargingPoolId",         ChargeDetailRecord.ChargingPoolId.ToString())
            //    : null,

            //ChargeDetailRecord.ChargingStationId   != null
            //    ? new JProperty("ChargingStationId",      ChargeDetailRecord.ChargingStationId.ToString())
            //    : null,

            ChargeDetailRecord.EVSE != null
                       ? new JProperty("EVSEId", ChargeDetailRecord.EVSE.Id.ToString())
                       : ChargeDetailRecord.EVSEId != null
                           ? new JProperty("EVSEId", ChargeDetailRecord.EVSEId.ToString())
                           : null,

            ChargeDetailRecord.ChargingProduct != null
                       ? new JProperty("ChargingProduct", JSONObject.Create(
                                           new JProperty("Id", ChargeDetailRecord.ChargingProduct.Id.ToString()),
                                           ChargeDetailRecord.ChargingProduct.MinDuration.HasValue
                                 ? new JProperty("MinDuration", ChargeDetailRecord.ChargingProduct.MinDuration.Value.TotalSeconds)
                                 : null,
                                           ChargeDetailRecord.ChargingProduct.StopChargingAfterTime.HasValue
                                 ? new JProperty("StopChargingAfterTime", ChargeDetailRecord.ChargingProduct.StopChargingAfterTime.Value.TotalSeconds)
                                 : null,
                                           ChargeDetailRecord.ChargingProduct.MinPower.HasValue
                                 ? new JProperty("MinPower", ChargeDetailRecord.ChargingProduct.MinPower.Value)
                                 : null,
                                           ChargeDetailRecord.ChargingProduct.MaxPower.HasValue
                                 ? new JProperty("MaxPower", ChargeDetailRecord.ChargingProduct.MaxPower.Value)
                                 : null,
                                           ChargeDetailRecord.ChargingProduct.MinEnergy.HasValue
                                 ? new JProperty("MinEnergy", ChargeDetailRecord.ChargingProduct.MinEnergy.Value)
                                 : null,
                                           ChargeDetailRecord.ChargingProduct.StopChargingAfterKWh.HasValue
                                 ? new JProperty("StopChargingAfterKWh", ChargeDetailRecord.ChargingProduct.StopChargingAfterKWh.Value)
                                 : null
                                           ))
                       : null,

            ChargeDetailRecord.EnergyMeterId != null
                       ? new JProperty("EnergyMeterId", ChargeDetailRecord.EnergyMeterId.ToString())
                       : null,

            ChargeDetailRecord.EnergyMeteringValues.Any()
                       ? new JProperty("EnergyMeteringValues", new JObject(
                                           ChargeDetailRecord.
                                           EnergyMeteringValues.
                                           Select(MeterValue => new JProperty(MeterValue.Timestamp.ToIso8601(),
                                                                              MeterValue.Value))
                                           ))
                       : null

            );