public JToken ToJSON(InfoStatus ExpandTags = InfoStatus.ShowIdOnly) => ExpandTags.Switch(this, info => new JObject(new JProperty("tag", info.Tag.ToJSON(true, ExpandDescription: InfoStatus.Expanded)), new JProperty("relevance", info.Value)), info => new JArray(info.Tag.Id.ToString(), info.Value));
public JToken ToJSON(InfoStatus ExpandTags = InfoStatus.ShowIdOnly) => ExpandTags.Switch(this, info => new JObject(new JProperty("tag1", info.Tag1.ToJSON(true, ExpandDescription: InfoStatus.Expanded)), new JProperty("label", info.Label.ToString()), new JProperty("value", info.Value), new JProperty("tag2", info.Tag2.ToJSON(true, ExpandDescription: InfoStatus.Expanded))), info => new JArray(info.Tag1.Id.ToString(), info.Label.ToString(), info.Value, info.Tag2.Id.ToString()));
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="Embedded">Whether this data is embedded into another data structure, e.g. into a OrganizationGroup.</param> /// <param name="IncludeCryptoHash">Whether to include the cryptograhical hash value of this object.</param> public virtual JObject ToJSON(Boolean Embedded = false, InfoStatus ExpandOrganizations = InfoStatus.ShowIdOnly, InfoStatus ExpandParentGroup = InfoStatus.ShowIdOnly, InfoStatus ExpandSubgroups = InfoStatus.ShowIdOnly, InfoStatus ExpandAttachedFiles = InfoStatus.ShowIdOnly, InfoStatus IncludeAttachedFileSignatures = InfoStatus.ShowIdOnly, Boolean IncludeCryptoHash = true) { var JSON = JSONObject.Create( Members.SafeAny() && ExpandOrganizations != InfoStatus.Hidden ? ExpandSubgroups.Switch( () => new JProperty("memberIds", new JArray(Members.SafeSelect(organization => organization.Id.ToString()))), () => new JProperty("members", new JArray(Members.SafeSelect(organization => organization.ToJSON(Embedded: true, //ExpandParentGroup: InfoStatus.Hidden, //ExpandSubgroups: InfoStatus.Expand, IncludeCryptoHash: IncludeCryptoHash))))) : null, ParentGroup != null && ExpandParentGroup != InfoStatus.Hidden ? ExpandParentGroup.Switch( () => new JProperty("parentGroupId", ParentGroup.Id.ToString()), () => new JProperty("parentGroup", ParentGroup.ToJSON())) : null, Subgroups.SafeAny() && ExpandSubgroups != InfoStatus.Hidden ? ExpandSubgroups.Switch( () => new JProperty("subgroupsIds", new JArray(Subgroups.SafeSelect(subgroup => subgroup.Id.ToString()))), () => new JProperty("subgroups", new JArray(Subgroups.SafeSelect(subgroup => subgroup.ToJSON(Embedded: true, ExpandParentGroup: InfoStatus.Hidden, ExpandSubgroups: InfoStatus.Expanded, IncludeCryptoHash: IncludeCryptoHash))))) : null ); return(JSON); }
protected JObject ToJSON(String JSONLDContext, Boolean Embedded = false, InfoStatus ExpandAttachedFiles = InfoStatus.ShowIdOnly, InfoStatus IncludeAttachedFileSignatures = InfoStatus.ShowIdOnly, Func <JObject, JObject> CustomAGroupSerializer = null) { var JSON = JSONObject.Create( new JProperty("@id", Id.ToString()), Embedded ? null : new JProperty("@context", JSONLDContext.ToString()), new JProperty("name", Name.ToJSON()), Description.IsNeitherNullNorEmpty() ? new JProperty("description", Description.ToJSON()) : null, AttachedFiles.SafeAny() && ExpandAttachedFiles != InfoStatus.Hidden ? ExpandAttachedFiles.Switch( () => new JProperty("attachedFileIds", new JArray(AttachedFiles.SafeSelect(attachedFile => attachedFile.Id.ToString()))), () => new JProperty("attachedFiles", new JArray(AttachedFiles.SafeSelect(attachedFile => attachedFile.ToJSON(Embedded: true, IncludeSignatures: IncludeAttachedFileSignatures, IncludeCryptoHash: true))))) : null, DataSource?.ToJSON("dataSource") ); return(CustomAGroupSerializer != null ? CustomAGroupSerializer(JSON) : JSON); }
/// <summary> /// Return a JSON representation of the given charging station. /// </summary> /// <param name="ChargingStation">A charging station.</param> /// <param name="Embedded">Whether this data is embedded into another data structure, e.g. into a charging pool.</param> public static JObject ToJSON(this ChargingStation ChargingStation, 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) => ChargingStation == null ? null : JSONObject.Create( ChargingStation.Id.ToJSON("@id"), Embedded ? null : new JProperty("@context", "https://open.charging.cloud/contexts/wwcp+json/ChargingStation"), ChargingStation.Name.IsNeitherNullNorEmpty() ? ChargingStation.Name.ToJSON("name") : null, ChargingStation.Description.IsNeitherNullNorEmpty() ? ChargingStation.Description.ToJSON("description") : null, ChargingStation.Brand != null ? ExpandBrandIds.Switch( () => new JProperty("brandId", ChargingStation.Brand.Id.ToString()), () => new JProperty("brand", ChargingStation.Brand.ToJSON())) : null, (!Embedded || ChargingStation.DataSource != ChargingStation.ChargingPool.DataSource) ? ChargingStation.DataSource.ToJSON("dataSource") : null, (!Embedded || ChargingStation.DataLicenses != ChargingStation.ChargingPool.DataLicenses) ? ExpandDataLicenses.Switch( () => new JProperty("dataLicenseIds", new JArray(ChargingStation.DataLicenses.SafeSelect(license => license.Id.ToString()))), () => new JProperty("dataLicenses", ChargingStation.DataLicenses.ToJSON())) : null, #region Embedded means it is served as a substructure of e.g. a charging station operator Embedded ? null : ExpandRoamingNetworkId.Switch( () => new JProperty("roamingNetworkId", ChargingStation.RoamingNetwork.Id.ToString()), () => new JProperty("roamingNetwork", ChargingStation.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", ChargingStation.Operator.Id.ToString()), () => new JProperty("chargingStationOperator", ChargingStation.Operator.ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingPoolIds: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden))), Embedded ? null : ExpandChargingPoolId.Switch( () => new JProperty("chargingPoolId", ChargingStation.ChargingPool.Id.ToString()), () => new JProperty("chargingPool", ChargingStation.ChargingPool.ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingStationOperatorId: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden))), #endregion (!Embedded || ChargingStation.GeoLocation != ChargingStation.ChargingPool.GeoLocation) ? ChargingStation.GeoLocation.Value.ToJSON("geoLocation") : null, (!Embedded || ChargingStation.Address != ChargingStation.ChargingPool.Address) ? ChargingStation.Address.ToJSON("address") : null, (!Embedded || ChargingStation.AuthenticationModes != ChargingStation.ChargingPool.AuthenticationModes) ? ChargingStation.AuthenticationModes.ToJSON("authenticationModes") : null, (!Embedded || ChargingStation.HotlinePhoneNumber != ChargingStation.ChargingPool.HotlinePhoneNumber) ? ChargingStation.HotlinePhoneNumber.ToJSON("hotlinePhoneNumber") : null, (!Embedded || ChargingStation.OpeningTimes != ChargingStation.ChargingPool.OpeningTimes) ? ChargingStation.OpeningTimes.ToJSON("openingTimes") : null, ExpandEVSEIds.Switch( () => new JProperty("EVSEIds", ChargingStation.EVSEIds.SafeAny() ? new JArray(ChargingStation.EVSEIds. OrderBy(evseid => evseid). Select(evseid => evseid.ToString())) : null), () => new JProperty("EVSEs", ChargingStation.EVSEs.SafeAny() ? new JArray(ChargingStation.EVSEs. OrderBy(evse => evse.Id). Select(evse => evse.ToJSON(Embedded: true))) : null)) );
/// <summary> /// Return a JSON representation for the given charging station operator. /// </summary> /// <param name="ChargingStationOperator">A charging station operator.</param> /// <param name="Embedded">Whether this data is embedded into another data structure, e.g. into a roaming network.</param> public static JObject ToJSON(this ChargingStationOperator ChargingStationOperator, Boolean Embedded = false, InfoStatus ExpandRoamingNetworkId = InfoStatus.ShowIdOnly, InfoStatus ExpandChargingPoolIds = InfoStatus.ShowIdOnly, InfoStatus ExpandChargingStationIds = InfoStatus.ShowIdOnly, InfoStatus ExpandEVSEIds = InfoStatus.ShowIdOnly, InfoStatus ExpandBrandIds = InfoStatus.ShowIdOnly, InfoStatus ExpandDataLicenses = InfoStatus.ShowIdOnly) => ChargingStationOperator == null ? null : JSONObject.Create( new JProperty("@id", ChargingStationOperator.Id.ToString()), !Embedded ? new JProperty("@context", "https://open.charging.cloud/contexts/wwcp+json/ChargingStationOperator") : null, new JProperty("name", ChargingStationOperator.Name.ToJSON()), ChargingStationOperator.Description.IsNeitherNullNorEmpty() ? ChargingStationOperator.Description.ToJSON("description") : null, ChargingStationOperator.DataSource.ToJSON("DataSource"), ExpandDataLicenses.Switch( () => new JProperty("dataLicenseIds", new JArray(ChargingStationOperator.DataLicenses.SafeSelect(license => license.Id.ToString()))), () => new JProperty("dataLicenses", ChargingStationOperator.DataLicenses.ToJSON())), #region Embedded means it is served as a substructure of e.g. a charging station operator Embedded ? null : ExpandRoamingNetworkId.Switch( () => new JProperty("roamingNetworkId", ChargingStationOperator.RoamingNetwork.Id.ToString()), () => new JProperty("roamingNetwork", ChargingStationOperator.RoamingNetwork.ToJSON(Embedded: true, ExpandChargingStationOperatorIds: InfoStatus.Hidden, ExpandChargingPoolIds: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden))), #endregion ChargingStationOperator.Address != null ? ChargingStationOperator.Address.ToJSON("address") : null, // API // MainKeys // RobotKeys // Endpoints // DNS SRV ChargingStationOperator.Logo.IsNotNullOrEmpty() ? new JProperty("logos", JSONArray.Create( JSONObject.Create( new JProperty("uri", ChargingStationOperator.Logo), new JProperty("description", I18NString.Empty.ToJSON()) ) )) : null, ChargingStationOperator.Homepage.IsNotNullOrEmpty() ? new JProperty("homepage", ChargingStationOperator.Homepage) : null, ChargingStationOperator.HotlinePhoneNumber.IsNotNullOrEmpty() ? new JProperty("hotline", ChargingStationOperator.HotlinePhoneNumber) : null, ChargingStationOperator.ChargingPools.Any() ? ExpandChargingPoolIds.Switch( () => new JProperty("chargingPoolIds", new JArray(ChargingStationOperator.ChargingPoolIds(). OrderBy(poolId => poolId). Select(poolId => poolId.ToString()))), () => new JProperty("chargingPools", new JArray(ChargingStationOperator.ChargingPools. OrderBy(poolId => poolId). ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingStationOperatorId: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden)))) : null, ChargingStationOperator.ChargingPools.Any() && ExpandChargingPoolIds == InfoStatus.Expand ? null : ExpandChargingStationIds.Switch( () => new JProperty("chargingStationIds", new JArray(ChargingStationOperator.ChargingStationIds(). OrderBy(stationid => stationid). Select(stationid => stationid.ToString()))), () => new JProperty("chargingStations", new JArray(ChargingStationOperator.ChargingStations. OrderBy(station => station). ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingStationOperatorId: InfoStatus.Hidden, ExpandChargingPoolId: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden)))), ChargingStationOperator.ChargingPools.Any() && (ExpandChargingPoolIds == InfoStatus.Expand || ExpandChargingStationIds == InfoStatus.Expand) ? null : ExpandEVSEIds.Switch( () => new JProperty("EVSEIds", new JArray(ChargingStationOperator.EVSEIds(). OrderBy(evseId => evseId). Select(evseId => evseId.ToString()))), () => new JProperty("EVSEs", new JArray(ChargingStationOperator.EVSEs. OrderBy(evse => evse). ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingStationOperatorId: InfoStatus.Hidden, ExpandChargingPoolId: InfoStatus.Hidden, ExpandChargingStationId: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden)))), ChargingStationOperator.Brands.Any() ? ExpandBrandIds.Switch( () => new JProperty("brandIds", new JArray(ChargingStationOperator.BrandIds. OrderBy(brandId => brandId). Select(brandId => brandId.ToString()))), () => new JProperty("brands", new JArray(ChargingStationOperator.Brands. OrderBy(brand => brand). ToJSON(Embedded: true, ExpandChargingPoolIds: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.ShowIdOnly)))) : null );
/// <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)) );
/// <summary> /// Return a JSON representation of the given EVSE. /// </summary> /// <param name="EVSE">An EVSE.</param> /// <param name="Embedded">Whether this data is embedded into another data structure, e.g. into a charging station.</param> public static JObject ToJSON(this EVSE EVSE, Boolean Embedded = false, InfoStatus ExpandRoamingNetworkId = InfoStatus.ShowIdOnly, InfoStatus ExpandChargingStationOperatorId = InfoStatus.ShowIdOnly, InfoStatus ExpandChargingPoolId = InfoStatus.ShowIdOnly, InfoStatus ExpandChargingStationId = InfoStatus.ShowIdOnly, InfoStatus ExpandBrandIds = InfoStatus.ShowIdOnly, InfoStatus ExpandDataLicenses = InfoStatus.ShowIdOnly) => EVSE == null ? null : JSONObject.Create( EVSE.Id.ToJSON("@id"), Embedded ? new JProperty("@context", "https://open.charging.cloud/contexts/wwcp+json/EVSE") : null, EVSE.Description.IsNeitherNullNorEmpty() ? EVSE.Description.ToJSON("description") : null, EVSE.Brand != null ? ExpandBrandIds.Switch( () => new JProperty("brandId", EVSE.Brand.Id.ToString()), () => new JProperty("brand", EVSE.Brand.ToJSON())) : null, (!Embedded || EVSE.DataSource != EVSE.ChargingStation.DataSource) ? EVSE.DataSource.ToJSON("dataSource") : null, (!Embedded || EVSE.DataLicenses != EVSE.ChargingStation.DataLicenses) ? ExpandDataLicenses.Switch( () => new JProperty("dataLicenseIds", new JArray(EVSE.DataLicenses.SafeSelect(license => license.Id.ToString()))), () => new JProperty("dataLicenses", EVSE.DataLicenses.ToJSON())) : null, #region Embedded means it is served as a substructure, e.g. of a charging station Embedded ? null : ExpandRoamingNetworkId.Switch( () => new JProperty("roamingNetworkId", EVSE.RoamingNetwork.Id.ToString()), () => new JProperty("roamingNetwork", EVSE.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", EVSE.Operator.Id.ToString()), () => new JProperty("chargingStationOperator", EVSE.Operator.ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingPoolIds: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden))), Embedded ? null : ExpandChargingPoolId.Switch( () => new JProperty("chargingPoolId", EVSE.ChargingPool.Id.ToString()), () => new JProperty("chargingPool", EVSE.ChargingPool.ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingStationOperatorId: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden))), Embedded ? null : ExpandChargingStationId.Switch( () => new JProperty("chargingStationId", EVSE.ChargingStation.Id.ToString()), () => new JProperty("chargingStation", EVSE.ChargingStation.ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingStationOperatorId: InfoStatus.Hidden, ExpandChargingPoolId: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden))), #endregion !Embedded ? EVSE.ChargingStation.GeoLocation.Value.ToJSON("geoLocation") : null, !Embedded ? EVSE.ChargingStation.Address.ToJSON("address") : null, !Embedded ? EVSE.ChargingStation.AuthenticationModes.ToJSON("authenticationModes") : null, EVSE.ChargingModes.HasValue && EVSE.ChargingModes.Value != ChargingModes.Unspecified ? new JProperty("chargingModes", new JArray(EVSE.ChargingModes.Value.ToText())) : null, EVSE.CurrentTypes.HasValue && EVSE.CurrentTypes.Value != CurrentTypes.Unspecified ? new JProperty("currentTypes", new JArray(EVSE.CurrentTypes.Value.ToText())) : null, EVSE.AverageVoltage.HasValue && EVSE.AverageVoltage > 0 ? new JProperty("averageVoltage", String.Format("{0:0.00}", EVSE.AverageVoltage)) : null, EVSE.MaxCurrent.HasValue && EVSE.MaxCurrent > 0 ? new JProperty("maxCurrent", String.Format("{0:0.00}", EVSE.MaxCurrent)) : null, EVSE.MaxPower.HasValue && EVSE.MaxPower.HasValue ? new JProperty("maxPower", String.Format("{0:0.00}", EVSE.MaxPower)) : null, EVSE.MaxCapacity.HasValue && EVSE.MaxCapacity.HasValue ? new JProperty("maxCapacity", String.Format("{0:0.00}", EVSE.MaxCapacity)) : null, EVSE.SocketOutlets.Count > 0 ? new JProperty("socketOutlets", new JArray(EVSE.SocketOutlets.ToJSON())) : null, EVSE.EnergyMeterId.HasValue ? new JProperty("energyMeterId", EVSE.EnergyMeterId) : null, !Embedded ? EVSE.ChargingStation.OpeningTimes.ToJSON("openingTimes") : null );
public static JObject ToFeature(this EVSE EVSE, InfoStatus ExpandRoamingNetworkId = InfoStatus.ShowIdOnly, InfoStatus ExpandOperatorId = InfoStatus.ShowIdOnly, InfoStatus ExpandChargingPoolId = InfoStatus.ShowIdOnly, InfoStatus ExpandChargingStationId = InfoStatus.ShowIdOnly, InfoStatus ExpandBrandIds = InfoStatus.ShowIdOnly, InfoStatus ExpandDataLicenses = InfoStatus.ShowIdOnly, JObject Properties = null) { #region Initial checks if (EVSE == null) { throw new ArgumentNullException(nameof(EVSE), "The given EVSE must not be null!"); } #endregion #region Documentation // { // // [...] // // { // "type": "Feature", // "properties": {}, // "geometry": { // "type": "Point", // "coordinates": [ // 10.579833984375, // 50.48197825997291 // ] // } // } // // } #endregion return(JSONObject.Create( new JProperty("type", "Feature"), new JProperty("properties", Properties ?? JSONObject.Create( new JProperty("@id", EVSE.Id.ToString()), new JProperty("@context", "https://open.charging.cloud/contexts/wwcp+geojson/EVSE"), EVSE.Description.IsNeitherNullNorEmpty() ? EVSE.Description.ToJSON("description") : null, EVSE.Brand != null ? ExpandBrandIds.Switch( () => new JProperty("brandId", EVSE.Brand.Id.ToString()), () => new JProperty("brand", EVSE.Brand.ToJSON())) : null, EVSE.DataSource.ToJSON("dataSource"), ExpandDataLicenses.Switch( () => new JProperty("dataLicenseIds", new JArray(EVSE.DataLicenses.SafeSelect(license => license.Id.ToString()))), () => new JProperty("dataLicenses", EVSE.DataLicenses.ToJSON())), ExpandRoamingNetworkId.Switch( () => new JProperty("roamingNetworkId", EVSE.RoamingNetwork.Id.ToString()), () => new JProperty("roamingNetwork", EVSE.RoamingNetwork.ToJSON(ExpandChargingStationOperatorIds: InfoStatus.Hidden, ExpandChargingPoolIds: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden))), ExpandOperatorId.Switch( () => new JProperty("chargingStationOperatorId", EVSE.Operator.Id.ToString()), () => new JProperty("chargingStationOperator", EVSE.Operator.ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingPoolIds: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden))), ExpandChargingPoolId.Switch( () => new JProperty("chargingPoolId", EVSE.ChargingPool.Id.ToString()), () => new JProperty("chargingPool", EVSE.ChargingPool.ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingStationOperatorId: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden))), ExpandChargingStationId.Switch( () => new JProperty("chargingStationId", EVSE.ChargingStation.Id.ToString()), () => new JProperty("chargingStation", EVSE.ChargingStation.ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingStationOperatorId: InfoStatus.Hidden, ExpandChargingPoolId: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden))), EVSE.ChargingStation.GeoLocation.Value.ToJSON("geoLocation"), EVSE.ChargingStation.Address.ToJSON("address"), EVSE.ChargingStation.AuthenticationModes.ToJSON("authenticationModes"), EVSE.ChargingModes != ChargingModes.Unspecified ? new JProperty("chargingModes", new JArray(EVSE.ChargingModes.Value.ToText())) : null, EVSE.CurrentTypes != CurrentTypes.Unspecified ? new JProperty("currentTypes", new JArray(EVSE.CurrentTypes.Value.ToText())) : null, EVSE.AverageVoltage.HasValue && EVSE.AverageVoltage > 0 ? new JProperty("averageVoltage", String.Format("{0:0.00}", EVSE.AverageVoltage)) : null, EVSE.MaxCurrent.HasValue && EVSE.MaxCurrent > 0 ? new JProperty("maxCurrent", String.Format("{0:0.00}", EVSE.MaxCurrent)) : null, EVSE.MaxPower.HasValue && EVSE.MaxPower.HasValue ? new JProperty("maxPower", String.Format("{0:0.00}", EVSE.MaxPower)) : null, EVSE.MaxCapacity.HasValue && EVSE.MaxCapacity.HasValue ? new JProperty("maxCapacity", String.Format("{0:0.00}", EVSE.MaxCapacity)) : null, EVSE.SocketOutlets.Count > 0 ? new JProperty("socketOutlets", new JArray(EVSE.SocketOutlets.ToJSON())) : null, EVSE.EnergyMeterId.HasValue ? new JProperty("energyMeterId", EVSE.EnergyMeterId) : null, EVSE.ChargingStation.OpeningTimes.ToJSON("openingTimes") )), new JProperty("geometry", JSONObject.Create( new JProperty("type", "Point"), new JProperty("coordinates", new JArray( EVSE.ChargingStation.GeoLocation.Value.Longitude.Value, EVSE.ChargingStation.GeoLocation.Value.Latitude.Value )) )) )); }
/// <summary> /// Return a JSON representation of the given roaming network. /// </summary> /// <param name="RoamingNetwork">A roaming network.</param> /// <param name="Embedded">Whether this data is embedded into another data structure.</param> public static JObject ToJSON(this IRoamingNetwork RoamingNetwork, Boolean Embedded = false, InfoStatus ExpandChargingStationOperatorIds = InfoStatus.ShowIdOnly, InfoStatus ExpandChargingPoolIds = InfoStatus.ShowIdOnly, InfoStatus ExpandChargingStationIds = InfoStatus.ShowIdOnly, InfoStatus ExpandEVSEIds = InfoStatus.ShowIdOnly, InfoStatus ExpandBrandIds = InfoStatus.ShowIdOnly, InfoStatus ExpandDataLicenses = InfoStatus.ShowIdOnly, InfoStatus ExpandEMobilityProviderId = InfoStatus.ShowIdOnly) => RoamingNetwork == null ? null : JSONObject.Create( new JProperty("@id", RoamingNetwork.Id.ToString()), Embedded ? null : new JProperty("@context", "https://open.charging.cloud/contexts/wwcp+json/RoamingNetwork"), new JProperty("name", RoamingNetwork.Name.ToJSON()), RoamingNetwork.Description.IsNeitherNullNorEmpty() ? RoamingNetwork.Description.ToJSON("description") : null, RoamingNetwork.DataSource.IsNeitherNullNorEmpty() ? RoamingNetwork.DataSource.ToJSON("dataSource") : null, RoamingNetwork.DataLicenses.Any() ? ExpandDataLicenses.Switch( () => new JProperty("dataLicenseIds", new JArray(RoamingNetwork.DataLicenses.SafeSelect(license => license.Id.ToString()))), () => new JProperty("dataLicenses", RoamingNetwork.DataLicenses.ToJSON())) : null, RoamingNetwork.ChargingStationOperators.Any() ? ExpandChargingStationOperatorIds.Switch( () => new JProperty("chargingStationOperatorIds", new JArray(RoamingNetwork.ChargingStationOperatorIds. OrderBy(id => id). Select(id => id.ToString()))), () => new JProperty("chargingStationOperators", new JArray(RoamingNetwork.ChargingStationOperators. OrderBy(cso => cso). ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingPoolIds: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden)))) : null, !RoamingNetwork.ChargingStationOperators.Any() || ExpandChargingStationOperatorIds == InfoStatus.Expand ? null : ExpandChargingPoolIds.Switch( () => new JProperty("chargingPoolIds", new JArray(RoamingNetwork.ChargingPoolIds(). OrderBy(id => id). Select(id => id.ToString()))), () => new JProperty("chargingPools", new JArray(RoamingNetwork.ChargingPools. OrderBy(pool => pool). ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingStationOperatorId: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden)))), !RoamingNetwork.ChargingStationOperators.Any() || (ExpandChargingPoolIds == InfoStatus.Expand || ExpandChargingStationOperatorIds == InfoStatus.Expand) ? null : ExpandChargingStationIds.Switch( () => new JProperty("chargingStationIds", new JArray(RoamingNetwork.ChargingStationIds(). OrderBy(id => id). Select(id => id.ToString()))), () => new JProperty("chargingStations", new JArray(RoamingNetwork.ChargingStations. OrderBy(station => station). ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingStationOperatorId: InfoStatus.Hidden, ExpandChargingPoolId: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden)))), !RoamingNetwork.ChargingStationOperators.Any() || (ExpandChargingStationIds == InfoStatus.Expand || ExpandChargingPoolIds == InfoStatus.Expand || ExpandChargingStationOperatorIds == InfoStatus.Expand) ? null : ExpandEVSEIds.Switch( () => new JProperty("EVSEIds", new JArray(RoamingNetwork.EVSEIds(). OrderBy(id => id). Select(id => id.ToString()))), () => new JProperty("EVSEs", new JArray(RoamingNetwork.EVSEs. OrderBy(evse => evse). ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandChargingStationOperatorId: InfoStatus.Hidden, ExpandChargingPoolId: InfoStatus.Hidden, ExpandChargingStationId: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden)))), RoamingNetwork.eMobilityProviders.Any() ? ExpandEMobilityProviderId.Switch( () => new JProperty("eMobilityProviderIds", new JArray(RoamingNetwork.ChargingStationOperatorIds. OrderBy(id => id). Select(id => id.ToString()))), () => new JProperty("eMobilityProviders", new JArray(RoamingNetwork.eMobilityProviders. OrderBy(emp => emp). ToJSON(Embedded: true, ExpandRoamingNetworkId: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden)))) : null );
/// <summary> /// Return a JSON representation for the given e-mobility provider. /// </summary> /// <param name="eMobilityProvider">An e-mobility provider.</param> /// <param name="Embedded">Whether this data is embedded into another data structure, e.g. into a roaming network.</param> public static JObject ToJSON(this eMobilityProvider eMobilityProvider, Boolean Embedded = false, InfoStatus ExpandRoamingNetworkId = InfoStatus.ShowIdOnly, InfoStatus ExpandBrandIds = InfoStatus.ShowIdOnly, InfoStatus ExpandDataLicenses = InfoStatus.ShowIdOnly) => eMobilityProvider == null ? null : JSONObject.Create( new JProperty("@id", eMobilityProvider.Id.ToString()), Embedded ? new JProperty("@context", "https://open.charging.cloud/contexts/wwcp+json/eMobilityProvider") : null, new JProperty("name", eMobilityProvider.Name.ToJSON()), eMobilityProvider.Description.IsNeitherNullNorEmpty() ? eMobilityProvider.Description.ToJSON("description") : null, eMobilityProvider.DataSource.ToJSON("DataSource"), ExpandDataLicenses.Switch( () => new JProperty("dataLicenseIds", new JArray(eMobilityProvider.DataLicenses.SafeSelect(license => license.Id.ToString()))), () => new JProperty("dataLicenses", eMobilityProvider.DataLicenses.ToJSON())), #region Embedded means it is served as a substructure of e.g. a charging station operator Embedded ? null : ExpandRoamingNetworkId.Switch( () => new JProperty("roamingNetworkId", eMobilityProvider.RoamingNetwork.Id.ToString()), () => new JProperty("roamingNetwork", eMobilityProvider.RoamingNetwork.ToJSON(Embedded: true, ExpandEMobilityProviderId: InfoStatus.Hidden, ExpandChargingPoolIds: InfoStatus.Hidden, ExpandChargingStationIds: InfoStatus.Hidden, ExpandEVSEIds: InfoStatus.Hidden, ExpandBrandIds: InfoStatus.Hidden, ExpandDataLicenses: InfoStatus.Hidden))), #endregion eMobilityProvider.Address != null ? eMobilityProvider.Address.ToJSON("address") : null, // LogoURI // API // MainKeys // RobotKeys // Endpoints // DNS SRV eMobilityProvider.Logo.IsNotNullOrEmpty() ? new JProperty("logos", JSONArray.Create( JSONObject.Create( new JProperty("uri", eMobilityProvider.Logo), new JProperty("description", I18NString.Empty.ToJSON()) ) )) : null, eMobilityProvider.Homepage.IsNotNullOrEmpty() ? new JProperty("homepage", eMobilityProvider.Homepage) : null, eMobilityProvider.HotlinePhoneNumber.IsNotNullOrEmpty() ? new JProperty("hotline", eMobilityProvider.HotlinePhoneNumber) : null, eMobilityProvider.DataLicenses.Any() ? new JProperty("dataLicenses", new JArray(eMobilityProvider.DataLicenses.Select(license => license.ToJSON()))) : null );