public static JArray ToJSON(this IEnumerable <OrganizationInfo2> OrganizationInfos) { if (OrganizationInfos?.Any() == false) { return(new JArray()); } return(JSONArray.Create(OrganizationInfos.Select(orgInfo => orgInfo.ToJSON()))); }
/// <summary> /// Return a JSON representation of this object. /// </summary> public JObject ToJSON() => JSONObject.Create( new JProperty("operatorId", OperatorId.ToString()), new JProperty("operatorName", OperatorName), new JProperty("chargingPools", JSONArray.Create( ChargingPools.Select(chargingPool => chargingPool.ToJSON())) ) );
public static JArray ToJSON(this IEnumerable <OrganizationInfo> OrganizationInfos) { if (OrganizationInfos?.Any() == false) { return(new JArray()); } return(JSONArray.Create(OrganizationInfos.Select(orgInfo => orgInfo.ToJSON(ExpandMembers: InfoStatus.Expanded)))); }
public JObject ToJSON() => JSONObject.Create( new JProperty("stationId", StationId.ToString()), new JProperty("address", Address.ToJSON()), new JProperty("geoCoordinates", GeoCoordinates.Value.ToJSON()), new JProperty("evses", JSONArray.Create( EVSEDataRecords.Select(evseDataRecord => evseDataRecord.ToJSON())) ) );
/// <summary> /// Return a JSON representation of this object. /// </summary> public JObject ToJSON() => JSONObject.Create( new JProperty("poolId", PoolId.ToString()), Address != null ? new JProperty("address", Address.ToJSON()) : null, GeoCoordinates.HasValue ? new JProperty("geoCoordinates", GeoCoordinates.Value.ToJSON()) : null, ChargingStations.SafeAny() ? new JProperty("chargingStations", JSONArray.Create(ChargingStations.Select(chargingStation => chargingStation.ToJSON()))) : 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 );
public static JObject ToJSON(this ParkingOperator ParkingOperator, Boolean Embedded = false, Boolean ExpandChargingRoamingNetworkId = false, Boolean ExpandChargingPoolIds = false, Boolean ExpandChargingStationIds = false, Boolean ExpandEVSEIds = false) => ParkingOperator != null ? JSONObject.Create( new JProperty("id", ParkingOperator.Id.ToString()), Embedded ?null : ExpandChargingRoamingNetworkId ?new JProperty("roamingNetwork", ParkingOperator.RoamingNetwork.ToJSON()) : new JProperty("roamingNetworkId", ParkingOperator.RoamingNetwork.Id.ToString()), new JProperty("name", ParkingOperator.Name.ToJSON()), new JProperty("description", ParkingOperator.Description.ToJSON()), // Address // LogoURI // API - RobotKeys, Endpoints, DNS SRV // MainKeys ParkingOperator.Logo.IsNotNullOrEmpty() ?new JProperty("logos", JSONArray.Create( JSONObject.Create( new JProperty("uri", ParkingOperator.Logo), new JProperty("description", I18NString.Empty.ToJSON()) ) )) : null, ParkingOperator.Homepage.IsNotNullOrEmpty() ?new JProperty("homepage", ParkingOperator.Homepage) : null, ParkingOperator.HotlinePhoneNumber.IsNotNullOrEmpty() ?new JProperty("hotline", ParkingOperator.HotlinePhoneNumber) : null, ParkingOperator.DataLicenses.Any() ?new JProperty("dataLicenses", new JArray(ParkingOperator.DataLicenses.Select(license => license.ToJSON()))) : null //new JProperty("chargingPools", ExpandChargingPoolIds // ? new JArray(ParkingOperator.ChargingPools. ToJSON(Embedded: true)) // : new JArray(ParkingOperator.ChargingPoolIds. Select(id => id.ToString()))), //new JProperty("chargingStations", ExpandChargingStationIds // ? new JArray(ParkingOperator.ChargingStations. ToJSON(Embedded: true)) // : new JArray(ParkingOperator.ChargingStationIds.Select(id => id.ToString()))), //new JProperty("evses", ExpandEVSEIds // ? new JArray(ParkingOperator.EVSEs. ToJSON(Embedded: true)) // : new JArray(ParkingOperator.EVSEIds. Select(id => id.ToString()))) ) : null;
private void RegisterURITemplates() { #region GET / // ----------------------------------------------------------------------- // curl -v -X GET -H "Accept: application/json" \ // http://127.0.0.1:3004/tracker HTTPServer.AddMethodCallback(HTTPHostname.Any, HTTPMethod.GET, URIPrefix, HTTPContentType.JSON_UTF8, HTTPDelegate: Request => { var Now = DateTime.UtcNow; var JSON = _LocalRoamingNetworks. Select(kvp => { var LocalRoamingNetwork = kvp.Value.First(rni => rni != null)?.RoamingNetwork; return(JSONObject.Create(new JProperty("id", kvp.Key.ToString()), LocalRoamingNetwork != null ? new JProperty("description", LocalRoamingNetwork?.Description?.ToJSON()) : null, new JProperty("rendezvousPoints", JSONArray.Create( kvp.Value. Select(rni => JSONObject.Create( new JProperty("priority", rni.priority), new JProperty("weight", rni.weight), new JProperty("hostname", rni.hostname), new JProperty("port", rni.port.ToString()), new JProperty("transport", rni.transport.ToString()), new JProperty("uriPrefix", rni.uriPrefix), new JProperty("contentType", rni.contentType.ToString()), new JProperty("protocol", rni.protocolType.ToString()), new JProperty("expiresAfter", rni.ExpiredAfter.ToIso8601()), new JProperty("publicKeys", new JArray()), new JProperty("signature", "...") )))), LocalRoamingNetwork != null ? new JProperty("statistics", JSONObject.Create( new JProperty("EVSEOperators", LocalRoamingNetwork?.ChargingStationOperators.Count()), new JProperty("EVServiceProviders", LocalRoamingNetwork?.eMobilityProviders.Count()), new JProperty("EMPRoamingProviders", LocalRoamingNetwork?.EMPRoamingProviders.Count()), new JProperty("EVSEOperatorRoamingProviders", LocalRoamingNetwork?.ChargingStationOperatorRoamingProviders.Count()), new JProperty("chargingPools", LocalRoamingNetwork?.ChargingPools.Count()), new JProperty("chargingStations", LocalRoamingNetwork?.ChargingStations.Count()), new JProperty("EVSEs", LocalRoamingNetwork?.EVSEs.Count()) )) : null )); }); return(Task.FromResult <HTTPResponse>( new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.OK, Server = HTTPServer.DefaultServerName, Date = DateTime.Now, ContentType = HTTPContentType.JSON_UTF8, Content = JSONObject.Create( new JProperty("id", Id.ToString()), new JProperty("description", Description.ToJSON()), new JProperty("timestamp", Now.ToIso8601()), new JProperty("roamingNetworks", new JArray(JSON)), new JProperty("publicKeys", new JArray()), new JProperty("signature", "...") ).ToUTF8Bytes(), Connection = "close" })); }); #endregion #region ANNOUNCE / // ----------------------------------------------------------------------- // curl -v -X NOTIFY -H "Content-Type: application/json" \ // -H "Accept: application/json" \ // -d "{ \"StatusList\": { \ // \"2014-10-13T22:14:01.862Z\": \"OutOfService\", \ // \"2014-10-13T21:32:15.386Z\": \"Charging\" \ // }" \ // http://127.0.0.1:3004/ext/BoschEBike/EVSEs/49*822*483*1/NotClosed HTTPServer.AddMethodCallback(HTTPHostname.Any, HTTPMethod.ANNOUNCE, URIPrefix, HTTPContentType.JSON_UTF8, HTTPDelegate: Request => { //SendEVSEDoorNotClosedNotifyLog(Request); #region Check HTTP Basic Authentication if (Request.Authorization == null || !_Logins.ContainsKey(Request.Authorization.Username) || _Logins[Request.Authorization.Username] != Request.Authorization.Password) { return(Task.FromResult <HTTPResponse>( //SendEVSEDoorNotClosedNotifiedLog( new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.Unauthorized, WWWAuthenticate = @"Basic realm=""WWCP tracker""", Server = HTTPServer.DefaultServerName, Date = DateTime.Now, Connection = "close" })); } #endregion //#region Check EVSEId parameter //HTTPResponse _HTTPResponse; //EVSE_Id EVSEId; //if (!Request.ParseEVSEId(HTTPServer.DefaultServerName, // out EVSEId, // out _HTTPResponse)) // return SendEVSEDoorNotClosedNotifiedLog(_HTTPResponse); //#endregion //#region Parse JSON //JSONWrapper JSON = null; //Object JSONToken = null; //if (!Request.TryParseJObjectRequestBody(out JSON, out _HTTPResponse)) // return SendEVSEDoorNotClosedNotifiedLog(_HTTPResponse); //// { //// "context" : "NO CONTEXT", //// "EventId" : "bd27b678-b3af-42b1-8dff-0af1cf3564ed", //// "Timestamp" : "2016-02-14T10:17:13GMT", //// "Event" : { //// "code" : 600, //// "eventName" : "EVSE Not Closed" //// }, //// "EVSEId" : "49*822*483*1" //// } //#region Parse EventId [mandatory] //String EventId = null; //if (!JSON.ParseMandatory("EventId", // "Unique event identification", // HTTPServer.DefaultServerName, // out EventId, // Request, // out _HTTPResponse)) // return SendEVSEDoorNotClosedNotifiedLog(_HTTPResponse); //#endregion //#region Parse Timestamp [mandatory] //DateTime EventTimestamp; //if (!JSON.ParseMandatory(Enumeration.Create("Timestamp", "TimeStamp"), // "The time stamp of the event", // HTTPServer.DefaultServerName, // out EventTimestamp, // Request, // out _HTTPResponse)) // return SendEVSEDoorNotClosedNotifiedLog(_HTTPResponse); //#endregion //#endregion //var Task = SendEVSEDoorNotClosedNotification(Request.Timestamp, // Request.CancellationToken, // Request.EventTrackingId, // MapIncomingEVSEIds != null ? MapIncomingEVSEIds(EVSEId) : EVSEId, // EventId, // EventTimestamp); //Task.Wait(TimeSpan.FromSeconds(60)); return(Task.FromResult <HTTPResponse>( // SendEVSEDoorNotClosedNotifiedLog( new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.OK, Server = HTTPServer.DefaultServerName, Date = DateTime.Now, Connection = "close" })); }); #endregion }
/// <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 );