예제 #1
0
        private async void SendMessage ()
        {
            //Get file and create xml SOAP message to be sent
            soap_message = new SOAP(file_txtbx.Text);

            //create http client
            //HttpClient client = new HttpClient();

            ip_address = ip_address_txtbx.Text;
            port = port_txtbx.Text;

            //create connection address
            Uri uri = new Uri(@"http://" + ip_address + ":" + port + @"/");

            //create connection
            WebRequest client = WebRequest.Create(uri);
            WebResponse response;
            //client.Timeout = 300000;
            client.Method = "POST";
            client.ContentType = "text/xml;charset=UTF-8";

            //send SOAP message
            using (StreamWriter writer = new StreamWriter(client.GetRequestStream()))
            {
               
                writer.WriteLine(soap_message.GetSoapMessage.ToString());
                
                writer.Close();
            }




            //get response 
            using (response = client.GetResponse())
            {
                client.GetRequestStream().Close();
                if (response != null)
                {
                    using (var answerReader = new StreamReader(response.GetResponseStream()))
                    {
                        var readString = answerReader.ReadToEnd();
                        textBox1.Text = readString.ToString();
                    }
                }
            }

            ////sets the contents of the message
            //var content = new ByteArrayContent(soap_message.GetSoapMessage);

            //var httpResponse = await client.PostAsync(uri.OriginalString, content);
            //textBox1.Text = await httpResponse.Content.ReadAsStringAsync();
        }
예제 #2
0
 public DrsService(
     SOAP drsSoap,
     IOptions <DrsOptions> drsOptions,
     ILogger <DrsService> logger,
     IDrsMapping drsMapping,
     IOperativesGateway operativesGateway,
     IAppointmentsGateway appointmentsGateway,
     IRepairsGateway repairsGateway)
 {
     _drsSoap             = drsSoap;
     _drsOptions          = drsOptions;
     _logger              = logger;
     _drsMapping          = drsMapping;
     _operativesGateway   = operativesGateway;
     _appointmentsGateway = appointmentsGateway;
     _repairsGateway      = repairsGateway;
 }
예제 #3
0
        } // ParseDidlItemMetaData()

        /*
         * <item id="33$@155" parentID="33$466" restricted="1" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/">
         * <dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">DTH-Unplugged</dc:title>
         * <upnp:class xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/">object.item.videoItem</upnp:class>
         * <dc:date xmlns:dc="http://purl.org/dc/elements/1.1/">2015-02-08T09:54:25</dc:date>
         * <res protocolInfo="http-get:*:video/avi:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000" resolution="512x384" size="698892352" bitrate="196265" duration="0:59:20.000" nrAudioChannels="2" sampleFrequency="44100">http://192.168.0.16:50002/v/NDLNA/155.avi</res>
         * </item>
         */

        /// <summary>
        /// Invokes an action.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="input">The input.</param>
        /// <returns>An <see cref="InvokeActionResult"/> object.</returns>
        private static async Task <InvokeActionResult> InvokeAction(UpnpServiceAction action, IEnumerable <object> input)
        {
            var soap   = new SOAP();
            var result = new InvokeActionResult();

            try
            {
                var res = await soap.Invoke(action.Service.ControlUrl,
                                            action.Service.Type, action, input.ToArray());

                result = res;
            }
            catch (Exception ex)
            {
                Log.Error("Error executing action", ex);
                result.Success = false;
            } // catch

            return(result);
        } // InvokeAction()
예제 #4
0
        } // ActionInfoControl()

        #endregion // CONSTRUCTION

        //// ---------------------------------------------------------------------

        #region UI METHODS
        /// <summary>
        /// Handles the Click event of the <c>btnInvokeAction</c> control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private async void BtnInvokeActionClick(object sender, EventArgs e)
        {
            this.rtfStatus.Clear();
#if true
            if (this.Action.Service.Type.Contains("ContentDirectory:2"))
            {
                var svc2 = new ContentDirectoryService(this.Action.Service);
                svc2.StatusDisplay = this;
                var x = await svc2.GetSearchCapabilities();

                ////var x2 = await svc2.BrowseMetaData("0");
                ////var x3 = await svc2.BrowseDirectChildren("0");
                ////var x3 = await svc2.BrowseDirectChildren("AV_ALL");
                var x4 = await svc2.GetFeatureList();
            }
#endif
            var soap = new SOAP();

            try
            {
                var input = new List <object>();
                for (var i = 0; i < this.Action.ArgumentsIn.Count; i++)
                {
                    var value        = this.dataGridInputs.Rows[i].Cells["colValue"].Value;
                    var variableInfo = this.Action.Service.GetVariableInfo(this.Action.ArgumentsIn[i]);
                    if ((value == null) && (variableInfo.Type == "i4"))
                    {
                        value = "0";
                    } // if

                    input.Add(value);
                } // foreach

                var result = await soap.Invoke(this.Action.Service.ControlUrl,
                                               this.Action.Service.Type, this.Action, input.ToArray());

                if (result?.Output != null)
                {
                    Log.Debug("Result:");
                    foreach (var obj in result.Output)
                    {
                        Log.Debug($"  {obj}");
                    } // foreach

                    for (var i = 0; i < this.Action.ArgumentsOut.Count; i++)
                    {
                        if (result.Output.Length < i)
                        {
                            continue;
                        } // if

                        this.dataGridOutputs.Rows[i].Cells[2].Value = result.Output[i];
                    } // foreach

                    this.DisplayStatusText("Action successfully executed.");
                } // if

                if ((result != null) && (!result.Success))
                {
                    this.DisplayStatusText($"Error executing action: {result.ErrorMessage} (code {result.ErrorCode})",
                                           Color.Red);
                } // if
            }
            catch (Exception ex)
            {
                Log.Error("Error executing action", ex);
                this.DisplayStatusText($"Error executing action: {ex.Message}", Color.Red);
            } // catch
        }     // BtnInvokeActionClick()
예제 #5
0
        static void Main(string[] args)
        {
            // SOAP instances


            SOAP soap = new SOAP()
            {
                Header = new Header()
                {
                    MIMHeader = new MIMHeader()
                    {
                    },
                    MIMadditionalHeader = new MIMadditionalHeader()
                    {
                    },
                    CryptoHeader = new CryptoHeader()
                    {
                    }
                },
                Body = new Body()
                {
                    MIMbody = new MIMbody()
                    {
                    }
                }
            };

            // SOAP NameSpace instance & serialization

            XmlSerializerNamespaces soapNS = new XmlSerializerNamespaces();

            soapNS.Add("mioa", "http://mioa.gov.mk/interop/mim/v1");
            soapNS.Add("xs", "http://www.w3.org/2001/XMLSchema");
            soapNS.Add("soap", "http://www.w3.org/2003/05/soap-envelope");

            // SOAP msg Serialization

            XmlSerializer xserSoap = new XmlSerializer(typeof(SOAP));

            xserSoap.Serialize(Console.Out, soap, soapNS);


            Console.WriteLine(Environment.NewLine + Environment.NewLine + Environment.NewLine);

            // FaultSOAP instances

            SOAPFault soapFault = new SOAPFault
            {
                Body = new FaultBody
                {
                    Fault = new Fault
                    {
                        Code = new Code {
                            SubCode = new SubCode {
                            }
                        },
                        Details = new Detail {
                        },
                        Reason  = new Reason {
                            Text = new Text {
                            }
                        }
                    }
                }
            };

            // FaultSOAP NameSpace instance & serialization

            XmlSerializerNamespaces soapFaultNS = new XmlSerializerNamespaces();

            soapFaultNS.Add("env", "http://www.w3.org/2003/05/soap-envelope");
            soapFaultNS.Add("m", "http://www.example.org/timeouts");
            soapFaultNS.Add("xml", "http://www.w3.org/XML/1998/namespace");

            // FaultSOAP msg Serialization

            XmlSerializer xserSoapFault = new XmlSerializer(typeof(SOAPFault));

            xserSoapFault.Serialize(Console.Out, soapFault, soapFaultNS);
        }
예제 #6
0
        /// <summary>
        /// Register all URL templates for this SOAP API.
        /// </summary>
        protected void RegisterURLTemplates()
        {
            #region /Authorization - AuthorizeStart

            SOAPServer.RegisterSOAPDelegate(HTTPHostname.Any,
                                            URLPrefix + AuthorizationURL,
                                            "AuthorizeStart",
                                            XML => XML.Descendants(OICPNS.Authorization + "eRoamingAuthorizeStart").FirstOrDefault(),
                                            async(HTTPRequest, AuthorizeStartXML) => {
                CPO.AuthorizeStartRequest AuthorizeStartRequest = null;
                CPO.AuthorizationStart AuthorizationStart       = null;


                #region Send OnAuthorizeStartSOAPRequest event

                var StartTime = DateTime.UtcNow;

                try
                {
                    if (OnAuthorizeStartSOAPRequest != null)
                    {
                        await Task.WhenAll(OnAuthorizeStartSOAPRequest.GetInvocationList().
                                           Cast <RequestLogHandler>().
                                           Select(e => e(StartTime,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    e.Log(nameof(EMPSOAPServer) + "." + nameof(OnAuthorizeStartSOAPRequest));
                }

                #endregion

                try
                {
                    if (CPO.AuthorizeStartRequest.TryParse(AuthorizeStartXML,
                                                           out AuthorizeStartRequest,
                                                           CustomAuthorizeStartRequestParser,
                                                           CustomIdentificationParser,
                                                           CustomRFIDIdentificationParser,
                                                           OnException,

                                                           HTTPRequest.Timestamp,
                                                           HTTPRequest.CancellationToken,
                                                           HTTPRequest.EventTrackingId,
                                                           HTTPRequest.Timeout ?? DefaultRequestTimeout))
                    {
                        #region Send OnAuthorizeStartRequest event

                        try
                        {
                            if (OnAuthorizeStartRequest != null)
                            {
                                await Task.WhenAll(OnAuthorizeStartRequest.GetInvocationList().
                                                   Cast <OnAuthorizeStartRequestDelegate>().
                                                   Select(e => e(StartTime,
                                                                 AuthorizeStartRequest.Timestamp.Value,
                                                                 this,
                                                                 ServiceName,
                                                                 AuthorizeStartRequest.EventTrackingId,
                                                                 AuthorizeStartRequest.OperatorId,
                                                                 AuthorizeStartRequest.Identification,
                                                                 AuthorizeStartRequest.EVSEId,
                                                                 AuthorizeStartRequest.SessionId,
                                                                 AuthorizeStartRequest.PartnerProductId,
                                                                 AuthorizeStartRequest.CPOPartnerSessionId,
                                                                 AuthorizeStartRequest.EMPPartnerSessionId,
                                                                 AuthorizeStartRequest.RequestTimeout ?? DefaultRequestTimeout))).
                                ConfigureAwait(false);
                            }
                        }
                        catch (Exception e)
                        {
                            e.Log(nameof(EMPSOAPServer) + "." + nameof(OnAuthorizeStartRequest));
                        }

                        #endregion

                        #region Call async subscribers

                        if (OnAuthorizeStart != null)
                        {
                            var results = await Task.WhenAll(OnAuthorizeStart.GetInvocationList().
                                                             Cast <OnAuthorizeStartDelegate>().
                                                             Select(e => e(DateTime.UtcNow,
                                                                           this,
                                                                           AuthorizeStartRequest))).
                                          ConfigureAwait(false);

                            AuthorizationStart = results.FirstOrDefault();
                        }

                        if (AuthorizationStart == null)
                        {
                            AuthorizationStart = CPO.AuthorizationStart.SystemError(
                                AuthorizeStartRequest,
                                "Could not process the incoming AuthorizationStart request!",
                                null,
                                AuthorizeStartRequest.SessionId,
                                AuthorizeStartRequest.CPOPartnerSessionId,
                                AuthorizeStartRequest.EMPPartnerSessionId
                                );
                        }

                        #endregion

                        #region Send OnAuthorizeStartResponse event

                        var EndTime = DateTime.UtcNow;

                        try
                        {
                            if (OnAuthorizeStartResponse != null)
                            {
                                await Task.WhenAll(OnAuthorizeStartResponse.GetInvocationList().
                                                   Cast <OnAuthorizeStartResponseDelegate>().
                                                   Select(e => e(EndTime,
                                                                 this,
                                                                 ServiceName,
                                                                 AuthorizeStartRequest.EventTrackingId,
                                                                 AuthorizeStartRequest.OperatorId,
                                                                 AuthorizeStartRequest.Identification,
                                                                 AuthorizeStartRequest.EVSEId,
                                                                 AuthorizeStartRequest.SessionId,
                                                                 AuthorizeStartRequest.PartnerProductId,
                                                                 AuthorizeStartRequest.CPOPartnerSessionId,
                                                                 AuthorizeStartRequest.EMPPartnerSessionId,
                                                                 AuthorizeStartRequest.RequestTimeout ?? DefaultRequestTimeout,
                                                                 AuthorizationStart,
                                                                 EndTime - StartTime))).
                                ConfigureAwait(false);
                            }
                        }
                        catch (Exception e)
                        {
                            e.Log(nameof(EMPSOAPServer) + "." + nameof(OnAuthorizeStartResponse));
                        }

                        #endregion
                    }

                    else
                    {
                        AuthorizationStart = CPO.AuthorizationStart.DataError(
                            AuthorizeStartRequest,
                            "Could not process the incoming AuthorizeStart request!"
                            );
                    }
                }
                catch (Exception e)
                {
                    AuthorizationStart = CPO.AuthorizationStart.DataError(
                        AuthorizeStartRequest,
                        e.Message,
                        e.StackTrace
                        );
                }


                #region Create SOAP response

                var HTTPResponse = new HTTPResponse.Builder(HTTPRequest)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server         = SOAPServer.HTTPServer.DefaultServerName,
                    Date           = DateTime.UtcNow,
                    ContentType    = HTTPContentType.XMLTEXT_UTF8,
                    Content        = SOAP.Encapsulation(AuthorizationStart.ToXML()).ToUTF8Bytes(),
                    Connection     = "close"
                };

                #endregion

                #region Send OnAuthorizeStartSOAPResponse event

                try
                {
                    if (OnAuthorizeStartSOAPResponse != null)
                    {
                        await Task.WhenAll(OnAuthorizeStartSOAPResponse.GetInvocationList().
                                           Cast <AccessLogHandler>().
                                           Select(e => e(HTTPResponse.Timestamp,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest,
                                                         HTTPResponse))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    e.Log(nameof(EMPSOAPServer) + "." + nameof(OnAuthorizeStartSOAPResponse));
                }

                #endregion

                return(HTTPResponse);
            });

            #endregion

            #region /Authorization - AuthorizeStop

            SOAPServer.RegisterSOAPDelegate(HTTPHostname.Any,
                                            URLPrefix + AuthorizationURL,
                                            "AuthorizeStop",
                                            XML => XML.Descendants(OICPNS.Authorization + "eRoamingAuthorizeStop").FirstOrDefault(),
                                            async(HTTPRequest, AuthorizeStopXML) => {
                CPO.AuthorizeStopRequest AuthorizeStopRequest = null;
                CPO.AuthorizationStop AuthorizationStop       = null;

                #region Send OnAuthorizeStopSOAPRequest event

                var StartTime = DateTime.UtcNow;

                try
                {
                    if (OnAuthorizeStopSOAPRequest != null)
                    {
                        await Task.WhenAll(OnAuthorizeStopSOAPRequest.GetInvocationList().
                                           Cast <RequestLogHandler>().
                                           Select(e => e(StartTime,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    e.Log(nameof(EMPSOAPServer) + "." + nameof(OnAuthorizeStartSOAPRequest));
                }

                #endregion


                try
                {
                    if (CPO.AuthorizeStopRequest.TryParse(AuthorizeStopXML,
                                                          out AuthorizeStopRequest,
                                                          CustomAuthorizeStopRequestParser,
                                                          CustomIdentificationParser,
                                                          CustomRFIDIdentificationParser,
                                                          OnException,

                                                          HTTPRequest.Timestamp,
                                                          HTTPRequest.CancellationToken,
                                                          HTTPRequest.EventTrackingId,
                                                          HTTPRequest.Timeout ?? DefaultRequestTimeout))
                    {
                        #region Send OnAuthorizeStopRequest event

                        try
                        {
                            if (OnAuthorizeStopRequest != null)
                            {
                                await Task.WhenAll(OnAuthorizeStopRequest.GetInvocationList().
                                                   Cast <OnAuthorizeStopRequestHandler>().
                                                   Select(e => e(StartTime,
                                                                 AuthorizeStopRequest.Timestamp.Value,
                                                                 this,
                                                                 ServiceName,
                                                                 AuthorizeStopRequest.EventTrackingId,
                                                                 AuthorizeStopRequest.SessionId,
                                                                 AuthorizeStopRequest.CPOPartnerSessionId,
                                                                 AuthorizeStopRequest.EMPPartnerSessionId,
                                                                 AuthorizeStopRequest.OperatorId,
                                                                 AuthorizeStopRequest.EVSEId,
                                                                 AuthorizeStopRequest.Identification,
                                                                 AuthorizeStopRequest.RequestTimeout ?? DefaultRequestTimeout))).
                                ConfigureAwait(false);
                            }
                        }
                        catch (Exception e)
                        {
                            e.Log(nameof(EMPSOAPServer) + "." + nameof(OnAuthorizeStopRequest));
                        }

                        #endregion

                        #region Call async subscribers

                        if (OnAuthorizeStop != null)
                        {
                            var results = await Task.WhenAll(OnAuthorizeStop.GetInvocationList().
                                                             Cast <OnAuthorizeStopDelegate>().
                                                             Select(e => e(DateTime.UtcNow,
                                                                           this,
                                                                           AuthorizeStopRequest))).
                                          ConfigureAwait(false);

                            AuthorizationStop = results.FirstOrDefault();
                        }

                        if (AuthorizationStop == null)
                        {
                            AuthorizationStop = CPO.AuthorizationStop.SystemError(
                                null,
                                "Could not process the incoming AuthorizeStop request!",
                                null,
                                AuthorizeStopRequest.SessionId,
                                AuthorizeStopRequest.CPOPartnerSessionId,
                                AuthorizeStopRequest.EMPPartnerSessionId
                                );
                        }

                        #endregion

                        #region Send OnAuthorizeStopResponse event

                        var EndTime = DateTime.UtcNow;

                        try
                        {
                            if (OnAuthorizeStopResponse != null)
                            {
                                await Task.WhenAll(OnAuthorizeStopResponse.GetInvocationList().
                                                   Cast <OnAuthorizeStopResponseHandler>().
                                                   Select(e => e(EndTime,
                                                                 this,
                                                                 ServiceName,
                                                                 AuthorizeStopRequest.EventTrackingId,
                                                                 AuthorizeStopRequest.SessionId,
                                                                 AuthorizeStopRequest.CPOPartnerSessionId,
                                                                 AuthorizeStopRequest.EMPPartnerSessionId,
                                                                 AuthorizeStopRequest.OperatorId,
                                                                 AuthorizeStopRequest.EVSEId,
                                                                 AuthorizeStopRequest.Identification,
                                                                 AuthorizeStopRequest.RequestTimeout ?? DefaultRequestTimeout,
                                                                 AuthorizationStop,
                                                                 EndTime - StartTime))).
                                ConfigureAwait(false);
                            }
                        }
                        catch (Exception e)
                        {
                            e.Log(nameof(EMPSOAPServer) + "." + nameof(OnAuthorizeStopResponse));
                        }

                        #endregion
                    }

                    else
                    {
                        AuthorizationStop = CPO.AuthorizationStop.DataError(
                            AuthorizeStopRequest,
                            "Could not process the incoming AuthorizeStop request!"
                            );
                    }
                }
                catch (Exception e)
                {
                    AuthorizationStop = CPO.AuthorizationStop.DataError(
                        AuthorizeStopRequest,
                        e.Message,
                        e.StackTrace
                        );
                }


                #region Create SOAP response

                var HTTPResponse = new HTTPResponse.Builder(HTTPRequest)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server         = SOAPServer.HTTPServer.DefaultServerName,
                    Date           = DateTime.UtcNow,
                    ContentType    = HTTPContentType.XMLTEXT_UTF8,
                    Content        = SOAP.Encapsulation(AuthorizationStop.ToXML()).ToUTF8Bytes(),
                    Connection     = "close"
                };

                #endregion

                #region Send OnAuthorizeStopSOAPResponse event

                try
                {
                    if (OnAuthorizeStopSOAPResponse != null)
                    {
                        await Task.WhenAll(OnAuthorizeStopSOAPResponse.GetInvocationList().
                                           Cast <AccessLogHandler>().
                                           Select(e => e(HTTPResponse.Timestamp,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest,
                                                         HTTPResponse))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    e.Log(nameof(EMPSOAPServer) + "." + nameof(OnAuthorizeStopSOAPResponse));
                }

                #endregion

                return(HTTPResponse);
            });

            #endregion

            #region /Authorization - ChargeDetailRecord

            // curl -v -X POST --data "@../Testdata-UID-01.xml" -H "Content-Type: text/xml" -H "Accept: text/xml" http://127.0.0.1:3114/RNs/PROD/Authorization
            SOAPServer.RegisterSOAPDelegate(HTTPHostname.Any,
                                            URLPrefix + AuthorizationURL,
                                            "ChargeDetailRecord",
                                            XML => XML.Descendants(OICPNS.Authorization + "eRoamingChargeDetailRecord").FirstOrDefault(),
                                            async(HTTPRequest, ChargeDetailRecordXML) => {
                CPO.SendChargeDetailRecordRequest SendChargeDetailRecordRequest     = null;
                Acknowledgement <CPO.SendChargeDetailRecordRequest> Acknowledgement = null;

                #region Send OnChargeDetailRecordSOAPRequest event

                var StartTime = DateTime.UtcNow;

                try
                {
                    if (OnChargeDetailRecordSOAPRequest != null)
                    {
                        await Task.WhenAll(OnChargeDetailRecordSOAPRequest.GetInvocationList().
                                           Cast <RequestLogHandler>().
                                           Select(e => e(StartTime,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    e.Log(nameof(EMPSOAPServer) + "." + nameof(OnChargeDetailRecordSOAPRequest));
                }

                #endregion

                try
                {
                    if (CPO.SendChargeDetailRecordRequest.TryParse(ChargeDetailRecordXML,
                                                                   out SendChargeDetailRecordRequest,
                                                                   CustomChargeDetailRecordParser,
                                                                   CustomIdentificationParser,
                                                                   CustomRFIDIdentificationParser,
                                                                   OnException,

                                                                   HTTPRequest.Timestamp,
                                                                   HTTPRequest.CancellationToken,
                                                                   HTTPRequest.EventTrackingId,
                                                                   HTTPRequest.Timeout ?? DefaultRequestTimeout))
                    {
                        #region Send OnChargeDetailRecordRequest event

                        try
                        {
                            if (OnChargeDetailRecordRequest != null)
                            {
                                await Task.WhenAll(OnChargeDetailRecordRequest.GetInvocationList().
                                                   Cast <OnChargeDetailRecordRequestHandler>().
                                                   Select(e => e(StartTime,
                                                                 SendChargeDetailRecordRequest.Timestamp.Value,
                                                                 this,
                                                                 ServiceName,
                                                                 SendChargeDetailRecordRequest.EventTrackingId,
                                                                 SendChargeDetailRecordRequest.ChargeDetailRecord,
                                                                 SendChargeDetailRecordRequest.RequestTimeout ?? DefaultRequestTimeout))).
                                ConfigureAwait(false);
                            }
                        }
                        catch (Exception e)
                        {
                            e.Log(nameof(EMPSOAPServer) + "." + nameof(OnChargeDetailRecordRequest));
                        }

                        #endregion

                        #region Call async subscribers

                        if (OnChargeDetailRecord != null)
                        {
                            var results = await Task.WhenAll(OnChargeDetailRecord.GetInvocationList().
                                                             Cast <OnChargeDetailRecordDelegate>().
                                                             Select(e => e(DateTime.UtcNow,
                                                                           this,
                                                                           SendChargeDetailRecordRequest))).
                                          ConfigureAwait(false);

                            Acknowledgement = results.FirstOrDefault();
                        }

                        if (Acknowledgement == null)
                        {
                            Acknowledgement = Acknowledgement <CPO.SendChargeDetailRecordRequest> .SystemError(
                                null,
                                "Could not process the incoming SendChargeDetailRecordRequest request!",
                                null
                                );
                        }

                        #endregion

                        #region Send OnChargeDetailRecordResponse event

                        var EndTime = DateTime.UtcNow;

                        try
                        {
                            if (OnChargeDetailRecordResponse != null)
                            {
                                await Task.WhenAll(OnChargeDetailRecordResponse.GetInvocationList().
                                                   Cast <OnChargeDetailRecordResponseHandler>().
                                                   Select(e => e(EndTime,
                                                                 this,
                                                                 ServiceName,
                                                                 SendChargeDetailRecordRequest.EventTrackingId,
                                                                 SendChargeDetailRecordRequest.ChargeDetailRecord,
                                                                 SendChargeDetailRecordRequest.RequestTimeout ?? DefaultRequestTimeout,
                                                                 Acknowledgement,
                                                                 EndTime - StartTime))).
                                ConfigureAwait(false);
                            }
                        }
                        catch (Exception e)
                        {
                            e.Log(nameof(EMPSOAPServer) + "." + nameof(OnChargeDetailRecordResponse));
                        }

                        #endregion
                    }

                    else
                    {
                        Acknowledgement = Acknowledgement <CPO.SendChargeDetailRecordRequest> .DataError(
                            SendChargeDetailRecordRequest,
                            "Could not process the incoming SendChargeDetailRecord request!"
                            );
                    }
                }
                catch (Exception e)
                {
                    Acknowledgement = Acknowledgement <CPO.SendChargeDetailRecordRequest> .DataError(
                        SendChargeDetailRecordRequest,
                        e.Message,
                        e.StackTrace
                        );
                }


                #region Create SOAP response

                var HTTPResponse = new HTTPResponse.Builder(HTTPRequest)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server         = SOAPServer.HTTPServer.DefaultServerName,
                    Date           = DateTime.UtcNow,
                    ContentType    = HTTPContentType.XMLTEXT_UTF8,
                    Content        = SOAP.Encapsulation(Acknowledgement.ToXML()).ToUTF8Bytes(),
                    Connection     = "close"
                };

                #endregion

                #region Send OnChargeDetailRecordSOAPResponse event

                try
                {
                    if (OnChargeDetailRecordSOAPResponse != null)
                    {
                        await Task.WhenAll(OnChargeDetailRecordSOAPResponse.GetInvocationList().
                                           Cast <AccessLogHandler>().
                                           Select(e => e(HTTPResponse.Timestamp,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest,
                                                         HTTPResponse))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    e.Log(nameof(EMPSOAPServer) + "." + nameof(OnChargeDetailRecordSOAPResponse));
                }

                #endregion

                return(HTTPResponse);
            });

            #endregion
        }
예제 #7
0
        /// <summary>
        /// Convert the given enumeration of EVSE data records to XML.
        /// </summary>
        /// <param name="EVSEDataRecords">An enumeration of EVSE data records.</param>
        /// <param name="RoamingNetwork">The WWCP roaming network.</param>
        /// <param name="XMLNamespaces">An optional delegate to process the XML namespaces.</param>
        /// <param name="EVSEDataRecord2XML">An optional delegate to process an EVSE data record XML before sending it somewhere.</param>
        /// <param name="XMLPostProcessing">An optional delegate to process the XML after its final creation.</param>
        public static XElement ToXML(this IEnumerable <EVSEDataRecord> EVSEDataRecords,
                                     RoamingNetwork RoamingNetwork,
                                     XMLNamespacesDelegate XMLNamespaces = null,
                                     //EVSEDataRecord2XMLDelegate        EVSEDataRecord2XML  = null,
                                     XMLPostProcessingDelegate XMLPostProcessing = null)
        {
            #region Initial checks

            if (EVSEDataRecords == null)
            {
                throw new ArgumentNullException(nameof(EVSEDataRecords), "The given enumeration of EVSE data records must not be null!");
            }

            var _EVSEDataRecords = EVSEDataRecords.ToArray();

            //if (EVSEDataRecord2XML == null)
            //    EVSEDataRecord2XML = (evsedatarecord, xml) => xml;

            if (XMLPostProcessing == null)
            {
                XMLPostProcessing = xml => xml;
            }

            #endregion

            return(XMLPostProcessing(
                       SOAP.Encapsulation(new XElement(OICPNS.EVSEData + "eRoamingEvseData",
                                                       new XElement(OICPNS.EVSEData + "EvseData",

                                                                    _EVSEDataRecords.Any()

                                                      ? _EVSEDataRecords.
                                                                    ToLookup(evsedatarecord => evsedatarecord.Id.OperatorId).
                                                                    Select(group => group.Any(evsedatarecord => evsedatarecord != null)

                                                                       ? new XElement(OICPNS.EVSEData + "OperatorEvseData",

                                                                                      new XElement(OICPNS.EVSEData + "OperatorID", group.Key.ToString()),

                                                                                      RoamingNetwork.GetChargingStationOperatorById(group.Key.ToWWCP().Value).Name.Any()
                                                                                 ? new XElement(OICPNS.EVSEData + "OperatorName", RoamingNetwork.GetChargingStationOperatorById(group.Key.ToWWCP().Value).Name.FirstText())
                                                                                 : null,

                                                                                      new XElement(OICPPlusNS.EVSEOperator + "DataLicenses",
                                                                                                   RoamingNetwork.GetChargingStationOperatorById(group.Key.ToWWCP().Value).DataLicenses.
                                                                                                   SafeSelect(license => new XElement(OICPPlusNS.EVSEOperator + "DataLicense",
                                                                                                                                      new XElement(OICPPlusNS.EVSEOperator + "Id", license.Id),
                                                                                                                                      new XElement(OICPPlusNS.EVSEOperator + "Description", license.Description),
                                                                                                                                      license.URIs.Any()
                                                                                                                   ? new XElement(OICPPlusNS.EVSEOperator + "DataLicenseURIs",
                                                                                                                                  license.URIs.SafeSelect(uri => new XElement(OICPPlusNS.EVSEOperator + "DataLicenseURI", uri)))
                                                                                                                   : null
                                                                                                                                      ))
                                                                                                   ),

                                                                                      // <EvseDataRecord> ... </EvseDataRecord>
                                                                                      group.Where(evsedatarecord => evsedatarecord != null).
                                                                                      //Select(evsedatarecord => EVSEDataRecord2XML(evsedatarecord, evsedatarecord.ToXML())).
                                                                                      ToArray()

                                                                                      )

                                                                       : null

                                                                           ).ToArray()

                                                        : null

                                                                    )
                                                       ),
                                          XMLNamespaces)));
        }
예제 #8
0
 public void GetMinLevel()
 {
     if (root_device != null)
     {
         //searching sub devices for a dimming service
         SubDevice.Service dimming = root_device.GetServiceByType("urn:schemas-upnp-org:service:DimmingService:1");
         if (dimming != null)
         {
             Console.WriteLine("Found the wan ip connection service.");
             Console.WriteLine("service control url: " + url_base + dimming.ControlUrl);
             Console.WriteLine("service type: [" + dimming.ServiceType + "]");
             string soap_method = "GetMinLevel";
             string soap_body = "<?xml version=\"1.0\"?>\r\n";
             soap_body += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n";
             soap_body += "<s:Body>\r\n";
             soap_body += "<m:" + soap_method + " xmlns:m=\"" + dimming.ServiceType + "\">\r\n";
             soap_body += "</m:" + soap_method + ">\r\n";
             soap_body += "</s:Body>\r\n";
             soap_body += "</s:Envelope>\r\n";
             string soap_action = dimming.ServiceType + "#" + soap_method;
             SOAP soap = new SOAP(url_base + dimming.ControlUrl, soap_body, soap_action);
             soap.RequestFinished += delegate(SOAP request_finished_soap, bool request_successful)
             {
                 bool successful = false;
                 if (request_successful)
                 {
                     //Console.WriteLine("Soap Response: \n" + request_finished_soap.Response);
                     string[] seps = { "\r\n" };
                     string[] lines = request_finished_soap.Response.Split(seps, StringSplitOptions.RemoveEmptyEntries);
                     if (lines.Length > 0)
                     {
                         if (lines[0] == "HTTP/1.1 200 OK")
                         {
                             if (request_finished_soap.Response.IndexOf(soap_method + "Response") != -1)
                             {
                                 int load_level_start = request_finished_soap.Response.IndexOf("<MinLevel>");
                                 if (load_level_start != -1)
                                 {
                                     string load_level_string = request_finished_soap.Response.Substring(load_level_start + "<MinLevel>".Length);
                                     int load_level_end = load_level_string.IndexOf("</MinLevel>");
                                     if (load_level_end != -1)
                                     {
                                         load_level_string = load_level_string.Substring(0, load_level_end);
                                         try
                                         {
                                             load_level = Byte.Parse(load_level_string);
                                             successful = true;
                                         }
                                         catch (Exception ex)
                                         {
                                             Console.WriteLine("error parsing min level: " + ex.Message);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 else Console.WriteLine("Soap Request failed.");
                 if (GettingMinLevelCompleted != null)
                     GettingMinLevelCompleted(this, successful);
             };
             soap.StartRequest();
         }
     }
 }
예제 #9
0
        /// <summary>
        /// Register all URL templates for this SOAP API.
        /// </summary>
        protected void RegisterURLTemplates()
        {
            #region / - ReserveNow

            SOAPServer.RegisterSOAPDelegate(HTTPHostname.Any,
                                            URLPrefix,
                                            "ReserveNow",
                                            XML => XML.Descendants(OCPPNS.OCPPv1_6_CP + "reserveNowRequest").FirstOrDefault(),
                                            async(Request, HeaderXML, ReserveNowXML) => {
                #region Send OnReserveNowSOAPRequest event

                try
                {
                    OnReserveNowSOAPRequest?.Invoke(DateTime.UtcNow,
                                                    this.SOAPServer.HTTPServer,
                                                    Request);
                }
                catch (Exception e)
                {
                    e.Log(nameof(ChargePointSOAPServer) + "." + nameof(OnReserveNowSOAPRequest));
                }

                #endregion


                var _OCPPHeader        = SOAPHeader.Parse(HeaderXML);
                var _ReserveNowRequest = ReserveNowRequest.Parse(ReserveNowXML,
                                                                 Request_Id.Parse(_OCPPHeader.MessageId),
                                                                 _OCPPHeader.ChargeBoxIdentity);

                ReserveNowResponse response = null;



                #region Call async subscribers

                if (response == null)
                {
                    var results = OnReserveNowRequest?.
                                  GetInvocationList()?.
                                  SafeSelect(subscriber => (subscriber as OnReserveNowDelegate)
                                                 (DateTime.UtcNow,
                                                 this,
                                                 Request.CancellationToken,
                                                 Request.EventTrackingId,
                                                 _OCPPHeader.ChargeBoxIdentity,
                                                 _ReserveNowRequest.ConnectorId,
                                                 _ReserveNowRequest.ReservationId,
                                                 _ReserveNowRequest.ExpiryDate,
                                                 _ReserveNowRequest.IdTag,
                                                 _ReserveNowRequest.ParentIdTag,
                                                 DefaultRequestTimeout)).
                                  ToArray();

                    if (results.Length > 0)
                    {
                        await Task.WhenAll(results);

                        response = results.FirstOrDefault()?.Result;
                    }

                    if (results.Length == 0 || response == null)
                    {
                        response = ReserveNowResponse.Failed(_ReserveNowRequest);
                    }
                }

                #endregion



                #region Create SOAPResponse

                var HTTPResponse = new HTTPResponse.Builder(Request)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server         = SOAPServer.HTTPServer.DefaultServerName,
                    Date           = DateTime.UtcNow,
                    ContentType    = HTTPContentType.XMLTEXT_UTF8,
                    Content        = SOAP.Encapsulation(_OCPPHeader.ChargeBoxIdentity,
                                                        "/ReserveNowResponse",
                                                        null,
                                                        _OCPPHeader.MessageId,   // MessageId from the request as RelatesTo Id
                                                        _OCPPHeader.To,          // Fake it!
                                                        _OCPPHeader.From,        // Fake it!
                                                        response.ToXML()).ToUTF8Bytes()
                };

                #endregion


                #region Send OnReserveNowSOAPResponse event

                try
                {
                    OnReserveNowSOAPResponse?.Invoke(HTTPResponse.Timestamp,
                                                     this.SOAPServer.HTTPServer,
                                                     Request,
                                                     HTTPResponse);
                }
                catch (Exception e)
                {
                    e.Log(nameof(ChargePointSOAPServer) + "." + nameof(OnReserveNowSOAPResponse));
                }

                #endregion

                return(HTTPResponse);
            });

            #endregion

            #region / - CancelReservation

            SOAPServer.RegisterSOAPDelegate(HTTPHostname.Any,
                                            URLPrefix,
                                            "CancelReservation",
                                            XML => XML.Descendants(OCPPNS.OCPPv1_6_CP + "cancelReservationRequest").FirstOrDefault(),
                                            async(Request, HeaderXML, CancelReservationXML) => {
                #region Send OnCancelReservationSOAPRequest event

                try
                {
                    OnCancelReservationSOAPRequest?.Invoke(DateTime.UtcNow,
                                                           this.SOAPServer.HTTPServer,
                                                           Request);
                }
                catch (Exception e)
                {
                    e.Log(nameof(ChargePointSOAPServer) + "." + nameof(OnCancelReservationSOAPRequest));
                }

                #endregion


                var _OCPPHeader = SOAPHeader.Parse(HeaderXML);
                var _CancelReservationRequest = CancelReservationRequest.Parse(CancelReservationXML,
                                                                               Request_Id.Parse(_OCPPHeader.MessageId),
                                                                               _OCPPHeader.ChargeBoxIdentity);

                CancelReservationResponse response = null;



                #region Call async subscribers

                if (response == null)
                {
                    var results = OnCancelReservationRequest?.
                                  GetInvocationList()?.
                                  SafeSelect(subscriber => (subscriber as OnCancelReservationDelegate)
                                                 (DateTime.UtcNow,
                                                 this,
                                                 Request.CancellationToken,
                                                 Request.EventTrackingId,
                                                 _OCPPHeader.ChargeBoxIdentity,
                                                 _CancelReservationRequest.ReservationId,
                                                 DefaultRequestTimeout)).
                                  ToArray();

                    if (results.Length > 0)
                    {
                        await Task.WhenAll(results);

                        response = results.FirstOrDefault()?.Result;
                    }

                    if (results.Length == 0 || response == null)
                    {
                        response = CancelReservationResponse.Failed(_CancelReservationRequest);
                    }
                }

                #endregion



                #region Create SOAPResponse

                var HTTPResponse = new HTTPResponse.Builder(Request)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server         = SOAPServer.HTTPServer.DefaultServerName,
                    Date           = DateTime.UtcNow,
                    ContentType    = HTTPContentType.XMLTEXT_UTF8,
                    Content        = SOAP.Encapsulation(_OCPPHeader.ChargeBoxIdentity,
                                                        "/CancelReservationResponse",
                                                        null,
                                                        _OCPPHeader.MessageId,   // MessageId from the request as RelatesTo Id
                                                        _OCPPHeader.To,          // Fake it!
                                                        _OCPPHeader.From,        // Fake it!
                                                        response.ToXML()).ToUTF8Bytes()
                };

                #endregion


                #region Send OnCancelReservationSOAPResponse event

                try
                {
                    OnCancelReservationSOAPResponse?.Invoke(HTTPResponse.Timestamp,
                                                            this.SOAPServer.HTTPServer,
                                                            Request,
                                                            HTTPResponse);
                }
                catch (Exception e)
                {
                    e.Log(nameof(ChargePointSOAPServer) + "." + nameof(OnCancelReservationSOAPResponse));
                }

                #endregion

                return(HTTPResponse);
            });

            #endregion

            #region / - RemoteStartTransaction

            SOAPServer.RegisterSOAPDelegate(HTTPHostname.Any,
                                            URLPrefix,
                                            "RemoteStartTransaction",
                                            XML => XML.Descendants(OCPPNS.OCPPv1_6_CP + "remoteStartTransactionRequest").FirstOrDefault(),
                                            async(Request, HeaderXML, RemoteStartTransactionXML) => {
                #region Send OnRemoteStartTransactionSOAPRequest event

                try
                {
                    OnRemoteStartTransactionSOAPRequest?.Invoke(DateTime.UtcNow,
                                                                this.SOAPServer.HTTPServer,
                                                                Request);
                }
                catch (Exception e)
                {
                    e.Log(nameof(ChargePointSOAPServer) + "." + nameof(OnRemoteStartTransactionSOAPRequest));
                }

                #endregion


                var _OCPPHeader = SOAPHeader.Parse(HeaderXML);
                var _RemoteStartTransactionRequest = RemoteStartTransactionRequest.Parse(RemoteStartTransactionXML,
                                                                                         Request_Id.Parse(_OCPPHeader.MessageId),
                                                                                         _OCPPHeader.ChargeBoxIdentity);

                RemoteStartTransactionResponse response = null;



                #region Call async subscribers

                if (response == null)
                {
                    var results = OnRemoteStartTransaction?.
                                  GetInvocationList()?.
                                  SafeSelect(subscriber => (subscriber as OnRemoteStartTransactionDelegate)
                                                 (DateTime.UtcNow,
                                                 this,
                                                 Request.CancellationToken,
                                                 Request.EventTrackingId,
                                                 //_OCPPHeader.ChargeBoxIdentity,
                                                 _RemoteStartTransactionRequest)).
                                  ToArray();

                    if (results.Length > 0)
                    {
                        await Task.WhenAll(results);

                        response = results.FirstOrDefault()?.Result;
                    }

                    if (results.Length == 0 || response == null)
                    {
                        response = RemoteStartTransactionResponse.Failed(_RemoteStartTransactionRequest);
                    }
                }

                #endregion



                #region Create SOAPResponse

                var HTTPResponse = new HTTPResponse.Builder(Request)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server         = SOAPServer.HTTPServer.DefaultServerName,
                    Date           = DateTime.UtcNow,
                    ContentType    = HTTPContentType.XMLTEXT_UTF8,
                    Content        = SOAP.Encapsulation(_OCPPHeader.ChargeBoxIdentity,
                                                        "/RemoteStartTransactionResponse",
                                                        NextMessageId(),
                                                        _OCPPHeader.MessageId,   // MessageId from the request as RelatesTo Id
                                                        _OCPPHeader.To,          // Fake it!
                                                        _OCPPHeader.From,        // Fake it!
                                                        response.ToXML()).ToUTF8Bytes()
                };

                #endregion


                #region Send OnRemoteStartTransactionSOAPResponse event

                try
                {
                    OnRemoteStartTransactionSOAPResponse?.Invoke(HTTPResponse.Timestamp,
                                                                 this.SOAPServer.HTTPServer,
                                                                 Request,
                                                                 HTTPResponse);
                }
                catch (Exception e)
                {
                    e.Log(nameof(ChargePointSOAPServer) + "." + nameof(OnRemoteStartTransactionSOAPResponse));
                }

                #endregion

                return(HTTPResponse);
            });

            #endregion

            #region / - RemoteStopTransaction

            SOAPServer.RegisterSOAPDelegate(HTTPHostname.Any,
                                            URLPrefix,
                                            "RemoteStopTransaction",
                                            XML => XML.Descendants(OCPPNS.OCPPv1_6_CP + "remoteStopTransactionRequest").FirstOrDefault(),
                                            async(Request, HeaderXML, RemoteStopTransactionXML) => {
                #region Send OnRemoteStopTransactionSOAPRequest event

                try
                {
                    OnRemoteStopTransactionSOAPRequest?.Invoke(DateTime.UtcNow,
                                                               this.SOAPServer.HTTPServer,
                                                               Request);
                }
                catch (Exception e)
                {
                    e.Log(nameof(ChargePointSOAPServer) + "." + nameof(OnRemoteStopTransactionSOAPRequest));
                }

                #endregion


                var _OCPPHeader = SOAPHeader.Parse(HeaderXML);
                var _RemoteStopTransactionRequest = RemoteStopTransactionRequest.Parse(RemoteStopTransactionXML,
                                                                                       Request_Id.Parse(_OCPPHeader.MessageId),
                                                                                       _OCPPHeader.ChargeBoxIdentity);

                RemoteStopTransactionResponse response = null;



                #region Call async subscribers

                if (response == null)
                {
                    var results = OnRemoteStopTransaction?.
                                  GetInvocationList()?.
                                  SafeSelect(subscriber => (subscriber as OnRemoteStopTransactionDelegate)
                                                 (DateTime.UtcNow,
                                                 this,
                                                 Request.CancellationToken,
                                                 Request.EventTrackingId,
                                                 //_OCPPHeader.ChargeBoxIdentity,
                                                 _RemoteStopTransactionRequest)).
                                  ToArray();

                    if (results.Length > 0)
                    {
                        await Task.WhenAll(results);

                        response = results.FirstOrDefault()?.Result;
                    }

                    if (results.Length == 0 || response == null)
                    {
                        response = RemoteStopTransactionResponse.Failed(_RemoteStopTransactionRequest);
                    }
                }

                #endregion



                #region Create SOAPResponse

                var HTTPResponse = new HTTPResponse.Builder(Request)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server         = SOAPServer.HTTPServer.DefaultServerName,
                    Date           = DateTime.UtcNow,
                    ContentType    = HTTPContentType.XMLTEXT_UTF8,
                    Content        = SOAP.Encapsulation(_OCPPHeader.ChargeBoxIdentity,
                                                        "/RemoteStopTransactionResponse",
                                                        null,
                                                        _OCPPHeader.MessageId,   // MessageId from the request as RelatesTo Id
                                                        _OCPPHeader.To,          // Fake it!
                                                        _OCPPHeader.From,        // Fake it!
                                                        response.ToXML()).ToUTF8Bytes()
                };

                #endregion


                #region Send OnRemoteStopTransactionSOAPResponse event

                try
                {
                    OnRemoteStopTransactionSOAPResponse?.Invoke(HTTPResponse.Timestamp,
                                                                this.SOAPServer.HTTPServer,
                                                                Request,
                                                                HTTPResponse);
                }
                catch (Exception e)
                {
                    e.Log(nameof(ChargePointSOAPServer) + "." + nameof(OnRemoteStopTransactionSOAPResponse));
                }

                #endregion

                return(HTTPResponse);
            });

            #endregion


            #region / - DataTransfer

            SOAPServer.RegisterSOAPDelegate(HTTPHostname.Any,
                                            URLPrefix,
                                            "DataTransfer",
                                            XML => XML.Descendants(OCPPNS.OCPPv1_6_CP + "dataTransferRequest").FirstOrDefault(),
                                            async(Request, HeaderXML, DataTransferXML) => {
                #region Send OnDataTransferSOAPRequest event

                try
                {
                    OnDataTransferSOAPRequest?.Invoke(DateTime.UtcNow,
                                                      this.SOAPServer.HTTPServer,
                                                      Request);
                }
                catch (Exception e)
                {
                    e.Log(nameof(ChargePointSOAPServer) + "." + nameof(OnDataTransferSOAPRequest));
                }

                #endregion


                var _OCPPHeader          = SOAPHeader.Parse(HeaderXML);
                var _DataTransferRequest = CS.DataTransferRequest.Parse(DataTransferXML,
                                                                        Request_Id.Parse(_OCPPHeader.MessageId),
                                                                        _OCPPHeader.ChargeBoxIdentity);

                CP.DataTransferResponse response = null;



                #region Call async subscribers

                if (response == null)
                {
                    var results = OnDataTransferRequest?.
                                  GetInvocationList()?.
                                  SafeSelect(subscriber => (subscriber as OnDataTransferDelegate)
                                                 (DateTime.UtcNow,
                                                 this,
                                                 Request.CancellationToken,
                                                 Request.EventTrackingId,
                                                 _OCPPHeader.ChargeBoxIdentity,
                                                 _DataTransferRequest.VendorId,
                                                 _DataTransferRequest.MessageId,
                                                 _DataTransferRequest.Data,
                                                 DefaultRequestTimeout)).
                                  ToArray();

                    if (results.Length > 0)
                    {
                        await Task.WhenAll(results);

                        response = results.FirstOrDefault()?.Result;
                    }

                    if (results.Length == 0 || response == null)
                    {
                        response = DataTransferResponse.Failed(_DataTransferRequest);
                    }
                }

                #endregion



                #region Create SOAPResponse

                var HTTPResponse = new HTTPResponse.Builder(Request)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server         = SOAPServer.HTTPServer.DefaultServerName,
                    Date           = DateTime.UtcNow,
                    ContentType    = HTTPContentType.XMLTEXT_UTF8,
                    Content        = SOAP.Encapsulation(_OCPPHeader.ChargeBoxIdentity,
                                                        "/DataTransferResponse",
                                                        null,
                                                        _OCPPHeader.MessageId,   // MessageId from the request as RelatesTo Id
                                                        _OCPPHeader.To,          // Fake it!
                                                        _OCPPHeader.From,        // Fake it!
                                                        response.ToXML()).ToUTF8Bytes()
                };

                #endregion


                #region Send OnDataTransferSOAPResponse event

                try
                {
                    OnDataTransferSOAPResponse?.Invoke(HTTPResponse.Timestamp,
                                                       this.SOAPServer.HTTPServer,
                                                       Request,
                                                       HTTPResponse);
                }
                catch (Exception e)
                {
                    e.Log(nameof(ChargePointSOAPServer) + "." + nameof(OnDataTransferSOAPResponse));
                }

                #endregion

                return(HTTPResponse);
            });

            #endregion
        }
예제 #10
0
            public void CheckForExistingPortMapping(PortMapping pm)
            {
                if (pm.Protocol != "TCP" && pm.Protocol != "UDP")
                   PortMappingCheckCompleted(this, pm,false, false);

                if (root_device != null)
                {
                    //searching sub devices for a wan ip connections service
                    SubDevice.Service wan_ip_connection = root_device.GetServiceByType("urn:schemas-upnp-org:service:WANIPConnection:1");
                    if (wan_ip_connection != null)
                    {
                        Console.WriteLine("Found the wan ip connection service.");
                        Console.WriteLine("service control url: " + url_base + wan_ip_connection.ControlUrl);
                        Console.WriteLine("service type: [" + wan_ip_connection.ServiceType + "]");
                        string soap_method = "GetSpecificPortMappingEntry";
                        string soap_body = "<?xml version=\"1.0\"?>\r\n";
                        soap_body += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n";
                        soap_body += "<s:Body>\r\n";
                        soap_body += "<m:" + soap_method + " xmlns:m=\"" + wan_ip_connection.ServiceType + "\">\r\n";
                        soap_body += "<NewRemoteHost>" + pm.RemoteHost + "</NewRemoteHost>";
                        soap_body += "<NewExternalPort>" + pm.ExternalPort + "</NewExternalPort>";
                        soap_body += "<NewProtocol>" + pm.Protocol + "</NewProtocol>";
                        soap_body += "</m:" + soap_method + ">\r\n";
                        soap_body += "</s:Body>\r\n";
                        soap_body += "</s:Envelope>\r\n";
                        string soap_action = wan_ip_connection.ServiceType + "#" + soap_method;
                        SOAP soap = new SOAP(url_base + wan_ip_connection.ControlUrl, soap_body, soap_action);
                        soap.RequestFinished += delegate(SOAP request_finished_soap, bool request_successful)
                        {
                            bool successful = false;
                            bool exists = false;
                            if (request_successful)
                            {
                                //Console.WriteLine("Soap Response: \n" + request_finished_soap.Response);
                                string[] seps = { "\r\n" };
                                string[] lines = request_finished_soap.Response.Split(seps, StringSplitOptions.RemoveEmptyEntries);
                                if (lines.Length > 0)
                                {
                                    if (lines[0] == "HTTP/1.1 200 OK")
                                    {
                                        if (request_finished_soap.Response.IndexOf(soap_method + "Response") != -1)
                                        {
                                            int values_found = 0;
                                            string internal_port = "0";
                                            int internal_port_start = request_finished_soap.Response.IndexOf("<NewInternalPort>");
                                            if (internal_port_start != -1)
                                            {
                                                internal_port = request_finished_soap.Response.Substring(internal_port_start + "<NewInternalPort>".Length);
                                                int internal_port_end = internal_port.IndexOf("</NewInternalPort>");
                                                if (internal_port_end != -1)
                                                {
                                                    internal_port = internal_port.Substring(0, internal_port_end);
                                                    values_found++;
                                                }
                                            }
                                            try
                                            {
                                                pm.InternalPort = int.Parse(internal_port);
                                            }
                                            catch (Exception ex)
                                            {
                                                Console.WriteLine("error parsing internal port: "+ex.Message);
                                            }
                                            int internal_client_start = request_finished_soap.Response.IndexOf("<NewInternalClient>");
                                            if (internal_client_start != -1)
                                            {
                                                pm.InternalClient = request_finished_soap.Response.Substring(internal_client_start + "<NewInternalClient>".Length);
                                                int internal_client_end = pm.InternalClient.IndexOf("</NewInternalClient>");
                                                if (internal_client_end != -1)
                                                {
                                                    pm.InternalClient = pm.InternalClient.Substring(0, internal_client_end);
                                                    values_found++;
                                                }
                                            }
                                            string enabled = "0";
                                            int enabled_start = request_finished_soap.Response.IndexOf("<NewEnabled>");
                                            if (enabled_start != -1)
                                            {
                                                enabled = request_finished_soap.Response.Substring(enabled_start + "<NewEnabled>".Length);
                                                int enabled_end = enabled.IndexOf("</NewEnabled>");
                                                if (enabled_end != -1)
                                                {
                                                    enabled = enabled.Substring(0, enabled_end);
                                                    values_found++;
                                                }
                                            }
                                            if (enabled == "1")
                                                pm.Enabled = true;
                                            else pm.Enabled = false;

                                            int description_start = request_finished_soap.Response.IndexOf("<NewPortMappingDescription>");
                                            if (description_start != -1)
                                            {
                                                pm.Description = request_finished_soap.Response.Substring(description_start + "<NewPortMappingDescription>".Length);
                                                int description_end = pm.Description.IndexOf("</NewPortMappingDescription>");
                                                if (description_end != -1)
                                                {
                                                    pm.Description = pm.Description.Substring(0, description_end);
                                                    values_found++;
                                                }
                                            }

                                            string lease_duration = "0";
                                            int lease_duration_start = request_finished_soap.Response.IndexOf("<NewLeaseDuration>");
                                            if (lease_duration_start != -1)
                                            {
                                                lease_duration = request_finished_soap.Response.Substring(lease_duration_start + "<NewLeaseDuration>".Length);
                                                int lease_duration_end = lease_duration.IndexOf("</NewLeaseDuration>");
                                                if (lease_duration_end != -1)
                                                {
                                                    lease_duration = lease_duration.Substring(0, lease_duration_end);
                                                    values_found++;
                                                }
                                            }
                                            try
                                            {
                                                pm.LeaseDuration = int.Parse(lease_duration);
                                            }
                                            catch (Exception ex)
                                            {
                                                Console.WriteLine("error parsing lease duration: " + ex.Message);
                                            }

                                            if (values_found == 5) exists = true;

                                        }
                                    }
                                }
                                successful = true;
                            }
                            else Console.WriteLine("Soap Request failed.");
                            if (PortMappingCheckCompleted != null)
                                PortMappingCheckCompleted(this, pm,exists, successful);
                        };
                        soap.StartRequest();

                    }
                }
            }
예제 #11
0
            public void AddPortMapping(PortMapping pm)
            {
                if (pm.Protocol != "TCP" && pm.Protocol != "UDP")
                    AddingPortMappingCompleted(this, pm, false);

                if (root_device != null)
                {
                    //searching sub devices for a wan ip connections service
                    SubDevice.Service wan_ip_connection = root_device.GetServiceByType("urn:schemas-upnp-org:service:WANIPConnection:1");
                    if (wan_ip_connection != null)
                    {
                        Console.WriteLine("Found the wan ip connection service.");
                        Console.WriteLine("service control url: " + url_base + wan_ip_connection.ControlUrl);
                        Console.WriteLine("service type: [" + wan_ip_connection.ServiceType + "]");
                        string soap_method = "AddPortMapping";
                        string soap_body = "<?xml version=\"1.0\"?>\r\n";
                        soap_body += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n";
                        soap_body += "<s:Body>\r\n";
                        soap_body += "<m:" + soap_method + " xmlns:m=\"" + wan_ip_connection.ServiceType + "\">\r\n";
                        soap_body += "<NewRemoteHost>" + pm.RemoteHost + "</NewRemoteHost>";
                        soap_body += "<NewExternalPort>" + pm.ExternalPort + "</NewExternalPort>";
                        soap_body += "<NewInternalClient>" + pm.InternalClient + "</NewInternalClient>";
                        soap_body += "<NewProtocol>" + pm.Protocol + "</NewProtocol>";
                        soap_body += "<NewInternalPort>" + pm.InternalPort + "</NewInternalPort>";
                        if (pm.Enabled)
                            soap_body += "<NewEnabled>1</NewEnabled>";
                        else soap_body += "<NewEnabled>0</NewEnabled>";
                        soap_body += "<NewPortMappingDescription>" + pm.Description + "</NewPortMappingDescription>";
                        soap_body += "<NewLeaseDuration>" + pm.LeaseDuration + "</NewLeaseDuration>";
                        soap_body += "</m:" + soap_method + ">\r\n";
                        soap_body += "</s:Body>\r\n";
                        soap_body += "</s:Envelope>\r\n";
                        string soap_action = wan_ip_connection.ServiceType + "#" + soap_method;
                        SOAP soap = new SOAP(url_base + wan_ip_connection.ControlUrl, soap_body, soap_action);
                        soap.RequestFinished += delegate(SOAP request_finished_soap, bool request_successful)
                        {
                            bool successful = false;
                            if (request_successful)
                            {
                                //Console.WriteLine("Soap Response: \n" + request_finished_soap.Response);
                                string[] seps = { "\r\n" };
                                string[] lines = request_finished_soap.Response.Split(seps, StringSplitOptions.RemoveEmptyEntries);
                                if (lines.Length > 0)
                                {
                                    if (lines[0] == "HTTP/1.1 200 OK")
                                    {
                                        if (request_finished_soap.Response.IndexOf(soap_method + "Response") != -1)
                                        {
                                            successful = true;
                                        }
                                    }
                                }
                            }
                            else Console.WriteLine("Soap Request failed.");
                            if (AddingPortMappingCompleted != null)
                                AddingPortMappingCompleted(this, pm, successful);
                        };
                        soap.StartRequest();

                    }
                }
            }
예제 #12
0
            public void SetPlaybackUrl(string playback_url)
            {
                if (root_device != null)
                {
                    //searching sub devices for a av transport service
                    SubDevice.Service transport = root_device.GetServiceByType("urn:schemas-upnp-org:service:AVTransport:1");
                    if (transport != null)
                    {
                        Console.WriteLine("Found the av transport service.");
                        Console.WriteLine("service control url: " + url_base + transport.ControlUrl);
                        Console.WriteLine("service type: [" + transport.ServiceType + "]");
                        string soap_method = "SetAVTransportURI";
                        string soap_body = "<?xml version=\"1.0\"?>\r\n";
                        soap_body += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n";
                        soap_body += "<s:Body>\r\n";
                        soap_body += "<m:" + soap_method + " xmlns:m=\"" + transport.ServiceType + "\">\r\n";
                        soap_body += "<InstanceID>0</InstanceID>";
                        soap_body += "<CurrentURI>" + playback_url + "</CurrentURI>";
                        soap_body += "<CurrentURIMetaData></CurrentURIMetaData>";
                        soap_body += "</m:" + soap_method + ">\r\n";
                        soap_body += "</s:Body>\r\n";
                        soap_body += "</s:Envelope>\r\n";
                        string soap_action = transport.ServiceType + "#" + soap_method;
                        SOAP soap = new SOAP(url_base + transport.ControlUrl, soap_body, soap_action);
                        soap.RequestFinished += delegate(SOAP request_finished_soap, bool request_successful)
                        {
                            bool successful = false;
                            if (request_successful)
                            {
                                //Console.WriteLine("Soap Response: \n" + request_finished_soap.Response);
                                string[] seps = { "\r\n" };
                                string[] lines = request_finished_soap.Response.Split(seps, StringSplitOptions.RemoveEmptyEntries);
                                if (lines.Length > 0)
                                {
                                    if (lines[0] == "HTTP/1.1 200 OK")
                                    {
                                        if (request_finished_soap.Response.IndexOf(soap_method + "Response") != -1)
                                        {
                                            successful = true;
                                        }
                                    }
                                }
                            }
                            else Console.WriteLine("Soap Request failed.");
                            if (SettingPlaybackUrlCompleted != null)
                                SettingPlaybackUrlCompleted(this, successful);
                        };
                        soap.StartRequest();

                    }
                }
            }
예제 #13
0
            public void SwitchPower(PowerStates state)
            {
                if (root_device != null)
                {
                    //searching sub devices for power switching service
                    SubDevice.Service power_switch = root_device.GetServiceByType("urn:schemas-upnp-org:service:SwitchPower:1");
                    if (power_switch != null)
                    {
                        Console.WriteLine("Found the power switch service.");
                        Console.WriteLine("service control url: " + url_base + power_switch.ControlUrl);
                        Console.WriteLine("service type: [" + power_switch.ServiceType + "]");
                        string soap_method = "SetTarget";
                        string soap_body = "<?xml version=\"1.0\"?>\r\n";
                        soap_body += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n";
                        soap_body += "<s:Body>\r\n";
                        soap_body += "<m:" + soap_method + " xmlns:m=\"" + power_switch.ServiceType + "\">\r\n";
                        if (state == PowerStates.On)
                            soap_body += "<newTargetValue>1</newTargetValue>";
                        else soap_body += "<newTargetValue>0</newTargetValue>";
                        soap_body += "</m:" + soap_method + ">\r\n";
                        soap_body += "</s:Body>\r\n";
                        soap_body += "</s:Envelope>\r\n";
                        string soap_action = power_switch.ServiceType + "#" + soap_method;
                        SOAP soap = new SOAP(url_base + power_switch.ControlUrl, soap_body, soap_action);
                        soap.RequestFinished += delegate(SOAP request_finished_soap, bool request_successful)
                        {
                            bool successful = false;
                            if (request_successful)
                            {
                                //Console.WriteLine("Soap Response: \n" + request_finished_soap.Response);
                                string[] seps = { "\r\n" };
                                string[] lines = request_finished_soap.Response.Split(seps, StringSplitOptions.RemoveEmptyEntries);
                                if (lines.Length > 0)
                                {
                                    if (lines[0] == "HTTP/1.1 200 OK")
                                    {
                                        if (request_finished_soap.Response.IndexOf(soap_method + "Response") != -1)
                                        {
                                            successful = true;
                                            status = state;
                                        }
                                    }
                                }
                            }
                            else Console.WriteLine("Soap Request failed.");
                            if (SwitchingPowerCompleted != null)
                                SwitchingPowerCompleted(this, successful);
                        };
                        soap.StartRequest();

                    }
                }
            }
예제 #14
0
            public void SetLoadLevel(byte level)
            {
                if (root_device != null)
                {
                    //searching sub devices for dimming service
                    SubDevice.Service dimming = root_device.GetServiceByType("urn:schemas-upnp-org:service:DimmingService:1");
                    if (dimming != null)
                    {
                        Console.WriteLine("Found the dimming service.");
                        Console.WriteLine("service control url: " + url_base + dimming.ControlUrl);
                        Console.WriteLine("service type: [" + dimming.ServiceType + "]");
                        string soap_method = "SetLoadLevelTarget";
                        string soap_body = "<?xml version=\"1.0\"?>\r\n";
                        soap_body += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n";
                        soap_body += "<s:Body>\r\n";
                        soap_body += "<m:" + soap_method + " xmlns:m=\"" + dimming.ServiceType + "\">\r\n";
                        soap_body += "<NewLoadLevelTarget>"+level.ToString()+"</NewLoadLevelTarget>";
                        soap_body += "</m:" + soap_method + ">\r\n";
                        soap_body += "</s:Body>\r\n";
                        soap_body += "</s:Envelope>\r\n";
                        string soap_action = dimming.ServiceType + "#" + soap_method;
                        SOAP soap = new SOAP(url_base + dimming.ControlUrl, soap_body, soap_action);
                        soap.RequestFinished += delegate(SOAP request_finished_soap, bool request_successful)
                        {
                            bool successful = false;
                            if (request_successful)
                            {
                                //Console.WriteLine("Soap Response: \n" + request_finished_soap.Response);
                                string[] seps = { "\r\n" };
                                string[] lines = request_finished_soap.Response.Split(seps, StringSplitOptions.RemoveEmptyEntries);
                                if (lines.Length > 0)
                                {
                                    if (lines[0] == "HTTP/1.1 200 OK")
                                    {
                                        if (request_finished_soap.Response.IndexOf(soap_method + "Response") != -1)
                                        {
                                            successful = true;
                                            load_level = level;
                                        }
                                    }
                                }
                            }
                            else Console.WriteLine("Soap Request failed.");
                            if (SettingLoadLevelCompleted != null)
                                SettingLoadLevelCompleted(this, successful);
                        };
                        soap.StartRequest();

                    }
                }
            }
예제 #15
0
            public void GetStatus()
            {
                if (root_device != null)
                {
                    //searching sub devices for a power switching service
                    SubDevice.Service power_switch = root_device.GetServiceByType("urn:schemas-upnp-org:service:SwitchPower:1");
                    if (power_switch != null)
                    {
                        Console.WriteLine("Found the power switch service.");
                        Console.WriteLine("service control url: " + url_base + power_switch.ControlUrl);
                        Console.WriteLine("service type: [" + power_switch.ServiceType + "]");
                        string soap_method = "GetStatus";
                        string soap_body = "<?xml version=\"1.0\"?>\r\n";
                        soap_body += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n";
                        soap_body += "<s:Body>\r\n";
                        soap_body += "<m:" + soap_method + " xmlns:m=\"" + power_switch.ServiceType + "\">\r\n";
                        soap_body += "</m:" + soap_method + ">\r\n";
                        soap_body += "</s:Body>\r\n";
                        soap_body += "</s:Envelope>\r\n";
                        string soap_action = power_switch.ServiceType + "#" + soap_method;
                        SOAP soap = new SOAP(url_base + power_switch.ControlUrl, soap_body, soap_action);
                        soap.RequestFinished += delegate(SOAP request_finished_soap, bool request_successful)
                        {
                            bool successful = false;
                            if (request_successful)
                            {
                                //TODO ===||
                                //        \/
                                //XmlNamespaceManager nsMgr = new XmlNamespaceManager(myXmlDoc.NameTable);
                                //nsMgr.AddNamespace("s", "http://schemas.xmlsoap.org/soap/envelope/");
                                //nsMgr.AddNamespace("m", power_switch.ServiceType);
                                //XmlNode urlNodes = doc.SelectNodes("/s:Body/s:m");
                                //Console.WriteLine("Soap Response: \n" + request_finished_soap.Response);
                                string[] seps = { "\r\n" };
                                string[] lines = request_finished_soap.Response.Split(seps, StringSplitOptions.RemoveEmptyEntries);
                                if (lines.Length > 0)
                                {
                                    if (lines[0] == "HTTP/1.1 200 OK")
                                    {
                                        if (request_finished_soap.Response.IndexOf(soap_method + "Response") != -1)
                                        {
                                            int stats_start = request_finished_soap.Response.IndexOf("<ResultStatus>");
                                            if (stats_start != -1)
                                            {
                                                string status_string = request_finished_soap.Response.Substring(stats_start + "<ResultStatus>".Length);
                                                int status_end = status_string.IndexOf("</ResultStatus>");
                                                if (status_end != -1)
                                                {
                                                    status_string = status_string.Substring(0, status_end);
                                                    if (status_string == "1")
                                                        status = PowerStates.On;
                                                    else status = PowerStates.Off;

                                                    successful = true;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else Console.WriteLine("Soap Request failed.");
                            if (GettingStatusCompleted != null)
                                GettingStatusCompleted(this, successful);
                        };
                        soap.StartRequest();
                    }
                }
            }
예제 #16
0
 public void RequestConnection()
 {
     if (root_device != null)
     {
         //searching sub devices for a wan ip connections service
         SubDevice.Service wan_ip_connection = root_device.GetServiceByType("urn:schemas-upnp-org:service:WANIPConnection:1");
         if (wan_ip_connection != null)
         {
             Console.WriteLine("Found the wan ip connection service.");
             Console.WriteLine("service control url: " + url_base + wan_ip_connection.ControlUrl);
             Console.WriteLine("service type: [" + wan_ip_connection.ServiceType + "]");
             string soap_method = "RequestConnection";
             string soap_body = "<?xml version=\"1.0\"?>\r\n";
             soap_body += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n";
             soap_body += "<s:Body>\r\n";
             soap_body += "<m:" + soap_method + " xmlns:m=\"" + wan_ip_connection.ServiceType + "\">\r\n";
             soap_body += "</m:" + soap_method + ">\r\n";
             soap_body += "</s:Body>\r\n";
             soap_body += "</s:Envelope>\r\n";
             string soap_action = wan_ip_connection.ServiceType + "#" + soap_method;
             SOAP soap = new SOAP(url_base + wan_ip_connection.ControlUrl, soap_body, soap_action);
             soap.RequestFinished += delegate(SOAP request_finished_soap, bool request_successful)
             {
                 bool successful = false;
                 if (request_successful)
                 {
                     //Console.WriteLine("Soap Response: \n" + request_finished_soap.Response);
                     string[] seps = { "\r\n" };
                     string[] lines = request_finished_soap.Response.Split(seps,StringSplitOptions.RemoveEmptyEntries);
                     if (lines.Length > 0)
                     {
                         if (lines[0] == "HTTP/1.1 200 OK")
                         {
                             if (request_finished_soap.Response.IndexOf(soap_method + "Response") != -1)
                                 successful = true;
                         }
                     }
                 }
                 else Console.WriteLine("Soap Request failed.");
                 if (ConnectionRequestCompleted != null)
                     ConnectionRequestCompleted(this, successful);
             };
             soap.StartRequest();
         }
     }
 }
예제 #17
0
        /// <summary>
        /// Convert the given enumeration of EVSEs into an EVSE status records XML.
        /// </summary>
        /// <param name="EVSEs">An enumeration of EVSEs.</param>
        /// <param name="RoamingNetwork">The WWCP roaming network.</param>
        /// <param name="XMLNamespaces">An optional delegate to process the XML namespaces.</param>
        /// <param name="EVSEStatusRecord2XML">An optional delegate to process an EVSE status record XML before sending it somewhere.</param>
        /// <param name="XMLPostProcessing">An optional delegate to process the XML after its final creation.</param>
        public static XElement ToXML(this IEnumerable <EVSE> EVSEs,
                                     RoamingNetwork RoamingNetwork,
                                     XMLNamespacesDelegate XMLNamespaces = null,
                                     //EVSEStatusRecord2XMLDelegate  EVSEStatusRecord2XML  = null,
                                     XMLPostProcessingDelegate XMLPostProcessing = null)
        {
            #region Initial checks

            if (EVSEs == null)
            {
                throw new ArgumentNullException(nameof(EVSEs), "The given enumeration of EVSEs must not be null!");
            }

            //if (EVSEStatusRecord2XML == null)
            //    EVSEStatusRecord2XML = (evsestatusrecord, xml) => xml;

            if (XMLPostProcessing == null)
            {
                XMLPostProcessing = xml => xml;
            }

            #endregion

            return(XMLPostProcessing(
                       SOAP.Encapsulation(new XElement(OICPNS.EVSEStatus + "eRoamingEvseStatus",
                                                       new XElement(OICPNS.EVSEStatus + "EvseStatuses",

                                                                    EVSEs.ToLookup(evse => evse.Operator,
                                                                                   evse => {
                try
                {
                    return WWCP.EVSEStatus.Snapshot(evse).AsOICPEVSEStatus();
                }
#pragma warning disable RCS1075  // Avoid empty catch clause that catches System.Exception.
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
                catch (Exception)
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
#pragma warning restore RCS1075  // Avoid empty catch clause that catches System.Exception.
                { }

                return null;
            }).

                                                                    Select(group => group.Any(evsestatusrecord => evsestatusrecord != null)

                                                            ? new XElement(OICPNS.EVSEStatus + "OperatorEvseStatus",

                                                                           new XElement(OICPNS.EVSEStatus + "OperatorID", group.Key.Id.ToString()),

                                                                           group.Key.Name.Any()
                                                                    ? new XElement(OICPNS.EVSEStatus + "OperatorName", group.Key.Name.FirstText())
                                                                    : null,

                                                                           new XElement(OICPPlusNS.EVSEOperator + "DataLicenses",
                                                                                        group.Key.DataLicenses.SafeSelect(license => new XElement(OICPPlusNS.EVSEOperator + "DataLicense",
                                                                                                                                                  new XElement(OICPPlusNS.EVSEOperator + "Id", license.Id),
                                                                                                                                                  new XElement(OICPPlusNS.EVSEOperator + "Description", license.Description),
                                                                                                                                                  license.URIs.Any()
                                                                                                                         ? new XElement(OICPPlusNS.EVSEOperator + "DataLicenseURIs",
                                                                                                                                        license.URIs.SafeSelect(uri => new XElement(OICPPlusNS.EVSEOperator + "DataLicenseURI", uri)))
                                                                                                                         : null
                                                                                                                                                  ))
                                                                                        ),

                                                                           // <EvseStatusRecord> ... </EvseStatusRecord>
                                                                           group.Where(evsestatusrecord => evsestatusrecord != null).
                                                                           //Select(evsestatusrecord => EVSEStatusRecord2XML(evsestatusrecord, evsestatusrecord.ToXML())).
                                                                           ToArray()

                                                                           )
                                                          : null

                                                                           ).ToArray()

                                                                    )
                                                       ),
                                          XMLNamespaces)));
        }
예제 #18
0
        /// <summary>
        /// Register all URI templates for this SOAP API.
        /// </summary>
        protected void RegisterURITemplates()
        {
            #region ~/ - GetServiceAuthorisation

            SOAPServer.RegisterSOAPDelegate(HTTPHostname.Any,
                                            URLPrefix + AuthorisationURL,
                                            "GetServiceAuthorisationRequest",
                                            XML => XML.Descendants(eMIPNS.Authorisation + "eMIP_FromIOP_GetServiceAuthorisationRequest").FirstOrDefault(),
                                            async(HTTPRequest, GetServiceAuthorisationXML) => {
                GetServiceAuthorisationResponse Response = null;

                #region Send OnGetServiceAuthorisationSOAPRequest event

                var StartTime = DateTime.UtcNow;

                try
                {
                    if (OnGetServiceAuthorisationSOAPRequest != null)
                    {
                        await Task.WhenAll(OnGetServiceAuthorisationSOAPRequest.GetInvocationList().
                                           Cast <RequestLogHandler>().
                                           Select(e => e(StartTime,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnGetServiceAuthorisationSOAPRequest));
                }

                #endregion


                if (GetServiceAuthorisationRequest.TryParse(GetServiceAuthorisationXML,
                                                            CustomGetServiceAuthorisationRequestParser,
                                                            out GetServiceAuthorisationRequest _GetServiceAuthorisationRequest,
                                                            OnException,

                                                            HTTPRequest,
                                                            HTTPRequest.Timestamp,
                                                            HTTPRequest.CancellationToken,
                                                            HTTPRequest.EventTrackingId,
                                                            HTTPRequest.Timeout ?? DefaultRequestTimeout))
                {
                    #region Send OnGetServiceAuthorisationRequest event

                    try
                    {
                        if (OnGetServiceAuthorisationRequest != null)
                        {
                            await Task.WhenAll(OnGetServiceAuthorisationRequest.GetInvocationList().
                                               Cast <OnGetServiceAuthorisationRequestDelegate>().
                                               Select(e => e(StartTime,
                                                             _GetServiceAuthorisationRequest.Timestamp.Value,
                                                             this,
                                                             ServiceName,
                                                             _GetServiceAuthorisationRequest.EventTrackingId,
                                                             _GetServiceAuthorisationRequest.TransactionId.Value,
                                                             _GetServiceAuthorisationRequest.PartnerId,
                                                             _GetServiceAuthorisationRequest.OperatorId,
                                                             _GetServiceAuthorisationRequest.TargetOperatorId,
                                                             _GetServiceAuthorisationRequest.EVSEId,
                                                             _GetServiceAuthorisationRequest.UserId,
                                                             _GetServiceAuthorisationRequest.RequestedServiceId,
                                                             _GetServiceAuthorisationRequest.ServiceSessionId,
                                                             _GetServiceAuthorisationRequest.BookingId,

                                                             _GetServiceAuthorisationRequest.RequestTimeout ?? DefaultRequestTimeout))).
                            ConfigureAwait(false);
                        }
                    }
                    catch (Exception e)
                    {
                        DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnGetServiceAuthorisationRequest));
                    }

                    #endregion

                    #region Call async subscribers

                    if (OnGetServiceAuthorisation != null)
                    {
                        var results = await Task.WhenAll(OnGetServiceAuthorisation.GetInvocationList().
                                                         Cast <OnGetServiceAuthorisationDelegate>().
                                                         Select(e => e(DateTime.UtcNow,
                                                                       this,
                                                                       _GetServiceAuthorisationRequest))).
                                      ConfigureAwait(false);

                        Response = results.FirstOrDefault();
                    }

                    //if (Response == null)
                    //    Response = Response<EMP.GetServiceAuthorisationRequest>.SystemError(
                    //                         _GetServiceAuthorisationRequest,
                    //                         "Could not process the incoming GetServiceAuthorisation request!",
                    //                         null,
                    //                         _GetServiceAuthorisationRequest.SessionId,
                    //                         _GetServiceAuthorisationRequest.PartnerSessionId
                    //                     );

                    #endregion

                    #region Send OnGetServiceAuthorisationResponse event

                    var EndTime = DateTime.UtcNow;

                    try
                    {
                        if (OnGetServiceAuthorisationResponse != null)
                        {
                            await Task.WhenAll(OnGetServiceAuthorisationResponse.GetInvocationList().
                                               Cast <OnGetServiceAuthorisationResponseDelegate>().
                                               Select(e => e(EndTime,
                                                             this,
                                                             ServiceName,
                                                             _GetServiceAuthorisationRequest.EventTrackingId,
                                                             _GetServiceAuthorisationRequest.TransactionId.Value,
                                                             _GetServiceAuthorisationRequest.PartnerId,
                                                             _GetServiceAuthorisationRequest.OperatorId,
                                                             _GetServiceAuthorisationRequest.TargetOperatorId,
                                                             _GetServiceAuthorisationRequest.EVSEId,
                                                             _GetServiceAuthorisationRequest.UserId,
                                                             _GetServiceAuthorisationRequest.RequestedServiceId,
                                                             _GetServiceAuthorisationRequest.ServiceSessionId,
                                                             _GetServiceAuthorisationRequest.BookingId,
                                                             _GetServiceAuthorisationRequest.RequestTimeout ?? DefaultRequestTimeout,
                                                             Response,
                                                             EndTime - StartTime))).
                            ConfigureAwait(false);
                        }
                    }
                    catch (Exception e)
                    {
                        DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnGetServiceAuthorisationResponse));
                    }

                    #endregion
                }

                //else
                //    Response = Response<EMP.GetServiceAuthorisationRequest>.DataError(
                //                          _GetServiceAuthorisationRequest,
                //                          "Could not process the incoming GetServiceAuthorisation request!"
                //                      );


                #region Create SOAPResponse

                var HTTPResponse = new HTTPResponse.Builder(HTTPRequest)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server         = SOAPServer.HTTPServer.DefaultServerName,
                    Date           = DateTime.UtcNow,
                    ContentType    = HTTPContentType.XMLTEXT_UTF8,
                    Content        = SOAP.Encapsulation(Response.ToXML(CustomGetServiceAuthorisationResponseSerializer)).ToUTF8Bytes(),
                    Connection     = "close"
                };

                #endregion

                #region Send OnGetServiceAuthorisationSOAPResponse event

                try
                {
                    if (OnGetServiceAuthorisationSOAPResponse != null)
                    {
                        await Task.WhenAll(OnGetServiceAuthorisationSOAPResponse.GetInvocationList().
                                           Cast <AccessLogHandler>().
                                           Select(e => e(HTTPResponse.Timestamp,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest,
                                                         HTTPResponse))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnGetServiceAuthorisationSOAPResponse));
                }

                #endregion

                return(HTTPResponse);
            });

            #endregion

            #region ~/ - SetSessionEventReport

            SOAPServer.RegisterSOAPDelegate(HTTPHostname.Any,
                                            URLPrefix + AuthorisationURL,
                                            "SetSessionEventReportRequest",
                                            XML => XML.Descendants(eMIPNS.Authorisation + "eMIP_FromIOP_SetSessionEventReportRequest").FirstOrDefault(),
                                            async(HTTPRequest, SetSessionEventReportXML) => {
                SetSessionEventReportResponse Response = null;

                #region Send OnSetSessionEventReportSOAPRequest event

                var StartTime = DateTime.UtcNow;

                try
                {
                    if (OnSetSessionEventReportSOAPRequest != null)
                    {
                        await Task.WhenAll(OnSetSessionEventReportSOAPRequest.GetInvocationList().
                                           Cast <RequestLogHandler>().
                                           Select(e => e(StartTime,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnSetSessionEventReportSOAPRequest));
                }

                #endregion


                if (SetSessionEventReportRequest.TryParse(SetSessionEventReportXML,
                                                          out SetSessionEventReportRequest _SetSessionEventReportRequest,
                                                          CustomSetSessionEventReportRequestParser,
                                                          CustomSessionEventParser,
                                                          OnException,

                                                          HTTPRequest,
                                                          HTTPRequest.Timestamp,
                                                          HTTPRequest.CancellationToken,
                                                          HTTPRequest.EventTrackingId,
                                                          HTTPRequest.Timeout ?? DefaultRequestTimeout))
                {
                    #region Send OnSetSessionEventReportRequest event

                    try
                    {
                        if (OnSetSessionEventReportRequest != null)
                        {
                            await Task.WhenAll(OnSetSessionEventReportRequest.GetInvocationList().
                                               Cast <OnSetSessionEventReportRequestDelegate>().
                                               Select(e => e(StartTime,
                                                             _SetSessionEventReportRequest.Timestamp.Value,
                                                             this,
                                                             ServiceName,
                                                             _SetSessionEventReportRequest.EventTrackingId,

                                                             _SetSessionEventReportRequest.PartnerId,
                                                             _SetSessionEventReportRequest.OperatorId,
                                                             _SetSessionEventReportRequest.TargetOperatorId,
                                                             _SetSessionEventReportRequest.ServiceSessionId,
                                                             _SetSessionEventReportRequest.SessionEvent,

                                                             _SetSessionEventReportRequest.TransactionId,
                                                             _SetSessionEventReportRequest.SalePartnerSessionId,

                                                             _SetSessionEventReportRequest.RequestTimeout ?? DefaultRequestTimeout))).
                            ConfigureAwait(false);
                        }
                    }
                    catch (Exception e)
                    {
                        DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnSetSessionEventReportRequest));
                    }

                    #endregion

                    #region Call async subscribers

                    if (OnSetSessionEventReport != null)
                    {
                        var results = await Task.WhenAll(OnSetSessionEventReport.GetInvocationList().
                                                         Cast <OnSetSessionEventReportDelegate>().
                                                         Select(e => e(DateTime.UtcNow,
                                                                       this,
                                                                       _SetSessionEventReportRequest))).
                                      ConfigureAwait(false);

                        Response = results.FirstOrDefault();
                    }

                    //if (Response == null)
                    //    Response = Response<EMP.SetSessionEventReportRequest>.SystemError(
                    //                         _SetSessionEventReportRequest,
                    //                         "Could not process the incoming SetSessionEventReport request!",
                    //                         null,
                    //                         _SetSessionEventReportRequest.SessionId,
                    //                         _SetSessionEventReportRequest.PartnerSessionId
                    //                     );

                    #endregion

                    #region Send OnSetSessionEventReportResponse event

                    var EndTime = DateTime.UtcNow;

                    try
                    {
                        if (OnSetSessionEventReportResponse != null)
                        {
                            await Task.WhenAll(OnSetSessionEventReportResponse.GetInvocationList().
                                               Cast <OnSetSessionEventReportResponseDelegate>().
                                               Select(e => e(EndTime,
                                                             this,
                                                             ServiceName,
                                                             _SetSessionEventReportRequest.EventTrackingId,

                                                             _SetSessionEventReportRequest.PartnerId,
                                                             _SetSessionEventReportRequest.OperatorId,
                                                             _SetSessionEventReportRequest.TargetOperatorId,
                                                             _SetSessionEventReportRequest.ServiceSessionId,
                                                             _SetSessionEventReportRequest.SessionEvent,

                                                             _SetSessionEventReportRequest.TransactionId,
                                                             _SetSessionEventReportRequest.SalePartnerSessionId,

                                                             _SetSessionEventReportRequest.RequestTimeout ?? DefaultRequestTimeout,
                                                             Response,
                                                             EndTime - StartTime))).
                            ConfigureAwait(false);
                        }
                    }
                    catch (Exception e)
                    {
                        DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnSetSessionEventReportResponse));
                    }

                    #endregion
                }

                //else
                //    Response = Response<EMP.SetSessionEventReportRequest>.DataError(
                //                          _SetSessionEventReportRequest,
                //                          "Could not process the incoming SetSessionEventReport request!"
                //                      );


                #region Create SOAPResponse

                var HTTPResponse = new HTTPResponse.Builder(HTTPRequest)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server         = SOAPServer.HTTPServer.DefaultServerName,
                    Date           = DateTime.UtcNow,
                    ContentType    = HTTPContentType.XMLTEXT_UTF8,
                    Content        = SOAP.Encapsulation(Response.ToXML(CustomSetSessionEventReportResponseSerializer)).ToUTF8Bytes(),
                    Connection     = "close"
                };

                #endregion

                #region Send OnSetSessionEventReportSOAPResponse event

                try
                {
                    if (OnSetSessionEventReportSOAPResponse != null)
                    {
                        await Task.WhenAll(OnSetSessionEventReportSOAPResponse.GetInvocationList().
                                           Cast <AccessLogHandler>().
                                           Select(e => e(HTTPResponse.Timestamp,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest,
                                                         HTTPResponse))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnSetSessionEventReportSOAPResponse));
                }

                #endregion

                return(HTTPResponse);
            });

            #endregion

            #region ~/ - SetChargeDetailRecord

            SOAPServer.RegisterSOAPDelegate(HTTPHostname.Any,
                                            URLPrefix + AuthorisationURL,
                                            "SetChargeDetailRecordRequest",
                                            XML => XML.Descendants(eMIPNS.Authorisation + "eMIP_FromIOP_SetChargeDetailRecordRequest").FirstOrDefault(),
                                            async(HTTPRequest, SetChargeDetailRecordXML) => {
                SetChargeDetailRecordResponse Response = null;

                #region Send OnSetChargeDetailRecordSOAPRequest event

                var StartTime = DateTime.UtcNow;

                try
                {
                    if (OnSetChargeDetailRecordSOAPRequest != null)
                    {
                        await Task.WhenAll(OnSetChargeDetailRecordSOAPRequest.GetInvocationList().
                                           Cast <RequestLogHandler>().
                                           Select(e => e(StartTime,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnSetChargeDetailRecordSOAPRequest));
                }

                #endregion


                if (SetChargeDetailRecordRequest.TryParse(SetChargeDetailRecordXML,
                                                          out SetChargeDetailRecordRequest _SetChargeDetailRecordRequest,
                                                          CustomSetChargeDetailRecordRequestParser,
                                                          CustomChargeDetailRecordParser,
                                                          CustomMeterReportParser,
                                                          OnException,

                                                          HTTPRequest,
                                                          HTTPRequest.Timestamp,
                                                          HTTPRequest.CancellationToken,
                                                          HTTPRequest.EventTrackingId,
                                                          HTTPRequest.Timeout ?? DefaultRequestTimeout))
                {
                    #region Send OnSetChargeDetailRecordRequest event

                    try
                    {
                        if (OnSetChargeDetailRecordRequest != null)
                        {
                            await Task.WhenAll(OnSetChargeDetailRecordRequest.GetInvocationList().
                                               Cast <OnSetChargeDetailRecordRequestDelegate>().
                                               Select(e => e(StartTime,
                                                             _SetChargeDetailRecordRequest.Timestamp.Value,
                                                             this,
                                                             ServiceName,
                                                             _SetChargeDetailRecordRequest.EventTrackingId,

                                                             _SetChargeDetailRecordRequest.PartnerId,
                                                             _SetChargeDetailRecordRequest.OperatorId,
                                                             _SetChargeDetailRecordRequest.ChargeDetailRecord,
                                                             _SetChargeDetailRecordRequest.TransactionId,

                                                             _SetChargeDetailRecordRequest.RequestTimeout ?? DefaultRequestTimeout))).
                            ConfigureAwait(false);
                        }
                    }
                    catch (Exception e)
                    {
                        DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnSetChargeDetailRecordRequest));
                    }

                    #endregion

                    #region Call async subscribers

                    if (OnSetChargeDetailRecord != null)
                    {
                        var results = await Task.WhenAll(OnSetChargeDetailRecord.GetInvocationList().
                                                         Cast <OnSetChargeDetailRecordDelegate>().
                                                         Select(e => e(DateTime.UtcNow,
                                                                       this,
                                                                       _SetChargeDetailRecordRequest))).
                                      ConfigureAwait(false);

                        Response = results.FirstOrDefault();
                    }

                    //if (Response == null)
                    //    Response = Response<EMP.SetChargeDetailRecordRequest>.SystemError(
                    //                         _SetChargeDetailRecordRequest,
                    //                         "Could not process the incoming SetChargeDetailRecord request!",
                    //                         null,
                    //                         _SetChargeDetailRecordRequest.SessionId,
                    //                         _SetChargeDetailRecordRequest.PartnerSessionId
                    //                     );

                    #endregion

                    #region Send OnSetChargeDetailRecordResponse event

                    var EndTime = DateTime.UtcNow;

                    try
                    {
                        if (OnSetChargeDetailRecordResponse != null)
                        {
                            await Task.WhenAll(OnSetChargeDetailRecordResponse.GetInvocationList().
                                               Cast <OnSetChargeDetailRecordResponseDelegate>().
                                               Select(e => e(EndTime,
                                                             this,
                                                             ServiceName,
                                                             _SetChargeDetailRecordRequest.EventTrackingId,

                                                             _SetChargeDetailRecordRequest.PartnerId,
                                                             _SetChargeDetailRecordRequest.OperatorId,
                                                             _SetChargeDetailRecordRequest.ChargeDetailRecord,
                                                             _SetChargeDetailRecordRequest.TransactionId,

                                                             _SetChargeDetailRecordRequest.RequestTimeout ?? DefaultRequestTimeout,
                                                             Response,
                                                             EndTime - StartTime))).
                            ConfigureAwait(false);
                        }
                    }
                    catch (Exception e)
                    {
                        DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnSetChargeDetailRecordResponse));
                    }

                    #endregion
                }

                //else
                //    Response = Response<EMP.SetChargeDetailRecordRequest>.DataError(
                //                          _SetChargeDetailRecordRequest,
                //                          "Could not process the incoming SetChargeDetailRecord request!"
                //                      );


                #region Create SOAPResponse

                var HTTPResponse = new HTTPResponse.Builder(HTTPRequest)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server         = SOAPServer.HTTPServer.DefaultServerName,
                    Date           = DateTime.UtcNow,
                    ContentType    = HTTPContentType.XMLTEXT_UTF8,
                    Content        = SOAP.Encapsulation(Response.ToXML(CustomSetChargeDetailRecordResponseSerializer)).ToUTF8Bytes(),
                    Connection     = "close"
                };

                #endregion

                #region Send OnSetChargeDetailRecordSOAPResponse event

                try
                {
                    if (OnSetChargeDetailRecordSOAPResponse != null)
                    {
                        await Task.WhenAll(OnSetChargeDetailRecordSOAPResponse.GetInvocationList().
                                           Cast <AccessLogHandler>().
                                           Select(e => e(HTTPResponse.Timestamp,
                                                         SOAPServer.HTTPServer,
                                                         HTTPRequest,
                                                         HTTPResponse))).
                        ConfigureAwait(false);
                    }
                }
                catch (Exception e)
                {
                    DebugX.LogException(e, nameof(EMPServer) + "." + nameof(OnSetChargeDetailRecordSOAPResponse));
                }

                #endregion

                return(HTTPResponse);
            });

            #endregion
        }
예제 #19
0
        MobileRemoteStop(MobileRemoteStopRequest Request)

        {
            #region Initial checks

            if (Request == null)
            {
                throw new ArgumentNullException(nameof(Request), "The given MobileRemoteStop request must not be null!");
            }

            Request = _CustomMobileRemoteStopRequestMapper(Request);

            if (Request == null)
            {
                throw new ArgumentNullException(nameof(Request), "The mapped MobileRemoteStop request must not be null!");
            }


            HTTPResponse <Acknowledgement <MobileRemoteStopRequest> > result = null;

            #endregion

            #region Send OnMobileRemoteStopRequest event

            var StartTime = DateTime.UtcNow;

            try
            {
                if (OnMobileRemoteStopRequest != null)
                {
                    await Task.WhenAll(OnMobileRemoteStopRequest.GetInvocationList().
                                       Cast <OnMobileRemoteStopRequestDelegate>().
                                       Select(e => e(StartTime,
                                                     Request.Timestamp.Value,
                                                     this,
                                                     ClientId,
                                                     Request.EventTrackingId,
                                                     Request.SessionId,
                                                     Request.RequestTimeout ?? RequestTimeout.Value))).
                    ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                e.Log(nameof(MobileClient) + "." + nameof(OnMobileRemoteStopRequest));
            }

            #endregion


            using (var _OICPClient = new SOAPClient(Hostname,
                                                    URLPathPrefix + MobileAuthorizationURL,
                                                    VirtualHostname,
                                                    RemotePort,
                                                    RemoteCertificateValidator,
                                                    ClientCertificateSelector,
                                                    UserAgent,
                                                    RequestTimeout,
                                                    DNSClient))

            {
                result = await _OICPClient.Query(_CustomMobileRemoteStopSOAPRequestMapper(Request,
                                                                                          SOAP.Encapsulation(Request.ToXML(CustomMobileRemoteStopRequestSerializer))),
                                                 "eRoamingMobileRemoteStop",
                                                 RequestLogDelegate :   OnMobileRemoteStartSOAPRequest,
                                                 ResponseLogDelegate :  OnMobileRemoteStartSOAPResponse,
                                                 CancellationToken :    Request.CancellationToken,
                                                 EventTrackingId :      Request.EventTrackingId,
                                                 RequestTimeout :         Request.RequestTimeout ?? RequestTimeout.Value,

                                                 #region OnSuccess

                                                 OnSuccess : XMLResponse => XMLResponse.ConvertContent(Request,
                                                                                                       (request, xml, onexception) =>
                                                                                                       Acknowledgement <MobileRemoteStopRequest> .Parse(request,
                                                                                                                                                        xml,
                                                                                                                                                        CustomAcknowledgementMobileRemoteStopParser,
                                                                                                                                                        CustomStatusCodeParser,
                                                                                                                                                        onexception)),

                                                 #endregion

                                                 #region OnSOAPFault

                                                 OnSOAPFault : (timestamp, soapclient, httpresponse) => {
                    SendSOAPError(timestamp, this, httpresponse.Content);

                    return(new HTTPResponse <Acknowledgement <MobileRemoteStopRequest> >(

                               httpresponse,

                               new Acknowledgement <MobileRemoteStopRequest>(
                                   Request,
                                   StatusCodes.DataError,
                                   httpresponse.Content.ToString()
                                   ),

                               IsFault: true

                               ));
                },

                                                 #endregion

                                                 #region OnHTTPError

                                                 OnHTTPError : (timestamp, soapclient, httpresponse) => {
                    SendHTTPError(timestamp, this, httpresponse);

                    return(new HTTPResponse <Acknowledgement <MobileRemoteStopRequest> >(

                               httpresponse,

                               new Acknowledgement <MobileRemoteStopRequest>(
                                   Request,
                                   StatusCodes.DataError,
                                   httpresponse.HTTPStatusCode.ToString(),
                                   httpresponse.HTTPBody.ToUTF8String()
                                   ),

                               IsFault: true

                               ));
                },

                                                 #endregion

                                                 #region OnException

                                                 OnException : (timestamp, sender, exception) => {
                    SendException(timestamp, sender, exception);

                    return(HTTPResponse <Acknowledgement <MobileRemoteStopRequest> > .ExceptionThrown(

                               new Acknowledgement <MobileRemoteStopRequest>(
                                   Request,
                                   StatusCodes.ServiceNotAvailable,
                                   exception.Message,
                                   exception.StackTrace
                                   ),

                               Exception: exception

                               ));
                }

                                                 #endregion

                                                 );
            }

            if (result == null)
            {
                result = HTTPResponse <Acknowledgement <MobileRemoteStopRequest> > .OK(
                    new Acknowledgement <MobileRemoteStopRequest>(
                        Request,
                        StatusCodes.SystemError,
                        "HTTP request failed!"
                        )
                    );
            }


            #region Send OnMobileRemoteStopResponse event

            var Endtime = DateTime.UtcNow;

            try
            {
                if (OnMobileRemoteStopResponse != null)
                {
                    await Task.WhenAll(OnMobileRemoteStopResponse.GetInvocationList().
                                       Cast <OnMobileRemoteStopResponseDelegate>().
                                       Select(e => e(Endtime,
                                                     Request.Timestamp.Value,
                                                     this,
                                                     ClientId,
                                                     Request.EventTrackingId,
                                                     Request.SessionId,
                                                     Request.RequestTimeout ?? RequestTimeout.Value,
                                                     result.Content,
                                                     Endtime - StartTime))).
                    ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                e.Log(nameof(MobileClient) + "." + nameof(OnMobileRemoteStopResponse));
            }

            #endregion

            return(result);
        }