public void Init() { #region CREATE /RNs/TestRN1 var URI = HTTPPath.Parse("/RNs/TestRN1"); using (var HTTPTask = _HTTPClient.Execute(client => client.CREATE(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.Created, HTTPResult.HTTPStatusCode, "'CREATE " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JObject( new JProperty("RoamingNetworkId", "TestRN1"), new JProperty("description", new JObject()) ).ToString(), JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'CREATE " + URI + "'!"); } } #endregion }
public void Cleanup() { var URI = HTTPPath.Parse("/RNs"); String[] RoamingNetworkIds = null; using (var HTTPTask = _HTTPClient.Execute(client => client.GET(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode); RoamingNetworkIds = JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()). AsEnumerable(). Select(v => (v as JObject)["RoamingNetworkId"].Value <String>()). ToArray(); } } foreach (var RoamingNetworkId in RoamingNetworkIds) { URI = HTTPPath.Parse("/RNs/" + RoamingNetworkId); using (var HTTPTask = _HTTPClient.Execute(client => client.DELETE(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode); } } } if (RemoteAddress == IPv4Address.Localhost) { HTTPAPI.Shutdown(); } }
public void CREATE() { #region Verify GET /RNs/TestRN1/SmartCities var URI = HTTPPath.Parse("/RNs/TestRN1/SmartCities"); using (var HTTPTask = _HTTPClient.Execute(client => client.GET(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JArray().ToString(), JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'GET " + URI + "'!"); } } #endregion #region Verify COUNT /RNs/TestRN1/SmartCities using (var HTTPTask = _HTTPClient.Execute(client => client.COUNT(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JObject(new JProperty("count", 0)).ToString(), JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'COUNT " + URI + "'!"); } } #endregion //#region CREATE /RNs/TestRN1 //URI = "/RNs/TestRN1"; //using (var HTTPTask = _HTTPClient.Execute(client => client.CREATE(URI, // requestbuilder => { // requestbuilder.Host = "localhost"; // requestbuilder.ContentType = HTTPContentType.JSON_UTF8; // requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); // }), // RequestTimeout: Timeout, // CancellationToken: new CancellationTokenSource().Token)) //{ // HTTPTask.Wait(Timeout); // using (var HTTPResult = HTTPTask.Result) // { // Assert.AreEqual(HTTPStatusCode.Created, HTTPResult.HTTPStatusCode, "'CREATE " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); // Assert.AreEqual(new JObject( // new JProperty("RoamingNetworkId", "TestRN1"), // new JProperty("description", new JObject()) // ).ToString(), // JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), // "Invalid response for 'CREATE " + URI + "'!"); // } //} //if (RemoteAddress == IPv4Address.Localhost) //{ // Assert.IsTrue(WWCPAPI.RoamingNetworkExists(HTTPHostname.Localhost, RoamingNetwork_Id.Parse("TestRN1")), "Roaming network 'TestRN1' was not found via .NET API!"); // var _TestRN1 = WWCPAPI.GetRoamingNetwork(HTTPHostname.Localhost, RoamingNetwork_Id.Parse("TestRN1")); // Assert.IsNotNull(_TestRN1, "Roaming network 'TestRN1' was not returned via .NET API!"); // Assert.IsFalse (_TestRN1.Description.Any(), "The description of roaming network 'TestRN1' must be empty!"); //} //#endregion //#region Verify GET /RNs //URI = "/RNs"; //using (var HTTPTask = _HTTPClient.Execute(client => client.GET(URI, // requestbuilder => { // requestbuilder.Host = "localhost"; // requestbuilder.ContentType = HTTPContentType.JSON_UTF8; // requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); // }), // RequestTimeout: Timeout, // CancellationToken: new CancellationTokenSource().Token)) //{ // HTTPTask.Wait(Timeout); // using (var HTTPResult = HTTPTask.Result) // { // Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); // Assert.AreEqual(new JArray( // new JObject( // new JProperty("RoamingNetworkId", "TestRN1"), // new JProperty("description", new JObject()) // ) // ).ToString(), // JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), // "Invalid response for 'GET " + URI + "'!"); // } //} //#endregion //#region Verify COUNT /RNs //using (var HTTPTask = _HTTPClient.Execute(client => client.COUNT(URI, // requestbuilder => { // requestbuilder.Host = "localhost"; // requestbuilder.ContentType = HTTPContentType.JSON_UTF8; // requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); // }), // RequestTimeout: Timeout, // CancellationToken: new CancellationTokenSource().Token)) //{ // HTTPTask.Wait(Timeout); // using (var HTTPResult = HTTPTask.Result) // { // Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); // Assert.AreEqual(new JObject(new JProperty("count", 1)).ToString(), // JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), // "Invalid response for 'COUNT " + URI + "'!"); // } //} //#endregion //#region CREATE /RNs/TestRN3 //URI = "/RNs/TestRN3"; //using (var HTTPTask = _HTTPClient.Execute(client => client.CREATE(URI, // requestbuilder => { // requestbuilder.Host = "localhost"; // requestbuilder.ContentType = HTTPContentType.JSON_UTF8; // requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); // requestbuilder.Content = JSONObject.Create( // new JProperty("description", JSONObject.Create( // new JProperty("en", "This is a roaming network!") // )) // ).ToUTF8Bytes(); // }), // RequestTimeout: Timeout, // CancellationToken: new CancellationTokenSource().Token)) //{ // HTTPTask.Wait(Timeout); // using (var HTTPResult = HTTPTask.Result) // { // Assert.AreEqual(HTTPStatusCode.Created, HTTPResult.HTTPStatusCode, "'CREATE " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); // Assert.AreEqual(new JObject( // new JProperty("RoamingNetworkId", "TestRN3"), // new JProperty("description", new JObject( // new JProperty("en", "This is a roaming network!") // )) // ).ToString(), // JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), // "Invalid response for 'CREATE " + URI + "'!"); // } //} //if (RemoteAddress == IPv4Address.Localhost) //{ // Assert.IsTrue(WWCPAPI.RoamingNetworkExists(HTTPHostname.Localhost, RoamingNetwork_Id.Parse("TestRN3")), "Roaming network 'TestRN3' was not found via .NET API!"); // var _TestRN3 = WWCPAPI.GetRoamingNetwork(HTTPHostname.Localhost, RoamingNetwork_Id.Parse("TestRN3")); // Assert.IsNotNull(_TestRN3, "Roaming network 'TestRN3' was not returned via .NET API!"); // Assert.IsTrue (_TestRN3.Description.Any(), "The description of roaming network 'TestRN3' must not be empty!"); // Assert.AreEqual (_TestRN3.Description.Count(), 1); // Assert.AreEqual (_TestRN3.Description[Languages.en], "This is a roaming network!"); //} //#endregion //#region CREATE /RNs/TestRN2 //URI = "/RNs/TestRN2"; //using (var HTTPTask = _HTTPClient.Execute(client => client.CREATE(URI, // requestbuilder => { // requestbuilder.Host = "localhost"; // requestbuilder.ContentType = HTTPContentType.JSON_UTF8; // requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); // requestbuilder.Content = JSONObject.Create( // new JProperty("description", JSONObject.Create( // new JProperty("de", "Auch ein schönes Roaming Netzwerk!"), // new JProperty("en", "This is another roaming network!") // )) // ).ToUTF8Bytes(); // }), // RequestTimeout: Timeout, // CancellationToken: new CancellationTokenSource().Token)) //{ // HTTPTask.Wait(Timeout); // using (var HTTPResult = HTTPTask.Result) // { // Assert.AreEqual(HTTPStatusCode.Created, HTTPResult.HTTPStatusCode, "'CREATE " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); // Assert.AreEqual(new JObject( // new JProperty("RoamingNetworkId", "TestRN2"), // new JProperty("description", new JObject( // new JProperty("de", "Auch ein schönes Roaming Netzwerk!"), // new JProperty("en", "This is another roaming network!") // )) // ).ToString(), // JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), // "Invalid response for 'CREATE " + URI + "'!"); // } //} //if (RemoteAddress == IPv4Address.Localhost) //{ // Assert.IsTrue(WWCPAPI.RoamingNetworkExists(HTTPHostname.Localhost, RoamingNetwork_Id.Parse("TestRN2")), "Roaming network 'TestRN2' was not found via .NET API!"); // var _TestRN2 = WWCPAPI.GetRoamingNetwork(HTTPHostname.Localhost, RoamingNetwork_Id.Parse("TestRN2")); // Assert.IsNotNull(_TestRN2, "Roaming network 'TestRN2' was not returned via .NET API!"); // Assert.IsTrue (_TestRN2.Description.Any(), "The description of roaming network 'TestRN2' must not be empty!"); // Assert.AreEqual (_TestRN2.Description.Count(), 2); // Assert.AreEqual (_TestRN2.Description[Languages.de], "Auch ein schönes Roaming Netzwerk!"); // Assert.AreEqual (_TestRN2.Description[Languages.en], "This is another roaming network!"); //} //#endregion //#region Verify GET /RNs //URI = "/RNs"; //using (var HTTPTask = _HTTPClient.Execute(client => client.GET(URI, // requestbuilder => { // requestbuilder.Host = "localhost"; // requestbuilder.ContentType = HTTPContentType.JSON_UTF8; // requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); // }), // RequestTimeout: Timeout, // CancellationToken: new CancellationTokenSource().Token)) //{ // HTTPTask.Wait(Timeout); // using (var HTTPResult = HTTPTask.Result) // { // Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); // Assert.AreEqual(new JArray( // new JObject( // new JProperty("RoamingNetworkId", "TestRN1"), // new JProperty("description", new JObject()) // ), // new JObject( // new JProperty("RoamingNetworkId", "TestRN2"), // new JProperty("description", JSONObject.Create( // new JProperty("de", "Auch ein schönes Roaming Netzwerk!"), // new JProperty("en", "This is another roaming network!") // )) // ), // new JObject( // new JProperty("RoamingNetworkId", "TestRN3"), // new JProperty("description", JSONObject.Create( // new JProperty("en", "This is a roaming network!")) // ) // ) // ).ToString(), // JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), // "Invalid response for 'GET " + URI + "'!"); // } //} //#endregion //#region Verify COUNT /RNs //using (var HTTPTask = _HTTPClient.Execute(client => client.COUNT(URI, // requestbuilder => { // requestbuilder.Host = "localhost"; // requestbuilder.ContentType = HTTPContentType.JSON_UTF8; // requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); // }), // RequestTimeout: Timeout, // CancellationToken: new CancellationTokenSource().Token)) //{ // HTTPTask.Wait(Timeout); // using (var HTTPResult = HTTPTask.Result) // { // Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); // Assert.AreEqual(new JObject(new JProperty("count", 3)).ToString(), // JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), // "Invalid response for 'COUNT " + URI + "'!"); // } //} //#endregion }
/// <summary> /// Attach JSON I/O to the given WWCP HTTP API. /// </summary> /// <param name="WWCPAPI">A WWCP HTTP API.</param> /// <param name="Hostname">Limit this JSON I/O handling to the given HTTP hostname.</param> /// <param name="URIPrefix">A common URI prefix for all URIs within this API.</param> public static void Attach_JSON_IO_eMobilityProviders(this WWCP_HTTPAPI WWCPAPI, HTTPHostname?Hostname = null, HTTPPath?URIPrefix = null) { var _Hostname = Hostname ?? HTTPHostname.Any; var _URIPrefix = URIPrefix ?? HTTPPath.Parse("/"); #region ~/RNs/{RoamingNetworkId}/eMobilityProviders #region GET ~/RNs/{RoamingNetworkId}/eMobilityProviders // ----------------------------------------------------------------------------------------- // curl -v -H "Accept: application/json" http://127.0.0.1:3004/RNs/Test/eMobilityProviders // ----------------------------------------------------------------------------------------- WWCPAPI.HTTPServer.AddMethodCallback(_Hostname, HTTPMethod.GET, _URIPrefix + "RNs/{RoamingNetworkId}/eMobilityProviders", HTTPContentType.JSON_UTF8, HTTPDelegate: Request => { #region Check parameters HTTPResponse _HTTPResponse; RoamingNetwork _RoamingNetwork; if (!Request.ParseRoamingNetwork(WWCPAPI, out _RoamingNetwork, out _HTTPResponse)) { return(Task.FromResult(_HTTPResponse)); } #endregion var skip = Request.QueryString.GetUInt64("skip"); var take = Request.QueryString.GetUInt64("take"); var expand = Request.QueryString.GetStrings("expand", true); //var expandChargingPools = !expand.Contains("-chargingpools"); //var expandChargingStations = !expand.Contains("-chargingstations"); //var expandBrands = expand.Contains("brands"); //ToDo: Getting the expected total count might be very expensive! var _ExpectedCount = _RoamingNetwork.eMobilityProviders.ULongCount(); return(Task.FromResult( new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.OK, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET, COUNT, STATUS", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ETag = "1", ContentType = HTTPContentType.JSON_UTF8, Content = _RoamingNetwork.eMobilityProviders. ToJSON(skip, take, false). //expandChargingPools, //expandChargingStations, //expandBrands). ToUTF8Bytes(), X_ExpectedTotalNumberOfItems = _ExpectedCount }.AsImmutable)); }); #endregion #region COUNT ~/RNs/{RoamingNetworkId}/eMobilityProviders // ---------------------------------------------------------------------------------------------------------------- // curl -v -X COUNT -H "Accept: application/json" http://127.0.0.1:3004/RNs/{RoamingNetworkId}/eMobilityProviders // ---------------------------------------------------------------------------------------------------------------- WWCPAPI.HTTPServer.AddMethodCallback(_Hostname, HTTPMethod.COUNT, _URIPrefix + "RNs/{RoamingNetworkId}/eMobilityProviders", HTTPContentType.JSON_UTF8, HTTPDelegate: Request => { #region Check parameters HTTPResponse _HTTPResponse; RoamingNetwork _RoamingNetwork; if (!Request.ParseRoamingNetwork(WWCPAPI, out _RoamingNetwork, out _HTTPResponse)) { return(Task.FromResult(_HTTPResponse)); } #endregion return(Task.FromResult( new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.OK, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET, COUNT, STATUS", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ETag = "1", ContentType = HTTPContentType.JSON_UTF8, Content = JSONObject.Create( new JProperty("count", _RoamingNetwork.ChargingStationOperators.ULongCount()) ).ToUTF8Bytes() }.AsImmutable)); }); #endregion #region GET ~/RNs/{RoamingNetworkId}/eMobilityProviders->AdminStatus // ------------------------------------------------------------------------------------------------------ // curl -v -H "Accept: application/json" http://127.0.0.1:3004/RNs/Test/eMobilityProviders->AdminStatus // ------------------------------------------------------------------------------------------------------ WWCPAPI.HTTPServer.AddMethodCallback(_Hostname, HTTPMethod.GET, _URIPrefix + "RNs/{RoamingNetworkId}/eMobilityProviders->AdminStatus", HTTPContentType.JSON_UTF8, HTTPDelegate: Request => { #region Check parameters HTTPResponse _HTTPResponse; RoamingNetwork _RoamingNetwork; if (!Request.ParseRoamingNetwork(WWCPAPI, out _RoamingNetwork, out _HTTPResponse)) { return(Task.FromResult(_HTTPResponse)); } #endregion var skip = Request.QueryString.GetUInt64("skip"); var take = Request.QueryString.GetUInt64("take"); var historysize = Request.QueryString.GetUInt64("historysize", 1); //ToDo: Getting the expected total count might be very expensive! var _ExpectedCount = _RoamingNetwork.ChargingStationOperatorAdminStatus.ULongCount(); return(Task.FromResult( new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.OK, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ETag = "1", ContentType = HTTPContentType.JSON_UTF8, Content = _RoamingNetwork.ChargingStationOperatorAdminStatus. OrderBy(kvp => kvp.Key). ToJSON(skip, take, historysize). ToUTF8Bytes(), X_ExpectedTotalNumberOfItems = _ExpectedCount }.AsImmutable)); }); #endregion #region GET ~/RNs/{RoamingNetworkId}/eMobilityProviders->Status // ------------------------------------------------------------------------------------------------- // curl -v -H "Accept: application/json" http://127.0.0.1:3004/RNs/Test/eMobilityProviders->Status // ------------------------------------------------------------------------------------------------- WWCPAPI.HTTPServer.AddMethodCallback(_Hostname, HTTPMethod.GET, _URIPrefix + "RNs/{RoamingNetworkId}/eMobilityProviders->Status", HTTPContentType.JSON_UTF8, HTTPDelegate: Request => { #region Check parameters HTTPResponse _HTTPResponse; RoamingNetwork _RoamingNetwork; if (!Request.ParseRoamingNetwork(WWCPAPI, out _RoamingNetwork, out _HTTPResponse)) { return(Task.FromResult(_HTTPResponse)); } #endregion var skip = Request.QueryString.GetUInt64("skip"); var take = Request.QueryString.GetUInt64("take"); var historysize = Request.QueryString.GetUInt64("historysize", 1); //ToDo: Getting the expected total count might be very expensive! var _ExpectedCount = _RoamingNetwork.ChargingStationOperatorStatus.ULongCount(); return(Task.FromResult( new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.OK, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ETag = "1", ContentType = HTTPContentType.JSON_UTF8, Content = _RoamingNetwork.ChargingStationOperatorStatus. OrderBy(kvp => kvp.Key). ToJSON(skip, take, historysize). ToUTF8Bytes(), X_ExpectedTotalNumberOfItems = _ExpectedCount }.AsImmutable)); }); #endregion #endregion #region ~/RNs/{RoamingNetworkId}/eMobilityProviders/{eMobilityProviderId} #region GET ~/RNs/{RoamingNetworkId}/eMobilityProviders/{eMobilityProviderId} WWCPAPI.HTTPServer.AddMethodCallback(_Hostname, HTTPMethod.GET, _URIPrefix + "RNs/{RoamingNetworkId}/eMobilityProviders/{eMobilityProviderId}", HTTPContentType.JSON_UTF8, HTTPDelegate: Request => { #region Check HTTP parameters if (!Request.ParseRoamingNetworkAndEMobilityProvider(WWCPAPI, out RoamingNetwork _RoamingNetwork, out eMobilityProvider _eMobilityProvider, out HTTPResponse _HTTPResponse)) { return(Task.FromResult(_HTTPResponse)); } #endregion return(Task.FromResult( new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.OK, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET, CREATE, DELETE", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ETag = "1", ContentType = HTTPContentType.JSON_UTF8, Content = _eMobilityProvider.ToJSON().ToUTF8Bytes() }.AsImmutable)); });
public void GET_and_COUNT() { #region Verify GET /RNs var URI = HTTPPath.Parse("/RNs"); using (var HTTPTask = _HTTPClient.Execute(client => client.GET(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JArray().ToString(), JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'GET " + URI + "'!"); } } #endregion #region Verify COUNT /RNs using (var HTTPTask = _HTTPClient.Execute(client => client.COUNT(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JObject(new JProperty("count", 0)).ToString(), JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'COUNT " + URI + "'!"); } } #endregion var RN_1 = WWCPAPI.CreateNewRoamingNetwork(Id: RoamingNetwork_Id.Parse("TEST_RN1"), Name: I18NString.Create(Languages.deu, "Test Roaming Netz 1"). Add(Languages.eng, "Test roaming network 1")); var RN_2 = WWCPAPI.CreateNewRoamingNetwork(Id: RoamingNetwork_Id.Parse("TEST_RN2"), Name: I18NString.Create(Languages.deu, "Test Roaming Netz 2"). Add(Languages.eng, "Test roaming network 2")); var RN_3 = WWCPAPI.CreateNewRoamingNetwork(Id: RoamingNetwork_Id.Parse("TEST_RN3"), Name: I18NString.Create(Languages.deu, "Test Roaming Netz 3"). Add(Languages.eng, "Test roaming network 3")); var RN_4 = WWCPAPI.CreateNewRoamingNetwork(Id: RoamingNetwork_Id.Parse("TEST_RN4"), Name: I18NString.Create(Languages.deu, "Test Roaming Netz 4"). Add(Languages.eng, "Test roaming network 4")); #region Verify GET /RNs URI = HTTPPath.Parse("/RNs"); using (var HTTPTask = _HTTPClient.Execute(client => client.GET(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JArray( new JObject(new JProperty("RoamingNetworkId", "TEST_RN1"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 1"), new JProperty("en", "Test roaming network 1")))), new JObject(new JProperty("RoamingNetworkId", "TEST_RN2"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 2"), new JProperty("en", "Test roaming network 2")))), new JObject(new JProperty("RoamingNetworkId", "TEST_RN3"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 3"), new JProperty("en", "Test roaming network 3")))), new JObject(new JProperty("RoamingNetworkId", "TEST_RN4"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 4"), new JProperty("en", "Test roaming network 4")))) ).ToString(), JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'GET " + URI + "'!"); } } #endregion #region Verify COUNT /RNs using (var HTTPTask = _HTTPClient.Execute(client => client.COUNT(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JObject(new JProperty("count", 4)).ToString(), JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'COUNT " + URI + "'!"); } } #endregion #region Verify GET /RNs?skip=2 URI = HTTPPath.Parse("/RNs?skip=2"); using (var HTTPTask = _HTTPClient.Execute(client => client.GET(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JArray( new JObject(new JProperty("RoamingNetworkId", "TEST_RN3"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 3"), new JProperty("en", "Test roaming network 3")))), new JObject(new JProperty("RoamingNetworkId", "TEST_RN4"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 4"), new JProperty("en", "Test roaming network 4")))) ).ToString(), JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'GET " + URI + "'!"); } } #endregion #region Verify GET /RNs?take=2 URI = HTTPPath.Parse("/RNs?take=2"); using (var HTTPTask = _HTTPClient.Execute(client => client.GET(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JArray( new JObject(new JProperty("RoamingNetworkId", "TEST_RN1"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 1"), new JProperty("en", "Test roaming network 1")))), new JObject(new JProperty("RoamingNetworkId", "TEST_RN2"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 2"), new JProperty("en", "Test roaming network 2")))) ).ToString(), JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'GET " + URI + "'!"); } } #endregion #region Verify GET /RNs?skip=1&take=2 URI = HTTPPath.Parse("/RNs?skip=1&take=2"); using (var HTTPTask = _HTTPClient.Execute(client => client.GET(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JArray( new JObject(new JProperty("RoamingNetworkId", "TEST_RN2"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 2"), new JProperty("en", "Test roaming network 2")))), new JObject(new JProperty("RoamingNetworkId", "TEST_RN3"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 3"), new JProperty("en", "Test roaming network 3")))) ).ToString(), JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'GET " + URI + "'!"); } } #endregion #region Verify GET /RNs?skip=8 URI = HTTPPath.Parse("/RNs?skip=8"); using (var HTTPTask = _HTTPClient.Execute(client => client.GET(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JArray().ToString(), JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'GET " + URI + "'!"); } } #endregion #region Verify GET /RNs/TEST_RN1 URI = HTTPPath.Parse("/RNs/TEST_RN1"); using (var HTTPTask = _HTTPClient.Execute(client => client.GET(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed! " + HTTPResult.HTTPBody.ToUTF8String()); Assert.AreEqual(new JObject(new JProperty("RoamingNetworkId", "TEST_RN1"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 1"), new JProperty("en", "Test roaming network 1"))) ).ToString(), JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'GET " + URI + "'!"); } } #endregion }
public void Test_Multitenancy_and_RoamingNetworks() { #region Verify GET /RNs on localhost var task0001 = _HTTPClient.Execute(client => client.GET(HTTPPath.Parse("/RNs"), requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token); task0001.Wait(Timeout); var result0001 = task0001.Result; Assert.AreEqual(HTTPStatusCode.OK, result0001.HTTPStatusCode); Assert.AreEqual(new JArray(new JObject(new JProperty("RoamingNetworkId", "TEST_RN1"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 1"), new JProperty("en", "Test roaming network 1"))))).ToString(), JArray.Parse(result0001.HTTPBody.ToUTF8String()).ToString()); #endregion #region Verify GET /RNs on virtualhost var task0002 = _HTTPClient.Execute(client => client.GET(HTTPPath.Parse("/RNs"), requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token); task0002.Wait(Timeout); var result0002 = task0002.Result; Assert.AreEqual(HTTPStatusCode.OK, result0002.HTTPStatusCode); Assert.AreEqual(new JArray(new JObject(new JProperty("RoamingNetworkId", "TEST_RN1"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 1"), new JProperty("en", "Test roaming network 1")))), new JObject(new JProperty("RoamingNetworkId", "TEST_RN2"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 2"), new JProperty("en", "Test roaming network 2"))))).ToString(), JArray.Parse(result0002.HTTPBody.ToUTF8String()).ToString()); #endregion #region Verify GET /RNs/TEST_RN1 on localhost var task0003 = _HTTPClient.Execute(client => client.GET(HTTPPath.Parse("/RNs/TEST_RN1"), requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token); task0003.Wait(Timeout); var result0003 = task0003.Result; Assert.AreEqual(HTTPStatusCode.OK, result0003.HTTPStatusCode); Assert.AreEqual(new JObject(new JProperty("RoamingNetworkId", "TEST_RN1"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 1"), new JProperty("en", "Test roaming network 1")))).ToString(), JObject.Parse(result0003.HTTPBody.ToUTF8String()).ToString()); #endregion #region Verify GET /RNs/TEST_RN1 on virtualhost var task0004 = _HTTPClient.Execute(client => client.GET(HTTPPath.Parse("/RNs/TEST_RN1"), requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token); task0004.Wait(Timeout); var result0004 = task0004.Result; Assert.AreEqual(HTTPStatusCode.OK, result0004.HTTPStatusCode); Assert.AreEqual(new JObject(new JProperty("RoamingNetworkId", "TEST_RN1"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 1"), new JProperty("en", "Test roaming network 1")))).ToString(), JObject.Parse(result0004.HTTPBody.ToUTF8String()).ToString()); #endregion #region Verify GET /RNs/TEST_RN2 on virtualhost var task0005 = _HTTPClient.Execute(client => client.GET(HTTPPath.Parse("/RNs/TEST_RN2"), requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token); task0005.Wait(Timeout); var result0005 = task0005.Result; Assert.AreEqual(HTTPStatusCode.OK, result0005.HTTPStatusCode); Assert.AreEqual(new JObject(new JProperty("RoamingNetworkId", "TEST_RN2"), new JProperty("description", new JObject(new JProperty("de", "Test Roaming Netz 2"), new JProperty("en", "Test roaming network 2")))).ToString(), JObject.Parse(result0005.HTTPBody.ToUTF8String()).ToString()); #endregion }
public void Test_ChargingPools() { var HTTPClient = new HTTPClient(IPv4Address.Localhost, RemotePort: IPPort.Parse(8000), DNSClient: HTTPAPI.DNSClient); var RN = OpenChargingCloudAPI.CreateNewRoamingNetwork(Id: RoamingNetwork_Id.Parse("TEST_RN1"), Name: I18NString.Create(Languages.deu, "Test Roaming Netz 1"). Add(Languages.eng, "Test roaming network 1")); var CPO = RN.CreateChargingStationOperator(ChargingStationOperatorId: ChargingStationOperator_Id.Parse("DE*GEF"), Name: I18NString.Create(Languages.deu, "GraphDefined"), Description: I18NString.Create(Languages.deu, "GraphDefined EVSE Operator"), Configurator: evseoperator => { evseoperator.AddDataLicense(DataLicense.OpenDatabaseLicense); }); #region Verify GET /RNs/TEST_RN1/ChargingPools var URI = HTTPPath.Parse("/RNs/TEST_RN1/ChargingPools"); using (var HTTPTask = HTTPClient.Execute(client => client.GET(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed!"); Assert.AreEqual(new JArray().ToString(), JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'GET " + URI + "'!"); } } #endregion #region Verify COUNT /RNs/TEST_RN1/ChargingPools using (var HTTPTask = HTTPClient.Execute(client => client.COUNT(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed!"); Assert.AreEqual(new JObject(new JProperty("count", 0)).ToString(), JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'COUNT " + URI + "'!"); } } #endregion var Pool_1 = CPO.CreateChargingPool(ChargingPool_Id.Parse(CPO.Id, "1111"), pool => { pool.Address = Address.Create(Country.Austria, "07741", I18NString.Create(Languages.deu, "Wien"), "Hofplatz", "17"); }); var Pool_2 = CPO.CreateChargingPool(ChargingPool_Id.Parse(CPO.Id, "2222"), pool => { pool.Address = Address.Create(Country.Germany, "07749", I18NString.Create(Languages.deu, "Jena"), "Biberweg", "18"); }); var Pool_3 = CPO.CreateChargingPool(ChargingPool_Id.Parse(CPO.Id, "3333"), pool => { pool.Address = Address.Create(Country.Belgium, "07758", I18NString.Create(Languages.bgn, "Brussels"), "Avenue", "19"); }); #region Verify GET /RNs/TEST_RN1/ChargingPools URI = HTTPPath.Parse("/RNs/TEST_RN1/ChargingPools"); using (var HTTPTask = HTTPClient.Execute(client => client.GET(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed!"); Assert.AreEqual(new JArray( new JObject(new JProperty("ChargingPoolId", "DE*GEF*P1111"), new JProperty("OperatorId", "DE*GEF"), new JProperty("Address", new JObject(new JProperty("houseNumber", "17"), new JProperty("street", "Hofplatz"), new JProperty("postalCode", "07741"), new JProperty("city", new JObject(new JProperty("de", "Wien")) ), new JProperty("country", new JObject(new JProperty("en", "Austria")) ) )), new JProperty("ChargingStations", new JArray()) ), new JObject(new JProperty("ChargingPoolId", "DE*GEF*P2222"), new JProperty("OperatorId", "DE*GEF"), new JProperty("Address", new JObject(new JProperty("houseNumber", "18"), new JProperty("street", "Biberweg"), new JProperty("postalCode", "07749"), new JProperty("city", new JObject(new JProperty("de", "Jena") )), new JProperty("country", new JObject( new JProperty("en", "Germany"), new JProperty("de", "Deutschland") ) ) )), new JProperty("ChargingStations", new JArray()) ), new JObject(new JProperty("ChargingPoolId", "DE*GEF*P3333"), new JProperty("OperatorId", "DE*GEF"), new JProperty("Address", new JObject(new JProperty("houseNumber", "19"), new JProperty("street", "Avenue"), new JProperty("postalCode", "07758"), new JProperty("city", new JObject(new JProperty("be", "Brussels")) ), new JProperty("country", new JObject(new JProperty("en", "Belgium")) ) )), new JProperty("ChargingStations", new JArray()) ) ).ToString(), JArray.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'GET " + URI + "'!"); } } #endregion #region Verify COUNT /RNs/TEST_RN1/ChargingPools using (var HTTPTask = HTTPClient.Execute(client => client.COUNT(URI, requestbuilder => { requestbuilder.Host = HTTPHostname.Localhost; requestbuilder.ContentType = HTTPContentType.JSON_UTF8; requestbuilder.Accept.Add(HTTPContentType.JSON_UTF8); }), RequestTimeout: Timeout, CancellationToken: new CancellationTokenSource().Token)) { HTTPTask.Wait(Timeout); using (var HTTPResult = HTTPTask.Result) { Assert.AreEqual(HTTPStatusCode.OK, HTTPResult.HTTPStatusCode, "'GET " + URI + "' failed!"); Assert.AreEqual(new JObject(new JProperty("count", 3)).ToString(), JObject.Parse(HTTPResult.HTTPBody.ToUTF8String()).ToString(), "Invalid response for 'COUNT " + URI + "'!"); } } #endregion }
/// <summary> /// Attach JSON I/O to the given WWCP HTTP API. /// </summary> /// <param name="WWCPAPI">A WWCP HTTP API.</param> /// <param name="Hostname">Limit this JSON I/O handling to the given HTTP hostname.</param> /// <param name="URIPrefix">A common URI prefix for all URIs within this API.</param> public static void Attach_JSON_IO_Reservations(this WWCP_HTTPAPI WWCPAPI, HTTPHostname?Hostname = null, HTTPPath?URIPrefix = null) { var _Hostname = Hostname ?? HTTPHostname.Any; var _URIPrefix = URIPrefix ?? HTTPPath.Parse("/"); #region ~/RNs/{RoamingNetworkId}/Reservations #region GET ~/RNs/{RoamingNetworkId}/Reservations // ---------------------------------------------------------------------------------- // curl -v -H "Accept: application/json" http://127.0.0.1:3004/RNs/Test/Reservations // ---------------------------------------------------------------------------------- WWCPAPI.HTTPServer.AddMethodCallback(_Hostname, HTTPMethod.GET, _URIPrefix + "/RNs/{RoamingNetworkId}/Reservations", HTTPContentType.JSON_UTF8, HTTPDelegate: async HTTPRequest => { #region Check HTTP Basic Authentication //if (HTTPRequest.Authorization == null || // HTTPRequest.Authorization.Username != HTTPLogin || // HTTPRequest.Authorization.Password != HTTPPassword) // return new HTTPResponse.Builder(HTTPRequest) { // HTTPStatusCode = HTTPStatusCode.Unauthorized, // WWWAuthenticate = @"Basic realm=""WWCP EV Charging""", // Server = _API.HTTPServer.DefaultServerName, // Date = DateTime.UtcNow, // Connection = "close" // }; #endregion #region Check parameters HTTPResponse _HTTPResponse; RoamingNetwork RoamingNetwork; if (!HTTPRequest.ParseRoamingNetwork(WWCPAPI, out RoamingNetwork, out _HTTPResponse)) { return(_HTTPResponse); } #endregion var skip = HTTPRequest.QueryString.GetUInt64("skip"); var take = HTTPRequest.QueryString.GetUInt32("take"); var _ChargingReservations = RoamingNetwork. ChargingReservations. OrderBy(reservation => reservation.Id.ToString()). Skip(skip). Take(take). ToArray(); //ToDo: Getting the expected total count might be very expensive! var _ExpectedCount = RoamingNetwork.ChargingReservations.LongCount(); return(new HTTPResponse.Builder(HTTPRequest) { HTTPStatusCode = _ChargingReservations.Any() ? HTTPStatusCode.OK : HTTPStatusCode.NoContent, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ETag = "1", ContentType = HTTPContentType.JSON_UTF8, Content = (_ChargingReservations.Any() ? _ChargingReservations.ToJSON() : new JArray() ).ToUTF8Bytes() }.Set(new HTTPHeaderField("X-ExpectedTotalNumberOfItems", typeof(UInt64), HeaderFieldType.Response, RequestPathSemantic.EndToEnd), _ExpectedCount)); }); #endregion #endregion #region ~/RNs/{RoamingNetworkId}/Reservations/{ReservationId} #region GET ~/RNs/{RoamingNetworkId}/Reservations/{ReservationId} // ----------------------------------------------------------------------------------- // curl -v -H "Accept: application/json" http://127.0.0.1:3004/RNs/Test/Reservations // ----------------------------------------------------------------------------------- WWCPAPI.HTTPServer.AddMethodCallback(_Hostname, HTTPMethod.GET, _URIPrefix + "RNs/{RoamingNetworkId}/Reservations/{ReservationId}", HTTPContentType.JSON_UTF8, HTTPDelegate: async HTTPRequest => { #region Check HTTP Basic Authentication //if (HTTPRequest.Authorization == null || // HTTPRequest.Authorization.Username != HTTPLogin || // HTTPRequest.Authorization.Password != HTTPPassword) // return new HTTPResponse.Builder(HTTPRequest) { // HTTPStatusCode = HTTPStatusCode.Unauthorized, // WWWAuthenticate = @"Basic realm=""WWCP EV Charging""", // Server = _API.HTTPServer.DefaultServerName, // Date = DateTime.UtcNow, // Connection = "close" // }; #endregion #region Check ChargingReservationId parameter HTTPResponse _HTTPResponse; RoamingNetwork RoamingNetwork; ChargingReservation Reservation; if (!HTTPRequest.ParseRoamingNetworkAndReservation(WWCPAPI, out RoamingNetwork, out Reservation, out _HTTPResponse)) { return(_HTTPResponse); } #endregion return(new HTTPResponse.Builder(HTTPRequest) { HTTPStatusCode = HTTPStatusCode.OK, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET, SETEXPIRED, DELETE", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ETag = "1", ContentType = HTTPContentType.JSON_UTF8, Content = Reservation.ToJSON().ToUTF8Bytes() }); }); #endregion #region SETEXPIRED ~/RNs/{RoamingNetworkId}/Reservations/{ReservationId} // ----------------------------------------------------------------------------------- // curl -v -H "Accept: application/json" http://127.0.0.1:3004/RNs/Test/Reservations // ----------------------------------------------------------------------------------- WWCPAPI.HTTPServer.AddMethodCallback(_Hostname, WWCP_HTTPAPI.SETEXPIRED, _URIPrefix + "RNs/{RoamingNetworkId}/Reservations/{ReservationId}", HTTPContentType.JSON_UTF8, HTTPDelegate: async Request => { #region Check HTTP Basic Authentication //if (HTTPRequest.Authorization == null || // HTTPRequest.Authorization.Username != HTTPLogin || // HTTPRequest.Authorization.Password != HTTPPassword) // return new HTTPResponse.Builder(HTTPRequest) { // HTTPStatusCode = HTTPStatusCode.Unauthorized, // WWWAuthenticate = @"Basic realm=""WWCP EV Charging""", // Server = _API.HTTPServer.DefaultServerName, // Date = DateTime.UtcNow, // Connection = "close" // }; #endregion #region Check ChargingReservationId parameter HTTPResponse _HTTPResponse; RoamingNetwork RoamingNetwork; ChargingReservation Reservation; if (!Request.ParseRoamingNetworkAndReservation(WWCPAPI, out RoamingNetwork, out Reservation, out _HTTPResponse)) { return(_HTTPResponse); } #endregion var response = RoamingNetwork.CancelReservation(Reservation.Id, ChargingReservationCancellationReason.Deleted, // null, //ToDo: Refacor me to make use of the ProviderId! // null, Request.Timestamp, Request.CancellationToken, Request.EventTrackingId, TimeSpan.FromSeconds(60)).Result; switch (response.Result) { case CancelReservationResultTypes.Success: return(new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.OK, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET, SETEXPIRED, DELETE", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ContentType = HTTPContentType.JSON_UTF8, Content = JSONObject.Create(new JProperty("en", "Reservation removed. Additional costs may be charged!")).ToUTF8Bytes() }); default: return(new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.InternalServerError, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET, DELETE", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ContentType = HTTPContentType.JSON_UTF8, Content = JSONObject.Create(new JProperty("description", "Could not remove reservation!")).ToUTF8Bytes() }); } }); #endregion #region DELETE ~/RNs/{RoamingNetworkId}/Reservations/{ReservationId} // ----------------------------------------------------------------------------------- // curl -v -H "Accept: application/json" http://127.0.0.1:3004/RNs/Test/Reservations // ----------------------------------------------------------------------------------- WWCPAPI.HTTPServer.AddMethodCallback(_Hostname, HTTPMethod.DELETE, _URIPrefix + "RNs/{RoamingNetworkId}/Reservations/{ReservationId}", HTTPContentType.JSON_UTF8, HTTPDelegate: async Request => { #region Check HTTP Basic Authentication //if (HTTPRequest.Authorization == null || // HTTPRequest.Authorization.Username != HTTPLogin || // HTTPRequest.Authorization.Password != HTTPPassword) // return new HTTPResponse.Builder(HTTPRequest) { // HTTPStatusCode = HTTPStatusCode.Unauthorized, // WWWAuthenticate = @"Basic realm=""WWCP EV Charging""", // Server = _API.HTTPServer.DefaultServerName, // Date = DateTime.UtcNow, // Connection = "close" // }; #endregion #region Check ChargingReservationId parameter HTTPResponse _HTTPResponse; RoamingNetwork RoamingNetwork; ChargingReservation Reservation; if (!Request.ParseRoamingNetworkAndReservation(WWCPAPI, out RoamingNetwork, out Reservation, out _HTTPResponse)) { return(_HTTPResponse); } #endregion var response = RoamingNetwork.CancelReservation(Reservation.Id, ChargingReservationCancellationReason.Deleted, // null, //ToDo: Refacor me to make use of the ProviderId! // null, Request.Timestamp, Request.CancellationToken, Request.EventTrackingId, TimeSpan.FromSeconds(60)).Result; switch (response.Result) { case CancelReservationResultTypes.Success: return(new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.OK, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET, SETEXPIRED, DELETE", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ContentType = HTTPContentType.JSON_UTF8, Content = JSONObject.Create(new JProperty("en", "Reservation removed. Additional costs may be charged!")).ToUTF8Bytes() }); default: return(new HTTPResponse.Builder(Request) { HTTPStatusCode = HTTPStatusCode.InternalServerError, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET, DELETE", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ContentType = HTTPContentType.JSON_UTF8, Content = JSONObject.Create(new JProperty("description", "Could not remove reservation!")).ToUTF8Bytes() }); } }); #endregion #endregion }
/// <summary> /// Attach JSON I/O to the given WWCP HTTP API. /// </summary> /// <param name="WWCPAPI">A WWCP HTTP API.</param> /// <param name="Hostname">Limit this JSON I/O handling to the given HTTP hostname.</param> /// <param name="URIPrefix">A common URI prefix for all URIs within this API.</param> public static void Attach_JSON_IO_ChargingSessions(this WWCP_HTTPAPI WWCPAPI, HTTPHostname?Hostname = null, HTTPPath?URIPrefix = null) { var _Hostname = Hostname ?? HTTPHostname.Any; var _URIPrefix = URIPrefix ?? HTTPPath.Parse("/"); #region ~/RNs/{RoamingNetworkId}/ChargingSessions WWCPAPI.HTTPServer.AddMethodCallback(_Hostname, HTTPMethod.GET, _URIPrefix + "ChargingSessions", HTTPContentType.JSON_UTF8, HTTPDelegate: async HTTPRequest => { #region Check HTTP Basic Authentication //if (HTTPRequest.Authorization == null || // HTTPRequest.Authorization.Username != HTTPLogin || // HTTPRequest.Authorization.Password != HTTPPassword) // return new HTTPResponse.Builder() { // HTTPStatusCode = HTTPStatusCode.Unauthorized, // WWWAuthenticate = @"Basic realm=""Bosch E-Bike""", // Server = _HTTPServer.DefaultServerName, // Date = DateTime.UtcNow, // Connection = "close" // }; #endregion #region Check parameters HTTPResponse _HTTPResponse; RoamingNetwork RoamingNetwork; if (!HTTPRequest.ParseRoamingNetwork(WWCPAPI, out RoamingNetwork, out _HTTPResponse)) { return(_HTTPResponse); } #endregion var skip = HTTPRequest.QueryString.GetUInt32("skip"); var take = HTTPRequest.QueryString.GetUInt32("take"); var _ChargingSessions = RoamingNetwork. ChargingSessions. OrderBy(session => session.Id.ToString()). Skip(skip). Take(take). ToArray(); //ToDo: Getting the expected total count might be very expensive! var _ExpectedCount = RoamingNetwork.ChargingSessions.LongCount(); return(new HTTPResponse.Builder(HTTPRequest) { HTTPStatusCode = _ChargingSessions.Any() ? HTTPStatusCode.OK : HTTPStatusCode.NoContent, Server = WWCPAPI.HTTPServer.DefaultServerName, Date = DateTime.UtcNow, AccessControlAllowOrigin = "*", AccessControlAllowMethods = "GET", AccessControlAllowHeaders = "Content-Type, Accept, Authorization", ETag = "1", ContentType = HTTPContentType.JSON_UTF8, Content = (_ChargingSessions.Any() ? _ChargingSessions.ToJSON() : new JArray() ).ToUTF8Bytes() }.Set(new HTTPHeaderField("X-ExpectedTotalNumberOfItems", typeof(UInt64), HeaderFieldType.Response, RequestPathSemantic.EndToEnd), _ExpectedCount)); }); #endregion #region ~/RNs/{RoamingNetworkId}/ChargeDetailRecords #endregion #region ~/RNs/{RoamingNetworkId}/ChargeDetailRecords/{ChargingSession_Id} #endregion }