/// <summary>
        /// Return a JSON representation of this object.
        /// </summary>
        /// <param name="CustomCDRLocationSerializer">A delegate to serialize custom location JSON objects.</param>
        public JObject ToJSON(CustomJObjectSerializerDelegate <CDRLocation> CustomCDRLocationSerializer = null)
        {
            var JSON = JSONObject.Create(

                new JProperty("id", Id.ToString()),

                Name.IsNotNullOrEmpty()
                               ? new JProperty("name", Name)
                               : null,

                new JProperty("address", Address),
                new JProperty("city", City),

                PostalCode.IsNotNullOrEmpty()
                               ? new JProperty("postal_code", PostalCode)
                               : null,

                new JProperty("country", Country),

                new JProperty("coordinates", new JObject(
                                  new JProperty("latitude", Coordinates.Latitude.Value.ToString("0.00000##").Replace(",", ".")),
                                  new JProperty("longitude", Coordinates.Longitude.Value.ToString("0.00000##").Replace(",", "."))
                                  )),

                new JProperty("evse_uid", EVSEUId.ToString()),
                new JProperty("evse_id", EVSEId.ToString()),
                new JProperty("connector_id", ConnectorId.ToString()),
                new JProperty("connector_standard", ConnectorStandard.ToString()),
                new JProperty("connector_format", ConnectorFormat.ToString()),
                new JProperty("connector_power_type", ConnectorPowerType.ToString())

                );

            return(CustomCDRLocationSerializer != null
                       ? CustomCDRLocationSerializer(this, JSON)
                       : JSON);
        }
Beispiel #2
0
        /// <summary>
        /// Return a JSON representation of this object.
        /// </summary>
        /// <param name="CustomSessionSerializer">A delegate to serialize custom session JSON objects.</param>
        /// <param name="CustomCDRTokenSerializer">A delegate to serialize custom charge detail record token JSON objects.</param>
        /// <param name="CustomEnergyMeterSerializer">A delegate to serialize custom energy meter JSON objects.</param>
        /// <param name="CustomTransparencySoftwareSerializer">A delegate to serialize custom transparency software JSON objects.</param>
        /// <param name="CustomChargingPeriodSerializer">A delegate to serialize custom charging period JSON objects.</param>
        /// <param name="CustomCDRDimensionSerializer">A delegate to serialize custom charge detail record dimension JSON objects.</param>
        /// <param name="CustomPriceSerializer">A delegate to serialize custom price JSON objects.</param>
        public JObject ToJSON(CustomJObjectSerializerDelegate <Session> CustomSessionSerializer         = null,
                              CustomJObjectSerializerDelegate <CDRToken> CustomCDRTokenSerializer       = null,
                              CustomJObjectSerializerDelegate <EnergyMeter> CustomEnergyMeterSerializer = null,
                              CustomJObjectSerializerDelegate <TransparencySoftware> CustomTransparencySoftwareSerializer = null,
                              CustomJObjectSerializerDelegate <ChargingPeriod> CustomChargingPeriodSerializer             = null,
                              CustomJObjectSerializerDelegate <CDRDimension> CustomCDRDimensionSerializer = null,
                              CustomJObjectSerializerDelegate <Price> CustomPriceSerializer = null)
        {
            var JSON = JSONObject.Create(

                new JProperty("country_code", CountryCode.ToString()),
                new JProperty("party_id", PartyId.ToString()),
                new JProperty("id", Id.ToString()),

                new JProperty("start_date_time", Start.ToIso8601()),

                End.HasValue
                               ? new JProperty("end_date_time", End.Value.ToIso8601())
                               : null,

                new JProperty("kwh", kWh),

                new JProperty("cdr_token", CDRToken.ToJSON(CustomCDRTokenSerializer)),
                new JProperty("auth_method", AuthMethod.ToString()),

                AuthorizationReference.HasValue
                               ? new JProperty("authorization_reference", AuthorizationReference.ToString())
                               : null,

                new JProperty("location_id", LocationId.ToString()),
                new JProperty("evse_uid", EVSEUId.ToString()),
                new JProperty("connector_id", ConnectorId.ToString()),

                MeterId.HasValue
                               ? new JProperty("meter_id", MeterId.ToString())
                               : null,

                EnergyMeter != null
                               ? new JProperty("energy_meter", EnergyMeter.ToJSON(CustomEnergyMeterSerializer))
                               : null,

                TransparencySoftwares.SafeAny()
                               ? new JProperty("transparency_softwares", new JArray(TransparencySoftwares.Select(software => software.ToJSON(CustomTransparencySoftwareSerializer))))
                               : null,

                new JProperty("currency", Currency.ToString()),

                ChargingPeriods.SafeAny()
                               ? new JProperty("charging_periods", new JArray(ChargingPeriods.Select(chargingPeriod => chargingPeriod.ToJSON(CustomChargingPeriodSerializer,
                                                                                                                                             CustomCDRDimensionSerializer))))
                               : null,

                TotalCosts.HasValue
                               ? new JProperty("total_cost", TotalCosts.Value.ToJSON(CustomPriceSerializer))
                               : null,

                new JProperty("status", Status.ToString()),


                new JProperty("last_updated", LastUpdated.ToIso8601())

                );

            return(CustomSessionSerializer != null
                       ? CustomSessionSerializer(this, JSON)
                       : JSON);
        }