clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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  
28 using Nini.Config;
29 using log4net;
30 using System;
31 using System.Reflection;
32 using System.IO;
33 using System.Net;
34 using System.Text;
35 using System.Text.RegularExpressions;
36 using System.Xml;
37 using System.Xml.Serialization;
38 using System.Collections.Generic;
39 using OpenSim.Server.Base;
40 using OpenSim.Services.Interfaces;
41 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
42 using OpenSim.Framework;
43 using OpenSim.Framework.Servers.HttpServer;
44 using OpenMetaverse;
45  
46 namespace OpenSim.Server.Handlers.Grid
47 {
48 public class GridServerPostHandler : BaseStreamHandler
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51  
52 private IGridService m_GridService;
53  
54 public GridServerPostHandler(IGridService service) :
55 base("POST", "/grid")
56 {
57 m_GridService = service;
58 }
59  
60 protected override byte[] ProcessRequest(string path, Stream requestData,
61 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
62 {
63 StreamReader sr = new StreamReader(requestData);
64 string body = sr.ReadToEnd();
65 sr.Close();
66 body = body.Trim();
67  
68 //m_log.DebugFormat("[XXX]: query String: {0}", body);
69  
70 try
71 {
72 Dictionary<string, object> request =
73 ServerUtils.ParseQueryString(body);
74  
75 if (!request.ContainsKey("METHOD"))
76 return FailureResult();
77  
78 string method = request["METHOD"].ToString();
79  
80 switch (method)
81 {
82 case "register":
83 return Register(request);
84  
85 case "deregister":
86 return Deregister(request);
87  
88 case "get_neighbours":
89 return GetNeighbours(request);
90  
91 case "get_region_by_uuid":
92 return GetRegionByUUID(request);
93  
94 case "get_region_by_position":
95 return GetRegionByPosition(request);
96  
97 case "get_region_by_name":
98 return GetRegionByName(request);
99  
100 case "get_regions_by_name":
101 return GetRegionsByName(request);
102  
103 case "get_region_range":
104 return GetRegionRange(request);
105  
106 case "get_default_regions":
107 return GetDefaultRegions(request);
108  
109 case "get_default_hypergrid_regions":
110 return GetDefaultHypergridRegions(request);
111  
112 case "get_fallback_regions":
113 return GetFallbackRegions(request);
114  
115 case "get_hyperlinks":
116 return GetHyperlinks(request);
117  
118 case "get_region_flags":
119 return GetRegionFlags(request);
120 }
121  
122 m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method);
123 }
124 catch (Exception e)
125 {
126 m_log.ErrorFormat("[GRID HANDLER]: Exception {0} {1}", e.Message, e.StackTrace);
127 }
128  
129 return FailureResult();
130 }
131  
132 #region Method-specific handlers
133  
134 byte[] Register(Dictionary<string, object> request)
135 {
136 UUID scopeID = UUID.Zero;
137 if (request.ContainsKey("SCOPEID"))
138 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
139 else
140 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
141  
142 int versionNumberMin = 0, versionNumberMax = 0;
143 if (request.ContainsKey("VERSIONMIN"))
144 Int32.TryParse(request["VERSIONMIN"].ToString(), out versionNumberMin);
145 else
146 m_log.WarnFormat("[GRID HANDLER]: no minimum protocol version in request to register region");
147  
148 if (request.ContainsKey("VERSIONMAX"))
149 Int32.TryParse(request["VERSIONMAX"].ToString(), out versionNumberMax);
150 else
151 m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region");
152  
153 // Check the protocol version
154 if ((versionNumberMin > ProtocolVersions.ServerProtocolVersionMax && versionNumberMax < ProtocolVersions.ServerProtocolVersionMax))
155 {
156 // Can't do, there is no overlap in the acceptable ranges
157 return FailureResult();
158 }
159  
160 Dictionary<string, object> rinfoData = new Dictionary<string, object>();
161 GridRegion rinfo = null;
162 try
163 {
164 foreach (KeyValuePair<string, object> kvp in request)
165 rinfoData[kvp.Key] = kvp.Value.ToString();
166 rinfo = new GridRegion(rinfoData);
167 }
168 catch (Exception e)
169 {
170 m_log.DebugFormat("[GRID HANDLER]: exception unpacking region data: {0}", e);
171 }
172  
173 string result = "Error communicating with grid service";
174 if (rinfo != null)
175 result = m_GridService.RegisterRegion(scopeID, rinfo);
176  
177 if (result == String.Empty)
178 return SuccessResult();
179 else
180 return FailureResult(result);
181 }
182  
183 byte[] Deregister(Dictionary<string, object> request)
184 {
185 UUID regionID = UUID.Zero;
186 if (request.ContainsKey("REGIONID"))
187 UUID.TryParse(request["REGIONID"].ToString(), out regionID);
188 else
189 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region");
190  
191 bool result = m_GridService.DeregisterRegion(regionID);
192  
193 if (result)
194 return SuccessResult();
195 else
196 return FailureResult();
197  
198 }
199  
200 byte[] GetNeighbours(Dictionary<string, object> request)
201 {
202 UUID scopeID = UUID.Zero;
203 if (request.ContainsKey("SCOPEID"))
204 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
205 else
206 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
207  
208 UUID regionID = UUID.Zero;
209 if (request.ContainsKey("REGIONID"))
210 UUID.TryParse(request["REGIONID"].ToString(), out regionID);
211 else
212 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
213  
214 List<GridRegion> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
215 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
216  
217 Dictionary<string, object> result = new Dictionary<string, object>();
218 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
219 result["result"] = "null";
220 else
221 {
222 int i = 0;
223 foreach (GridRegion rinfo in rinfos)
224 {
225 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
226 result["region" + i] = rinfoDict;
227 i++;
228 }
229 }
230  
231 string xmlString = ServerUtils.BuildXmlResponse(result);
232  
233 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
234 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
235 }
236  
237 byte[] GetRegionByUUID(Dictionary<string, object> request)
238 {
239 UUID scopeID = UUID.Zero;
240 if (request.ContainsKey("SCOPEID"))
241 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
242 else
243 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
244  
245 UUID regionID = UUID.Zero;
246 if (request.ContainsKey("REGIONID"))
247 UUID.TryParse(request["REGIONID"].ToString(), out regionID);
248 else
249 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
250  
251 GridRegion rinfo = m_GridService.GetRegionByUUID(scopeID, regionID);
252 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
253  
254 Dictionary<string, object> result = new Dictionary<string, object>();
255 if (rinfo == null)
256 result["result"] = "null";
257 else
258 result["result"] = rinfo.ToKeyValuePairs();
259  
260 string xmlString = ServerUtils.BuildXmlResponse(result);
261  
262 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
263 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
264 }
265  
266 byte[] GetRegionByPosition(Dictionary<string, object> request)
267 {
268 UUID scopeID = UUID.Zero;
269 if (request.ContainsKey("SCOPEID"))
270 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
271 else
272 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position");
273  
274 int x = 0, y = 0;
275 if (request.ContainsKey("X"))
276 Int32.TryParse(request["X"].ToString(), out x);
277 else
278 m_log.WarnFormat("[GRID HANDLER]: no X in request to get region by position");
279 if (request.ContainsKey("Y"))
280 Int32.TryParse(request["Y"].ToString(), out y);
281 else
282 m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position");
283  
284 GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
285 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
286  
287 Dictionary<string, object> result = new Dictionary<string, object>();
288 if (rinfo == null)
289 result["result"] = "null";
290 else
291 result["result"] = rinfo.ToKeyValuePairs();
292  
293 string xmlString = ServerUtils.BuildXmlResponse(result);
294  
295 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
296 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
297 }
298  
299 byte[] GetRegionByName(Dictionary<string, object> request)
300 {
301 UUID scopeID = UUID.Zero;
302 if (request.ContainsKey("SCOPEID"))
303 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
304 else
305 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by name");
306  
307 string regionName = string.Empty;
308 if (request.ContainsKey("NAME"))
309 regionName = request["NAME"].ToString();
310 else
311 m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name");
312  
313 GridRegion rinfo = m_GridService.GetRegionByName(scopeID, regionName);
314 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
315  
316 Dictionary<string, object> result = new Dictionary<string, object>();
317 if (rinfo == null)
318 result["result"] = "null";
319 else
320 result["result"] = rinfo.ToKeyValuePairs();
321  
322 string xmlString = ServerUtils.BuildXmlResponse(result);
323  
324 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
325 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
326 }
327  
328 byte[] GetRegionsByName(Dictionary<string, object> request)
329 {
330 UUID scopeID = UUID.Zero;
331 if (request.ContainsKey("SCOPEID"))
332 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
333 else
334 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get regions by name");
335  
336 string regionName = string.Empty;
337 if (request.ContainsKey("NAME"))
338 regionName = request["NAME"].ToString();
339 else
340 m_log.WarnFormat("[GRID HANDLER]: no NAME in request to get regions by name");
341  
342 int max = 0;
343 if (request.ContainsKey("MAX"))
344 Int32.TryParse(request["MAX"].ToString(), out max);
345 else
346 m_log.WarnFormat("[GRID HANDLER]: no MAX in request to get regions by name");
347  
348 List<GridRegion> rinfos = m_GridService.GetRegionsByName(scopeID, regionName, max);
349 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
350  
351 Dictionary<string, object> result = new Dictionary<string, object>();
352 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
353 result["result"] = "null";
354 else
355 {
356 int i = 0;
357 foreach (GridRegion rinfo in rinfos)
358 {
359 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
360 result["region" + i] = rinfoDict;
361 i++;
362 }
363 }
364  
365 string xmlString = ServerUtils.BuildXmlResponse(result);
366  
367 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
368 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
369 }
370  
371 byte[] GetRegionRange(Dictionary<string, object> request)
372 {
373 //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
374 UUID scopeID = UUID.Zero;
375 if (request.ContainsKey("SCOPEID"))
376 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
377 else
378 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
379  
380 int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
381 if (request.ContainsKey("XMIN"))
382 Int32.TryParse(request["XMIN"].ToString(), out xmin);
383 else
384 m_log.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range");
385 if (request.ContainsKey("XMAX"))
386 Int32.TryParse(request["XMAX"].ToString(), out xmax);
387 else
388 m_log.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range");
389 if (request.ContainsKey("YMIN"))
390 Int32.TryParse(request["YMIN"].ToString(), out ymin);
391 else
392 m_log.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range");
393 if (request.ContainsKey("YMAX"))
394 Int32.TryParse(request["YMAX"].ToString(), out ymax);
395 else
396 m_log.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range");
397  
398  
399 List<GridRegion> rinfos = m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
400  
401 Dictionary<string, object> result = new Dictionary<string, object>();
402 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
403 result["result"] = "null";
404 else
405 {
406 int i = 0;
407 foreach (GridRegion rinfo in rinfos)
408 {
409 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
410 result["region" + i] = rinfoDict;
411 i++;
412 }
413 }
414 string xmlString = ServerUtils.BuildXmlResponse(result);
415  
416 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
417 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
418 }
419  
420 byte[] GetDefaultRegions(Dictionary<string, object> request)
421 {
422 //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions");
423 UUID scopeID = UUID.Zero;
424 if (request.ContainsKey("SCOPEID"))
425 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
426 else
427 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
428  
429 List<GridRegion> rinfos = m_GridService.GetDefaultRegions(scopeID);
430  
431 Dictionary<string, object> result = new Dictionary<string, object>();
432 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
433 result["result"] = "null";
434 else
435 {
436 int i = 0;
437 foreach (GridRegion rinfo in rinfos)
438 {
439 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
440 result["region" + i] = rinfoDict;
441 i++;
442 }
443 }
444 string xmlString = ServerUtils.BuildXmlResponse(result);
445  
446 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
447 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
448 }
449  
450 byte[] GetDefaultHypergridRegions(Dictionary<string, object> request)
451 {
452 //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions");
453 UUID scopeID = UUID.Zero;
454 if (request.ContainsKey("SCOPEID"))
455 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
456 else
457 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
458  
459 List<GridRegion> rinfos = m_GridService.GetDefaultHypergridRegions(scopeID);
460  
461 Dictionary<string, object> result = new Dictionary<string, object>();
462 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
463 result["result"] = "null";
464 else
465 {
466 int i = 0;
467 foreach (GridRegion rinfo in rinfos)
468 {
469 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
470 result["region" + i] = rinfoDict;
471 i++;
472 }
473 }
474 string xmlString = ServerUtils.BuildXmlResponse(result);
475  
476 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
477 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
478 }
479  
480 byte[] GetFallbackRegions(Dictionary<string, object> request)
481 {
482 //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
483 UUID scopeID = UUID.Zero;
484 if (request.ContainsKey("SCOPEID"))
485 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
486 else
487 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get fallback regions");
488  
489 int x = 0, y = 0;
490 if (request.ContainsKey("X"))
491 Int32.TryParse(request["X"].ToString(), out x);
492 else
493 m_log.WarnFormat("[GRID HANDLER]: no X in request to get fallback regions");
494 if (request.ContainsKey("Y"))
495 Int32.TryParse(request["Y"].ToString(), out y);
496 else
497 m_log.WarnFormat("[GRID HANDLER]: no Y in request to get fallback regions");
498  
499  
500 List<GridRegion> rinfos = m_GridService.GetFallbackRegions(scopeID, x, y);
501  
502 Dictionary<string, object> result = new Dictionary<string, object>();
503 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
504 result["result"] = "null";
505 else
506 {
507 int i = 0;
508 foreach (GridRegion rinfo in rinfos)
509 {
510 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
511 result["region" + i] = rinfoDict;
512 i++;
513 }
514 }
515 string xmlString = ServerUtils.BuildXmlResponse(result);
516  
517 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
518 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
519 }
520  
521 byte[] GetHyperlinks(Dictionary<string, object> request)
522 {
523 //m_log.DebugFormat("[GRID HANDLER]: GetHyperlinks");
524 UUID scopeID = UUID.Zero;
525 if (request.ContainsKey("SCOPEID"))
526 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
527 else
528 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get linked regions");
529  
530 List<GridRegion> rinfos = m_GridService.GetHyperlinks(scopeID);
531  
532 Dictionary<string, object> result = new Dictionary<string, object>();
533 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
534 result["result"] = "null";
535 else
536 {
537 int i = 0;
538 foreach (GridRegion rinfo in rinfos)
539 {
540 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
541 result["region" + i] = rinfoDict;
542 i++;
543 }
544 }
545 string xmlString = ServerUtils.BuildXmlResponse(result);
546  
547 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
548 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
549 }
550  
551 byte[] GetRegionFlags(Dictionary<string, object> request)
552 {
553 UUID scopeID = UUID.Zero;
554 if (request.ContainsKey("SCOPEID"))
555 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
556 else
557 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
558  
559 UUID regionID = UUID.Zero;
560 if (request.ContainsKey("REGIONID"))
561 UUID.TryParse(request["REGIONID"].ToString(), out regionID);
562 else
563 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
564  
565 int flags = m_GridService.GetRegionFlags(scopeID, regionID);
566 // m_log.DebugFormat("[GRID HANDLER]: flags for region {0}: {1}", regionID, flags);
567  
568 Dictionary<string, object> result = new Dictionary<string, object>();
569 result["result"] = flags.ToString();
570  
571 string xmlString = ServerUtils.BuildXmlResponse(result);
572  
573 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
574 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
575 }
576  
577 #endregion
578  
579 #region Misc
580  
581 private byte[] SuccessResult()
582 {
583 XmlDocument doc = new XmlDocument();
584  
585 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
586 "", "");
587  
588 doc.AppendChild(xmlnode);
589  
590 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
591 "");
592  
593 doc.AppendChild(rootElement);
594  
595 XmlElement result = doc.CreateElement("", "Result", "");
596 result.AppendChild(doc.CreateTextNode("Success"));
597  
598 rootElement.AppendChild(result);
599  
600 return DocToBytes(doc);
601 }
602  
603 private byte[] FailureResult()
604 {
605 return FailureResult(String.Empty);
606 }
607  
608 private byte[] FailureResult(string msg)
609 {
610 XmlDocument doc = new XmlDocument();
611  
612 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
613 "", "");
614  
615 doc.AppendChild(xmlnode);
616  
617 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
618 "");
619  
620 doc.AppendChild(rootElement);
621  
622 XmlElement result = doc.CreateElement("", "Result", "");
623 result.AppendChild(doc.CreateTextNode("Failure"));
624  
625 rootElement.AppendChild(result);
626  
627 XmlElement message = doc.CreateElement("", "Message", "");
628 message.AppendChild(doc.CreateTextNode(msg));
629  
630 rootElement.AppendChild(message);
631  
632 return DocToBytes(doc);
633 }
634  
635 private byte[] DocToBytes(XmlDocument doc)
636 {
637 MemoryStream ms = new MemoryStream();
638 XmlTextWriter xw = new XmlTextWriter(ms, null);
639 xw.Formatting = Formatting.Indented;
640 doc.WriteTo(xw);
641 xw.Flush();
642  
643 return ms.ToArray();
644 }
645  
646 #endregion
647 }
648 }