AppearanceTableMapper.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.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 OpenSim 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;
  28. using System.Collections.Generic;
  29. using System.Text;
  30. using OpenSim.Region.Environment.Scenes;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Data.Base;
  33. namespace OpenSim.Region.Modules.AvatarFactory
  34. {
  35. public class AppearanceRowMapper : BaseRowMapper<AvatarAppearance>
  36. {
  37. public AppearanceRowMapper(BaseSchema schema, AvatarAppearance obj)
  38. : base(schema, obj)
  39. {
  40. }
  41. }
  42. public class AppearanceTableMapper : BaseTableMapper<AppearanceRowMapper, Guid>
  43. {
  44. public AppearanceTableMapper(BaseDatabaseConnector database, string tableName)
  45. : base(database, tableName)
  46. {
  47. BaseSchema<AppearanceRowMapper> rowMapperSchema = new BaseSchema<AppearanceRowMapper>(this);
  48. m_schema = rowMapperSchema;
  49. m_keyFieldMapper = rowMapperSchema.AddMapping<Guid>("UUID",
  50. delegate(AppearanceRowMapper mapper) { return mapper.Object.ScenePresenceID.UUID; },
  51. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.ScenePresenceID = new libsecondlife.LLUUID(value.ToString()); });
  52. rowMapperSchema.AddMapping<uint>("Serial",
  53. delegate(AppearanceRowMapper mapper) { return (uint)mapper.Object.WearablesSerial; },
  54. delegate(AppearanceRowMapper mapper, uint value) { mapper.Object.WearablesSerial = (int)value; });
  55. rowMapperSchema.AddMapping<Guid>("WearableItem0",
  56. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].ItemID.UUID; },
  57. delegate(AppearanceRowMapper mapper, Guid value)
  58. {
  59. if (mapper.Object.Wearables == null)
  60. {
  61. mapper.Object.Wearables = new OpenSim.Framework.AvatarWearable[13];
  62. for (int i = 0; i < 13; i++)
  63. {
  64. mapper.Object.Wearables[i] = new AvatarWearable();
  65. }
  66. }
  67. mapper.Object.Wearables[0].ItemID = new libsecondlife.LLUUID(value.ToString());
  68. });
  69. rowMapperSchema.AddMapping<Guid>("WearableAsset0",
  70. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].AssetID.UUID; },
  71. delegate(AppearanceRowMapper mapper, Guid value)
  72. { mapper.Object.Wearables[0].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  73. rowMapperSchema.AddMapping<Guid>("WearableItem1",
  74. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].ItemID.UUID; },
  75. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[1].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  76. rowMapperSchema.AddMapping<Guid>("WearableAsset1",
  77. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].AssetID.UUID; },
  78. delegate(AppearanceRowMapper mapper, Guid value)
  79. { mapper.Object.Wearables[1].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  80. rowMapperSchema.AddMapping<Guid>("WearableItem2",
  81. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].ItemID.UUID; },
  82. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[2].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  83. rowMapperSchema.AddMapping<Guid>("WearableAsset2",
  84. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].AssetID.UUID; },
  85. delegate(AppearanceRowMapper mapper, Guid value)
  86. { mapper.Object.Wearables[2].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  87. rowMapperSchema.AddMapping<Guid>("WearableItem3",
  88. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].ItemID.UUID; },
  89. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[3].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  90. rowMapperSchema.AddMapping<Guid>("WearableAsset3",
  91. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].AssetID.UUID; },
  92. delegate(AppearanceRowMapper mapper, Guid value)
  93. { mapper.Object.Wearables[3].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  94. rowMapperSchema.AddMapping<Guid>("WearableItem4",
  95. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].ItemID.UUID; },
  96. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[4].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  97. rowMapperSchema.AddMapping<Guid>("WearableAsset4",
  98. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].AssetID.UUID; },
  99. delegate(AppearanceRowMapper mapper, Guid value)
  100. { mapper.Object.Wearables[4].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  101. rowMapperSchema.AddMapping<Guid>("WearableItem5",
  102. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].ItemID.UUID; },
  103. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[5].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  104. rowMapperSchema.AddMapping<Guid>("WearableAsset5",
  105. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].AssetID.UUID; },
  106. delegate(AppearanceRowMapper mapper, Guid value)
  107. { mapper.Object.Wearables[5].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  108. rowMapperSchema.AddMapping<Guid>("WearableItem6",
  109. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].ItemID.UUID; },
  110. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[6].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  111. rowMapperSchema.AddMapping<Guid>("WearableAsset6",
  112. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].AssetID.UUID; },
  113. delegate(AppearanceRowMapper mapper, Guid value)
  114. { mapper.Object.Wearables[6].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  115. rowMapperSchema.AddMapping<Guid>("WearableItem7",
  116. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].ItemID.UUID; },
  117. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[7].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  118. rowMapperSchema.AddMapping<Guid>("WearableAsset7",
  119. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].AssetID.UUID; },
  120. delegate(AppearanceRowMapper mapper, Guid value)
  121. { mapper.Object.Wearables[7].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  122. rowMapperSchema.AddMapping<Guid>("WearableItem8",
  123. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].ItemID.UUID; },
  124. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[8].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  125. rowMapperSchema.AddMapping<Guid>("WearableAsset8",
  126. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].AssetID.UUID; },
  127. delegate(AppearanceRowMapper mapper, Guid value)
  128. { mapper.Object.Wearables[8].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  129. rowMapperSchema.AddMapping<Guid>("WearableItem9",
  130. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].ItemID.UUID; },
  131. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[9].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  132. rowMapperSchema.AddMapping<Guid>("WearableAsset9",
  133. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].AssetID.UUID; },
  134. delegate(AppearanceRowMapper mapper, Guid value)
  135. { mapper.Object.Wearables[9].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  136. rowMapperSchema.AddMapping<Guid>("WearableItem10",
  137. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].ItemID.UUID; },
  138. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[10].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  139. rowMapperSchema.AddMapping<Guid>("WearableAsset10",
  140. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].AssetID.UUID; },
  141. delegate(AppearanceRowMapper mapper, Guid value)
  142. { mapper.Object.Wearables[10].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  143. rowMapperSchema.AddMapping<Guid>("WearableItem11",
  144. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].ItemID.UUID; },
  145. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[11].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  146. rowMapperSchema.AddMapping<Guid>("WearableAsset11",
  147. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].AssetID.UUID; },
  148. delegate(AppearanceRowMapper mapper, Guid value)
  149. { mapper.Object.Wearables[11].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  150. rowMapperSchema.AddMapping<Guid>("WearableItem12",
  151. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].ItemID.UUID; },
  152. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[12].ItemID = new libsecondlife.LLUUID(value.ToString()); });
  153. rowMapperSchema.AddMapping<Guid>("WearableAsset12",
  154. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].AssetID.UUID; },
  155. delegate(AppearanceRowMapper mapper, Guid value)
  156. { mapper.Object.Wearables[12].AssetID = new libsecondlife.LLUUID(value.ToString()); });
  157. }
  158. public bool Add(Guid userID, AvatarAppearance appearance)
  159. {
  160. AppearanceRowMapper mapper = CreateRowMapper(appearance);
  161. return Add(mapper);
  162. }
  163. public bool Update(Guid userID, AvatarAppearance appearance)
  164. {
  165. AppearanceRowMapper mapper = CreateRowMapper(appearance);
  166. return Update(appearance.ScenePresenceID.UUID, mapper);
  167. }
  168. protected AppearanceRowMapper CreateRowMapper(AvatarAppearance appearance)
  169. {
  170. return new AppearanceRowMapper(m_schema, appearance);
  171. }
  172. protected AppearanceRowMapper CreateRowMapper()
  173. {
  174. return CreateRowMapper(new AvatarAppearance());
  175. }
  176. protected AppearanceRowMapper FromReader(BaseDataReader reader, AvatarAppearance appearance)
  177. {
  178. AppearanceRowMapper mapper = CreateRowMapper(appearance);
  179. mapper.FillObject(reader);
  180. return mapper;
  181. }
  182. public override AppearanceRowMapper FromReader(BaseDataReader reader)
  183. {
  184. AppearanceRowMapper mapper = CreateRowMapper();
  185. mapper.FillObject(reader);
  186. return mapper;
  187. }
  188. public bool TryGetValue(Guid presenceID, out AvatarAppearance val)
  189. {
  190. AppearanceRowMapper mapper;
  191. if (TryGetValue(presenceID, out mapper))
  192. {
  193. val = mapper.Object;
  194. return true;
  195. }
  196. else
  197. {
  198. val = null;
  199. return false;
  200. }
  201. }
  202. }
  203. }