GridServerPostHandler.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using Nini.Config;
  28. using log4net;
  29. using System;
  30. using System.Reflection;
  31. using System.IO;
  32. using System.Net;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Xml;
  36. using System.Xml.Serialization;
  37. using System.Collections.Generic;
  38. using OpenSim.Server.Base;
  39. using OpenSim.Services.Interfaces;
  40. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  41. using OpenSim.Framework;
  42. using OpenSim.Framework.Servers.HttpServer;
  43. using OpenMetaverse;
  44. namespace OpenSim.Server.Handlers.Grid
  45. {
  46. public class GridServerPostHandler : BaseStreamHandler
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. private IGridService m_GridService;
  50. public GridServerPostHandler(IGridService service) :
  51. base("POST", "/grid")
  52. {
  53. m_GridService = service;
  54. }
  55. public override byte[] Handle(string path, Stream requestData,
  56. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  57. {
  58. StreamReader sr = new StreamReader(requestData);
  59. string body = sr.ReadToEnd();
  60. sr.Close();
  61. body = body.Trim();
  62. //m_log.DebugFormat("[XXX]: query String: {0}", body);
  63. try
  64. {
  65. Dictionary<string, object> request =
  66. ServerUtils.ParseQueryString(body);
  67. if (!request.ContainsKey("METHOD"))
  68. return FailureResult();
  69. string method = request["METHOD"].ToString();
  70. switch (method)
  71. {
  72. case "register":
  73. return Register(request);
  74. case "deregister":
  75. return Deregister(request);
  76. case "get_neighbours":
  77. return GetNeighbours(request);
  78. case "get_region_by_uuid":
  79. return GetRegionByUUID(request);
  80. case "get_region_by_position":
  81. return GetRegionByPosition(request);
  82. case "get_region_by_name":
  83. return GetRegionByName(request);
  84. case "get_regions_by_name":
  85. return GetRegionsByName(request);
  86. case "get_region_range":
  87. return GetRegionRange(request);
  88. case "get_default_regions":
  89. return GetDefaultRegions(request);
  90. case "get_fallback_regions":
  91. return GetFallbackRegions(request);
  92. case "get_hyperlinks":
  93. return GetHyperlinks(request);
  94. case "get_region_flags":
  95. return GetRegionFlags(request);
  96. }
  97. m_log.DebugFormat("[GRID HANDLER]: unknown method {0} request {1}", method.Length, method);
  98. }
  99. catch (Exception e)
  100. {
  101. m_log.DebugFormat("[GRID HANDLER]: Exception {0}", e);
  102. }
  103. return FailureResult();
  104. }
  105. #region Method-specific handlers
  106. byte[] Register(Dictionary<string, object> request)
  107. {
  108. UUID scopeID = UUID.Zero;
  109. if (request.ContainsKey("SCOPEID"))
  110. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  111. else
  112. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
  113. int versionNumberMin = 0, versionNumberMax = 0;
  114. if (request.ContainsKey("VERSIONMIN"))
  115. Int32.TryParse(request["VERSIONMIN"].ToString(), out versionNumberMin);
  116. else
  117. m_log.WarnFormat("[GRID HANDLER]: no minimum protocol version in request to register region");
  118. if (request.ContainsKey("VERSIONMAX"))
  119. Int32.TryParse(request["VERSIONMAX"].ToString(), out versionNumberMax);
  120. else
  121. m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region");
  122. // Check the protocol version
  123. if ((versionNumberMin > ProtocolVersions.ServerProtocolVersionMax && versionNumberMax < ProtocolVersions.ServerProtocolVersionMax))
  124. {
  125. // Can't do, there is no overlap in the acceptable ranges
  126. return FailureResult();
  127. }
  128. Dictionary<string, object> rinfoData = new Dictionary<string, object>();
  129. GridRegion rinfo = null;
  130. try
  131. {
  132. foreach (KeyValuePair<string, object> kvp in request)
  133. rinfoData[kvp.Key] = kvp.Value.ToString();
  134. rinfo = new GridRegion(rinfoData);
  135. }
  136. catch (Exception e)
  137. {
  138. m_log.DebugFormat("[GRID HANDLER]: exception unpacking region data: {0}", e);
  139. }
  140. string result = "Error communicating with grid service";
  141. if (rinfo != null)
  142. result = m_GridService.RegisterRegion(scopeID, rinfo);
  143. if (result == String.Empty)
  144. return SuccessResult();
  145. else
  146. return FailureResult(result);
  147. }
  148. byte[] Deregister(Dictionary<string, object> request)
  149. {
  150. UUID regionID = UUID.Zero;
  151. if (request.ContainsKey("REGIONID"))
  152. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  153. else
  154. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region");
  155. bool result = m_GridService.DeregisterRegion(regionID);
  156. if (result)
  157. return SuccessResult();
  158. else
  159. return FailureResult();
  160. }
  161. byte[] GetNeighbours(Dictionary<string, object> request)
  162. {
  163. UUID scopeID = UUID.Zero;
  164. if (request.ContainsKey("SCOPEID"))
  165. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  166. else
  167. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
  168. UUID regionID = UUID.Zero;
  169. if (request.ContainsKey("REGIONID"))
  170. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  171. else
  172. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
  173. List<GridRegion> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
  174. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  175. Dictionary<string, object> result = new Dictionary<string, object>();
  176. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  177. result["result"] = "null";
  178. else
  179. {
  180. int i = 0;
  181. foreach (GridRegion rinfo in rinfos)
  182. {
  183. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  184. result["region" + i] = rinfoDict;
  185. i++;
  186. }
  187. }
  188. string xmlString = ServerUtils.BuildXmlResponse(result);
  189. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  190. UTF8Encoding encoding = new UTF8Encoding();
  191. return encoding.GetBytes(xmlString);
  192. }
  193. byte[] GetRegionByUUID(Dictionary<string, object> request)
  194. {
  195. UUID scopeID = UUID.Zero;
  196. if (request.ContainsKey("SCOPEID"))
  197. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  198. else
  199. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
  200. UUID regionID = UUID.Zero;
  201. if (request.ContainsKey("REGIONID"))
  202. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  203. else
  204. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
  205. GridRegion rinfo = m_GridService.GetRegionByUUID(scopeID, regionID);
  206. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  207. Dictionary<string, object> result = new Dictionary<string, object>();
  208. if (rinfo == null)
  209. result["result"] = "null";
  210. else
  211. result["result"] = rinfo.ToKeyValuePairs();
  212. string xmlString = ServerUtils.BuildXmlResponse(result);
  213. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  214. UTF8Encoding encoding = new UTF8Encoding();
  215. return encoding.GetBytes(xmlString);
  216. }
  217. byte[] GetRegionByPosition(Dictionary<string, object> request)
  218. {
  219. UUID scopeID = UUID.Zero;
  220. if (request.ContainsKey("SCOPEID"))
  221. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  222. else
  223. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position");
  224. int x = 0, y = 0;
  225. if (request.ContainsKey("X"))
  226. Int32.TryParse(request["X"].ToString(), out x);
  227. else
  228. m_log.WarnFormat("[GRID HANDLER]: no X in request to get region by position");
  229. if (request.ContainsKey("Y"))
  230. Int32.TryParse(request["Y"].ToString(), out y);
  231. else
  232. m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position");
  233. GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
  234. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  235. Dictionary<string, object> result = new Dictionary<string, object>();
  236. if (rinfo == null)
  237. result["result"] = "null";
  238. else
  239. result["result"] = rinfo.ToKeyValuePairs();
  240. string xmlString = ServerUtils.BuildXmlResponse(result);
  241. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  242. UTF8Encoding encoding = new UTF8Encoding();
  243. return encoding.GetBytes(xmlString);
  244. }
  245. byte[] GetRegionByName(Dictionary<string, object> request)
  246. {
  247. UUID scopeID = UUID.Zero;
  248. if (request.ContainsKey("SCOPEID"))
  249. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  250. else
  251. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by name");
  252. string regionName = string.Empty;
  253. if (request.ContainsKey("NAME"))
  254. regionName = request["NAME"].ToString();
  255. else
  256. m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name");
  257. GridRegion rinfo = m_GridService.GetRegionByName(scopeID, regionName);
  258. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  259. Dictionary<string, object> result = new Dictionary<string, object>();
  260. if (rinfo == null)
  261. result["result"] = "null";
  262. else
  263. result["result"] = rinfo.ToKeyValuePairs();
  264. string xmlString = ServerUtils.BuildXmlResponse(result);
  265. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  266. UTF8Encoding encoding = new UTF8Encoding();
  267. return encoding.GetBytes(xmlString);
  268. }
  269. byte[] GetRegionsByName(Dictionary<string, object> request)
  270. {
  271. UUID scopeID = UUID.Zero;
  272. if (request.ContainsKey("SCOPEID"))
  273. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  274. else
  275. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get regions by name");
  276. string regionName = string.Empty;
  277. if (request.ContainsKey("NAME"))
  278. regionName = request["NAME"].ToString();
  279. else
  280. m_log.WarnFormat("[GRID HANDLER]: no NAME in request to get regions by name");
  281. int max = 0;
  282. if (request.ContainsKey("MAX"))
  283. Int32.TryParse(request["MAX"].ToString(), out max);
  284. else
  285. m_log.WarnFormat("[GRID HANDLER]: no MAX in request to get regions by name");
  286. List<GridRegion> rinfos = m_GridService.GetRegionsByName(scopeID, regionName, max);
  287. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  288. Dictionary<string, object> result = new Dictionary<string, object>();
  289. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  290. result["result"] = "null";
  291. else
  292. {
  293. int i = 0;
  294. foreach (GridRegion rinfo in rinfos)
  295. {
  296. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  297. result["region" + i] = rinfoDict;
  298. i++;
  299. }
  300. }
  301. string xmlString = ServerUtils.BuildXmlResponse(result);
  302. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  303. UTF8Encoding encoding = new UTF8Encoding();
  304. return encoding.GetBytes(xmlString);
  305. }
  306. byte[] GetRegionRange(Dictionary<string, object> request)
  307. {
  308. //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
  309. UUID scopeID = UUID.Zero;
  310. if (request.ContainsKey("SCOPEID"))
  311. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  312. else
  313. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
  314. int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
  315. if (request.ContainsKey("XMIN"))
  316. Int32.TryParse(request["XMIN"].ToString(), out xmin);
  317. else
  318. m_log.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range");
  319. if (request.ContainsKey("XMAX"))
  320. Int32.TryParse(request["XMAX"].ToString(), out xmax);
  321. else
  322. m_log.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range");
  323. if (request.ContainsKey("YMIN"))
  324. Int32.TryParse(request["YMIN"].ToString(), out ymin);
  325. else
  326. m_log.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range");
  327. if (request.ContainsKey("YMAX"))
  328. Int32.TryParse(request["YMAX"].ToString(), out ymax);
  329. else
  330. m_log.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range");
  331. List<GridRegion> rinfos = m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
  332. Dictionary<string, object> result = new Dictionary<string, object>();
  333. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  334. result["result"] = "null";
  335. else
  336. {
  337. int i = 0;
  338. foreach (GridRegion rinfo in rinfos)
  339. {
  340. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  341. result["region" + i] = rinfoDict;
  342. i++;
  343. }
  344. }
  345. string xmlString = ServerUtils.BuildXmlResponse(result);
  346. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  347. UTF8Encoding encoding = new UTF8Encoding();
  348. return encoding.GetBytes(xmlString);
  349. }
  350. byte[] GetDefaultRegions(Dictionary<string, object> request)
  351. {
  352. //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions");
  353. UUID scopeID = UUID.Zero;
  354. if (request.ContainsKey("SCOPEID"))
  355. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  356. else
  357. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
  358. List<GridRegion> rinfos = m_GridService.GetDefaultRegions(scopeID);
  359. Dictionary<string, object> result = new Dictionary<string, object>();
  360. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  361. result["result"] = "null";
  362. else
  363. {
  364. int i = 0;
  365. foreach (GridRegion rinfo in rinfos)
  366. {
  367. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  368. result["region" + i] = rinfoDict;
  369. i++;
  370. }
  371. }
  372. string xmlString = ServerUtils.BuildXmlResponse(result);
  373. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  374. UTF8Encoding encoding = new UTF8Encoding();
  375. return encoding.GetBytes(xmlString);
  376. }
  377. byte[] GetFallbackRegions(Dictionary<string, object> request)
  378. {
  379. //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
  380. UUID scopeID = UUID.Zero;
  381. if (request.ContainsKey("SCOPEID"))
  382. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  383. else
  384. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get fallback regions");
  385. int x = 0, y = 0;
  386. if (request.ContainsKey("X"))
  387. Int32.TryParse(request["X"].ToString(), out x);
  388. else
  389. m_log.WarnFormat("[GRID HANDLER]: no X in request to get fallback regions");
  390. if (request.ContainsKey("Y"))
  391. Int32.TryParse(request["Y"].ToString(), out y);
  392. else
  393. m_log.WarnFormat("[GRID HANDLER]: no Y in request to get fallback regions");
  394. List<GridRegion> rinfos = m_GridService.GetFallbackRegions(scopeID, x, y);
  395. Dictionary<string, object> result = new Dictionary<string, object>();
  396. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  397. result["result"] = "null";
  398. else
  399. {
  400. int i = 0;
  401. foreach (GridRegion rinfo in rinfos)
  402. {
  403. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  404. result["region" + i] = rinfoDict;
  405. i++;
  406. }
  407. }
  408. string xmlString = ServerUtils.BuildXmlResponse(result);
  409. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  410. UTF8Encoding encoding = new UTF8Encoding();
  411. return encoding.GetBytes(xmlString);
  412. }
  413. byte[] GetHyperlinks(Dictionary<string, object> request)
  414. {
  415. //m_log.DebugFormat("[GRID HANDLER]: GetHyperlinks");
  416. UUID scopeID = UUID.Zero;
  417. if (request.ContainsKey("SCOPEID"))
  418. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  419. else
  420. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get linked regions");
  421. List<GridRegion> rinfos = m_GridService.GetHyperlinks(scopeID);
  422. Dictionary<string, object> result = new Dictionary<string, object>();
  423. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  424. result["result"] = "null";
  425. else
  426. {
  427. int i = 0;
  428. foreach (GridRegion rinfo in rinfos)
  429. {
  430. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  431. result["region" + i] = rinfoDict;
  432. i++;
  433. }
  434. }
  435. string xmlString = ServerUtils.BuildXmlResponse(result);
  436. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  437. UTF8Encoding encoding = new UTF8Encoding();
  438. return encoding.GetBytes(xmlString);
  439. }
  440. byte[] GetRegionFlags(Dictionary<string, object> request)
  441. {
  442. UUID scopeID = UUID.Zero;
  443. if (request.ContainsKey("SCOPEID"))
  444. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  445. else
  446. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
  447. UUID regionID = UUID.Zero;
  448. if (request.ContainsKey("REGIONID"))
  449. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  450. else
  451. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
  452. int flags = m_GridService.GetRegionFlags(scopeID, regionID);
  453. // m_log.DebugFormat("[GRID HANDLER]: flags for region {0}: {1}", regionID, flags);
  454. Dictionary<string, object> result = new Dictionary<string, object>();
  455. result["result"] = flags.ToString();
  456. string xmlString = ServerUtils.BuildXmlResponse(result);
  457. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  458. UTF8Encoding encoding = new UTF8Encoding();
  459. return encoding.GetBytes(xmlString);
  460. }
  461. #endregion
  462. #region Misc
  463. private byte[] SuccessResult()
  464. {
  465. XmlDocument doc = new XmlDocument();
  466. XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
  467. "", "");
  468. doc.AppendChild(xmlnode);
  469. XmlElement rootElement = doc.CreateElement("", "ServerResponse",
  470. "");
  471. doc.AppendChild(rootElement);
  472. XmlElement result = doc.CreateElement("", "Result", "");
  473. result.AppendChild(doc.CreateTextNode("Success"));
  474. rootElement.AppendChild(result);
  475. return DocToBytes(doc);
  476. }
  477. private byte[] FailureResult()
  478. {
  479. return FailureResult(String.Empty);
  480. }
  481. private byte[] FailureResult(string msg)
  482. {
  483. XmlDocument doc = new XmlDocument();
  484. XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
  485. "", "");
  486. doc.AppendChild(xmlnode);
  487. XmlElement rootElement = doc.CreateElement("", "ServerResponse",
  488. "");
  489. doc.AppendChild(rootElement);
  490. XmlElement result = doc.CreateElement("", "Result", "");
  491. result.AppendChild(doc.CreateTextNode("Failure"));
  492. rootElement.AppendChild(result);
  493. XmlElement message = doc.CreateElement("", "Message", "");
  494. message.AppendChild(doc.CreateTextNode(msg));
  495. rootElement.AppendChild(message);
  496. return DocToBytes(doc);
  497. }
  498. private byte[] DocToBytes(XmlDocument doc)
  499. {
  500. MemoryStream ms = new MemoryStream();
  501. XmlTextWriter xw = new XmlTextWriter(ms, null);
  502. xw.Formatting = Formatting.Indented;
  503. doc.WriteTo(xw);
  504. xw.Flush();
  505. return ms.ToArray();
  506. }
  507. #endregion
  508. }
  509. }