PageRenderTime 56ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/VirtualReality/aurora-sim
C# | 136 lines | 90 code | 13 blank | 33 comment | 8 complexity | 30a31951e7c460addb6de254bf091698 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 System.Collections.Generic;
  28. using System.Data;
  29. using Aurora.Framework;
  30. using Nini.Config;
  31. using OpenMetaverse;
  32. namespace Aurora.Services.DataService
  33. {
  34. //This will always be local, as this is only used by the grid server.
  35. //The region server should not be using this class.
  36. public class LocalAvatarArchiverConnector : IAvatarArchiverConnector
  37. {
  38. private IGenericData GD;
  39. #region IAvatarArchiverConnector Members
  40. public void Initialize(IGenericData GenericData, IConfigSource source, IRegistryCore simBase,
  41. string defaultConnectionString)
  42. {
  43. if (source.Configs["AuroraConnectors"].GetString("AvatarArchiverConnector", "LocalConnector") == "LocalConnector")
  44. {
  45. GD = GenericData;
  46. if (source.Configs[Name] != null)
  47. {
  48. defaultConnectionString = source.Configs[Name].GetString("ConnectionString", defaultConnectionString);
  49. }
  50. GD.ConnectToDatabase(defaultConnectionString, "AvatarArchive",
  51. source.Configs["AuroraConnectors"].GetBoolean("ValidateTables", true));
  52. DataManager.DataManager.RegisterPlugin(this);
  53. }
  54. }
  55. public string Name
  56. {
  57. get { return "IAvatarArchiverConnector"; }
  58. }
  59. public AvatarArchive GetAvatarArchive(string Name)
  60. {
  61. QueryFilter filter = new QueryFilter();
  62. filter.andFilters["Name"] = Name;
  63. List<string> RetVal = GD.Query(new string[] { "*" }, "avatararchives", filter, null, null, null);
  64. return (RetVal.Count == 0) ? null : new AvatarArchive {
  65. Name = RetVal[0],
  66. ArchiveXML = RetVal[1]
  67. };
  68. }
  69. /// <summary>
  70. /// Returns a list object of AvatarArchives. This is being used for WebUI
  71. /// </summary>
  72. /// <param name = "Public"></param>
  73. /// <returns></returns>
  74. public List<AvatarArchive> GetAvatarArchives(bool isPublic)
  75. {
  76. List<AvatarArchive> returnValue = new List<AvatarArchive>();
  77. DataReaderConnection RetVal = null;
  78. try
  79. {
  80. RetVal = GD.QueryData("where IsPublic = 1", "avatararchives", "Name, Snapshot, IsPublic");
  81. while (RetVal.DataReader.Read())
  82. {
  83. AvatarArchive Archive = new AvatarArchive
  84. {
  85. Name = RetVal.DataReader["Name"].ToString(),
  86. Snapshot = RetVal.DataReader["Snapshot"].ToString(),
  87. IsPublic = int.Parse(RetVal.DataReader["IsPublic"].ToString())
  88. };
  89. returnValue.Add(Archive);
  90. }
  91. }
  92. catch
  93. {
  94. GD.CloseDatabase(RetVal);
  95. }
  96. return returnValue;
  97. }
  98. public void SaveAvatarArchive(AvatarArchive archive)
  99. {
  100. QueryFilter filter = new QueryFilter();
  101. filter.andFilters["Name"] = archive.Name;
  102. List<string> Check = GD.Query(new string[] { "Name" }, "avatararchives", filter, null, null, null);
  103. if (Check.Count == 0)
  104. {
  105. GD.Insert("avatararchives", new object[]{
  106. archive.Name,
  107. archive.ArchiveXML,
  108. archive.Snapshot,
  109. archive.IsPublic
  110. });
  111. }
  112. else
  113. {
  114. Dictionary<string, object> values = new Dictionary<string, object>(1);
  115. values["Archive"] = archive.ArchiveXML;
  116. values["Snapshot"] = archive.Snapshot;
  117. values["IsPublic"] = archive.IsPublic;
  118. GD.Update("avatararchives", values, null, filter, null, null);
  119. }
  120. }
  121. #endregion
  122. }
  123. }