diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs | 264 |
1 files changed, 0 insertions, 264 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs deleted file mode 100644 index fdda150..0000000 --- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs +++ /dev/null | |||
@@ -1,264 +0,0 @@ | |||
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 OpenSimulator 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.Reflection; | ||
31 | using System.Threading; | ||
32 | using log4net; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | |||
36 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | |||
40 | //using HyperGrid.Framework; | ||
41 | //using OpenSim.Region.Communications.Hypergrid; | ||
42 | |||
43 | namespace OpenSim.Region.Framework.Scenes.Hypergrid | ||
44 | { | ||
45 | public class HGAssetMapper | ||
46 | { | ||
47 | #region Fields | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | // This maps between inventory server urls and inventory server clients | ||
51 | // private Dictionary<string, InventoryClient> m_inventoryServers = new Dictionary<string, InventoryClient>(); | ||
52 | |||
53 | private Scene m_scene; | ||
54 | |||
55 | private IHyperAssetService m_hyper; | ||
56 | IHyperAssetService HyperlinkAssets | ||
57 | { | ||
58 | get | ||
59 | { | ||
60 | if (m_hyper == null) | ||
61 | m_hyper = m_scene.RequestModuleInterface<IHyperAssetService>(); | ||
62 | return m_hyper; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | #endregion | ||
67 | |||
68 | #region Constructor | ||
69 | |||
70 | public HGAssetMapper(Scene scene) | ||
71 | { | ||
72 | m_scene = scene; | ||
73 | } | ||
74 | |||
75 | #endregion | ||
76 | |||
77 | #region Internal functions | ||
78 | |||
79 | // private string UserAssetURL(UUID userID) | ||
80 | // { | ||
81 | // CachedUserInfo uinfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(userID); | ||
82 | // if (uinfo != null) | ||
83 | // return (uinfo.UserProfile.UserAssetURI == "") ? null : uinfo.UserProfile.UserAssetURI; | ||
84 | // return null; | ||
85 | // } | ||
86 | |||
87 | // private string UserInventoryURL(UUID userID) | ||
88 | // { | ||
89 | // CachedUserInfo uinfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(userID); | ||
90 | // if (uinfo != null) | ||
91 | // return (uinfo.UserProfile.UserInventoryURI == "") ? null : uinfo.UserProfile.UserInventoryURI; | ||
92 | // return null; | ||
93 | // } | ||
94 | |||
95 | |||
96 | public AssetBase FetchAsset(string url, UUID assetID) | ||
97 | { | ||
98 | AssetBase asset = m_scene.AssetService.Get(url + "/" + assetID.ToString()); | ||
99 | |||
100 | if (asset != null) | ||
101 | { | ||
102 | m_log.DebugFormat("[HGScene]: Copied asset {0} from {1} to local asset server. ", asset.ID, url); | ||
103 | return asset; | ||
104 | } | ||
105 | return null; | ||
106 | } | ||
107 | |||
108 | public bool PostAsset(string url, AssetBase asset) | ||
109 | { | ||
110 | if (asset != null) | ||
111 | { | ||
112 | // See long comment in AssetCache.AddAsset | ||
113 | if (!asset.Temporary || asset.Local) | ||
114 | { | ||
115 | // We need to copy the asset into a new asset, because | ||
116 | // we need to set its ID to be URL+UUID, so that the | ||
117 | // HGAssetService dispatches it to the remote grid. | ||
118 | // It's not pretty, but the best that can be done while | ||
119 | // not having a global naming infrastructure | ||
120 | AssetBase asset1 = new AssetBase(asset.FullID, asset.Name, asset.Type); | ||
121 | Copy(asset, asset1); | ||
122 | try | ||
123 | { | ||
124 | asset1.ID = url + "/" + asset.ID; | ||
125 | } | ||
126 | catch | ||
127 | { | ||
128 | m_log.Warn("[HGScene]: Oops."); | ||
129 | } | ||
130 | |||
131 | m_scene.AssetService.Store(asset1); | ||
132 | m_log.DebugFormat("[HGScene]: Posted copy of asset {0} from local asset server to {1}", asset1.ID, url); | ||
133 | } | ||
134 | return true; | ||
135 | } | ||
136 | else | ||
137 | m_log.Warn("[HGScene]: Tried to post asset to remote server, but asset not in local cache."); | ||
138 | |||
139 | return false; | ||
140 | } | ||
141 | |||
142 | private void Copy(AssetBase from, AssetBase to) | ||
143 | { | ||
144 | to.Data = from.Data; | ||
145 | to.Description = from.Description; | ||
146 | to.FullID = from.FullID; | ||
147 | to.ID = from.ID; | ||
148 | to.Local = from.Local; | ||
149 | to.Name = from.Name; | ||
150 | to.Temporary = from.Temporary; | ||
151 | to.Type = from.Type; | ||
152 | |||
153 | } | ||
154 | |||
155 | // TODO: unused | ||
156 | // private void Dump(Dictionary<UUID, bool> lst) | ||
157 | // { | ||
158 | // m_log.Debug("XXX -------- UUID DUMP ------- XXX"); | ||
159 | // foreach (KeyValuePair<UUID, bool> kvp in lst) | ||
160 | // m_log.Debug(" >> " + kvp.Key + " (texture? " + kvp.Value + ")"); | ||
161 | // m_log.Debug("XXX -------- UUID DUMP ------- XXX"); | ||
162 | // } | ||
163 | |||
164 | #endregion | ||
165 | |||
166 | |||
167 | #region Public interface | ||
168 | |||
169 | public void Get(UUID assetID, UUID ownerID) | ||
170 | { | ||
171 | // Get the item from the remote asset server onto the local AssetCache | ||
172 | // and place an entry in m_assetMap | ||
173 | |||
174 | string userAssetURL = HyperlinkAssets.GetUserAssetServer(ownerID); | ||
175 | if ((userAssetURL != string.Empty) && (userAssetURL != HyperlinkAssets.GetSimAssetServer())) | ||
176 | { | ||
177 | m_log.Debug("[HGScene]: Fetching object " + assetID + " from asset server " + userAssetURL); | ||
178 | AssetBase asset = FetchAsset(userAssetURL, assetID); | ||
179 | |||
180 | if (asset != null) | ||
181 | { | ||
182 | // OK, now fetch the inside. | ||
183 | Dictionary<UUID, int> ids = new Dictionary<UUID, int>(); | ||
184 | HGUuidGatherer uuidGatherer = new HGUuidGatherer(this, m_scene.AssetService, userAssetURL); | ||
185 | uuidGatherer.GatherAssetUuids(asset.FullID, (AssetType)asset.Type, ids); | ||
186 | foreach (UUID uuid in ids.Keys) | ||
187 | FetchAsset(userAssetURL, uuid); | ||
188 | |||
189 | m_log.DebugFormat("[HGScene]: Successfully fetched asset {0} from asset server {1}", asset.ID, userAssetURL); | ||
190 | |||
191 | } | ||
192 | else | ||
193 | m_log.Warn("[HGScene]: Could not fetch asset from remote asset server " + userAssetURL); | ||
194 | } | ||
195 | else | ||
196 | m_log.Debug("[HGScene]: user's asset server is the local region's asset server"); | ||
197 | } | ||
198 | |||
199 | //public InventoryItemBase Get(InventoryItemBase item, UUID rootFolder, CachedUserInfo userInfo) | ||
200 | //{ | ||
201 | // InventoryClient invCli = null; | ||
202 | // string inventoryURL = UserInventoryURL(item.Owner); | ||
203 | // if (!m_inventoryServers.TryGetValue(inventoryURL, out invCli)) | ||
204 | // { | ||
205 | // m_log.Debug("[HGScene]: Starting new InventorytClient for " + inventoryURL); | ||
206 | // invCli = new InventoryClient(inventoryURL); | ||
207 | // m_inventoryServers.Add(inventoryURL, invCli); | ||
208 | // } | ||
209 | |||
210 | // item = invCli.GetInventoryItem(item); | ||
211 | // if (item != null) | ||
212 | // { | ||
213 | // // Change the folder, stick it in root folder, all items flattened out here in this region cache | ||
214 | // item.Folder = rootFolder; | ||
215 | // //userInfo.AddItem(item); don't use this, it calls back to the inventory server | ||
216 | // lock (userInfo.RootFolder.Items) | ||
217 | // { | ||
218 | // userInfo.RootFolder.Items[item.ID] = item; | ||
219 | // } | ||
220 | |||
221 | // } | ||
222 | // return item; | ||
223 | //} | ||
224 | |||
225 | public void Post(UUID assetID, UUID ownerID) | ||
226 | { | ||
227 | // Post the item from the local AssetCache onto the remote asset server | ||
228 | // and place an entry in m_assetMap | ||
229 | |||
230 | string userAssetURL = HyperlinkAssets.GetUserAssetServer(ownerID); | ||
231 | if ((userAssetURL != string.Empty) && (userAssetURL != HyperlinkAssets.GetSimAssetServer())) | ||
232 | { | ||
233 | m_log.Debug("[HGScene]: Posting object " + assetID + " to asset server " + userAssetURL); | ||
234 | AssetBase asset = m_scene.AssetService.Get(assetID.ToString()); | ||
235 | if (asset != null) | ||
236 | { | ||
237 | Dictionary<UUID, int> ids = new Dictionary<UUID, int>(); | ||
238 | HGUuidGatherer uuidGatherer = new HGUuidGatherer(this, m_scene.AssetService, string.Empty); | ||
239 | uuidGatherer.GatherAssetUuids(asset.FullID, (AssetType)asset.Type, ids); | ||
240 | foreach (UUID uuid in ids.Keys) | ||
241 | { | ||
242 | asset = m_scene.AssetService.Get(uuid.ToString()); | ||
243 | if (asset == null) | ||
244 | m_log.DebugFormat("[HGScene]: Could not find asset {0}", uuid); | ||
245 | else | ||
246 | PostAsset(userAssetURL, asset); | ||
247 | } | ||
248 | |||
249 | // maybe all pieces got there... | ||
250 | m_log.DebugFormat("[HGScene]: Successfully posted item {0} to asset server {1}", assetID, userAssetURL); | ||
251 | |||
252 | } | ||
253 | else | ||
254 | m_log.DebugFormat("[HGScene]: Something wrong with asset {0}, it could not be found", assetID); | ||
255 | } | ||
256 | else | ||
257 | m_log.Debug("[HGScene]: user's asset server is local region's asset server"); | ||
258 | |||
259 | } | ||
260 | |||
261 | #endregion | ||
262 | |||
263 | } | ||
264 | } | ||