PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

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