/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomTariffSerializer">A delegate to serialize custom tariff JSON objects.</param> /// <param name="CustomTariffElementSerializer">A delegate to serialize custom tariff element JSON objects.</param> /// <param name="CustomPriceComponentSerializer">A delegate to serialize custom price component JSON objects.</param> /// <param name="CustomTariffRestrictionsSerializer">A delegate to serialize custom tariff restrictions JSON objects.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <Tariff> CustomTariffSerializer = null, CustomJObjectSerializerDelegate <TariffElement> CustomTariffElementSerializer = null, CustomJObjectSerializerDelegate <PriceComponent> CustomPriceComponentSerializer = null, CustomJObjectSerializerDelegate <TariffRestrictions> CustomTariffRestrictionsSerializer = null) { var JSON = JSONObject.Create( new JProperty("country_code", CountryCode.ToString()), new JProperty("party_id", PartyId.ToString()), new JProperty("id", Id.ToString()), new JProperty("currency", Currency.ToString()), TariffType.HasValue ? new JProperty("type", TariffType.Value.ToString()) : null, TariffAltText.SafeAny() ? new JProperty("tariff_alt_text", new JArray(TariffAltText.Select(tariffAltText => tariffAltText.ToJSON()))) : null, TariffAltURL.HasValue ? new JProperty("tariff_alt_url", TariffAltURL.ToString()) : null, MinPrice.HasValue ? new JProperty("min_price", MinPrice.Value.ToJSON()) : null, MaxPrice.HasValue ? new JProperty("max_price", MaxPrice.Value.ToJSON()) : null, TariffElements.SafeAny() ? new JProperty("elements", new JArray(TariffElements.Select(tariffElement => tariffElement.ToJSON(CustomTariffElementSerializer, CustomPriceComponentSerializer, CustomTariffRestrictionsSerializer)))) : null, Start.HasValue ? new JProperty("start_date_time", Start.Value.ToIso8601()) : null, End.HasValue ? new JProperty("end_date_time", End.Value.ToIso8601()) : null, EnergyMix != null ? new JProperty("energy_mix", EnergyMix.ToJSON()) : null, new JProperty("last_updated", LastUpdated.ToIso8601()) ); return(CustomTariffSerializer != null ? CustomTariffSerializer(this, JSON) : JSON); }
/// <summary> /// Create a new charging tariff. /// </summary> /// <param name="CountryCode">The ISO-3166 alpha-2 country code of the CPO that 'owns' this session.</param> /// <param name="PartyId">The Id of the CPO that 'owns' this session (following the ISO-15118 standard).</param> /// <param name="Id">The identification of the tariff within the CPOs platform (and suboperator platforms).</param> /// <param name="Currency">ISO 4217 code of the currency used for this tariff.</param> /// <param name="TariffElements">An enumeration of tariff elements.</param> /// /// <param name="TariffType">Defines the type of the tariff.</param> /// <param name="TariffAltText">Multi-language alternative tariff info text.</param> /// <param name="TariffAltURL">URL to a web page that contains an explanation of the tariff information in human readable form.</param> /// <param name="MinPrice">Minimum charging price.</param> /// <param name="MaxPrice">Maximum charging price.</param> /// <param name="Start">The timestamp when this tariff becomes active.</param> /// <param name="End">The timestamp after which this tariff is no longer valid.</param> /// <param name="EnergyMix">Optional details on the energy supplied with this tariff.</param> /// <param name="LastUpdated">Timestamp when this tariff was last updated (or created).</param> public Tariff(CountryCode CountryCode, Party_Id PartyId, Tariff_Id Id, Currency Currency, IEnumerable <TariffElement> TariffElements, TariffTypes?TariffType = null, IEnumerable <DisplayText> TariffAltText = null, URL?TariffAltURL = null, Price?MinPrice = null, Price?MaxPrice = null, DateTime?Start = null, DateTime?End = null, EnergyMix EnergyMix = null, DateTime?LastUpdated = null) { if (!TariffElements.SafeAny()) { throw new ArgumentNullException(nameof(TariffElements), "The given enumeration of tariff elements must not be null or empty!"); } this.CountryCode = CountryCode; this.PartyId = PartyId; this.Id = Id; this.Currency = Currency; this.TariffElements = TariffElements.Distinct(); this.TariffType = TariffType; this.TariffAltText = TariffAltText?.Distinct() ?? new DisplayText[0]; this.TariffAltURL = TariffAltURL; this.MinPrice = MinPrice; this.MaxPrice = MaxPrice; this.Start = Start; this.End = End; this.EnergyMix = EnergyMix; this.LastUpdated = LastUpdated ?? DateTime.Now; CalcSHA256Hash(); }