diff options
Diffstat (limited to 'OpenSim/Services/Connectors/Grid/GridServicesConnector.cs')
-rw-r--r-- | OpenSim/Services/Connectors/Grid/GridServicesConnector.cs | 681 |
1 files changed, 681 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs new file mode 100644 index 0000000..f982cc1 --- /dev/null +++ b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs | |||
@@ -0,0 +1,681 @@ | |||
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 log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace OpenSim.Services.Connectors | ||
42 | { | ||
43 | public class GridServicesConnector : IGridService | ||
44 | { | ||
45 | private static readonly ILog m_log = | ||
46 | LogManager.GetLogger( | ||
47 | MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private string m_ServerURI = String.Empty; | ||
50 | |||
51 | private ExpiringCache<ulong, GridRegion> m_regionCache = | ||
52 | new ExpiringCache<ulong, GridRegion>(); | ||
53 | |||
54 | public GridServicesConnector() | ||
55 | { | ||
56 | } | ||
57 | |||
58 | public GridServicesConnector(string serverURI) | ||
59 | { | ||
60 | m_ServerURI = serverURI.TrimEnd('/'); | ||
61 | } | ||
62 | |||
63 | public GridServicesConnector(IConfigSource source) | ||
64 | { | ||
65 | Initialise(source); | ||
66 | } | ||
67 | |||
68 | public virtual void Initialise(IConfigSource source) | ||
69 | { | ||
70 | IConfig gridConfig = source.Configs["GridService"]; | ||
71 | if (gridConfig == null) | ||
72 | { | ||
73 | m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); | ||
74 | throw new Exception("Grid connector init error"); | ||
75 | } | ||
76 | |||
77 | string serviceURI = gridConfig.GetString("GridServerURI", | ||
78 | String.Empty); | ||
79 | |||
80 | if (serviceURI == String.Empty) | ||
81 | { | ||
82 | m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService"); | ||
83 | throw new Exception("Grid connector init error"); | ||
84 | } | ||
85 | m_ServerURI = serviceURI; | ||
86 | } | ||
87 | |||
88 | |||
89 | #region IGridService | ||
90 | |||
91 | public string RegisterRegion(UUID scopeID, GridRegion regionInfo) | ||
92 | { | ||
93 | Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs(); | ||
94 | Dictionary<string, object> sendData = new Dictionary<string,object>(); | ||
95 | foreach (KeyValuePair<string, object> kvp in rinfo) | ||
96 | sendData[kvp.Key] = (string)kvp.Value; | ||
97 | |||
98 | sendData["SCOPEID"] = scopeID.ToString(); | ||
99 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
100 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
101 | sendData["METHOD"] = "register"; | ||
102 | |||
103 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
104 | string uri = m_ServerURI + "/grid"; | ||
105 | // m_log.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString); | ||
106 | try | ||
107 | { | ||
108 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); | ||
109 | if (reply != string.Empty) | ||
110 | { | ||
111 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
112 | |||
113 | if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "success")) | ||
114 | { | ||
115 | return String.Empty; | ||
116 | } | ||
117 | else if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "failure")) | ||
118 | { | ||
119 | m_log.ErrorFormat( | ||
120 | "[GRID CONNECTOR]: Registration failed: {0} when contacting {1}", replyData["Message"], uri); | ||
121 | |||
122 | return replyData["Message"].ToString(); | ||
123 | } | ||
124 | else if (!replyData.ContainsKey("Result")) | ||
125 | { | ||
126 | m_log.ErrorFormat( | ||
127 | "[GRID CONNECTOR]: reply data does not contain result field when contacting {0}", uri); | ||
128 | } | ||
129 | else | ||
130 | { | ||
131 | m_log.ErrorFormat( | ||
132 | "[GRID CONNECTOR]: unexpected result {0} when contacting {1}", replyData["Result"], uri); | ||
133 | |||
134 | return "Unexpected result " + replyData["Result"].ToString(); | ||
135 | } | ||
136 | } | ||
137 | else | ||
138 | { | ||
139 | m_log.ErrorFormat( | ||
140 | "[GRID CONNECTOR]: RegisterRegion received null reply when contacting grid server at {0}", uri); | ||
141 | } | ||
142 | } | ||
143 | catch (Exception e) | ||
144 | { | ||
145 | m_log.ErrorFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
146 | } | ||
147 | |||
148 | return string.Format("Error communicating with the grid service at {0}", uri); | ||
149 | } | ||
150 | |||
151 | public bool DeregisterRegion(UUID regionID) | ||
152 | { | ||
153 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
154 | |||
155 | sendData["REGIONID"] = regionID.ToString(); | ||
156 | |||
157 | sendData["METHOD"] = "deregister"; | ||
158 | |||
159 | string uri = m_ServerURI + "/grid"; | ||
160 | |||
161 | try | ||
162 | { | ||
163 | string reply | ||
164 | = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); | ||
165 | |||
166 | if (reply != string.Empty) | ||
167 | { | ||
168 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
169 | |||
170 | if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success")) | ||
171 | return true; | ||
172 | } | ||
173 | else | ||
174 | m_log.DebugFormat("[GRID CONNECTOR]: DeregisterRegion received null reply"); | ||
175 | } | ||
176 | catch (Exception e) | ||
177 | { | ||
178 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
179 | } | ||
180 | |||
181 | return false; | ||
182 | } | ||
183 | |||
184 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) | ||
185 | { | ||
186 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
187 | |||
188 | sendData["SCOPEID"] = scopeID.ToString(); | ||
189 | sendData["REGIONID"] = regionID.ToString(); | ||
190 | |||
191 | sendData["METHOD"] = "get_neighbours"; | ||
192 | |||
193 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
194 | |||
195 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
196 | string reply = string.Empty; | ||
197 | string uri = m_ServerURI + "/grid"; | ||
198 | |||
199 | try | ||
200 | { | ||
201 | reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); | ||
202 | } | ||
203 | catch (Exception e) | ||
204 | { | ||
205 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
206 | return rinfos; | ||
207 | } | ||
208 | |||
209 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
210 | |||
211 | if (replyData != null) | ||
212 | { | ||
213 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
214 | //m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); | ||
215 | foreach (object r in rinfosList) | ||
216 | { | ||
217 | if (r is Dictionary<string, object>) | ||
218 | { | ||
219 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
220 | rinfos.Add(rinfo); | ||
221 | } | ||
222 | } | ||
223 | } | ||
224 | else | ||
225 | m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received null response", | ||
226 | scopeID, regionID); | ||
227 | |||
228 | return rinfos; | ||
229 | } | ||
230 | |||
231 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) | ||
232 | { | ||
233 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
234 | |||
235 | sendData["SCOPEID"] = scopeID.ToString(); | ||
236 | sendData["REGIONID"] = regionID.ToString(); | ||
237 | |||
238 | sendData["METHOD"] = "get_region_by_uuid"; | ||
239 | |||
240 | string reply = string.Empty; | ||
241 | string uri = m_ServerURI + "/grid"; | ||
242 | try | ||
243 | { | ||
244 | reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); | ||
245 | } | ||
246 | catch (Exception e) | ||
247 | { | ||
248 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
249 | return null; | ||
250 | } | ||
251 | |||
252 | GridRegion rinfo = null; | ||
253 | |||
254 | if (reply != string.Empty) | ||
255 | { | ||
256 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
257 | |||
258 | if ((replyData != null) && (replyData["result"] != null)) | ||
259 | { | ||
260 | if (replyData["result"] is Dictionary<string, object>) | ||
261 | rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]); | ||
262 | //else | ||
263 | // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", | ||
264 | // scopeID, regionID); | ||
265 | } | ||
266 | else | ||
267 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", | ||
268 | scopeID, regionID); | ||
269 | } | ||
270 | else | ||
271 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID received null reply"); | ||
272 | |||
273 | return rinfo; | ||
274 | } | ||
275 | |||
276 | public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) | ||
277 | { | ||
278 | ulong regionHandle = Util.UIntsToLong((uint)x, (uint)y); | ||
279 | |||
280 | if (m_regionCache.Contains(regionHandle)) | ||
281 | return (GridRegion)m_regionCache[regionHandle]; | ||
282 | |||
283 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
284 | |||
285 | sendData["SCOPEID"] = scopeID.ToString(); | ||
286 | sendData["X"] = x.ToString(); | ||
287 | sendData["Y"] = y.ToString(); | ||
288 | |||
289 | sendData["METHOD"] = "get_region_by_position"; | ||
290 | string reply = string.Empty; | ||
291 | string uri = m_ServerURI + "/grid"; | ||
292 | try | ||
293 | { | ||
294 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
295 | uri, | ||
296 | ServerUtils.BuildQueryString(sendData)); | ||
297 | } | ||
298 | catch (Exception e) | ||
299 | { | ||
300 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
301 | return null; | ||
302 | } | ||
303 | |||
304 | GridRegion rinfo = null; | ||
305 | if (reply != string.Empty) | ||
306 | { | ||
307 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
308 | |||
309 | if ((replyData != null) && (replyData["result"] != null)) | ||
310 | { | ||
311 | if (replyData["result"] is Dictionary<string, object>) | ||
312 | rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]); | ||
313 | //else | ||
314 | // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received no region", | ||
315 | // scopeID, x, y); | ||
316 | } | ||
317 | else | ||
318 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response", | ||
319 | scopeID, x, y); | ||
320 | } | ||
321 | else | ||
322 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply"); | ||
323 | |||
324 | m_regionCache.Add(regionHandle, rinfo, TimeSpan.FromSeconds(600)); | ||
325 | |||
326 | return rinfo; | ||
327 | } | ||
328 | |||
329 | public GridRegion GetRegionByName(UUID scopeID, string regionName) | ||
330 | { | ||
331 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
332 | |||
333 | sendData["SCOPEID"] = scopeID.ToString(); | ||
334 | sendData["NAME"] = regionName; | ||
335 | |||
336 | sendData["METHOD"] = "get_region_by_name"; | ||
337 | string reply = string.Empty; | ||
338 | string uri = m_ServerURI + "/grid"; | ||
339 | try | ||
340 | { | ||
341 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
342 | uri, | ||
343 | ServerUtils.BuildQueryString(sendData)); | ||
344 | } | ||
345 | catch (Exception e) | ||
346 | { | ||
347 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
348 | return null; | ||
349 | } | ||
350 | |||
351 | GridRegion rinfo = null; | ||
352 | if (reply != string.Empty) | ||
353 | { | ||
354 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
355 | |||
356 | if ((replyData != null) && (replyData["result"] != null)) | ||
357 | { | ||
358 | if (replyData["result"] is Dictionary<string, object>) | ||
359 | rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]); | ||
360 | } | ||
361 | else | ||
362 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response", | ||
363 | scopeID, regionName); | ||
364 | } | ||
365 | else | ||
366 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName received null reply"); | ||
367 | |||
368 | return rinfo; | ||
369 | } | ||
370 | |||
371 | public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) | ||
372 | { | ||
373 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
374 | |||
375 | sendData["SCOPEID"] = scopeID.ToString(); | ||
376 | sendData["NAME"] = name; | ||
377 | sendData["MAX"] = maxNumber.ToString(); | ||
378 | |||
379 | sendData["METHOD"] = "get_regions_by_name"; | ||
380 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
381 | string reply = string.Empty; | ||
382 | string uri = m_ServerURI + "/grid"; | ||
383 | try | ||
384 | { | ||
385 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
386 | uri, | ||
387 | ServerUtils.BuildQueryString(sendData)); | ||
388 | } | ||
389 | catch (Exception e) | ||
390 | { | ||
391 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
392 | return rinfos; | ||
393 | } | ||
394 | |||
395 | if (reply != string.Empty) | ||
396 | { | ||
397 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
398 | |||
399 | if (replyData != null) | ||
400 | { | ||
401 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
402 | foreach (object r in rinfosList) | ||
403 | { | ||
404 | if (r is Dictionary<string, object>) | ||
405 | { | ||
406 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
407 | rinfos.Add(rinfo); | ||
408 | } | ||
409 | } | ||
410 | } | ||
411 | else | ||
412 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response", | ||
413 | scopeID, name, maxNumber); | ||
414 | } | ||
415 | else | ||
416 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName received null reply"); | ||
417 | |||
418 | return rinfos; | ||
419 | } | ||
420 | |||
421 | public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) | ||
422 | { | ||
423 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
424 | |||
425 | sendData["SCOPEID"] = scopeID.ToString(); | ||
426 | sendData["XMIN"] = xmin.ToString(); | ||
427 | sendData["XMAX"] = xmax.ToString(); | ||
428 | sendData["YMIN"] = ymin.ToString(); | ||
429 | sendData["YMAX"] = ymax.ToString(); | ||
430 | |||
431 | sendData["METHOD"] = "get_region_range"; | ||
432 | |||
433 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
434 | string reply = string.Empty; | ||
435 | string uri = m_ServerURI + "/grid"; | ||
436 | |||
437 | try | ||
438 | { | ||
439 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
440 | uri, | ||
441 | ServerUtils.BuildQueryString(sendData)); | ||
442 | |||
443 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
444 | } | ||
445 | catch (Exception e) | ||
446 | { | ||
447 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
448 | return rinfos; | ||
449 | } | ||
450 | |||
451 | if (reply != string.Empty) | ||
452 | { | ||
453 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
454 | |||
455 | if (replyData != null) | ||
456 | { | ||
457 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
458 | foreach (object r in rinfosList) | ||
459 | { | ||
460 | if (r is Dictionary<string, object>) | ||
461 | { | ||
462 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
463 | rinfos.Add(rinfo); | ||
464 | } | ||
465 | } | ||
466 | } | ||
467 | else | ||
468 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response", | ||
469 | scopeID, xmin, xmax, ymin, ymax); | ||
470 | } | ||
471 | else | ||
472 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange received null reply"); | ||
473 | |||
474 | return rinfos; | ||
475 | } | ||
476 | |||
477 | public List<GridRegion> GetDefaultRegions(UUID scopeID) | ||
478 | { | ||
479 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
480 | |||
481 | sendData["SCOPEID"] = scopeID.ToString(); | ||
482 | |||
483 | sendData["METHOD"] = "get_default_regions"; | ||
484 | |||
485 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
486 | string reply = string.Empty; | ||
487 | string uri = m_ServerURI + "/grid"; | ||
488 | try | ||
489 | { | ||
490 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
491 | uri, | ||
492 | ServerUtils.BuildQueryString(sendData)); | ||
493 | |||
494 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
495 | } | ||
496 | catch (Exception e) | ||
497 | { | ||
498 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
499 | return rinfos; | ||
500 | } | ||
501 | |||
502 | if (reply != string.Empty) | ||
503 | { | ||
504 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
505 | |||
506 | if (replyData != null) | ||
507 | { | ||
508 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
509 | foreach (object r in rinfosList) | ||
510 | { | ||
511 | if (r is Dictionary<string, object>) | ||
512 | { | ||
513 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
514 | rinfos.Add(rinfo); | ||
515 | } | ||
516 | } | ||
517 | } | ||
518 | else | ||
519 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions {0} received null response", | ||
520 | scopeID); | ||
521 | } | ||
522 | else | ||
523 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply"); | ||
524 | |||
525 | return rinfos; | ||
526 | } | ||
527 | |||
528 | public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y) | ||
529 | { | ||
530 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
531 | |||
532 | sendData["SCOPEID"] = scopeID.ToString(); | ||
533 | sendData["X"] = x.ToString(); | ||
534 | sendData["Y"] = y.ToString(); | ||
535 | |||
536 | sendData["METHOD"] = "get_fallback_regions"; | ||
537 | |||
538 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
539 | string reply = string.Empty; | ||
540 | string uri = m_ServerURI + "/grid"; | ||
541 | try | ||
542 | { | ||
543 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
544 | uri, | ||
545 | ServerUtils.BuildQueryString(sendData)); | ||
546 | |||
547 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
548 | } | ||
549 | catch (Exception e) | ||
550 | { | ||
551 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
552 | return rinfos; | ||
553 | } | ||
554 | |||
555 | if (reply != string.Empty) | ||
556 | { | ||
557 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
558 | |||
559 | if (replyData != null) | ||
560 | { | ||
561 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
562 | foreach (object r in rinfosList) | ||
563 | { | ||
564 | if (r is Dictionary<string, object>) | ||
565 | { | ||
566 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
567 | rinfos.Add(rinfo); | ||
568 | } | ||
569 | } | ||
570 | } | ||
571 | else | ||
572 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response", | ||
573 | scopeID, x, y); | ||
574 | } | ||
575 | else | ||
576 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply"); | ||
577 | |||
578 | return rinfos; | ||
579 | } | ||
580 | |||
581 | public List<GridRegion> GetHyperlinks(UUID scopeID) | ||
582 | { | ||
583 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
584 | |||
585 | sendData["SCOPEID"] = scopeID.ToString(); | ||
586 | |||
587 | sendData["METHOD"] = "get_hyperlinks"; | ||
588 | |||
589 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
590 | string reply = string.Empty; | ||
591 | string uri = m_ServerURI + "/grid"; | ||
592 | try | ||
593 | { | ||
594 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
595 | uri, | ||
596 | ServerUtils.BuildQueryString(sendData)); | ||
597 | |||
598 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
599 | } | ||
600 | catch (Exception e) | ||
601 | { | ||
602 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
603 | return rinfos; | ||
604 | } | ||
605 | |||
606 | if (reply != string.Empty) | ||
607 | { | ||
608 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
609 | |||
610 | if (replyData != null) | ||
611 | { | ||
612 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
613 | foreach (object r in rinfosList) | ||
614 | { | ||
615 | if (r is Dictionary<string, object>) | ||
616 | { | ||
617 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
618 | rinfos.Add(rinfo); | ||
619 | } | ||
620 | } | ||
621 | } | ||
622 | else | ||
623 | m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks {0} received null response", | ||
624 | scopeID); | ||
625 | } | ||
626 | else | ||
627 | m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks received null reply"); | ||
628 | |||
629 | return rinfos; | ||
630 | } | ||
631 | |||
632 | public int GetRegionFlags(UUID scopeID, UUID regionID) | ||
633 | { | ||
634 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
635 | |||
636 | sendData["SCOPEID"] = scopeID.ToString(); | ||
637 | sendData["REGIONID"] = regionID.ToString(); | ||
638 | |||
639 | sendData["METHOD"] = "get_region_flags"; | ||
640 | |||
641 | string reply = string.Empty; | ||
642 | string uri = m_ServerURI + "/grid"; | ||
643 | try | ||
644 | { | ||
645 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
646 | uri, | ||
647 | ServerUtils.BuildQueryString(sendData)); | ||
648 | } | ||
649 | catch (Exception e) | ||
650 | { | ||
651 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
652 | return -1; | ||
653 | } | ||
654 | |||
655 | int flags = -1; | ||
656 | |||
657 | if (reply != string.Empty) | ||
658 | { | ||
659 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
660 | |||
661 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
662 | { | ||
663 | Int32.TryParse((string)replyData["result"], out flags); | ||
664 | //else | ||
665 | // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received wrong type {2}", | ||
666 | // scopeID, regionID, replyData["result"].GetType()); | ||
667 | } | ||
668 | else | ||
669 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response", | ||
670 | scopeID, regionID); | ||
671 | } | ||
672 | else | ||
673 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags received null reply"); | ||
674 | |||
675 | return flags; | ||
676 | } | ||
677 | |||
678 | #endregion | ||
679 | |||
680 | } | ||
681 | } | ||