opensim-development – Blame information for rev 1

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