当前位置: 首页>>代码示例>>C#>>正文


C# XDeclaration.ToString方法代码示例

本文整理汇总了C#中System.Xml.Linq.XDeclaration.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# XDeclaration.ToString方法的具体用法?C# XDeclaration.ToString怎么用?C# XDeclaration.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XDeclaration的用法示例。


在下文中一共展示了XDeclaration.ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteResponseAsync

        private async Task WriteResponseAsync(string request, ITcpSocketClient socket )
        {
            Stream writeStream = socket.WriteStream;
            IGWClient client = null;
            Dictionary<string, string> parameters = null;
            const string C_REPTYPE = "reptype";
            const string C_CONTENTTYPE_HTML = "text/html; charset=utf-8;";
            const string C_REPTYPE_XML = "xml";
            const string C_CONTENTTYPE_XML = "text/xml; charset=utf-8;";
#if JSON
            const string C_REPTYPE_JSON = "json"; 
            const string C_CONTENTTYPE_JSON = "application/json";
#endif

            
          

            const string C_HTTP_CODE_OK = "200";
            const string C_HTTP_CODE_BADREQUEST = "400";
            const string C_HTTP_CODE_NOTFOUND = "404";
            const string C_HTTP_CODE_INTERNAL_ERROR = "500";

            string httpCode = C_HTTP_CODE_OK;
            string httpCodeTest = "";
            string httpContent = "";
            string httpContentType = C_CONTENTTYPE_XML; // default XML
            

            // parse request to get client and parametres items
            RequestParse(request, out client, out parameters);

            if (client != null)
            {
                // check response format to use
                if (parameters != null && parameters.ContainsKey(C_REPTYPE))
                {
                    if (parameters[C_REPTYPE] == C_REPTYPE_XML)
                        httpContentType = C_CONTENTTYPE_XML;
#if JSON
                    else if (parameters[C_REPTYPE] == C_REPTYPE_JSON)
                        httpContentType = C_CONTENTTYPE_JSON;
#endif
                    else
                    {
                        client = null; // bad => simulate 400
                        httpCode = C_HTTP_CODE_BADREQUEST;                     
                    }
                }
            }
            else
            {
                httpCode = C_HTTP_CODE_NOTFOUND;
            }

            if (client != null)
            {
                // transfert request to client                
                GWClientResult ret = await client.ExecuteAsync(parameters);

                if (ret!= null)
                {
                    // contruct response
                    XElement xresult = new XElement("Result");
                    XElement xrequest = new XElement("Request");
                    XElement xresponse = new XElement("Response");

                    
                    xrequest.Add(new XElement("Uri", request));
                    xrequest.Add(new XElement("RemoteAddress", socket.RemoteAddress));
                    xrequest.Add(new XElement("RemotePort", socket.RemotePort));                    
                    XElement  xparams = new XElement("Parameters");
                    if (parameters != null)
                    {
                        foreach (var parmeter in parameters)
                        {
                            XElement xparam = new XElement("Parameter");
                            xparam.Add(new XAttribute("Key", parmeter.Key));
                            xparam.Add(new XElement("Value", parmeter.Value));
                            xparams.Add(xparam);
                        }
                    }
                    xrequest.Add(xparams);
                    

                    xresponse.Add(new XElement("Success", ret.Success ? "1" : "0"));
                    xresponse.Add(new XElement("Message", ret.Message));
                    xresponse.Add(ret.Data);

                    xresult.Add(xrequest);
                    xresult.Add(xresponse);
                    ret.Data.Add(new XAttribute("ClientName", client.Name));

                    if (httpContentType == C_CONTENTTYPE_XML)
                    {
                        XDeclaration decl = new XDeclaration("1.0", "UTF-8", null);
                        httpContent = decl.ToString() + "\r\n" + xresult.ToString();
                    }
#if JSON
                    else if (httpContentType == C_CONTENTTYPE_JSON)
                    {
//.........这里部分代码省略.........
开发者ID:2B2i,项目名称:2B2i.Dom,代码行数:101,代码来源:GWServerHttp.cs


注:本文中的System.Xml.Linq.XDeclaration.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。