/// <summary>
        /// Create a new WWCP HTTP API logger using the default logging delegates.
        /// </summary>
        /// <param name="OpenChargingCloudAPI">A WWCP API.</param>
        /// <param name="Context">A context of this API.</param>
        /// <param name="LogfileCreator">A delegate to create a log file from the given context and log file name.</param>
        public OpenChargingCloudAPILogger(OpenChargingCloudAPI OpenChargingCloudAPI,
                                          String Context = DefaultContext,
                                          LogfileCreatorDelegate LogfileCreator = null)

            : this(OpenChargingCloudAPI,
                   Context,
                   null,
                   null,
                   null,
                   null,
                   LogfileCreator : LogfileCreator)

        {
        }
        /// <summary>
        /// Attach CSV I/O to the given WWCP HTTP API.
        /// </summary>
        /// <param name="OpenChargingCloudAPI">A WWCP HTTP API.</param>
        /// <param name="Hostname">Limit this CSV 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_CSV_IO(this OpenChargingCloudAPI OpenChargingCloudAPI,
                                         HTTPHostname?Hostname = null,
                                         HTTPPath?URIPrefix    = null)
        {
            var _Hostname = Hostname ?? HTTPHostname.Any;

            // /AdminStatus
            // /Status

            //WWCPAPI.Attach_CSV_IO_RoamingNetworks   (Hostname, URIPrefix);
            //WWCPAPI.Attach_CSV_IO_ChargingOperators (Hostname, URIPrefix);
            //WWCPAPI.Attach_CSV_IO_ParkingOperators  (Hostname, URIPrefix);
            //WWCPAPI.Attach_CSV_IO_EMobilityProviders(Hostname, URIPrefix);
            //WWCPAPI.Attach_CSV_IO_SmartCities       (Hostname, URIPrefix);
            //WWCPAPI.Attach_CSV_IO_Reservations      (Hostname, URIPrefix);
            //WWCPAPI.Attach_CSV_IO_ChargingSessions  (Hostname, URIPrefix);
        }
Beispiel #3
0
        protected ATests()
        {
            _DNSClient = new DNSClient(SearchForIPv6DNSServers: false);

            if (RemoteAddress == IPv4Address.Localhost)
            {
                //HTTPAPI = new HTTPServer<RoamingNetworks, RoamingNetwork>(
                //              TCPPort:            RemotePort,
                //              DefaultServerName:  "GraphDefined WWCP Unit Tests",
                //              DNSClient:          _DNSClient
                //          );

                OpenChargingCloudAPI = new OpenChargingCloudAPI(LocalPort: IPPort.Parse(8001));
                //WWCPAPI.Attach_GeoJSON_IO();

                OpenChargingCloudAPI.Start();
            }
        }
Beispiel #4
0
        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 = 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 RN_2 = OpenChargingCloudAPI.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 = OpenChargingCloudAPI.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 = OpenChargingCloudAPI.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
        }
        /// <summary>
        /// Create a new WWCP HTTP API logger using the given logging delegates.
        /// </summary>
        /// <param name="OpenChargingCloudAPI">A WWCP API.</param>
        /// <param name="Context">A context of this API.</param>
        ///
        /// <param name="LogHTTPRequest_toConsole">A delegate to log incoming HTTP requests to console.</param>
        /// <param name="LogHTTPResponse_toConsole">A delegate to log HTTP requests/responses to console.</param>
        /// <param name="LogHTTPRequest_toDisc">A delegate to log incoming HTTP requests to disc.</param>
        /// <param name="LogHTTPResponse_toDisc">A delegate to log HTTP requests/responses to disc.</param>
        ///
        /// <param name="LogHTTPRequest_toNetwork">A delegate to log incoming HTTP requests to a network target.</param>
        /// <param name="LogHTTPResponse_toNetwork">A delegate to log HTTP requests/responses to a network target.</param>
        /// <param name="LogHTTPRequest_toHTTPSSE">A delegate to log incoming HTTP requests to a HTTP server sent events source.</param>
        /// <param name="LogHTTPResponse_toHTTPSSE">A delegate to log HTTP requests/responses to a HTTP server sent events source.</param>
        ///
        /// <param name="LogHTTPError_toConsole">A delegate to log HTTP errors to console.</param>
        /// <param name="LogHTTPError_toDisc">A delegate to log HTTP errors to disc.</param>
        /// <param name="LogHTTPError_toNetwork">A delegate to log HTTP errors to a network target.</param>
        /// <param name="LogHTTPError_toHTTPSSE">A delegate to log HTTP errors to a HTTP server sent events source.</param>
        ///
        /// <param name="LogfileCreator">A delegate to create a log file from the given context and log file name.</param>
        public OpenChargingCloudAPILogger(OpenChargingCloudAPI OpenChargingCloudAPI,
                                          String Context,

                                          HTTPRequestLoggerDelegate LogHTTPRequest_toConsole,
                                          HTTPResponseLoggerDelegate LogHTTPResponse_toConsole,
                                          HTTPRequestLoggerDelegate LogHTTPRequest_toDisc,
                                          HTTPResponseLoggerDelegate LogHTTPResponse_toDisc,

                                          HTTPRequestLoggerDelegate LogHTTPRequest_toNetwork   = null,
                                          HTTPResponseLoggerDelegate LogHTTPResponse_toNetwork = null,
                                          HTTPRequestLoggerDelegate LogHTTPRequest_toHTTPSSE   = null,
                                          HTTPResponseLoggerDelegate LogHTTPResponse_toHTTPSSE = null,

                                          HTTPResponseLoggerDelegate LogHTTPError_toConsole = null,
                                          HTTPResponseLoggerDelegate LogHTTPError_toDisc    = null,
                                          HTTPResponseLoggerDelegate LogHTTPError_toNetwork = null,
                                          HTTPResponseLoggerDelegate LogHTTPError_toHTTPSSE = null,

                                          LogfileCreatorDelegate LogfileCreator = null)

            : base(OpenChargingCloudAPI.HTTPServer,//.InternalHTTPServer,
                   Context,

                   LogHTTPRequest_toConsole,
                   LogHTTPResponse_toConsole,
                   LogHTTPRequest_toDisc,
                   LogHTTPResponse_toDisc,

                   LogHTTPRequest_toNetwork,
                   LogHTTPResponse_toNetwork,
                   LogHTTPRequest_toHTTPSSE,
                   LogHTTPResponse_toHTTPSSE,

                   LogHTTPError_toConsole,
                   LogHTTPError_toDisc,
                   LogHTTPError_toNetwork,
                   LogHTTPError_toHTTPSSE,

                   LogfileCreator)

        {
            #region Initial checks

            if (OpenChargingCloudAPI == null)
            {
                throw new ArgumentNullException(nameof(OpenChargingCloudAPI), "The given WWCP HTTP API must not be null!");
            }

            #endregion

            this.OpenChargingCloudAPI = OpenChargingCloudAPI;

            #region EVSEs

            RegisterEvent2("GetEVSEsStatusRequest",
                           handler => OpenChargingCloudAPI.OnGetEVSEsStatusRequest += handler,
                           handler => OpenChargingCloudAPI.OnGetEVSEsStatusRequest -= handler,
                           "EVSEStatus", "EVSE", "Status", "Request", "All").
            RegisterDefaultConsoleLogTarget(this).
            RegisterDefaultDiscLogTarget(this);

            //RegisterEvent2("GetEVSEsStatusResponse",
            //               handler => OpenChargingCloudAPI.OnGetEVSEsStatusResponse += handler,
            //               handler => OpenChargingCloudAPI.OnGetEVSEsStatusResponse -= handler,
            //               "EVSEStatus", "EVSE", "Status", "Response", "All").
            //    RegisterDefaultConsoleLogTarget(this).
            //    RegisterDefaultDiscLogTarget(this);

            #endregion


            #region Register auth start/stop log events

            RegisterEvent2("AuthEVSEStart",
                           handler => OpenChargingCloudAPI.OnAuthStartEVSERequest += handler,
                           handler => OpenChargingCloudAPI.OnAuthStartEVSERequest -= handler,
                           "Auth", "AuthEVSE", "AuthStart", "All").
            RegisterDefaultConsoleLogTarget(this).
            RegisterDefaultDiscLogTarget(this);

            RegisterEvent2("AuthEVSEStarted",
                           handler => OpenChargingCloudAPI.OnAuthStartEVSEResponse += handler,
                           handler => OpenChargingCloudAPI.OnAuthStartEVSEResponse -= handler,
                           "Auth", "AuthEVSE", "AuthStarted", "All").
            RegisterDefaultConsoleLogTarget(this).
            RegisterDefaultDiscLogTarget(this);

            RegisterEvent2("AuthEVSEStop",
                           handler => OpenChargingCloudAPI.OnAuthStopEVSERequest += handler,
                           handler => OpenChargingCloudAPI.OnAuthStopEVSERequest -= handler,
                           "Auth", "AuthEVSE", "AuthStop", "All").
            RegisterDefaultConsoleLogTarget(this).
            RegisterDefaultDiscLogTarget(this);

            RegisterEvent2("AuthEVSEStopped",
                           handler => OpenChargingCloudAPI.OnAuthStopEVSEResponse += handler,
                           handler => OpenChargingCloudAPI.OnAuthStopEVSEResponse -= handler,
                           "Auth", "AuthEVSE", "AuthStopped", "All").
            RegisterDefaultConsoleLogTarget(this).
            RegisterDefaultDiscLogTarget(this);

            #endregion

            #region Register remote start/stop log events

            RegisterEvent2("RemoteEVSEStart",
                           handler => OpenChargingCloudAPI.OnSendRemoteStartEVSERequest += handler,
                           handler => OpenChargingCloudAPI.OnSendRemoteStartEVSERequest -= handler,
                           "Remote", "RemoteEVSE", "RemoteStart", "All").
            RegisterDefaultConsoleLogTarget(this).
            RegisterDefaultDiscLogTarget(this);

            RegisterEvent2("RemoteEVSEStarted",
                           handler => OpenChargingCloudAPI.OnSendRemoteStartEVSEResponse += handler,
                           handler => OpenChargingCloudAPI.OnSendRemoteStartEVSEResponse -= handler,
                           "Remote", "RemoteEVSE", "RemoteStarted", "All").
            RegisterDefaultConsoleLogTarget(this).
            RegisterDefaultDiscLogTarget(this);

            RegisterEvent2("RemoteEVSEStop",
                           handler => OpenChargingCloudAPI.OnSendRemoteStopEVSERequest += handler,
                           handler => OpenChargingCloudAPI.OnSendRemoteStopEVSERequest -= handler,
                           "Remote", "RemoteEVSE", "RemoteStop", "All").
            RegisterDefaultConsoleLogTarget(this).
            RegisterDefaultDiscLogTarget(this);

            RegisterEvent2("RemoteEVSEStopped",
                           handler => OpenChargingCloudAPI.OnSendRemoteStopEVSEResponse += handler,
                           handler => OpenChargingCloudAPI.OnSendRemoteStopEVSEResponse -= handler,
                           "Remote", "RemoteEVSE", "RemoteStopped", "All").
            RegisterDefaultConsoleLogTarget(this).
            RegisterDefaultDiscLogTarget(this);

            #endregion

            #region Register CDR log events

            RegisterEvent2("SendCDR",
                           handler => OpenChargingCloudAPI.OnSendCDRsRequest += handler,
                           handler => OpenChargingCloudAPI.OnSendCDRsRequest -= handler,
                           "CDR", "All").
            RegisterDefaultConsoleLogTarget(this).
            RegisterDefaultDiscLogTarget(this);

            RegisterEvent2("CDRSent",
                           handler => OpenChargingCloudAPI.OnSendCDRsResponse += handler,
                           handler => OpenChargingCloudAPI.OnSendCDRsResponse -= handler,
                           "CDR", "All").
            RegisterDefaultConsoleLogTarget(this).
            RegisterDefaultDiscLogTarget(this);

            #endregion
        }
        /// <summary>
        /// Attach JSON I/O to the given WWCP HTTP API.
        /// </summary>
        /// <param name="OpenChargingCloudAPI">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_SmartCities(this OpenChargingCloudAPI OpenChargingCloudAPI,
                                                      HTTPHostname?_Hostname = null,
                                                      HTTPPath?_URIPrefix    = null)
        {
            var Hostname  = _Hostname ?? HTTPHostname.Any;
            var URIPrefix = _URIPrefix ?? HTTPPath.Parse("/");

            #region ~/RNs/{RoamingNetworkId}/SmartCities

            #region GET         ~/RNs/{RoamingNetworkId}/SmartCities

            // -----------------------------------------------------------------------------------------
            // curl -v -H "Accept: application/json" http://127.0.0.1:3004/RNs/Test/SmartCities
            // -----------------------------------------------------------------------------------------
            OpenChargingCloudAPI.HTTPServer.AddMethodCallback(Hostname,
                                                              HTTPMethod.GET,
                                                              URIPrefix + "RNs/{RoamingNetworkId}/SmartCities",
                                                              HTTPContentType.JSON_UTF8,
                                                              HTTPDelegate: Request => {
                #region Check parameters

                HTTPResponse _HTTPResponse;
                RoamingNetwork _RoamingNetwork;

                if (!Request.ParseRoamingNetwork(OpenChargingCloudAPI, 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");
                //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.SmartCities.ULongCount();

                return(Task.FromResult(
                           new HTTPResponse.Builder(Request)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server = OpenChargingCloudAPI.HTTPServer.DefaultServerName,
                    Date = DateTime.UtcNow,
                    AccessControlAllowOrigin = "*",
                    AccessControlAllowMethods = "GET, COUNT, STATUS",
                    AccessControlAllowHeaders = "Content-Type, Accept, Authorization",
                    ETag = "1",
                    ContentType = HTTPContentType.JSON_UTF8,
                    Content = _RoamingNetwork.SmartCities.
                              ToJSON(skip,
                                     take,
                                     false).
                              //expandChargingPools,
                              //expandChargingStations,
                              //expandBrands).
                              ToUTF8Bytes(),
                    X_ExpectedTotalNumberOfItems = _ExpectedCount
                }.AsImmutable));
            });

            #endregion

            #region COUNT       ~/RNs/{RoamingNetworkId}/SmartCities

            // ----------------------------------------------------------------------------------------------------------------
            // curl -v -X COUNT -H "Accept: application/json" http://127.0.0.1:3004/RNs/{RoamingNetworkId}/SmartCities
            // ----------------------------------------------------------------------------------------------------------------
            OpenChargingCloudAPI.HTTPServer.AddMethodCallback(Hostname,
                                                              HTTPMethod.COUNT,
                                                              URIPrefix + "RNs/{RoamingNetworkId}/SmartCities",
                                                              HTTPContentType.JSON_UTF8,
                                                              HTTPDelegate: Request => {
                #region Check parameters

                HTTPResponse _HTTPResponse;
                RoamingNetwork _RoamingNetwork;

                if (!Request.ParseRoamingNetwork(OpenChargingCloudAPI, out _RoamingNetwork, out _HTTPResponse))
                {
                    return(Task.FromResult(_HTTPResponse));
                }

                #endregion

                return(Task.FromResult(
                           new HTTPResponse.Builder(Request)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server = OpenChargingCloudAPI.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}/SmartCities->AdminStatus

            // ------------------------------------------------------------------------------------------------------
            // curl -v -H "Accept: application/json" http://127.0.0.1:3004/RNs/Test/SmartCities->AdminStatus
            // ------------------------------------------------------------------------------------------------------
            OpenChargingCloudAPI.HTTPServer.AddMethodCallback(Hostname,
                                                              HTTPMethod.GET,
                                                              URIPrefix + "RNs/{RoamingNetworkId}/SmartCities->AdminStatus",
                                                              HTTPContentType.JSON_UTF8,
                                                              HTTPDelegate: Request => {
                #region Check parameters

                HTTPResponse _HTTPResponse;
                RoamingNetwork _RoamingNetwork;

                if (!Request.ParseRoamingNetwork(OpenChargingCloudAPI, 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 = OpenChargingCloudAPI.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}/SmartCities->Status

            // -------------------------------------------------------------------------------------------------
            // curl -v -H "Accept: application/json" http://127.0.0.1:3004/RNs/Test/SmartCities->Status
            // -------------------------------------------------------------------------------------------------
            OpenChargingCloudAPI.HTTPServer.AddMethodCallback(Hostname,
                                                              HTTPMethod.GET,
                                                              URIPrefix + "RNs/{RoamingNetworkId}/SmartCities->Status",
                                                              HTTPContentType.JSON_UTF8,
                                                              HTTPDelegate: Request => {
                #region Check parameters

                HTTPResponse _HTTPResponse;
                RoamingNetwork _RoamingNetwork;

                if (!Request.ParseRoamingNetwork(OpenChargingCloudAPI, 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 = OpenChargingCloudAPI.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}/SmartCities/{SmartCityId}

            #region GET         ~/RNs/{RoamingNetworkId}/SmartCities/{SmartCityId}

            OpenChargingCloudAPI.HTTPServer.AddMethodCallback(HTTPHostname.Any,
                                                              HTTPMethod.GET,
                                                              URIPrefix + "RNs/{RoamingNetworkId}/SmartCities/{SmartCityId}",
                                                              HTTPContentType.JSON_UTF8,
                                                              HTTPDelegate: Request => {
                #region Check HTTP parameters

                HTTPResponse _HTTPResponse;
                RoamingNetwork _RoamingNetwork;
                SmartCityProxy _SmartCity;

                if (!Request.ParseRoamingNetworkAndSmartCity(OpenChargingCloudAPI,
                                                             out _RoamingNetwork,
                                                             out _SmartCity,
                                                             out _HTTPResponse))
                {
                    return(Task.FromResult(_HTTPResponse));
                }

                #endregion

                return(Task.FromResult(
                           new HTTPResponse.Builder(Request)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server = OpenChargingCloudAPI.HTTPServer.DefaultServerName,
                    Date = DateTime.UtcNow,
                    AccessControlAllowOrigin = "*",
                    AccessControlAllowMethods = "GET, CREATE, DELETE",
                    AccessControlAllowHeaders = "Content-Type, Accept, Authorization",
                    ETag = "1",
                    ContentType = HTTPContentType.JSON_UTF8,
                    Content = _SmartCity.ToJSON().ToUTF8Bytes()
                }.AsImmutable));
            });

            #endregion

            #endregion
        }
 public static void RegisterXML(this OpenChargingCloudAPI OpenChargingCloudAPI,
                                RoamingNetworks RoamingNetworks)
 {
 }