예제 #1
0
        /// <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);
        }
예제 #2
0
파일: Tariff.cs 프로젝트: 0nenote/WWCP_OCPI
        /// <summary>
        /// Return a JSON representation of this object.
        /// </summary>
        public JObject ToJSON()

        => JSONObject.Create(new JProperty("id", Id.ToString()),
                             new JProperty("currency", Currency.ISOCode),
                             TariffText != null && TariffText.Any() ? JSONHelper.ToJSON("tariff_alt_text", TariffText)      : null,
                             TariffUrl != null                     ? new JProperty("tariff_alt_url", TariffUrl.ToString()) : null,
                             TariffElements.Any()
                                     ? new JProperty("elements", new JArray(TariffElements.Select(TariffElement => TariffElement.ToJSON())))
                                     : null,
                             EnergyMix != null
                                     ? new JProperty("energy_mix", EnergyMix.ToJSON())
                                     : null);
예제 #3
0
        /// <summary>
        /// Return a JSON representation of the given charging tariff.
        /// </summary>
        /// <param name="Embedded">Whether this data is embedded into another data structure, e.g. into a charging station operator.</param>
        public JObject ToJSON(Boolean Embedded = false,
                              InfoStatus ExpandRoamingNetworkId          = InfoStatus.ShowIdOnly,
                              InfoStatus ExpandChargingStationOperatorId = InfoStatus.ShowIdOnly,
                              InfoStatus ExpandChargingPoolId            = InfoStatus.ShowIdOnly,
                              InfoStatus ExpandEVSEIds      = InfoStatus.Expand,
                              InfoStatus ExpandBrandIds     = InfoStatus.ShowIdOnly,
                              InfoStatus ExpandDataLicenses = InfoStatus.ShowIdOnly)


        => JSONObject.Create(

            Id.ToJSON("@id"),

            Embedded
                             ? null
                             : new JProperty("@context", "https://open.charging.cloud/contexts/wwcp+json/ChargingTariff"),

            Name.IsNeitherNullNorEmpty()
                             ? Name.ToJSON("name")
                             : null,

            Description.IsNeitherNullNorEmpty()
                             ? Description.ToJSON("description")
                             : null,

            Brand != null
                             ? ExpandBrandIds.Switch(
                () => new JProperty("brandId", Brand.Id.ToString()),
                () => new JProperty("brand", Brand.ToJSON()))
                             : null,

            (!Embedded || DataSource != Operator.DataSource)
                             ? DataSource.ToJSON("dataSource")
                             : null,

            //(!Embedded || DataLicenses != Operator.DataLicenses)
            //    ? ExpandDataLicenses.Switch(
            //        () => new JProperty("dataLicenseIds",  new JArray(DataLicenses.SafeSelect(license => license.Id.ToString()))),
            //        () => new JProperty("dataLicenses",    DataLicenses.ToJSON()))
            //    : null,


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

            TariffURI != null
                             ? new JProperty("URI", TariffURI.ToString())
                             : null,

            TariffElements.Any()
                             ? new JProperty("elements", new JArray(TariffElements.Select(TariffElement => TariffElement.ToJSON())))
                             : null,

            EnergyMix != null
                             ? new JProperty("energy_mix", EnergyMix.ToJSON())
                             : null,



            Operator.ChargingStationGroups.Any(group => group.Tariff == this)
                             ? new JProperty("chargingStations", new JArray(Operator.ChargingStationGroups.
                                                                            Where(group => group.Tariff == this).
                                                                            Select(group => group.AllowedMemberIds.
                                                                                   Select(id => id.ToString()))))
                             : null,

            Operator.EVSEGroups.Any(group => group.Tariff == this)
                             ? new JProperty("EVSEs", new JArray(Operator.EVSEGroups.
                                                                 Where(group => group.Tariff == this).
                                                                 Select(group => group.AllowedMemberIds.
                                                                        Select(id => id.ToString()))))
                             : null



            //                 #region Embedded means it is served as a substructure of e.g. a charging station operator

            //                 Embedded
            //                     ? null
            //                     : ExpandRoamingNetworkId.Switch(
            //                           () => new JProperty("roamingNetworkId",           RoamingNetwork.Id. ToString()),
            //                           () => new JProperty("roamingNetwork",             RoamingNetwork.    ToJSON(Embedded:                          true,
            //                                                                                                                            ExpandChargingStationOperatorIds:  InfoStatus.Hidden,
            //                                                                                                                            ExpandChargingPoolIds:             InfoStatus.Hidden,
            //                                                                                                                            ExpandChargingStationIds:          InfoStatus.Hidden,
            //                                                                                                                            ExpandEVSEIds:                     InfoStatus.Hidden,
            //                                                                                                                            ExpandBrandIds:                    InfoStatus.Hidden,
            //                                                                                                                            ExpandDataLicenses:                InfoStatus.Hidden))),

            //                 Embedded
            //                     ? null
            //                     : ExpandChargingStationOperatorId.Switch(
            //                           () => new JProperty("chargingStationOperatorId",  Operator.Id.       ToString()),
            //                           () => new JProperty("chargingStationOperator",    Operator.          ToJSON(Embedded:                          true,
            //                                                                                                                            ExpandRoamingNetworkId:            InfoStatus.Hidden,
            //                                                                                                                            ExpandChargingPoolIds:             InfoStatus.Hidden,
            //                                                                                                                            ExpandChargingStationIds:          InfoStatus.Hidden,
            //                                                                                                                            ExpandEVSEIds:                     InfoStatus.Hidden,
            //                                                                                                                            ExpandBrandIds:                    InfoStatus.Hidden,
            //                                                                                                                            ExpandDataLicenses:                InfoStatus.Hidden))),

            //                 #endregion

            //                 ExpandEVSEIds.Switch(
            //                     () => new JProperty("EVSEIds",
            //                                         EVSEIds.SafeAny()
            //                                             ? new JArray(EVSEIds.
            //                                                                               OrderBy(evseid => evseid).
            //                                                                               Select (evseid => evseid.ToString()))
            //                                             : null),

            //                     () => new JProperty("EVSEs",
            //                                         EVSEs.SafeAny()
            //                                             ? new JArray(EVSEs.
            //                                                                               OrderBy(evse   => evse.Id).
            //                                                                               Select (evse   => evse.  ToJSON(Embedded: true)))
            //                                             : null))

            );