/// <summary>
 /// Try to parse the given text representation of an AuthorizeStart request.
 /// </summary>
 /// <param name="Text">The text to parse.</param>
 /// <param name="OperatorIdURL">The EVSE operator identification given in the URL of the HTTP request.</param>
 /// <param name="RequestTimeout">The timeout for this request.</param>
 /// <param name="AuthorizeStartRequest">The parsed AuthorizeStart request.</param>
 /// <param name="ErrorResponse">An optional error response.</param>
 /// <param name="Timestamp">The optional timestamp of the request.</param>
 /// <param name="EventTrackingId">An optional event tracking identification for correlating this request with other events.</param>
 /// <param name="CustomAuthorizeStartRequestParser">A delegate to parse custom AuthorizeStart request JSON objects.</param>
 public static Boolean TryParse(String Text,
                                Operator_Id OperatorIdURL,
                                TimeSpan RequestTimeout,
                                out AuthorizeStartRequest AuthorizeStartRequest,
                                out String ErrorResponse,
                                DateTime?Timestamp = null,
                                EventTracking_Id EventTrackingId = null,
                                CustomJObjectParserDelegate <AuthorizeStartRequest> CustomAuthorizeStartRequestParser = null)
 {
     try
     {
         return(TryParse(JObject.Parse(Text),
                         OperatorIdURL,
                         RequestTimeout,
                         out AuthorizeStartRequest,
                         out ErrorResponse,
                         Timestamp,
                         EventTrackingId,
                         CustomAuthorizeStartRequestParser));
     }
     catch (Exception e)
     {
         AuthorizeStartRequest = default;
         ErrorResponse         = "The given text representation of an AuthorizeStart request is invalid: " + e.Message;
         return(false);
     }
 }
Пример #2
0
        /// <summary>
        /// Create a new operator EVSE data object.
        /// </summary>
        /// <param name="EVSEDataRecords">An enumeration of EVSE data records.</param>
        /// <param name="OperatorId">The unqiue identification of the EVSE operator maintaining the given EVSE data records.</param>
        /// <param name="OperatorName">The name of the EVSE operator maintaining the given EVSE data records.</param>
        ///
        /// <param name="CustomData">Optional customer specific data, e.g. in combination with custom parsers and serializers.</param>
        public OperatorEVSEData(IEnumerable <EVSEDataRecord> EVSEDataRecords,
                                Operator_Id OperatorId,
                                String OperatorName,

                                JObject CustomData = null)
        {
            if (!EVSEDataRecords.SafeAny())
            {
                throw new ArgumentNullException(nameof(EVSEDataRecords), "The given enumeration of EVSE data records must not be null or empty!");
            }

            OperatorName = OperatorName?.Trim();

            if (OperatorName.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(OperatorName), "The given EVSE operator name must not be null or empty!");
            }

            var duplicateEVSEDataRecords = EVSEDataRecords.GroupBy(evseDataRecord => evseDataRecord.Id).Where(group => group.Count() > 1).ToArray();

            if (duplicateEVSEDataRecords.SafeAny())
            {
                throw new ArgumentException("The following EVSE Ids are not unique: " + duplicateEVSEDataRecords.AggregateWith(", "), nameof(EVSEDataRecords));
            }

            this.EVSEDataRecords = EVSEDataRecords;
            this.OperatorId      = OperatorId;
            this.OperatorName    = OperatorName;

            this.CustomData = CustomData;
        }
        /// <summary>
        /// Create a new AuthorizeStart request.
        /// </summary>
        /// <param name="OperatorId">The unqiue identification of the EVSE operator sending this request.</param>
        /// <param name="Identification">Authentication data used to authorize the user or the car.</param>
        /// <param name="EVSEId">An optional EVSE identification.</param>
        /// <param name="PartnerProductId">An optional partner product identification (for identifying a charging tariff).</param>
        /// <param name="SessionId">An optional charging session identification.</param>
        /// <param name="CPOPartnerSessionId">An optional CPO partner session identification.</param>
        /// <param name="EMPPartnerSessionId">An optional EMP partner session identification.</param>
        /// <param name="CustomData">Optional customer specific data, e.g. in combination with custom parsers and serializers.</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 AuthorizeStartRequest(Operator_Id OperatorId,
                                     Identification Identification,
                                     EVSE_Id?EVSEId = null,
                                     PartnerProduct_Id?PartnerProductId = null,
                                     Session_Id?SessionId = null,
                                     CPOPartnerSession_Id?CPOPartnerSessionId = null,
                                     EMPPartnerSession_Id?EMPPartnerSessionId = null,
                                     JObject CustomData = null,

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

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

        {
            this.OperatorId          = OperatorId;
            this.Identification      = Identification;
            this.EVSEId              = EVSEId;
            this.PartnerProductId    = PartnerProductId;
            this.SessionId           = SessionId;
            this.CPOPartnerSessionId = CPOPartnerSessionId;
            this.EMPPartnerSessionId = EMPPartnerSessionId;
        }
Пример #4
0
        /// <summary>
        /// Parse the given string as an EVSE identification.
        /// </summary>
        /// <param name="OperatorId">The unique identification of a charging station operator.</param>
        /// <param name="Suffix">The suffix of the EVSE identification.</param>
        public static EVSE_Id Parse(Operator_Id OperatorId,
                                    String Suffix)
        {
            #region Initial checks

            if (Suffix != null)
            {
                Suffix = Suffix.Trim();
            }

            if (Suffix.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Suffix), "The given text-representation of an EVSE identification suffix must not be null or empty!");
            }

            #endregion

            switch (OperatorId.Format)
            {
            case OperatorIdFormats.DIN:
                return(Parse(OperatorId + "*" + Suffix));

            case OperatorIdFormats.ISO:
                return(Parse(OperatorId + "E" + Suffix));

            default:     // ISO_STAR
                return(Parse(OperatorId + "*E" + Suffix));
            }
        }
        /// <summary>
        /// Create a valid charging pool identification based on the given parameters.
        /// </summary>
        /// <param name="OperatorId">The identification of an operator.</param>
        /// <param name="Address">The address of the charging pool.</param>
        /// <param name="GeoLocation">An optional geo location of the charging pool.</param>
        /// <param name="SubOperatorName">An optional name of the charging pool suboperator.</param>
        /// <param name="Length">The maximum size of the generated charging pool identification suffix [12 &lt; n &lt; 50].</param>
        /// <param name="Mapper">A delegate to modify a generated charging pool identification suffix.</param>
        public static ChargingPool_Id Generate(Operator_Id OperatorId,
                                               Address Address,
                                               GeoCoordinates?GeoLocation = null,
                                               String SubOperatorName     = null,
                                               Byte Length = 15,
                                               Func <String, String> Mapper = null)
        {
            if (Length < 12)
            {
                Length = 12;
            }

            if (Length > 50)
            {
                Length = 50;
            }

            var Suffix = new SHA256CryptoServiceProvider().
                         ComputeHash(Encoding.UTF8.GetBytes(
                                         String.Concat(
                                             OperatorId.ToString(),
                                             Address.ToString(),
                                             GeoLocation?.ToString() ?? "",
                                             SubOperatorName ?? ""
                                             )
                                         )).
                         ToHexString().
                         SubstringMax(Length).
                         ToUpper();

            return(Parse(Mapper != null
                            ? Mapper(Suffix)
                            : Suffix));
        }
Пример #6
0
        /// <summary>
        /// Generate a new unique identification of an EVSE.
        /// </summary>
        /// <param name="OperatorId">The unique identification of a charging station operator.</param>
        /// <param name="Length">The expected length of the EVSE identification suffix</param>
        /// <param name="Mapper">A delegate to modify the newly generated EVSE identification.</param>
        public static EVSE_Id Random(Operator_Id OperatorId,
                                     Byte Length = 12,
                                     Func <String, String> Mapper = null)


        => new EVSE_Id(OperatorId,
                       Mapper != null
                               ? Mapper(random.RandomString(Length))
                               :        random.RandomString(Length));
Пример #7
0
        /// <summary>
        /// Generate a new Electric Vehicle Supply Equipment (EVSE) identification
        /// based on the given charging station operator and identification suffix.
        /// </summary>
        /// <param name="OperatorId">The unique identification of a charging station operator.</param>
        /// <param name="Suffix">The suffix of the EVSE identification.</param>
        private EVSE_Id(Operator_Id OperatorId,
                        String Suffix)
        {
            if (Suffix.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Suffix), "The EVSE identification suffix must not be null or empty!");
            }

            this.OperatorId = OperatorId;
            this.Suffix     = Suffix;
        }
Пример #8
0
 public EVSEInfo(Operator_Id OperatorId,
                 ChargingPool_Id PoolId,
                 Address PoolAddress,
                 GeoCoordinates?PoolLocation,
                 ChargingStation_Id?StationId)
 {
     this.OperatorId   = OperatorId;
     this.PoolId       = PoolId;
     this.PoolAddress  = PoolAddress;
     this.PoolLocation = PoolLocation;
     this.StationId    = StationId;
 }
Пример #9
0
        public OperatorInfo(Operator_Id OperatorId,
                            String?OperatorName = null,
                            IEnumerable <ChargingPoolInfo>?ChargingPools = null)
        {
            if (OperatorId.IsNullOrEmpty)
            {
                throw new ArgumentNullException(nameof(OperatorId), "The given parameter must not be null!");
            }

            this.OperatorId     = OperatorId;
            this.OperatorName   = OperatorName;
            this._ChargingPools = ChargingPools != null
                                       ? ChargingPools.ToDictionary(pool => pool.PoolId)
                                       : new Dictionary <ChargingPool_Id, ChargingPoolInfo>();
        }
Пример #10
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;
        }
        /// <summary>
        /// Parse the given text representation of an AuthorizeStart request.
        /// </summary>
        /// <param name="Text">The text to parse.</param>
        /// <param name="OperatorIdURL">The EVSE operator identification given in the URL of the HTTP request.</param>
        /// <param name="RequestTimeout">The timeout for this request.</param>
        /// <param name="Timestamp">The optional timestamp of the request.</param>
        /// <param name="EventTrackingId">An optional event tracking identification for correlating this request with other events.</param>
        /// <param name="CustomAuthorizeStartRequestParser">A delegate to parse custom AuthorizeStart request JSON objects.</param>
        public static AuthorizeStartRequest Parse(String Text,
                                                  Operator_Id OperatorIdURL,
                                                  TimeSpan RequestTimeout,
                                                  DateTime?Timestamp = null,
                                                  EventTracking_Id EventTrackingId = null,
                                                  CustomJObjectParserDelegate <AuthorizeStartRequest> CustomAuthorizeStartRequestParser = null)
        {
            if (TryParse(Text,
                         OperatorIdURL,
                         RequestTimeout,
                         out AuthorizeStartRequest auhorizeStartRequest,
                         out String ErrorResponse,
                         Timestamp,
                         EventTrackingId,
                         CustomAuthorizeStartRequestParser))
            {
                return(auhorizeStartRequest);
            }

            throw new ArgumentException("The given text representation of an AuthorizeStart request is invalid: " + ErrorResponse, nameof(Text));
        }
Пример #12
0
        // https://github.com/hubject/oicp/blob/master/OICP-2.3/OICP%202.3%20CPO/02_CPO_Services_and_Operations.asciidoc#eRoamingChargeDetailRecord

        // {
        //   "CPOPartnerSessionID": "string",
        //   "CalibrationLawVerificationInfo": {
        //     "CalibrationLawCertificateID": "string",
        //     "PublicKey": "string",
        //     "MeteringSignatureUrl": "string",
        //     "MeteringSignatureEncodingFormat": "string",
        //     "SignedMeteringValuesVerificationInstruction": "string"
        //   },
        //   "ChargingEnd": "2021-01-11T16:16:08.800Z",
        //   "ChargingStart": "2021-01-11T16:16:08.800Z",
        //   "ConsumedEnergy": 0,
        //   "EMPPartnerSessionID": "string",
        //   "EvseID": "string",
        //   "HubOperatorID": "string",
        //   "HubProviderID": "string",
        //   "Identification": {
        //     "RFIDMifareFamilyIdentification": {
        //       "UID": "string"
        //     },
        //     "QRCodeIdentification": {
        //       "EvcoID": "string",
        //       "HashedPIN": {
        //         "Function": "Bcrypt",
        //         "LegacyHashData": {
        //           "Function": "MD5",
        //           "Salt": "string",
        //           "Value": "string"
        //         },
        //         "Value": "string"
        //       },
        //       "PIN": "string"
        //     },
        //     "PlugAndChargeIdentification": {
        //       "EvcoID": "string"
        //     },
        //     "RemoteIdentification": {
        //       "EvcoID": "string"
        //     },
        //     "RFIDIdentification": {
        //       "EvcoID": "string",
        //       "ExpiryDate": "2021-01-11T16:16:08.800Z",
        //       "PrintedNumber": "string",
        //       "RFID": "mifareCls",
        //       "UID": "string"
        //     }
        //   },
        //   "MeterValueEnd": 0,
        //   "MeterValueInBetween": {
        //     "meterValues": [
        //       0
        //     ]
        //   },
        //   "MeterValueStart": 0,
        //   "PartnerProductID": "string",
        //   "SessionEnd": "2021-01-11T16:16:08.800Z",
        //   "SessionID": "string",
        //   "SessionStart": "2021-01-11T16:16:08.800Z",
        //   "SignedMeteringValues": [
        //     {
        //       "SignedMeteringValue": "string",
        //       "MeteringStatus": "Start"
        //     }
        //   ]
        // }

        #endregion

        #region (static) Parse   (JSON, CustomChargeDetailRecordRequestParser = null)

        /// <summary>
        /// Parse the given JSON representation of a ChargeDetailRecord request.
        /// </summary>
        /// <param name="JSON">The JSON to parse.</param>
        /// <param name="OperatorIdURL">The unqiue identification of the operator sending the given charge detail record (not the suboperator or the operator of the EVSE).</param>
        /// <param name="RequestTimeout">The timeout for this request.</param>
        /// <param name="Timestamp">The optional timestamp of the request.</param>
        /// <param name="EventTrackingId">An optional event tracking identification for correlating this request with other events.</param>
        /// <param name="CustomChargeDetailRecordRequestParser">A delegate to parse custom ChargeDetailRecord JSON objects.</param>
        public static ChargeDetailRecordRequest Parse(JObject JSON,
                                                      Operator_Id OperatorIdURL,
                                                      TimeSpan RequestTimeout,
                                                      DateTime?Timestamp = null,
                                                      EventTracking_Id EventTrackingId = null,
                                                      CustomJObjectParserDelegate <ChargeDetailRecordRequest> CustomChargeDetailRecordRequestParser = null)
        {
            if (TryParse(JSON,
                         OperatorIdURL,
                         RequestTimeout,
                         out ChargeDetailRecordRequest authorizeRemoteStopRequest,
                         out String ErrorResponse,
                         Timestamp,
                         EventTrackingId,
                         CustomChargeDetailRecordRequestParser))
            {
                return(authorizeRemoteStopRequest);
            }

            throw new ArgumentException("The given JSON representation of a ChargeDetailRecord request is invalid: " + ErrorResponse, nameof(JSON));
        }
Пример #13
0
        /// <summary>
        /// Try to parse the given text-representation of an EVSE identification.
        /// </summary>
        /// <param name="Text">A text-representation of an EVSE identification.</param>
        /// <param name="EVSEId">The parsed EVSE identification.</param>
        public static Boolean TryParse(String Text, out EVSE_Id EVSEId)
        {
            Text = Text?.Trim();

            if (Text.IsNotNullOrEmpty())
            {
                try
                {
                    var MatchCollection = EVSEId_RegEx.Matches(Text);

                    if (MatchCollection.Count == 1)
                    {
                        // New format...
                        if (Operator_Id.TryParse(MatchCollection[0].Groups[1].Value, out Operator_Id operatorId))
                        {
                            EVSEId = new EVSE_Id(operatorId,
                                                 MatchCollection[0].Groups[2].Value);

                            return(true);
                        }

                        // Old format...
                        if (Operator_Id.TryParse(MatchCollection[0].Groups[3].Value, out operatorId))
                        {
                            EVSEId = new EVSE_Id(operatorId,
                                                 MatchCollection[0].Groups[4].Value);

                            return(true);
                        }
                    }
                }
                catch
                { }
            }

            EVSEId = default;
            return(false);
        }
        /// <summary>
        /// Create a new operator EVSE status object.
        /// </summary>
        /// <param name="EVSEStatusRecords">An enumeration of EVSE status records.</param>
        /// <param name="OperatorId">The unqiue identification of the EVSE operator maintaining the given EVSE status records.</param>
        /// <param name="OperatorName">The name of the EVSE operator maintaining the given EVSE status records.</param>
        ///
        /// <param name="CustomData">Optional customer specific data, e.g. in combination with custom parsers and serializers.</param>
        public OperatorEVSEStatus(IEnumerable <EVSEStatusRecord> EVSEStatusRecords,
                                  Operator_Id OperatorId,
                                  String OperatorName,

                                  JObject CustomData = null)
        {
            if (!EVSEStatusRecords.SafeAny())
            {
                throw new ArgumentNullException(nameof(EVSEStatusRecords), "The given enumeration of EVSE status records must not be null or empty!");
            }

            OperatorName = OperatorName?.Trim();

            if (OperatorName.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(OperatorName), "The given EVSE operator name must not be null or empty!");
            }

            this.EVSEStatusRecords = EVSEStatusRecords;
            this.OperatorId        = OperatorId;
            this.OperatorName      = OperatorName;

            this.CustomData = CustomData;
        }
        /// <summary>
        /// Try to parse the given JSON representation of an AuthorizeStart request.
        /// </summary>
        /// <param name="JSON">The JSON to parse.</param>
        /// <param name="OperatorIdURL">The EVSE operator identification given in the URL of the HTTP request.</param>
        /// <param name="RequestTimeout">The timeout for this request.</param>
        /// <param name="AuthorizeStartRequest">The parsed AuthorizeStart request.</param>
        /// <param name="ErrorResponse">An optional error response.</param>
        /// <param name="Timestamp">The optional timestamp of the request.</param>
        /// <param name="EventTrackingId">An optional event tracking identification for correlating this request with other events.</param>
        /// <param name="CustomAuthorizeStartRequestParser">A delegate to parse custom AuthorizeStart request JSON objects.</param>
        public static Boolean TryParse(JObject JSON,
                                       Operator_Id OperatorIdURL,
                                       TimeSpan RequestTimeout,
                                       out AuthorizeStartRequest AuthorizeStartRequest,
                                       out String ErrorResponse,
                                       DateTime?Timestamp = null,
                                       EventTracking_Id EventTrackingId = null,
                                       CustomJObjectParserDelegate <AuthorizeStartRequest> CustomAuthorizeStartRequestParser = null)
        {
            try
            {
                AuthorizeStartRequest = default;

                if (JSON?.HasValues != true)
                {
                    ErrorResponse = "The given JSON object must not be null or empty!";
                    return(false);
                }

                #region Parse OperatorId                [mandatory]

                if (!JSON.ParseMandatory("OperatorID",
                                         "operator identification",
                                         Operator_Id.TryParse,
                                         out Operator_Id OperatorId,
                                         out ErrorResponse))
                {
                    return(false);
                }

                if (OperatorId != OperatorIdURL)
                {
                    ErrorResponse = "Inconsistend operator identifications: '" + OperatorIdURL + "' (URL) <> '" + OperatorId + "' (JSON)!";
                    return(false);
                }

                #endregion

                #region Parse Identification            [mandatory]

                if (!JSON.ParseMandatoryJSON2("Identification",
                                              "identification",
                                              OICPv2_3.Identification.TryParse,
                                              out Identification Identification,
                                              out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse EVSEId                    [optional]

                if (JSON.ParseOptional("EvseID",
                                       "EVSE identification",
                                       EVSE_Id.TryParse,
                                       out EVSE_Id? EVSEId,
                                       out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse PartnerProductId          [optional]

                if (JSON.ParseOptional("PartnerProductID",
                                       "partner product identification",
                                       PartnerProduct_Id.TryParse,
                                       out PartnerProduct_Id? PartnerProductId,
                                       out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse SessionId                 [optional]

                if (JSON.ParseOptional("SessionID",
                                       "session identification",
                                       Session_Id.TryParse,
                                       out Session_Id? SessionId,
                                       out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse CPOPartnerSessionId       [optional]

                if (JSON.ParseOptional("CPOPartnerSessionID",
                                       "CPO product session identification",
                                       CPOPartnerSession_Id.TryParse,
                                       out CPOPartnerSession_Id? CPOPartnerSessionId,
                                       out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse EMPPartnerSessionId       [optional]

                if (JSON.ParseOptional("EMPPartnerSessionID",
                                       "EMP product session identification",
                                       EMPPartnerSession_Id.TryParse,
                                       out EMPPartnerSession_Id? EMPPartnerSessionId,
                                       out ErrorResponse))
                {
                    if (ErrorResponse != null)
                    {
                        return(false);
                    }
                }

                #endregion

                #region Parse CustomData                [optional]

                var CustomData = JSON["CustomData"] as JObject;

                #endregion


                AuthorizeStartRequest = new AuthorizeStartRequest(OperatorId,
                                                                  Identification,
                                                                  EVSEId,
                                                                  PartnerProductId,
                                                                  SessionId,
                                                                  CPOPartnerSessionId,
                                                                  EMPPartnerSessionId,
                                                                  CustomData,
                                                                  Timestamp,
                                                                  null,
                                                                  EventTrackingId,
                                                                  RequestTimeout);

                if (CustomAuthorizeStartRequestParser != null)
                {
                    AuthorizeStartRequest = CustomAuthorizeStartRequestParser(JSON,
                                                                              AuthorizeStartRequest);
                }

                return(true);
            }
            catch (Exception e)
            {
                AuthorizeStartRequest = default;
                ErrorResponse         = "The given JSON representation of an AuthorizeStart request is invalid: " + e.Message;
                return(false);
            }
        }
Пример #16
0
        /// <summary>
        /// Try to parse the given JSON representation of a ChargeDetailRecord request.
        /// </summary>
        /// <param name="JSON">The JSON to parse.</param>
        /// <param name="OperatorIdURL">The unqiue identification of the operator sending the given charge detail record (not the suboperator or the operator of the EVSE).</param>
        /// <param name="RequestTimeout">The timeout for this request.</param>
        /// <param name="ChargeDetailRecordRequest">The parsed ChargeDetailRecord request.</param>
        /// <param name="ErrorResponse">An optional error response.</param>
        /// <param name="Timestamp">The optional timestamp of the request.</param>
        /// <param name="EventTrackingId">An optional event tracking identification for correlating this request with other events.</param>
        /// <param name="CustomChargeDetailRecordRequestParser">A delegate to parse custom ChargeDetailRecord request JSON objects.</param>
        public static Boolean TryParse(JObject JSON,
                                       Operator_Id OperatorIdURL,
                                       TimeSpan RequestTimeout,
                                       out ChargeDetailRecordRequest ChargeDetailRecordRequest,
                                       out String ErrorResponse,
                                       DateTime?Timestamp = null,
                                       EventTracking_Id EventTrackingId = null,
                                       CustomJObjectParserDelegate <ChargeDetailRecordRequest> CustomChargeDetailRecordRequestParser = null)
        {
            try
            {
                ChargeDetailRecordRequest = default;

                if (JSON?.HasValues != true)
                {
                    ErrorResponse = "The given JSON object must not be null or empty!";
                    return(false);
                }

                #region Parse ChargeDetailRecord     [mandatory]

                if (!OICPv2_3.ChargeDetailRecord.TryParse(JSON,
                                                          out ChargeDetailRecord ChargeDetailRecord,
                                                          out ErrorResponse))
                {
                    return(false);
                }

                #endregion

                #region Parse CustomData             [optional]

                var CustomData = JSON["CustomData"] as JObject;

                #endregion


                ChargeDetailRecordRequest = new ChargeDetailRecordRequest(ChargeDetailRecord,
                                                                          OperatorIdURL,
                                                                          CustomData,

                                                                          Timestamp,
                                                                          null,
                                                                          EventTrackingId,
                                                                          RequestTimeout);

                if (CustomChargeDetailRecordRequestParser != null)
                {
                    ChargeDetailRecordRequest = CustomChargeDetailRecordRequestParser(JSON,
                                                                                      ChargeDetailRecordRequest);
                }

                return(true);
            }
            catch (Exception e)
            {
                ChargeDetailRecordRequest = default;
                ErrorResponse             = "The given JSON representation of a ChargeDetailRecord request is invalid: " + e.Message;
                return(false);
            }
        }