clockwerk-opensim – Blame information for rev 1
?pathlinks?
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 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.Framework.ServiceAuth; |
||
37 | using OpenSim.Services.Interfaces; |
||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
||
39 | using OpenSim.Server.Base; |
||
40 | using OpenMetaverse; |
||
41 | |||
42 | namespace OpenSim.Services.Connectors |
||
43 | { |
||
44 | public class GridServicesConnector : BaseServiceConnector, IGridService |
||
45 | { |
||
46 | private static readonly ILog m_log = |
||
47 | LogManager.GetLogger( |
||
48 | MethodBase.GetCurrentMethod().DeclaringType); |
||
49 | |||
50 | private string m_ServerURI = String.Empty; |
||
51 | |||
52 | public GridServicesConnector() |
||
53 | { |
||
54 | } |
||
55 | |||
56 | public GridServicesConnector(string serverURI) |
||
57 | { |
||
58 | m_ServerURI = serverURI.TrimEnd('/'); |
||
59 | } |
||
60 | |||
61 | public GridServicesConnector(IConfigSource source) |
||
62 | { |
||
63 | Initialise(source); |
||
64 | } |
||
65 | |||
66 | public virtual void Initialise(IConfigSource source) |
||
67 | { |
||
68 | IConfig gridConfig = source.Configs["GridService"]; |
||
69 | if (gridConfig == null) |
||
70 | { |
||
71 | m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); |
||
72 | throw new Exception("Grid connector init error"); |
||
73 | } |
||
74 | |||
75 | string serviceURI = gridConfig.GetString("GridServerURI", |
||
76 | String.Empty); |
||
77 | |||
78 | if (serviceURI == String.Empty) |
||
79 | { |
||
80 | m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService"); |
||
81 | throw new Exception("Grid connector init error"); |
||
82 | } |
||
83 | m_ServerURI = serviceURI; |
||
84 | |||
85 | base.Initialise(source, "GridService"); |
||
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, m_Auth); |
||
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), m_Auth); |
||
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, m_Auth); |
||
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), m_Auth); |
||
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 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
||
279 | |||
280 | sendData["SCOPEID"] = scopeID.ToString(); |
||
281 | sendData["X"] = x.ToString(); |
||
282 | sendData["Y"] = y.ToString(); |
||
283 | |||
284 | sendData["METHOD"] = "get_region_by_position"; |
||
285 | string reply = string.Empty; |
||
286 | string uri = m_ServerURI + "/grid"; |
||
287 | try |
||
288 | { |
||
289 | reply = SynchronousRestFormsRequester.MakeRequest("POST", |
||
290 | uri, |
||
291 | ServerUtils.BuildQueryString(sendData), m_Auth); |
||
292 | } |
||
293 | catch (Exception e) |
||
294 | { |
||
295 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); |
||
296 | return null; |
||
297 | } |
||
298 | |||
299 | GridRegion rinfo = null; |
||
300 | if (reply != string.Empty) |
||
301 | { |
||
302 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
||
303 | |||
304 | if ((replyData != null) && (replyData["result"] != null)) |
||
305 | { |
||
306 | if (replyData["result"] is Dictionary<string, object>) |
||
307 | rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]); |
||
308 | //else |
||
309 | // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received no region", |
||
310 | // scopeID, x, y); |
||
311 | } |
||
312 | else |
||
313 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response", |
||
314 | scopeID, x, y); |
||
315 | } |
||
316 | else |
||
317 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply"); |
||
318 | |||
319 | return rinfo; |
||
320 | } |
||
321 | |||
322 | public GridRegion GetRegionByName(UUID scopeID, string regionName) |
||
323 | { |
||
324 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
||
325 | |||
326 | sendData["SCOPEID"] = scopeID.ToString(); |
||
327 | sendData["NAME"] = regionName; |
||
328 | |||
329 | sendData["METHOD"] = "get_region_by_name"; |
||
330 | string reply = string.Empty; |
||
331 | string uri = m_ServerURI + "/grid"; |
||
332 | try |
||
333 | { |
||
334 | reply = SynchronousRestFormsRequester.MakeRequest("POST", |
||
335 | uri, |
||
336 | ServerUtils.BuildQueryString(sendData), m_Auth); |
||
337 | } |
||
338 | catch (Exception e) |
||
339 | { |
||
340 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); |
||
341 | return null; |
||
342 | } |
||
343 | |||
344 | GridRegion rinfo = null; |
||
345 | if (reply != string.Empty) |
||
346 | { |
||
347 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
||
348 | |||
349 | if ((replyData != null) && (replyData["result"] != null)) |
||
350 | { |
||
351 | if (replyData["result"] is Dictionary<string, object>) |
||
352 | rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]); |
||
353 | } |
||
354 | else |
||
355 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response", |
||
356 | scopeID, regionName); |
||
357 | } |
||
358 | else |
||
359 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName received null reply"); |
||
360 | |||
361 | return rinfo; |
||
362 | } |
||
363 | |||
364 | public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) |
||
365 | { |
||
366 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
||
367 | |||
368 | sendData["SCOPEID"] = scopeID.ToString(); |
||
369 | sendData["NAME"] = name; |
||
370 | sendData["MAX"] = maxNumber.ToString(); |
||
371 | |||
372 | sendData["METHOD"] = "get_regions_by_name"; |
||
373 | List<GridRegion> rinfos = new List<GridRegion>(); |
||
374 | string reply = string.Empty; |
||
375 | string uri = m_ServerURI + "/grid"; |
||
376 | try |
||
377 | { |
||
378 | reply = SynchronousRestFormsRequester.MakeRequest("POST", |
||
379 | uri, |
||
380 | ServerUtils.BuildQueryString(sendData), m_Auth); |
||
381 | } |
||
382 | catch (Exception e) |
||
383 | { |
||
384 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); |
||
385 | return rinfos; |
||
386 | } |
||
387 | |||
388 | if (reply != string.Empty) |
||
389 | { |
||
390 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
||
391 | |||
392 | if (replyData != null) |
||
393 | { |
||
394 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; |
||
395 | foreach (object r in rinfosList) |
||
396 | { |
||
397 | if (r is Dictionary<string, object>) |
||
398 | { |
||
399 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); |
||
400 | rinfos.Add(rinfo); |
||
401 | } |
||
402 | } |
||
403 | } |
||
404 | else |
||
405 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response", |
||
406 | scopeID, name, maxNumber); |
||
407 | } |
||
408 | else |
||
409 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName received null reply"); |
||
410 | |||
411 | return rinfos; |
||
412 | } |
||
413 | |||
414 | public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) |
||
415 | { |
||
416 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
||
417 | |||
418 | sendData["SCOPEID"] = scopeID.ToString(); |
||
419 | sendData["XMIN"] = xmin.ToString(); |
||
420 | sendData["XMAX"] = xmax.ToString(); |
||
421 | sendData["YMIN"] = ymin.ToString(); |
||
422 | sendData["YMAX"] = ymax.ToString(); |
||
423 | |||
424 | sendData["METHOD"] = "get_region_range"; |
||
425 | |||
426 | List<GridRegion> rinfos = new List<GridRegion>(); |
||
427 | string reply = string.Empty; |
||
428 | string uri = m_ServerURI + "/grid"; |
||
429 | |||
430 | try |
||
431 | { |
||
432 | reply = SynchronousRestFormsRequester.MakeRequest("POST", |
||
433 | uri, |
||
434 | ServerUtils.BuildQueryString(sendData), m_Auth); |
||
435 | |||
436 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); |
||
437 | } |
||
438 | catch (Exception e) |
||
439 | { |
||
440 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); |
||
441 | return rinfos; |
||
442 | } |
||
443 | |||
444 | if (reply != string.Empty) |
||
445 | { |
||
446 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
||
447 | |||
448 | if (replyData != null) |
||
449 | { |
||
450 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; |
||
451 | foreach (object r in rinfosList) |
||
452 | { |
||
453 | if (r is Dictionary<string, object>) |
||
454 | { |
||
455 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); |
||
456 | rinfos.Add(rinfo); |
||
457 | } |
||
458 | } |
||
459 | } |
||
460 | else |
||
461 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response", |
||
462 | scopeID, xmin, xmax, ymin, ymax); |
||
463 | } |
||
464 | else |
||
465 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange received null reply"); |
||
466 | |||
467 | return rinfos; |
||
468 | } |
||
469 | |||
470 | public List<GridRegion> GetDefaultRegions(UUID scopeID) |
||
471 | { |
||
472 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
||
473 | |||
474 | sendData["SCOPEID"] = scopeID.ToString(); |
||
475 | |||
476 | sendData["METHOD"] = "get_default_regions"; |
||
477 | |||
478 | List<GridRegion> rinfos = new List<GridRegion>(); |
||
479 | string reply = string.Empty; |
||
480 | string uri = m_ServerURI + "/grid"; |
||
481 | try |
||
482 | { |
||
483 | reply = SynchronousRestFormsRequester.MakeRequest("POST", |
||
484 | uri, |
||
485 | ServerUtils.BuildQueryString(sendData), m_Auth); |
||
486 | |||
487 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); |
||
488 | } |
||
489 | catch (Exception e) |
||
490 | { |
||
491 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); |
||
492 | return rinfos; |
||
493 | } |
||
494 | |||
495 | if (reply != string.Empty) |
||
496 | { |
||
497 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
||
498 | |||
499 | if (replyData != null) |
||
500 | { |
||
501 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; |
||
502 | foreach (object r in rinfosList) |
||
503 | { |
||
504 | if (r is Dictionary<string, object>) |
||
505 | { |
||
506 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); |
||
507 | rinfos.Add(rinfo); |
||
508 | } |
||
509 | } |
||
510 | } |
||
511 | else |
||
512 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions {0} received null response", |
||
513 | scopeID); |
||
514 | } |
||
515 | else |
||
516 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply"); |
||
517 | |||
518 | return rinfos; |
||
519 | } |
||
520 | |||
521 | public List<GridRegion> GetDefaultHypergridRegions(UUID scopeID) |
||
522 | { |
||
523 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
||
524 | |||
525 | sendData["SCOPEID"] = scopeID.ToString(); |
||
526 | |||
527 | sendData["METHOD"] = "get_default_hypergrid_regions"; |
||
528 | |||
529 | List<GridRegion> rinfos = new List<GridRegion>(); |
||
530 | string reply = string.Empty; |
||
531 | string uri = m_ServerURI + "/grid"; |
||
532 | try |
||
533 | { |
||
534 | reply = SynchronousRestFormsRequester.MakeRequest("POST", |
||
535 | uri, |
||
536 | ServerUtils.BuildQueryString(sendData), m_Auth); |
||
537 | |||
538 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); |
||
539 | } |
||
540 | catch (Exception e) |
||
541 | { |
||
542 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); |
||
543 | return rinfos; |
||
544 | } |
||
545 | |||
546 | if (reply != string.Empty) |
||
547 | { |
||
548 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
||
549 | |||
550 | if (replyData != null) |
||
551 | { |
||
552 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; |
||
553 | foreach (object r in rinfosList) |
||
554 | { |
||
555 | if (r is Dictionary<string, object>) |
||
556 | { |
||
557 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); |
||
558 | rinfos.Add(rinfo); |
||
559 | } |
||
560 | } |
||
561 | } |
||
562 | else |
||
563 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultHypergridRegions {0} received null response", |
||
564 | scopeID); |
||
565 | } |
||
566 | else |
||
567 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultHypergridRegions received null reply"); |
||
568 | |||
569 | return rinfos; |
||
570 | } |
||
571 | |||
572 | public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y) |
||
573 | { |
||
574 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
||
575 | |||
576 | sendData["SCOPEID"] = scopeID.ToString(); |
||
577 | sendData["X"] = x.ToString(); |
||
578 | sendData["Y"] = y.ToString(); |
||
579 | |||
580 | sendData["METHOD"] = "get_fallback_regions"; |
||
581 | |||
582 | List<GridRegion> rinfos = new List<GridRegion>(); |
||
583 | string reply = string.Empty; |
||
584 | string uri = m_ServerURI + "/grid"; |
||
585 | try |
||
586 | { |
||
587 | reply = SynchronousRestFormsRequester.MakeRequest("POST", |
||
588 | uri, |
||
589 | ServerUtils.BuildQueryString(sendData), m_Auth); |
||
590 | |||
591 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); |
||
592 | } |
||
593 | catch (Exception e) |
||
594 | { |
||
595 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); |
||
596 | return rinfos; |
||
597 | } |
||
598 | |||
599 | if (reply != string.Empty) |
||
600 | { |
||
601 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
||
602 | |||
603 | if (replyData != null) |
||
604 | { |
||
605 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; |
||
606 | foreach (object r in rinfosList) |
||
607 | { |
||
608 | if (r is Dictionary<string, object>) |
||
609 | { |
||
610 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); |
||
611 | rinfos.Add(rinfo); |
||
612 | } |
||
613 | } |
||
614 | } |
||
615 | else |
||
616 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response", |
||
617 | scopeID, x, y); |
||
618 | } |
||
619 | else |
||
620 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply"); |
||
621 | |||
622 | return rinfos; |
||
623 | } |
||
624 | |||
625 | public List<GridRegion> GetHyperlinks(UUID scopeID) |
||
626 | { |
||
627 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
||
628 | |||
629 | sendData["SCOPEID"] = scopeID.ToString(); |
||
630 | |||
631 | sendData["METHOD"] = "get_hyperlinks"; |
||
632 | |||
633 | List<GridRegion> rinfos = new List<GridRegion>(); |
||
634 | string reply = string.Empty; |
||
635 | string uri = m_ServerURI + "/grid"; |
||
636 | try |
||
637 | { |
||
638 | reply = SynchronousRestFormsRequester.MakeRequest("POST", |
||
639 | uri, |
||
640 | ServerUtils.BuildQueryString(sendData), m_Auth); |
||
641 | |||
642 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); |
||
643 | } |
||
644 | catch (Exception e) |
||
645 | { |
||
646 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); |
||
647 | return rinfos; |
||
648 | } |
||
649 | |||
650 | if (reply != string.Empty) |
||
651 | { |
||
652 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
||
653 | |||
654 | if (replyData != null) |
||
655 | { |
||
656 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; |
||
657 | foreach (object r in rinfosList) |
||
658 | { |
||
659 | if (r is Dictionary<string, object>) |
||
660 | { |
||
661 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); |
||
662 | rinfos.Add(rinfo); |
||
663 | } |
||
664 | } |
||
665 | } |
||
666 | else |
||
667 | m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks {0} received null response", |
||
668 | scopeID); |
||
669 | } |
||
670 | else |
||
671 | m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks received null reply"); |
||
672 | |||
673 | return rinfos; |
||
674 | } |
||
675 | |||
676 | public int GetRegionFlags(UUID scopeID, UUID regionID) |
||
677 | { |
||
678 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
||
679 | |||
680 | sendData["SCOPEID"] = scopeID.ToString(); |
||
681 | sendData["REGIONID"] = regionID.ToString(); |
||
682 | |||
683 | sendData["METHOD"] = "get_region_flags"; |
||
684 | |||
685 | string reply = string.Empty; |
||
686 | string uri = m_ServerURI + "/grid"; |
||
687 | try |
||
688 | { |
||
689 | reply = SynchronousRestFormsRequester.MakeRequest("POST", |
||
690 | uri, |
||
691 | ServerUtils.BuildQueryString(sendData), m_Auth); |
||
692 | } |
||
693 | catch (Exception e) |
||
694 | { |
||
695 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); |
||
696 | return -1; |
||
697 | } |
||
698 | |||
699 | int flags = -1; |
||
700 | |||
701 | if (reply != string.Empty) |
||
702 | { |
||
703 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
||
704 | |||
705 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) |
||
706 | { |
||
707 | Int32.TryParse((string)replyData["result"], out flags); |
||
708 | //else |
||
709 | // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received wrong type {2}", |
||
710 | // scopeID, regionID, replyData["result"].GetType()); |
||
711 | } |
||
712 | else |
||
713 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response", |
||
714 | scopeID, regionID); |
||
715 | } |
||
716 | else |
||
717 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags received null reply"); |
||
718 | |||
719 | return flags; |
||
720 | } |
||
721 | |||
722 | public Dictionary<string, object> GetExtraFeatures() |
||
723 | { |
||
724 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
||
725 | Dictionary<string, object> extraFeatures = new Dictionary<string, object>(); |
||
726 | |||
727 | sendData["METHOD"] = "get_grid_extra_features"; |
||
728 | |||
729 | string reply = string.Empty; |
||
730 | string uri = m_ServerURI + "/grid"; |
||
731 | |||
732 | try |
||
733 | { |
||
734 | reply = SynchronousRestFormsRequester.MakeRequest("POST", |
||
735 | uri, |
||
736 | ServerUtils.BuildQueryString(sendData), m_Auth); |
||
737 | } |
||
738 | catch (Exception e) |
||
739 | { |
||
740 | m_log.DebugFormat("[GRID CONNECTOR]: GetExtraFeatures - Exception when contacting grid server at {0}: {1}", uri, e.Message); |
||
741 | return extraFeatures; |
||
742 | } |
||
743 | |||
744 | if (reply != string.Empty) |
||
745 | { |
||
746 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
||
747 | |||
748 | if ((replyData != null) && replyData.Count > 0) |
||
749 | { |
||
750 | foreach (string key in replyData.Keys) |
||
751 | { |
||
752 | extraFeatures[key] = replyData[key].ToString(); |
||
753 | } |
||
754 | } |
||
755 | } |
||
756 | else |
||
757 | m_log.DebugFormat("[GRID CONNECTOR]: GetExtraServiceURLs received null reply"); |
||
758 | |||
759 | return extraFeatures; |
||
760 | } |
||
761 | #endregion |
||
762 | |||
763 | } |
||
764 | } |