remove duplicated serialization code

prebuild-update
Justin Clark-Casey (justincc) 2010-08-03 15:58:17 +01:00
parent 60df76314f
commit ac07d853b8
2 changed files with 29 additions and 67 deletions

View File

@ -1238,7 +1238,7 @@ namespace OpenSim.Framework
return null; return null;
} }
public void WriteXml(XmlWriter writer) public string ToXml()
{ {
lock (this) lock (this)
{ {
@ -1265,18 +1265,26 @@ namespace OpenSim.Framework
xtw.WriteEndElement(); xtw.WriteEndElement();
xtw.Flush(); xtw.Flush();
writer.WriteRaw(sw.ToString()); return sw.ToString();
} }
} }
} }
} }
public void ReadXml(XmlReader reader) public void WriteXml(XmlWriter writer)
{ {
if (reader.IsEmptyElement) writer.WriteRaw(ToXml());
return; }
string rawXml = reader.ReadInnerXml(); public static MediaList FromXml(string rawXml)
{
MediaList ml = new MediaList();
ml.ReadXml(rawXml);
return ml;
}
public void ReadXml(string rawXml)
{
using (StringReader sr = new StringReader(rawXml)) using (StringReader sr = new StringReader(rawXml))
{ {
using (XmlTextReader xtr = new XmlTextReader(sr)) using (XmlTextReader xtr = new XmlTextReader(sr))
@ -1292,8 +1300,6 @@ namespace OpenSim.Framework
xtr.ReadStartElement("osmedia"); xtr.ReadStartElement("osmedia");
OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml()); OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml());
List<MediaEntry> mediaEntries = new List<MediaEntry>();
foreach (OSD osdMe in osdMeArray) foreach (OSD osdMe in osdMeArray)
{ {
MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry()); MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry());
@ -1304,6 +1310,14 @@ namespace OpenSim.Framework
} }
} }
} }
public void ReadXml(XmlReader reader)
{
if (reader.IsEmptyElement)
return;
ReadXml(reader.ReadInnerXml());
}
} }
} }
} }

View File

@ -203,34 +203,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
if (null == part.Shape.MediaRaw) if (null == part.Shape.MediaRaw)
return; return;
using (StringReader sr = new StringReader(part.Shape.MediaRaw)) part.Shape.Media = PrimitiveBaseShape.MediaList.FromXml(part.Shape.MediaRaw);
{
using (XmlTextReader xtr = new XmlTextReader(sr))
{
xtr.MoveToContent();
string type = xtr.GetAttribute("type");
//m_log.DebugFormat("[MOAP]: Loaded media texture entry with type {0}", type);
if (type != MEDIA_TEXTURE_TYPE)
return;
xtr.ReadStartElement("osmedia");
OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml());
PrimitiveBaseShape.MediaList mediaEntries = new PrimitiveBaseShape.MediaList();
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) protected void OnSceneObjectPartPreSave(SceneObjectPart part)
@ -238,32 +211,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
if (null == part.Shape.Media) if (null == part.Shape.Media)
return; return;
using (StringWriter sw = new StringWriter()) part.Shape.MediaRaw = part.Shape.Media.ToXml();
{
using (XmlTextWriter xtw = new XmlTextWriter(sw))
{
xtw.WriteStartElement("osmedia");
xtw.WriteAttributeString("type", MEDIA_TEXTURE_TYPE);
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();
}
}
} }
protected void OnSceneObjectPartCopy(SceneObjectPart copy, SceneObjectPart original, bool userExposed) protected void OnSceneObjectPartCopy(SceneObjectPart copy, SceneObjectPart original, bool userExposed)