relocate serialization code from SQLiteRegionData to MoapModule using load and save events.

This is better modularity.  It also allows MoapModule to be replaced with some other media module that may behave completely differently in the future.
Remaining non-modularity:
PrimitiveBaseShape needs explicit Media and MediaRaw fields.  MediaRaw is required in order to shuttle the pre-serialization data back and forth from the database layer.
The database also needs to know about MediaRaw though not about Media.
IMO, it would be extremely nice to remove these hard codings but this is a bridge too far at the present time.
prebuild-update
Justin Clark-Casey (justincc) 2010-07-26 21:09:54 +01:00
parent c70d57ff98
commit d5e8272ad4
3 changed files with 76 additions and 55 deletions

View File

@ -31,7 +31,6 @@ using System.Data;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Xml;
using log4net;
using Mono.Data.Sqlite;
using OpenMetaverse;
@ -1862,28 +1861,7 @@ namespace OpenSim.Data.SQLite
s.ExtraParams = (byte[]) row["ExtraParams"];
if (!(row["Media"] is System.DBNull))
{
using (StringReader sr = new StringReader((string)row["Media"]))
{
using (XmlTextReader xtr = new XmlTextReader(sr))
{
xtr.ReadStartElement("osmedia");
OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml());
List<MediaEntry> mediaEntries = new List<MediaEntry>();
foreach (OSD osdMe in osdMeArray)
{
MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry());
mediaEntries.Add(me);
}
s.Media = mediaEntries;
xtr.ReadEndElement();
}
}
}
s.MediaRaw = (string)row["Media"];
return s;
}
@ -1928,36 +1906,7 @@ namespace OpenSim.Data.SQLite
row["Texture"] = s.TextureEntry;
row["ExtraParams"] = s.ExtraParams;
if (null != s.Media)
{
using (StringWriter sw = new StringWriter())
{
using (XmlTextWriter xtw = new XmlTextWriter(sw))
{
xtw.WriteStartElement("osmedia");
xtw.WriteAttributeString("type", "sl");
xtw.WriteAttributeString("major_version", "0");
xtw.WriteAttributeString("minor_version", "1");
OSDArray meArray = new OSDArray();
foreach (MediaEntry me in s.Media)
{
OSD osd = (null == me ? new OSD() : me.GetOSD());
meArray.Add(osd);
}
xtw.WriteStartElement("osdata");
xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray));
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.Flush();
row["Media"] = sw.ToString();
}
}
}
row["Media"] = s.MediaRaw;
}
/// <summary>

View File

@ -173,6 +173,12 @@ namespace OpenSim.Framework
}
}
/// <summary>
/// Raw media data suitable for serialization operations. This should only ever be used by an IMoapModule.
/// </summary>
[XmlIgnore]
public string MediaRaw { get; set; }
/// <summary>
/// Entries to store media textures on each face
/// </summary>

View File

@ -32,6 +32,7 @@ using System.Collections.Specialized;
using System.Reflection;
using System.IO;
using System.Web;
using System.Xml;
using log4net;
using Mono.Addins;
using Nini.Config;
@ -46,6 +47,7 @@ using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using Caps = OpenSim.Framework.Capabilities.Caps;
using OSDArray = OpenMetaverse.StructuredData.OSDArray;
using OSDMap = OpenMetaverse.StructuredData.OSDMap;
namespace OpenSim.Region.CoreModules.Media.Moap
@ -162,12 +164,76 @@ namespace OpenSim.Region.CoreModules.Media.Moap
public void OnSceneObjectLoaded(SceneObjectGroup so)
{
m_log.DebugFormat("[MOAP]: OnSceneObjectLoaded fired for {0} {1}", so.Name, so.UUID);
so.ForEachPart(OnSceneObjectPartLoaded);
}
public void OnSceneObjectPreSave(SceneObjectGroup persistingSo, SceneObjectGroup originalSo)
{
m_log.DebugFormat("[MOAP]: OnSceneObjectPreSave fired for {0} {1}", persistingSo.Name, persistingSo.UUID);
}
m_log.DebugFormat("[MOAP]: OnSceneObjectPreSave fired for {0} {1}", persistingSo.Name, persistingSo.UUID);
persistingSo.ForEachPart(OnSceneObjectPartPreSave);
}
protected void OnSceneObjectPartLoaded(SceneObjectPart part)
{
if (null == part.Shape.MediaRaw)
return;
using (StringReader sr = new StringReader(part.Shape.MediaRaw))
{
using (XmlTextReader xtr = new XmlTextReader(sr))
{
xtr.ReadStartElement("osmedia");
OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml());
List<MediaEntry> mediaEntries = new List<MediaEntry>();
foreach (OSD osdMe in osdMeArray)
{
MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry());
mediaEntries.Add(me);
}
xtr.ReadEndElement();
part.Shape.Media = mediaEntries;
}
}
}
protected void OnSceneObjectPartPreSave(SceneObjectPart part)
{
if (null == part.Shape.Media)
return;
using (StringWriter sw = new StringWriter())
{
using (XmlTextWriter xtw = new XmlTextWriter(sw))
{
xtw.WriteStartElement("osmedia");
xtw.WriteAttributeString("type", "sl");
xtw.WriteAttributeString("major_version", "0");
xtw.WriteAttributeString("minor_version", "1");
OSDArray meArray = new OSDArray();
foreach (MediaEntry me in part.Shape.Media)
{
OSD osd = (null == me ? new OSD() : me.GetOSD());
meArray.Add(osd);
}
xtw.WriteStartElement("osdata");
xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray));
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.Flush();
part.Shape.MediaRaw = sw.ToString();
}
}
}
public MediaEntry GetMediaEntry(SceneObjectPart part, int face)
{