30 using System.Collections.Generic;
33 using System.Reflection;
36 using OpenSim.Framework;
37 using OpenSim.Framework.Console;
39 using OpenSim.Framework.ServiceAuth;
40 using OpenSim.Server.Base;
41 using OpenSim.Services.Interfaces;
43 using OpenMetaverse.StructuredData;
45 namespace OpenSim.Services.Connectors
49 private static readonly ILog m_log =
51 MethodBase.GetCurrentMethod().DeclaringType);
53 private string m_ServerURI = String.Empty;
61 m_ServerURI = serverURI.TrimEnd(
'/');
71 IConfig config = source.Configs[
"MapImageService"];
74 m_log.Error(
"[MAP IMAGE CONNECTOR]: MapImageService missing");
75 throw new Exception(
"MapImage connector init error");
78 string serviceURI = config.GetString(
"MapImageServerURI",
81 if (serviceURI == String.Empty)
83 m_log.Error(
"[MAP IMAGE CONNECTOR]: No Server URI named in section MapImageService");
84 throw new Exception(
"MapImage connector init error");
86 m_ServerURI = serviceURI;
87 m_ServerURI = serviceURI.TrimEnd(
'/');
88 base.Initialise(source,
"MapImageService");
93 reason = string.Empty;
94 int tickstart = Util.EnvironmentTickCount();
95 Dictionary<string, object> sendData =
new Dictionary<string, object>();
96 sendData[
"X"] = x.ToString();
97 sendData[
"Y"] = y.ToString();
99 string reqString = ServerUtils.BuildQueryString(sendData);
100 string uri = m_ServerURI +
"/removemap";
104 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
108 if (reply !=
string.Empty)
110 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
112 if (replyData.ContainsKey(
"Result") && (replyData[
"Result"].ToString().ToLower() ==
"success"))
116 else if (replyData.ContainsKey(
"Result") && (replyData[
"Result"].ToString().ToLower() ==
"failure"))
118 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: Delete failed: {0}", replyData[
"Message"].ToString());
119 reason = replyData[
"Message"].ToString();
122 else if (!replyData.ContainsKey(
"Result"))
124 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: reply data does not contain result field");
128 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: unexpected result {0}", replyData[
"Result"].ToString());
129 reason =
"Unexpected result " + replyData[
"Result"].ToString();
135 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: Map post received null reply");
140 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: Exception when contacting map server at {0}: {1}", uri, e.Message);
145 int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
146 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: map tile deleted in {0}ms", tickdiff);
154 reason = string.Empty;
155 int tickstart = Util.EnvironmentTickCount();
156 Dictionary<string, object> sendData =
new Dictionary<string, object>();
157 sendData[
"X"] = x.ToString();
158 sendData[
"Y"] = y.ToString();
159 sendData[
"SCOPE"] = scopeID.ToString();
161 string reqString = ServerUtils.BuildQueryString(sendData);
162 string uri = m_ServerURI +
"/removemap";
166 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
169 if (reply !=
string.Empty)
171 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
173 if (replyData.ContainsKey(
"Result") && (replyData[
"Result"].ToString().ToLower() ==
"success"))
177 else if (replyData.ContainsKey(
"Result") && (replyData[
"Result"].ToString().ToLower() ==
"failure"))
179 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: Delete failed: {0}", replyData[
"Message"].ToString());
180 reason = replyData[
"Message"].ToString();
183 else if (!replyData.ContainsKey(
"Result"))
185 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: reply data does not contain result field");
189 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: unexpected result {0}", replyData[
"Result"].ToString());
190 reason =
"Unexpected result " + replyData[
"Result"].ToString();
196 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: Map post received null reply");
201 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: Exception when contacting map server at {0}: {1}", uri, e.Message);
206 int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
207 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: map tile deleted in {0}ms", tickdiff);
213 public bool AddMapTile(
int x,
int y, byte[] jpgData, UUID scopeID, out
string reason)
215 reason = string.Empty;
216 int tickstart = Util.EnvironmentTickCount();
217 Dictionary<string, object> sendData =
new Dictionary<string, object>();
218 sendData[
"X"] = x.ToString();
219 sendData[
"Y"] = y.ToString();
220 sendData[
"SCOPE"] = scopeID.ToString();
221 sendData[
"TYPE"] =
"image/jpeg";
222 sendData[
"DATA"] = Convert.ToBase64String(jpgData);
224 string reqString = ServerUtils.BuildQueryString(sendData);
225 string uri = m_ServerURI +
"/map";
229 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
233 if (reply !=
string.Empty)
235 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
237 if (replyData.ContainsKey(
"Result") && (replyData[
"Result"].ToString().ToLower() ==
"success"))
241 else if (replyData.ContainsKey(
"Result") && (replyData[
"Result"].ToString().ToLower() ==
"failure"))
243 reason = string.Format(
"Map post to {0} failed: {1}", uri, replyData[
"Message"].ToString());
244 m_log.WarnFormat(
"[MAP IMAGE CONNECTOR]: {0}", reason);
248 else if (!replyData.ContainsKey(
"Result"))
250 reason = string.Format(
"Reply data from {0} does not contain result field", uri);
251 m_log.WarnFormat(
"[MAP IMAGE CONNECTOR]: {0}", reason);
255 reason = string.Format(
"Unexpected result {0} from {1}" + replyData[
"Result"].ToString(), uri);
256 m_log.WarnFormat(
"[MAP IMAGE CONNECTOR]: {0}", reason);
261 reason = string.Format(
"Map post received null reply from {0}", uri);
262 m_log.WarnFormat(
"[MAP IMAGE CONNECTOR]: {0}", reason);
267 reason = string.Format(
"Exception when posting to map server at {0}: {1}", uri, e.Message);
268 m_log.WarnFormat(
"[MAP IMAGE CONNECTOR]: {0}", reason);
273 int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
274 m_log.DebugFormat(
"[MAP IMAGE CONNECTOR]: map tile uploaded in {0}ms", tickdiff);
283 format = string.Empty;
284 new Exception(
"GetMapTile method not Implemented");
bool AddMapTile(int x, int y, byte[] jpgData, UUID scopeID, out string reason)
bool RemoveMapTile(int x, int y, out string reason)
byte[] GetMapTile(string fileName, UUID scopeID, out string format)
MapImageServicesConnector()
virtual void Initialise(IConfigSource source)
MapImageServicesConnector(IConfigSource source)
bool RemoveMapTile(int x, int y, UUID scopeID, out string reason)
MapImageServicesConnector(string serverURI)