AppearanceTableMapper.cs 13 KB

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