Esempio n. 1
0
        /// <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);
Esempio n. 2
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))

            );