public JObject ToJSON() => JSONObject.Create( new JProperty("@id", Id.ToString()), new JProperty("timestamp", Timestamp.ToIso8601()), new JProperty("startTime", StartTime.ToIso8601()), new JProperty("duration", Duration.TotalMinutes), new JProperty("endTime", EndTime.ToIso8601()), new JProperty("consumedReservationTime", ConsumedReservationTime.TotalMinutes), new JProperty("reservationLevel", ReservationLevel.ToString()), ProviderId.HasValue ? new JProperty("providerId", ProviderId.ToString()) : null, StartAuthentication != null ? new JProperty("authentication", EndTime.ToIso8601()) : null, RoamingNetworkId.HasValue ? new JProperty("roamingNetworkId", RoamingNetworkId.ToString()) : null, ChargingPoolId.HasValue ? new JProperty("chargingPoolId", ChargingPoolId.ToString()) : null, ChargingStationId.HasValue ? new JProperty("chargingStationId", ChargingStationId.ToString()) : null, EVSEId.HasValue ? new JProperty("EVSEId", EVSEId.ToString()) : null, ChargingProduct != null ? new JProperty("chargingProduct", ChargingProduct.ToJSON()) : null, ChargingSession != null ? new JProperty("chargingSessionId", ChargingSession.Id.ToString()) : null );
//public ChargingSession AddUserData(String Key, Object Value) //{ // this._UserDefined //} public JObject ToJSON(Boolean Embedded = false) => JSONObject.Create( Id.ToJSON("@id"), Embedded ? new JProperty("@context", "https://open.charging.cloud/contexts/wwcp+json/chargingSession") : null, new JProperty("sessionTime", JSONObject.Create( new JProperty("start", SessionTime.StartTime.ToIso8601()), SessionTime.EndTime.HasValue ? new JProperty("end", SessionTime.EndTime.Value.ToIso8601()) : null )), new JProperty("duration", Duration.TotalSeconds), RoamingNetworkId.HasValue ? new JProperty("roamingNetworkId", RoamingNetworkId.ToString()) : null, ChargingStationOperatorId.HasValue ? new JProperty("chargingStationOperatorId", ChargingStationOperatorId.ToString()) : null, ChargingPoolId.HasValue ? new JProperty("chargingPoolId", ChargingPoolId. ToString()) : null, ChargingStationId.HasValue ? new JProperty("chargingStationId", ChargingStationId. ToString()) : null, EVSEId.HasValue ? new JProperty("EVSEId", EVSEId. ToString()) : null, ChargingProduct != null ? new JProperty("chargingProduct", ChargingProduct. ToJSON()) : null, ProviderIdStart != null ? new JProperty("providerIdStart", ProviderIdStart.ToString()) : null, ProviderIdStop != null ? new JProperty("providerIdStop", ProviderIdStop.ToString()) : null, AuthenticationStart.IsDefined() ? new JProperty("authenticationStart", AuthenticationStart.ToJSON()) : null, AuthenticationStop.IsDefined() ? new JProperty("authenticationStop", AuthenticationStop.ToJSON()) : null, Reservation != null ? new JProperty("reservation", new JObject( new JProperty("reservationId", Reservation.Id.ToString()), new JProperty("start", Reservation.StartTime.ToIso8601()), new JProperty("duration", Reservation.Duration.TotalSeconds) ) ) : ReservationId != null ? new JProperty("reservationId", ReservationId.ToString()) : null, EnergyMeterId.HasValue ? new JProperty("energyMeterId", EnergyMeterId.ToString()) : null, EnergyMeteringValues.Any() ? new JProperty("energyMeterValues", new JObject( EnergyMeteringValues. Select(MeterValue => new JProperty(MeterValue.Timestamp.ToIso8601(), MeterValue.Value)) )) : null );