diff options
author | Jeff Ames | 2008-04-07 14:19:08 +0000 |
---|---|---|
committer | Jeff Ames | 2008-04-07 14:19:08 +0000 |
commit | 8833a72388a07db48eb1fc135bf3919da13fb1db (patch) | |
tree | e9ba61c9b6a2eb78d664a8a5fa8d49ddfd4e1332 /OpenSim/Region/DataSnapshot/DataSnapshotManager.cs | |
parent | Thank you kindly Diva & KMeisthax for adding the beginnings (diff) | |
download | opensim-SC-8833a72388a07db48eb1fc135bf3919da13fb1db.zip opensim-SC-8833a72388a07db48eb1fc135bf3919da13fb1db.tar.gz opensim-SC-8833a72388a07db48eb1fc135bf3919da13fb1db.tar.bz2 opensim-SC-8833a72388a07db48eb1fc135bf3919da13fb1db.tar.xz |
Update svn properties.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/DataSnapshot/DataSnapshotManager.cs | 1048 |
1 files changed, 524 insertions, 524 deletions
diff --git a/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs b/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs index 1831f0a..cb9ce44 100644 --- a/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs +++ b/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs | |||
@@ -1,524 +1,524 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Xml; | 32 | using System.Xml; |
33 | using System.IO; | 33 | using System.IO; |
34 | using System.Text; | 34 | using System.Text; |
35 | using System.Timers; | 35 | using System.Timers; |
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenSim.Framework.Communications; | 37 | using OpenSim.Framework.Communications; |
38 | using OpenSim.Region.Environment.Interfaces; | 38 | using OpenSim.Region.Environment.Interfaces; |
39 | using OpenSim.Region.Environment.Scenes; | 39 | using OpenSim.Region.Environment.Scenes; |
40 | using Nini.Config; | 40 | using Nini.Config; |
41 | using libsecondlife; | 41 | using libsecondlife; |
42 | using libsecondlife.Packets; | 42 | using libsecondlife.Packets; |
43 | 43 | ||
44 | namespace OpenSim.Region.DataSnapshot | 44 | namespace OpenSim.Region.DataSnapshot |
45 | { | 45 | { |
46 | public class DataSnapshotManager : IRegionModule | 46 | public class DataSnapshotManager : IRegionModule |
47 | { | 47 | { |
48 | #region Class members | 48 | #region Class members |
49 | private List<Scene> m_scenes = new List<Scene>(); | 49 | private List<Scene> m_scenes = new List<Scene>(); |
50 | private log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | 50 | private log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
51 | private bool m_enabled = false; | 51 | private bool m_enabled = false; |
52 | private bool m_configLoaded = false; | 52 | private bool m_configLoaded = false; |
53 | internal object m_syncInit = new object(); | 53 | internal object m_syncInit = new object(); |
54 | private DataRequestHandler m_requests = null; | 54 | private DataRequestHandler m_requests = null; |
55 | private Dictionary<Scene, List<IDataSnapshotProvider>> m_dataproviders = new Dictionary<Scene, List<IDataSnapshotProvider>>(); | 55 | private Dictionary<Scene, List<IDataSnapshotProvider>> m_dataproviders = new Dictionary<Scene, List<IDataSnapshotProvider>>(); |
56 | private Dictionary<String, String> m_gridinfo = new Dictionary<String, String>(); | 56 | private Dictionary<String, String> m_gridinfo = new Dictionary<String, String>(); |
57 | //private int m_oldestSnapshot = 0; | 57 | //private int m_oldestSnapshot = 0; |
58 | private int m_maxSnapshots = 500; | 58 | private int m_maxSnapshots = 500; |
59 | private int m_lastSnapshot = 0; | 59 | private int m_lastSnapshot = 0; |
60 | private string m_snapsDir = "DataSnapshot"; | 60 | private string m_snapsDir = "DataSnapshot"; |
61 | private string m_dataServices = "noservices"; | 61 | private string m_dataServices = "noservices"; |
62 | private string m_listener_port = "9000"; //TODO: Set default port over 9000 | 62 | private string m_listener_port = "9000"; //TODO: Set default port over 9000 |
63 | private string m_hostname = "127.0.0.1"; | 63 | private string m_hostname = "127.0.0.1"; |
64 | private Timer m_periodic = null; | 64 | private Timer m_periodic = null; |
65 | private int m_period = 60; // in seconds | 65 | private int m_period = 60; // in seconds |
66 | private List<String> m_disabledModules = new List<String>(); | 66 | private List<String> m_disabledModules = new List<String>(); |
67 | #endregion | 67 | #endregion |
68 | 68 | ||
69 | #region IRegionModule | 69 | #region IRegionModule |
70 | public void Close() | 70 | public void Close() |
71 | { | 71 | { |
72 | 72 | ||
73 | } | 73 | } |
74 | 74 | ||
75 | public void Initialise(Scene scene, Nini.Config.IConfigSource config) | 75 | public void Initialise(Scene scene, Nini.Config.IConfigSource config) |
76 | { | 76 | { |
77 | if (!m_scenes.Contains(scene)) | 77 | if (!m_scenes.Contains(scene)) |
78 | m_scenes.Add(scene); | 78 | m_scenes.Add(scene); |
79 | 79 | ||
80 | if (!m_configLoaded) { | 80 | if (!m_configLoaded) { |
81 | m_configLoaded = true; | 81 | m_configLoaded = true; |
82 | m_log.Info("[DATASNAPSHOT]: Loading configuration"); | 82 | m_log.Info("[DATASNAPSHOT]: Loading configuration"); |
83 | //Read from the config for options | 83 | //Read from the config for options |
84 | lock (m_syncInit) { | 84 | lock (m_syncInit) { |
85 | try { | 85 | try { |
86 | m_enabled = config.Configs["DataSnapshot"].GetBoolean("index_sims", m_enabled); | 86 | m_enabled = config.Configs["DataSnapshot"].GetBoolean("index_sims", m_enabled); |
87 | if (config.Configs["Startup"].GetBoolean("gridmode", true)) | 87 | if (config.Configs["Startup"].GetBoolean("gridmode", true)) |
88 | { | 88 | { |
89 | m_gridinfo.Add("gridserverURL", config.Configs["Network"].GetString("grid_server_url", "harbl")); | 89 | m_gridinfo.Add("gridserverURL", config.Configs["Network"].GetString("grid_server_url", "harbl")); |
90 | m_gridinfo.Add("userserverURL", config.Configs["Network"].GetString("user_server_url", "harbl")); | 90 | m_gridinfo.Add("userserverURL", config.Configs["Network"].GetString("user_server_url", "harbl")); |
91 | m_gridinfo.Add("assetserverURL", config.Configs["Network"].GetString("asset_server_url", "harbl")); | 91 | m_gridinfo.Add("assetserverURL", config.Configs["Network"].GetString("asset_server_url", "harbl")); |
92 | } | 92 | } |
93 | else | 93 | else |
94 | { | 94 | { |
95 | //Non gridmode stuff | 95 | //Non gridmode stuff |
96 | } | 96 | } |
97 | 97 | ||
98 | m_gridinfo.Add("Name", config.Configs["DataSnapshot"].GetString("gridname", "harbl")); | 98 | m_gridinfo.Add("Name", config.Configs["DataSnapshot"].GetString("gridname", "harbl")); |
99 | m_maxSnapshots = config.Configs["DataSnapshot"].GetInt("max_snapshots", m_maxSnapshots); | 99 | m_maxSnapshots = config.Configs["DataSnapshot"].GetInt("max_snapshots", m_maxSnapshots); |
100 | m_period = config.Configs["DataSnapshot"].GetInt("default_snapshot_period", m_period); | 100 | m_period = config.Configs["DataSnapshot"].GetInt("default_snapshot_period", m_period); |
101 | m_snapsDir = config.Configs["DataSnapshot"].GetString("snapshot_cache_directory", m_snapsDir); | 101 | m_snapsDir = config.Configs["DataSnapshot"].GetString("snapshot_cache_directory", m_snapsDir); |
102 | m_dataServices = config.Configs["DataSnapshot"].GetString("data_services", m_dataServices); | 102 | m_dataServices = config.Configs["DataSnapshot"].GetString("data_services", m_dataServices); |
103 | m_listener_port = config.Configs["Network"].GetString("http_listener_port", m_listener_port); | 103 | m_listener_port = config.Configs["Network"].GetString("http_listener_port", m_listener_port); |
104 | //BUG: Naming a search data module "DESUDESUDESU" will cause it to not get loaded by default. | 104 | //BUG: Naming a search data module "DESUDESUDESU" will cause it to not get loaded by default. |
105 | //RESOLUTION: Wontfix, there are no Suiseiseki-loving developers | 105 | //RESOLUTION: Wontfix, there are no Suiseiseki-loving developers |
106 | String[] annoying_string_array = config.Configs["DataSnapshot"].GetString("disable_modules", "DESUDESUDESU").Split(".".ToCharArray()); | 106 | String[] annoying_string_array = config.Configs["DataSnapshot"].GetString("disable_modules", "DESUDESUDESU").Split(".".ToCharArray()); |
107 | foreach (String bloody_wanker in annoying_string_array) { | 107 | foreach (String bloody_wanker in annoying_string_array) { |
108 | m_disabledModules.Add(bloody_wanker); | 108 | m_disabledModules.Add(bloody_wanker); |
109 | } | 109 | } |
110 | 110 | ||
111 | } catch (Exception) { | 111 | } catch (Exception) { |
112 | m_log.Info("[DATASNAPSHOT]: Could not load configuration. DataSnapshot will be disabled."); | 112 | m_log.Info("[DATASNAPSHOT]: Could not load configuration. DataSnapshot will be disabled."); |
113 | m_enabled = false; | 113 | m_enabled = false; |
114 | return; | 114 | return; |
115 | } | 115 | } |
116 | 116 | ||
117 | } | 117 | } |
118 | } | 118 | } |
119 | if (Directory.Exists(m_snapsDir)) | 119 | if (Directory.Exists(m_snapsDir)) |
120 | { | 120 | { |
121 | m_log.Info("[DATASNAPSHOT] DataSnapshot directory already exists."); | 121 | m_log.Info("[DATASNAPSHOT] DataSnapshot directory already exists."); |
122 | } | 122 | } |
123 | else | 123 | else |
124 | { | 124 | { |
125 | // Try to create the directory. | 125 | // Try to create the directory. |
126 | m_log.Info("[DATASNAPSHOT] Creating " + m_snapsDir + " directory."); | 126 | m_log.Info("[DATASNAPSHOT] Creating " + m_snapsDir + " directory."); |
127 | try | 127 | try |
128 | { | 128 | { |
129 | Directory.CreateDirectory(m_snapsDir); | 129 | Directory.CreateDirectory(m_snapsDir); |
130 | } | 130 | } |
131 | catch (Exception) | 131 | catch (Exception) |
132 | { | 132 | { |
133 | m_log.Error("[DATASNAPSHOT] Failed to create " + m_snapsDir + " directory."); | 133 | m_log.Error("[DATASNAPSHOT] Failed to create " + m_snapsDir + " directory."); |
134 | } | 134 | } |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | if (m_enabled) | 138 | if (m_enabled) |
139 | { | 139 | { |
140 | m_log.Info("[DATASNAPSHOT]: Scene added to module."); | 140 | m_log.Info("[DATASNAPSHOT]: Scene added to module."); |
141 | } | 141 | } |
142 | else | 142 | else |
143 | { | 143 | { |
144 | m_log.Warn("[DATASNAPSHOT]: Data snapshot disabled, not adding scene to module (or anything else)."); | 144 | m_log.Warn("[DATASNAPSHOT]: Data snapshot disabled, not adding scene to module (or anything else)."); |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | public bool IsSharedModule | 148 | public bool IsSharedModule |
149 | { | 149 | { |
150 | get { return true; } | 150 | get { return true; } |
151 | } | 151 | } |
152 | 152 | ||
153 | public string Name | 153 | public string Name |
154 | { | 154 | { |
155 | get { return "External Data Generator"; } | 155 | get { return "External Data Generator"; } |
156 | } | 156 | } |
157 | 157 | ||
158 | public void PostInitialise() | 158 | public void PostInitialise() |
159 | { | 159 | { |
160 | if (m_enabled) | 160 | if (m_enabled) |
161 | { | 161 | { |
162 | //Right now, only load ISearchData objects in the current assembly. | 162 | //Right now, only load ISearchData objects in the current assembly. |
163 | //Eventually allow it to load ISearchData objects from all assemblies. | 163 | //Eventually allow it to load ISearchData objects from all assemblies. |
164 | Assembly currentasm = Assembly.GetExecutingAssembly(); | 164 | Assembly currentasm = Assembly.GetExecutingAssembly(); |
165 | 165 | ||
166 | //Stolen from ModuleLoader.cs | 166 | //Stolen from ModuleLoader.cs |
167 | foreach (Type pluginType in currentasm.GetTypes()) | 167 | foreach (Type pluginType in currentasm.GetTypes()) |
168 | { | 168 | { |
169 | if (pluginType.IsPublic) | 169 | if (pluginType.IsPublic) |
170 | { | 170 | { |
171 | if (!pluginType.IsAbstract) | 171 | if (!pluginType.IsAbstract) |
172 | { | 172 | { |
173 | if (pluginType.GetInterface("IDataSnapshotProvider") != null) | 173 | if (pluginType.GetInterface("IDataSnapshotProvider") != null) |
174 | { | 174 | { |
175 | foreach (Scene scene in m_scenes) | 175 | foreach (Scene scene in m_scenes) |
176 | { | 176 | { |
177 | IDataSnapshotProvider module = (IDataSnapshotProvider)Activator.CreateInstance(pluginType); | 177 | IDataSnapshotProvider module = (IDataSnapshotProvider)Activator.CreateInstance(pluginType); |
178 | module.Initialize(scene, this); | 178 | module.Initialize(scene, this); |
179 | //module.PrepareData(); | 179 | //module.PrepareData(); |
180 | List<IDataSnapshotProvider> providerlist = null; | 180 | List<IDataSnapshotProvider> providerlist = null; |
181 | m_dataproviders.TryGetValue(scene, out providerlist); | 181 | m_dataproviders.TryGetValue(scene, out providerlist); |
182 | if (providerlist == null) | 182 | if (providerlist == null) |
183 | { | 183 | { |
184 | providerlist = new List<IDataSnapshotProvider>(); | 184 | providerlist = new List<IDataSnapshotProvider>(); |
185 | m_dataproviders.Add(scene, providerlist); | 185 | m_dataproviders.Add(scene, providerlist); |
186 | } | 186 | } |
187 | providerlist.Add(module); | 187 | providerlist.Add(module); |
188 | 188 | ||
189 | } | 189 | } |
190 | m_log.Info("[DATASNAPSHOT]: Added new data provider type: " + pluginType.Name); | 190 | m_log.Info("[DATASNAPSHOT]: Added new data provider type: " + pluginType.Name); |
191 | } | 191 | } |
192 | } | 192 | } |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | //Hand it the first scene, assuming that all scenes have the same BaseHTTPServer | 196 | //Hand it the first scene, assuming that all scenes have the same BaseHTTPServer |
197 | m_requests = new DataRequestHandler(m_scenes[0], this); | 197 | m_requests = new DataRequestHandler(m_scenes[0], this); |
198 | 198 | ||
199 | //Create timer | 199 | //Create timer |
200 | m_periodic = new Timer(); | 200 | m_periodic = new Timer(); |
201 | m_periodic.Interval = m_period * 1000; | 201 | m_periodic.Interval = m_period * 1000; |
202 | m_periodic.Elapsed += SnapshotTimerCallback; | 202 | m_periodic.Elapsed += SnapshotTimerCallback; |
203 | m_periodic.Enabled = true; | 203 | m_periodic.Enabled = true; |
204 | 204 | ||
205 | m_hostname = m_scenes[0].RegionInfo.ExternalHostName; | 205 | m_hostname = m_scenes[0].RegionInfo.ExternalHostName; |
206 | 206 | ||
207 | MakeNewSnapshot(); //Make the initial snapshot | 207 | MakeNewSnapshot(); //Make the initial snapshot |
208 | 208 | ||
209 | if (m_dataServices != "noservices") | 209 | if (m_dataServices != "noservices") |
210 | NotifyDataServices(m_dataServices); | 210 | NotifyDataServices(m_dataServices); |
211 | } | 211 | } |
212 | } | 212 | } |
213 | #endregion | 213 | #endregion |
214 | 214 | ||
215 | #region Associated helper functions | 215 | #region Associated helper functions |
216 | 216 | ||
217 | string DataFileName(Scene scene) | 217 | string DataFileName(Scene scene) |
218 | { | 218 | { |
219 | return Path.Combine(m_snapsDir, Path.ChangeExtension(scene.RegionInfo.RegionName, "xml")); | 219 | return Path.Combine(m_snapsDir, Path.ChangeExtension(scene.RegionInfo.RegionName, "xml")); |
220 | //return (m_snapsDir + Path.DirectorySeparatorChar + scene.RegionInfo.RegionName + ".xml"); | 220 | //return (m_snapsDir + Path.DirectorySeparatorChar + scene.RegionInfo.RegionName + ".xml"); |
221 | } | 221 | } |
222 | 222 | ||
223 | Scene SceneForName(string name) | 223 | Scene SceneForName(string name) |
224 | { | 224 | { |
225 | foreach (Scene scene in m_scenes) | 225 | foreach (Scene scene in m_scenes) |
226 | if (scene.RegionInfo.RegionName == name) | 226 | if (scene.RegionInfo.RegionName == name) |
227 | return scene; | 227 | return scene; |
228 | 228 | ||
229 | return null; | 229 | return null; |
230 | } | 230 | } |
231 | 231 | ||
232 | #endregion | 232 | #endregion |
233 | 233 | ||
234 | #region [Private] XML snapshot generator | 234 | #region [Private] XML snapshot generator |
235 | 235 | ||
236 | private XmlDocument Snapshot(Scene scene) | 236 | private XmlDocument Snapshot(Scene scene) |
237 | { | 237 | { |
238 | XmlDocument basedoc = new XmlDocument(); | 238 | XmlDocument basedoc = new XmlDocument(); |
239 | XmlNode regionElement = MakeRegionNode(scene, basedoc); | 239 | XmlNode regionElement = MakeRegionNode(scene, basedoc); |
240 | 240 | ||
241 | regionElement.AppendChild(GetGridSnapshotData(basedoc)); | 241 | regionElement.AppendChild(GetGridSnapshotData(basedoc)); |
242 | XmlNode regionData = basedoc.CreateNode(XmlNodeType.Element, "data", ""); | 242 | XmlNode regionData = basedoc.CreateNode(XmlNodeType.Element, "data", ""); |
243 | 243 | ||
244 | foreach (KeyValuePair<Scene, List<IDataSnapshotProvider>> dataprovider in m_dataproviders) | 244 | foreach (KeyValuePair<Scene, List<IDataSnapshotProvider>> dataprovider in m_dataproviders) |
245 | { | 245 | { |
246 | if (dataprovider.Key == scene) | 246 | if (dataprovider.Key == scene) |
247 | { | 247 | { |
248 | foreach (IDataSnapshotProvider provider in dataprovider.Value) | 248 | foreach (IDataSnapshotProvider provider in dataprovider.Value) |
249 | { | 249 | { |
250 | XmlNode data = provider.RequestSnapshotData(basedoc); | 250 | XmlNode data = provider.RequestSnapshotData(basedoc); |
251 | regionData.AppendChild(data); | 251 | regionData.AppendChild(data); |
252 | } | 252 | } |
253 | } | 253 | } |
254 | } | 254 | } |
255 | 255 | ||
256 | regionElement.AppendChild(regionData); | 256 | regionElement.AppendChild(regionData); |
257 | 257 | ||
258 | basedoc.AppendChild(regionElement); | 258 | basedoc.AppendChild(regionElement); |
259 | 259 | ||
260 | return basedoc; | 260 | return basedoc; |
261 | } | 261 | } |
262 | 262 | ||
263 | private XmlNode MakeRegionNode(Scene scene, XmlDocument basedoc) | 263 | private XmlNode MakeRegionNode(Scene scene, XmlDocument basedoc) |
264 | { | 264 | { |
265 | XmlNode docElement = basedoc.CreateNode(XmlNodeType.Element, "region", ""); | 265 | XmlNode docElement = basedoc.CreateNode(XmlNodeType.Element, "region", ""); |
266 | 266 | ||
267 | XmlAttribute attr = basedoc.CreateAttribute("category"); | 267 | XmlAttribute attr = basedoc.CreateAttribute("category"); |
268 | attr.Value = GetRegionCategory(scene); | 268 | attr.Value = GetRegionCategory(scene); |
269 | docElement.Attributes.Append(attr); | 269 | docElement.Attributes.Append(attr); |
270 | 270 | ||
271 | attr = basedoc.CreateAttribute("entities"); | 271 | attr = basedoc.CreateAttribute("entities"); |
272 | attr.Value = scene.Entities.Count.ToString(); | 272 | attr.Value = scene.Entities.Count.ToString(); |
273 | docElement.Attributes.Append(attr); | 273 | docElement.Attributes.Append(attr); |
274 | 274 | ||
275 | //attr = basedoc.CreateAttribute("parcels"); | 275 | //attr = basedoc.CreateAttribute("parcels"); |
276 | //attr.Value = scene.LandManager.landList.Count.ToString(); | 276 | //attr.Value = scene.LandManager.landList.Count.ToString(); |
277 | //docElement.Attributes.Append(attr); | 277 | //docElement.Attributes.Append(attr); |
278 | 278 | ||
279 | 279 | ||
280 | XmlNode infoblock = basedoc.CreateNode(XmlNodeType.Element, "info", ""); | 280 | XmlNode infoblock = basedoc.CreateNode(XmlNodeType.Element, "info", ""); |
281 | 281 | ||
282 | XmlNode infopiece = basedoc.CreateNode(XmlNodeType.Element, "uuid", ""); | 282 | XmlNode infopiece = basedoc.CreateNode(XmlNodeType.Element, "uuid", ""); |
283 | infopiece.InnerText = scene.RegionInfo.RegionID.ToString(); | 283 | infopiece.InnerText = scene.RegionInfo.RegionID.ToString(); |
284 | infoblock.AppendChild(infopiece); | 284 | infoblock.AppendChild(infopiece); |
285 | 285 | ||
286 | infopiece = basedoc.CreateNode(XmlNodeType.Element, "url", ""); | 286 | infopiece = basedoc.CreateNode(XmlNodeType.Element, "url", ""); |
287 | infopiece.InnerText = "http://" + m_hostname + ":" + m_listener_port; | 287 | infopiece.InnerText = "http://" + m_hostname + ":" + m_listener_port; |
288 | infoblock.AppendChild(infopiece); | 288 | infoblock.AppendChild(infopiece); |
289 | 289 | ||
290 | infopiece = basedoc.CreateNode(XmlNodeType.Element, "name", ""); | 290 | infopiece = basedoc.CreateNode(XmlNodeType.Element, "name", ""); |
291 | infopiece.InnerText = scene.RegionInfo.RegionName; | 291 | infopiece.InnerText = scene.RegionInfo.RegionName; |
292 | infoblock.AppendChild(infopiece); | 292 | infoblock.AppendChild(infopiece); |
293 | 293 | ||
294 | docElement.AppendChild(infoblock); | 294 | docElement.AppendChild(infoblock); |
295 | 295 | ||
296 | return docElement; | 296 | return docElement; |
297 | } | 297 | } |
298 | 298 | ||
299 | private XmlNode GetGridSnapshotData(XmlDocument factory) | 299 | private XmlNode GetGridSnapshotData(XmlDocument factory) |
300 | { | 300 | { |
301 | XmlNode griddata = factory.CreateNode(XmlNodeType.Element, "grid", ""); | 301 | XmlNode griddata = factory.CreateNode(XmlNodeType.Element, "grid", ""); |
302 | 302 | ||
303 | foreach (KeyValuePair<String, String> GridData in m_gridinfo) | 303 | foreach (KeyValuePair<String, String> GridData in m_gridinfo) |
304 | { | 304 | { |
305 | //TODO: make it lowercase tag names for diva | 305 | //TODO: make it lowercase tag names for diva |
306 | XmlNode childnode = factory.CreateNode(XmlNodeType.Element, GridData.Key, ""); | 306 | XmlNode childnode = factory.CreateNode(XmlNodeType.Element, GridData.Key, ""); |
307 | childnode.InnerText = GridData.Value; | 307 | childnode.InnerText = GridData.Value; |
308 | griddata.AppendChild(childnode); | 308 | griddata.AppendChild(childnode); |
309 | } | 309 | } |
310 | 310 | ||
311 | return griddata; | 311 | return griddata; |
312 | } | 312 | } |
313 | 313 | ||
314 | private String GetRegionCategory(Scene scene) | 314 | private String GetRegionCategory(Scene scene) |
315 | { | 315 | { |
316 | 316 | ||
317 | //Boolean choice between: | 317 | //Boolean choice between: |
318 | // "PG" - Mormontown | 318 | // "PG" - Mormontown |
319 | // "Mature" - Sodom and Gomorrah | 319 | // "Mature" - Sodom and Gomorrah |
320 | // (Depreciated) "Patriotic Nigra Testing Sandbox" - Abandon Hope All Ye Who Enter Here | 320 | // (Depreciated) "Patriotic Nigra Testing Sandbox" - Abandon Hope All Ye Who Enter Here |
321 | if ((scene.RegionInfo.EstateSettings.simAccess & Simulator.SimAccess.Mature) == Simulator.SimAccess.Mature) | 321 | if ((scene.RegionInfo.EstateSettings.simAccess & Simulator.SimAccess.Mature) == Simulator.SimAccess.Mature) |
322 | { | 322 | { |
323 | return "Mature"; | 323 | return "Mature"; |
324 | } | 324 | } |
325 | else if ((scene.RegionInfo.EstateSettings.simAccess & Simulator.SimAccess.PG) == Simulator.SimAccess.PG) | 325 | else if ((scene.RegionInfo.EstateSettings.simAccess & Simulator.SimAccess.PG) == Simulator.SimAccess.PG) |
326 | { | 326 | { |
327 | return "PG"; | 327 | return "PG"; |
328 | } | 328 | } |
329 | else | 329 | else |
330 | { | 330 | { |
331 | return "Unknown"; | 331 | return "Unknown"; |
332 | } | 332 | } |
333 | } | 333 | } |
334 | 334 | ||
335 | /* Code's closed due to AIDS, See EstateSnapshot.cs for CURE | 335 | /* Code's closed due to AIDS, See EstateSnapshot.cs for CURE |
336 | private XmlNode GetEstateSnapshotData(Scene scene, XmlDocument factory) | 336 | private XmlNode GetEstateSnapshotData(Scene scene, XmlDocument factory) |
337 | { | 337 | { |
338 | //Estate data section - contains who owns a set of sims and the name of the set. | 338 | //Estate data section - contains who owns a set of sims and the name of the set. |
339 | //In Opensim all the estate names are the same as the Master Avatar (owner of the sim) | 339 | //In Opensim all the estate names are the same as the Master Avatar (owner of the sim) |
340 | XmlNode estatedata = factory.CreateNode(XmlNodeType.Element, "estate", ""); | 340 | XmlNode estatedata = factory.CreateNode(XmlNodeType.Element, "estate", ""); |
341 | 341 | ||
342 | LLUUID ownerid = scene.RegionInfo.MasterAvatarAssignedUUID; | 342 | LLUUID ownerid = scene.RegionInfo.MasterAvatarAssignedUUID; |
343 | String firstname = scene.RegionInfo.MasterAvatarFirstName; | 343 | String firstname = scene.RegionInfo.MasterAvatarFirstName; |
344 | String lastname = scene.RegionInfo.MasterAvatarLastName; | 344 | String lastname = scene.RegionInfo.MasterAvatarLastName; |
345 | String hostname = scene.RegionInfo.ExternalHostName; | 345 | String hostname = scene.RegionInfo.ExternalHostName; |
346 | 346 | ||
347 | XmlNode user = factory.CreateNode(XmlNodeType.Element, "owner", ""); | 347 | XmlNode user = factory.CreateNode(XmlNodeType.Element, "owner", ""); |
348 | 348 | ||
349 | XmlNode username = factory.CreateNode(XmlNodeType.Element, "name", ""); | 349 | XmlNode username = factory.CreateNode(XmlNodeType.Element, "name", ""); |
350 | username.InnerText = firstname + " " + lastname; | 350 | username.InnerText = firstname + " " + lastname; |
351 | user.AppendChild(username); | 351 | user.AppendChild(username); |
352 | 352 | ||
353 | XmlNode useruuid = factory.CreateNode(XmlNodeType.Element, "uuid", ""); | 353 | XmlNode useruuid = factory.CreateNode(XmlNodeType.Element, "uuid", ""); |
354 | useruuid.InnerText = ownerid.ToString(); | 354 | useruuid.InnerText = ownerid.ToString(); |
355 | user.AppendChild(useruuid); | 355 | user.AppendChild(useruuid); |
356 | 356 | ||
357 | estatedata.AppendChild(user); | 357 | estatedata.AppendChild(user); |
358 | 358 | ||
359 | return estatedata; | 359 | return estatedata; |
360 | } */ | 360 | } */ |
361 | 361 | ||
362 | #endregion | 362 | #endregion |
363 | 363 | ||
364 | #region [Public] Snapshot storage functions | 364 | #region [Public] Snapshot storage functions |
365 | 365 | ||
366 | public void MakeNewSnapshot() | 366 | public void MakeNewSnapshot() |
367 | { | 367 | { |
368 | foreach (Scene scene in m_scenes) | 368 | foreach (Scene scene in m_scenes) |
369 | { | 369 | { |
370 | XmlDocument snapshot = Snapshot(scene); | 370 | XmlDocument snapshot = Snapshot(scene); |
371 | 371 | ||
372 | string path = DataFileName(scene); | 372 | string path = DataFileName(scene); |
373 | 373 | ||
374 | try | 374 | try |
375 | { | 375 | { |
376 | using (XmlTextWriter snapXWriter = new XmlTextWriter(path, Encoding.Default)) | 376 | using (XmlTextWriter snapXWriter = new XmlTextWriter(path, Encoding.Default)) |
377 | { | 377 | { |
378 | snapXWriter.Formatting = Formatting.Indented; | 378 | snapXWriter.Formatting = Formatting.Indented; |
379 | snapXWriter.WriteStartDocument(); | 379 | snapXWriter.WriteStartDocument(); |
380 | snapshot.WriteTo(snapXWriter); | 380 | snapshot.WriteTo(snapXWriter); |
381 | snapXWriter.WriteEndDocument(); | 381 | snapXWriter.WriteEndDocument(); |
382 | 382 | ||
383 | m_lastSnapshot++; | 383 | m_lastSnapshot++; |
384 | } | 384 | } |
385 | } | 385 | } |
386 | catch (Exception e) | 386 | catch (Exception e) |
387 | { | 387 | { |
388 | m_log.Warn("[DATASNAPSHOT]: Caught unknown exception while trying to save snapshot: " + path + "\n" + e.ToString()); | 388 | m_log.Warn("[DATASNAPSHOT]: Caught unknown exception while trying to save snapshot: " + path + "\n" + e.ToString()); |
389 | } | 389 | } |
390 | m_log.Info("[DATASNAPSHOT]: Made external data snapshot " + path); | 390 | m_log.Info("[DATASNAPSHOT]: Made external data snapshot " + path); |
391 | } | 391 | } |
392 | } | 392 | } |
393 | 393 | ||
394 | /** | 394 | /** |
395 | * Reply to the http request | 395 | * Reply to the http request |
396 | */ | 396 | */ |
397 | public XmlDocument GetSnapshot(string regionName) | 397 | public XmlDocument GetSnapshot(string regionName) |
398 | { | 398 | { |
399 | XmlDocument requestedSnap = new XmlDocument(); | 399 | XmlDocument requestedSnap = new XmlDocument(); |
400 | requestedSnap.AppendChild(requestedSnap.CreateXmlDeclaration("1.0", null, null)); | 400 | requestedSnap.AppendChild(requestedSnap.CreateXmlDeclaration("1.0", null, null)); |
401 | requestedSnap.AppendChild(requestedSnap.CreateWhitespace("\r\n")); | 401 | requestedSnap.AppendChild(requestedSnap.CreateWhitespace("\r\n")); |
402 | XmlNode regiondata = requestedSnap.CreateNode(XmlNodeType.Element, "regiondata", ""); | 402 | XmlNode regiondata = requestedSnap.CreateNode(XmlNodeType.Element, "regiondata", ""); |
403 | try | 403 | try |
404 | { | 404 | { |
405 | if (regionName == null || regionName == "") | 405 | if (regionName == null || regionName == "") |
406 | { | 406 | { |
407 | foreach (Scene scene in m_scenes) | 407 | foreach (Scene scene in m_scenes) |
408 | { | 408 | { |
409 | string path = DataFileName(scene); | 409 | string path = DataFileName(scene); |
410 | XmlDocument regionSnap = new XmlDocument(); | 410 | XmlDocument regionSnap = new XmlDocument(); |
411 | regionSnap.PreserveWhitespace = true; | 411 | regionSnap.PreserveWhitespace = true; |
412 | 412 | ||
413 | regionSnap.Load(path); | 413 | regionSnap.Load(path); |
414 | XmlNode nodeOrig = regionSnap["region"]; | 414 | XmlNode nodeOrig = regionSnap["region"]; |
415 | XmlNode nodeDest = requestedSnap.ImportNode(nodeOrig, true); | 415 | XmlNode nodeDest = requestedSnap.ImportNode(nodeOrig, true); |
416 | //requestedSnap.AppendChild(nodeDest); | 416 | //requestedSnap.AppendChild(nodeDest); |
417 | 417 | ||
418 | regiondata.AppendChild(requestedSnap.CreateWhitespace("\r\n")); | 418 | regiondata.AppendChild(requestedSnap.CreateWhitespace("\r\n")); |
419 | regiondata.AppendChild(nodeDest); | 419 | regiondata.AppendChild(nodeDest); |
420 | } | 420 | } |
421 | } | 421 | } |
422 | else | 422 | else |
423 | { | 423 | { |
424 | Scene scene = SceneForName(regionName); | 424 | Scene scene = SceneForName(regionName); |
425 | requestedSnap.Load(DataFileName(scene)); | 425 | requestedSnap.Load(DataFileName(scene)); |
426 | } | 426 | } |
427 | // requestedSnap.InsertBefore(requestedSnap.CreateXmlDeclaration("1.0", null, null), | 427 | // requestedSnap.InsertBefore(requestedSnap.CreateXmlDeclaration("1.0", null, null), |
428 | // requestedSnap.DocumentElement); | 428 | // requestedSnap.DocumentElement); |
429 | requestedSnap.AppendChild(regiondata); | 429 | requestedSnap.AppendChild(regiondata); |
430 | regiondata.AppendChild(requestedSnap.CreateWhitespace("\r\n")); | 430 | regiondata.AppendChild(requestedSnap.CreateWhitespace("\r\n")); |
431 | 431 | ||
432 | 432 | ||
433 | } | 433 | } |
434 | catch (XmlException e) | 434 | catch (XmlException e) |
435 | { | 435 | { |
436 | m_log.Warn("[DATASNAPSHOT]: XmlException while trying to load snapshot: " + e.ToString()); | 436 | m_log.Warn("[DATASNAPSHOT]: XmlException while trying to load snapshot: " + e.ToString()); |
437 | requestedSnap = GetErrorMessage(regionName, e); | 437 | requestedSnap = GetErrorMessage(regionName, e); |
438 | } | 438 | } |
439 | catch (Exception e) | 439 | catch (Exception e) |
440 | { | 440 | { |
441 | m_log.Warn("[DATASNAPSHOT]: Caught unknown exception while trying to load snapshot: " + e.StackTrace); | 441 | m_log.Warn("[DATASNAPSHOT]: Caught unknown exception while trying to load snapshot: " + e.StackTrace); |
442 | requestedSnap = GetErrorMessage(regionName, e); | 442 | requestedSnap = GetErrorMessage(regionName, e); |
443 | } | 443 | } |
444 | 444 | ||
445 | 445 | ||
446 | return requestedSnap; | 446 | return requestedSnap; |
447 | } | 447 | } |
448 | 448 | ||
449 | private XmlDocument GetErrorMessage(string regionName, Exception e) | 449 | private XmlDocument GetErrorMessage(string regionName, Exception e) |
450 | { | 450 | { |
451 | XmlDocument errorMessage = new XmlDocument(); | 451 | XmlDocument errorMessage = new XmlDocument(); |
452 | XmlNode error = errorMessage.CreateNode(XmlNodeType.Element, "error", ""); | 452 | XmlNode error = errorMessage.CreateNode(XmlNodeType.Element, "error", ""); |
453 | XmlNode region = errorMessage.CreateNode(XmlNodeType.Element, "region", ""); | 453 | XmlNode region = errorMessage.CreateNode(XmlNodeType.Element, "region", ""); |
454 | region.InnerText = regionName; | 454 | region.InnerText = regionName; |
455 | 455 | ||
456 | XmlNode exception = errorMessage.CreateNode(XmlNodeType.Element, "exception", ""); | 456 | XmlNode exception = errorMessage.CreateNode(XmlNodeType.Element, "exception", ""); |
457 | exception.InnerText = e.ToString(); | 457 | exception.InnerText = e.ToString(); |
458 | 458 | ||
459 | error.AppendChild(region); | 459 | error.AppendChild(region); |
460 | error.AppendChild(exception); | 460 | error.AppendChild(exception); |
461 | errorMessage.AppendChild(error); | 461 | errorMessage.AppendChild(error); |
462 | 462 | ||
463 | return errorMessage; | 463 | return errorMessage; |
464 | } | 464 | } |
465 | 465 | ||
466 | #endregion | 466 | #endregion |
467 | 467 | ||
468 | #region Event callbacks | 468 | #region Event callbacks |
469 | 469 | ||
470 | private void SnapshotTimerCallback(object timer, ElapsedEventArgs args) | 470 | private void SnapshotTimerCallback(object timer, ElapsedEventArgs args) |
471 | { | 471 | { |
472 | MakeNewSnapshot(); | 472 | MakeNewSnapshot(); |
473 | //Add extra calls here | 473 | //Add extra calls here |
474 | } | 474 | } |
475 | 475 | ||
476 | #endregion | 476 | #endregion |
477 | 477 | ||
478 | #region External data services | 478 | #region External data services |
479 | private void NotifyDataServices(string servicesStr) | 479 | private void NotifyDataServices(string servicesStr) |
480 | { | 480 | { |
481 | Stream reply = null; | 481 | Stream reply = null; |
482 | string delimStr = ";"; | 482 | string delimStr = ";"; |
483 | char [] delimiter = delimStr.ToCharArray(); | 483 | char [] delimiter = delimStr.ToCharArray(); |
484 | 484 | ||
485 | string[] services = servicesStr.Split(delimiter); | 485 | string[] services = servicesStr.Split(delimiter); |
486 | 486 | ||
487 | for (int i = 0; i < services.Length; i++) | 487 | for (int i = 0; i < services.Length; i++) |
488 | { | 488 | { |
489 | string url = services[i].Trim(); | 489 | string url = services[i].Trim(); |
490 | RestClient cli = new RestClient(url); | 490 | RestClient cli = new RestClient(url); |
491 | cli.AddQueryParameter("host", m_hostname); | 491 | cli.AddQueryParameter("host", m_hostname); |
492 | cli.AddQueryParameter("port", m_listener_port); | 492 | cli.AddQueryParameter("port", m_listener_port); |
493 | cli.RequestMethod = "GET"; | 493 | cli.RequestMethod = "GET"; |
494 | try | 494 | try |
495 | { | 495 | { |
496 | reply = cli.Request(); | 496 | reply = cli.Request(); |
497 | } | 497 | } |
498 | catch (System.Net.WebException) | 498 | catch (System.Net.WebException) |
499 | { | 499 | { |
500 | m_log.Warn("[DATASNAPSHOT] Unable to notify " + url); | 500 | m_log.Warn("[DATASNAPSHOT] Unable to notify " + url); |
501 | } | 501 | } |
502 | catch (Exception e) | 502 | catch (Exception e) |
503 | { | 503 | { |
504 | m_log.Warn("[DATASNAPSHOT] Ignoring unknown exception " + e.ToString()); | 504 | m_log.Warn("[DATASNAPSHOT] Ignoring unknown exception " + e.ToString()); |
505 | } | 505 | } |
506 | byte[] response = new byte[1024]; | 506 | byte[] response = new byte[1024]; |
507 | int n = 0; | 507 | int n = 0; |
508 | try | 508 | try |
509 | { | 509 | { |
510 | n = reply.Read(response, 0, 1024); | 510 | n = reply.Read(response, 0, 1024); |
511 | } | 511 | } |
512 | catch (Exception e) | 512 | catch (Exception e) |
513 | { | 513 | { |
514 | m_log.Warn("[DATASNAPSHOT] Unable to decode reply from data service. Ignoring. " + e.StackTrace); | 514 | m_log.Warn("[DATASNAPSHOT] Unable to decode reply from data service. Ignoring. " + e.StackTrace); |
515 | } | 515 | } |
516 | // This is not quite working, so... | 516 | // This is not quite working, so... |
517 | string responseStr = System.Text.ASCIIEncoding.UTF8.GetString(response); | 517 | string responseStr = System.Text.ASCIIEncoding.UTF8.GetString(response); |
518 | m_log.Info("[DATASNAPSHOT] data service notified: " + url); | 518 | m_log.Info("[DATASNAPSHOT] data service notified: " + url); |
519 | } | 519 | } |
520 | 520 | ||
521 | } | 521 | } |
522 | #endregion | 522 | #endregion |
523 | } | 523 | } |
524 | } | 524 | } |