30 using System.Collections.Generic;
32 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Framework.ServiceAuth;
36 using OpenSim.Services.Interfaces;
39 using OpenSim.Server.Base;
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 private string m_ServerURI = String.Empty;
56 m_ServerURI = serverURI.TrimEnd(
'/');
60 : base(source,
"AgentPreferencesService")
67 IConfig gridConfig = source.Configs[
"AgentPreferencesService"];
68 if (gridConfig == null)
70 m_log.Error(
"[AGENT PREFERENCES CONNECTOR]: AgentPreferencesService missing from OpenSim.ini");
71 throw new Exception(
"Agent Preferences connector init error");
74 string serviceURI = gridConfig.GetString(
"AgentPreferencesServerURI", String.Empty);
76 if (serviceURI == String.Empty)
78 m_log.Error(
"[AGENT PREFERENCES CONNECTOR]: No Server URI named in section AgentPreferences");
79 throw new Exception(
"Agent Preferences connector init error");
81 m_ServerURI = serviceURI;
83 base.Initialise(source,
"AgentPreferencesService");
86 #region IAgentPreferencesService
90 Dictionary<string, object> sendData =
new Dictionary<string, object>();
92 string reply = string.Empty;
93 string uri = String.Concat(m_ServerURI,
"/agentprefs");
95 sendData[
"METHOD"] =
"getagentprefs";
96 sendData[
"UserID"] = principalID;
97 string reqString = ServerUtils.BuildQueryString(sendData);
102 reply = SynchronousRestFormsRequester.MakeRequest(
"POST", uri, reqString, m_Auth);
103 if (String.IsNullOrEmpty(reply))
105 m_log.DebugFormat(
"[AGENT PREFERENCES CONNECTOR]: GetAgentPreferences received null or empty reply");
111 m_log.DebugFormat(
"[AGENT PREFERENCES CONNECTOR]: Exception when contacting agent preferences server at {0}: {1}", uri, e.Message);
114 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
115 if (replyData != null)
117 if (replyData.ContainsKey(
"result") &&
118 (replyData[
"result"].ToString() ==
"null" || replyData[
"result"].ToString() ==
"Failure"))
120 m_log.DebugFormat(
"[AGENT PREFERENCES CONNECTOR]: GetAgentPreferences received Failure response");
126 m_log.DebugFormat(
"[AGENT PREFERENCES CONNECTOR]: GetAgentPreferences received null response");
135 Dictionary<string, object> sendData =
new Dictionary<string, object>();
137 sendData[
"METHOD"] =
"setagentprefs";
139 sendData[
"PrincipalID"] = data.PrincipalID.ToString();
140 sendData[
"AccessPrefs"] = data.AccessPrefs;
141 sendData[
"HoverHeight"] = data.HoverHeight.ToString();
142 sendData[
"Language"] = data.Language;
143 sendData[
"LanguageIsPublic"] = data.LanguageIsPublic.ToString();
144 sendData[
"PermEveryone"] = data.PermEveryone.ToString();
145 sendData[
"PermGroup"] = data.PermGroup.ToString();
146 sendData[
"PermNextOwner"] = data.PermNextOwner.ToString();
148 string uri = String.Concat(m_ServerURI,
"/agentprefs");
149 string reqString = ServerUtils.BuildQueryString(sendData);
154 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST", uri, reqString, m_Auth);
155 if (reply !=
string.Empty)
157 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
159 if (replyData.ContainsKey(
"result"))
161 if (replyData[
"result"].ToString().ToLower() ==
"success")
168 m_log.DebugFormat(
"[AGENT PREFERENCES CONNECTOR]: StoreAgentPreferences reply data does not contain result field");
173 m_log.DebugFormat(
"[AGENT PREFERENCES CONNECTOR]: StoreAgentPreferences received empty reply");
177 m_log.DebugFormat(
"[AGENT PREFERENCES CONNECTOR]: Exception when contacting agent preferences server at {0}: {1}", uri, e.Message);
185 Dictionary<string, object> sendData =
new Dictionary<string, object>();
186 string reply = string.Empty;
188 sendData[
"METHOD"] =
"getagentlang";
189 sendData[
"UserID"] = principalID.ToString();
191 string uri = String.Concat(m_ServerURI,
"/agentprefs");
192 string reqString = ServerUtils.BuildQueryString(sendData);
196 reply = SynchronousRestFormsRequester.MakeRequest(
"POST", uri, reqString, m_Auth);
197 if (String.IsNullOrEmpty(reply))
199 m_log.DebugFormat(
"[AGENT PREFERENCES CONNECTOR]: GetLang received null or empty reply");
205 m_log.DebugFormat(
"[AGENT PREFERENCES CONNECTOR]: Exception when contacting agent preferences server at {0}: {1}", uri, e.Message);
208 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
209 if (replyData != null)
211 if (replyData.ContainsKey(
"result") &&
212 (replyData[
"result"].ToString() ==
"null" || replyData[
"result"].ToString() ==
"Failure"))
214 m_log.DebugFormat(
"[AGENT PREFERENCES CONNECTOR]: GetLang received Failure response");
217 if (replyData.ContainsKey(
"Language"))
218 return replyData[
"Language"].ToString();
222 m_log.DebugFormat(
"[AGENT PREFERENCES CONNECTOR]: GetLang received null response");
228 #endregion IAgentPreferencesService
virtual void Initialise(IConfigSource source)
AgentPreferencesServicesConnector(IConfigSource source)
OpenSim.Services.Interfaces.GridRegion GridRegion
AgentPrefs GetAgentPreferences(UUID principalID)
OpenSim.Services.Interfaces.IAvatarService IAvatarService
AgentPreferencesServicesConnector(string serverURI)
bool StoreAgentPreferences(AgentPrefs data)
Interactive OpenSim region server
string GetLang(UUID principalID)
AgentPreferencesServicesConnector()