本文整理汇总了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)
{
//.........这里部分代码省略.........