PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Aurora/Services/DataService/Connectors/Local/LocalAgentConnector.cs

https://bitbucket.org/VirtualReality/software-testing
C# | 168 lines | 100 code | 23 blank | 45 comment | 14 complexity | ccf0141af914fca203307658c42819c8 MD5 | raw file
  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.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 Aurora-Sim 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. using Aurora.Framework;
  28. using Aurora.Framework.DatabaseInterfaces;
  29. using Aurora.Framework.Modules;
  30. using Aurora.Framework.Services;
  31. using Aurora.Framework.Services.ClassHelpers.Profile;
  32. using Aurora.Framework.Utilities;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenMetaverse.StructuredData;
  36. using System.Collections.Generic;
  37. namespace Aurora.Services.DataService
  38. {
  39. public class LocalAgentConnector : ConnectorBase, IAgentConnector
  40. {
  41. private IGenericData GD;
  42. private GenericAccountCache<IAgentInfo> m_cache = new GenericAccountCache<IAgentInfo>();
  43. #region IAgentConnector Members
  44. public void Initialize(IGenericData GenericData, IConfigSource source, IRegistryCore simBase,
  45. string defaultConnectionString)
  46. {
  47. GD = GenericData;
  48. if (source.Configs[Name] != null)
  49. defaultConnectionString = source.Configs[Name].GetString("ConnectionString", defaultConnectionString);
  50. if (GD != null)
  51. GD.ConnectToDatabase(defaultConnectionString, "Agent",
  52. source.Configs["AuroraConnectors"].GetBoolean("ValidateTables", true));
  53. Framework.Utilities.DataManager.RegisterPlugin(Name + "Local", this);
  54. if (source.Configs["AuroraConnectors"].GetString("AgentConnector", "LocalConnector") == "LocalConnector")
  55. {
  56. Framework.Utilities.DataManager.RegisterPlugin(this);
  57. }
  58. Init(simBase, Name);
  59. }
  60. public string Name
  61. {
  62. get { return "IAgentConnector"; }
  63. }
  64. /// <summary>
  65. /// Gets the info about the agent (TOS data, maturity info, language, etc)
  66. /// </summary>
  67. /// <param name="agentID"></param>
  68. /// <returns></returns>
  69. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  70. public IAgentInfo GetAgent(UUID agentID)
  71. {
  72. IAgentInfo agent = new IAgentInfo();
  73. if (m_cache.Get(agentID, out agent))
  74. return agent;
  75. else
  76. agent = new IAgentInfo();
  77. object remoteValue = DoRemoteForUser(agentID, agentID);
  78. if (remoteValue != null || m_doRemoteOnly)
  79. {
  80. m_cache.Cache(agentID, (IAgentInfo) remoteValue);
  81. return (IAgentInfo) remoteValue;
  82. }
  83. List<string> query = null;
  84. try
  85. {
  86. QueryFilter filter = new QueryFilter();
  87. filter.andFilters["ID"] = agentID;
  88. filter.andFilters["`Key`"] = "AgentInfo";
  89. query = GD.Query(new string[1] {"`Value`"}, "userdata", filter, null, null, null);
  90. }
  91. catch
  92. {
  93. }
  94. if (query == null || query.Count == 0)
  95. {
  96. m_cache.Cache(agentID, null);
  97. return null; //Couldn't find it, return null then.
  98. }
  99. OSDMap agentInfo = (OSDMap) OSDParser.DeserializeLLSDXml(query[0]);
  100. agent.FromOSD(agentInfo);
  101. agent.PrincipalID = agentID;
  102. m_cache.Cache(agentID, agent);
  103. return agent;
  104. }
  105. /// <summary>
  106. /// Updates the language and maturity params of the agent.
  107. /// Note: we only allow for this on the grid side
  108. /// </summary>
  109. /// <param name="agent"></param>
  110. //[CanBeReflected(ThreatLevel = ThreatLevel.Full)]
  111. public void UpdateAgent(IAgentInfo agent)
  112. {
  113. CacheAgent(agent);
  114. /*object remoteValue = DoRemoteForUser(agent.PrincipalID, agent.ToOSD());
  115. if (remoteValue != null || m_doRemoteOnly)
  116. return;*/
  117. Dictionary<string, object> values = new Dictionary<string, object>(1);
  118. values["Value"] = OSDParser.SerializeLLSDXmlString(agent.ToOSD());
  119. QueryFilter filter = new QueryFilter();
  120. filter.andFilters["ID"] = agent.PrincipalID;
  121. filter.andFilters["`Key`"] = "AgentInfo";
  122. GD.Update("userdata", values, null, filter, null, null);
  123. }
  124. public void CacheAgent(IAgentInfo agent)
  125. {
  126. m_cache.Cache(agent.PrincipalID, agent);
  127. }
  128. /// <summary>
  129. /// Creates a new database entry for the agent.
  130. /// Note: we only allow for this on the grid side
  131. /// </summary>
  132. /// <param name="agentID"></param>
  133. public void CreateNewAgent(UUID agentID)
  134. {
  135. List<object> values = new List<object> {agentID, "AgentInfo"};
  136. IAgentInfo info = new IAgentInfo {PrincipalID = agentID};
  137. values.Add(OSDParser.SerializeLLSDXmlString(info.ToOSD())); //Value which is a default Profile
  138. GD.Insert("userdata", values.ToArray());
  139. }
  140. #endregion
  141. public void Dispose()
  142. {
  143. }
  144. }
  145. }