remove duplicated serialization code
parent
60df76314f
commit
ac07d853b8
|
@ -1238,7 +1238,7 @@ namespace OpenSim.Framework
|
|||
return null;
|
||||
}
|
||||
|
||||
public void WriteXml(XmlWriter writer)
|
||||
public string ToXml()
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
|
@ -1265,18 +1265,26 @@ namespace OpenSim.Framework
|
|||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Flush();
|
||||
writer.WriteRaw(sw.ToString());
|
||||
return sw.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadXml(XmlReader reader)
|
||||
|
||||
public void WriteXml(XmlWriter writer)
|
||||
{
|
||||
writer.WriteRaw(ToXml());
|
||||
}
|
||||
|
||||
public static MediaList FromXml(string rawXml)
|
||||
{
|
||||
if (reader.IsEmptyElement)
|
||||
return;
|
||||
|
||||
string rawXml = reader.ReadInnerXml();
|
||||
MediaList ml = new MediaList();
|
||||
ml.ReadXml(rawXml);
|
||||
return ml;
|
||||
}
|
||||
|
||||
public void ReadXml(string rawXml)
|
||||
{
|
||||
using (StringReader sr = new StringReader(rawXml))
|
||||
{
|
||||
using (XmlTextReader xtr = new XmlTextReader(sr))
|
||||
|
@ -1292,8 +1300,6 @@ namespace OpenSim.Framework
|
|||
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());
|
||||
|
@ -1303,7 +1309,15 @@ namespace OpenSim.Framework
|
|||
xtr.ReadEndElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadXml(XmlReader reader)
|
||||
{
|
||||
if (reader.IsEmptyElement)
|
||||
return;
|
||||
|
||||
ReadXml(reader.ReadInnerXml());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -203,67 +203,15 @@ namespace OpenSim.Region.CoreModules.Media.Moap
|
|||
if (null == part.Shape.MediaRaw)
|
||||
return;
|
||||
|
||||
using (StringReader sr = new StringReader(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;
|
||||
}
|
||||
}
|
||||
part.Shape.Media = PrimitiveBaseShape.MediaList.FromXml(part.Shape.MediaRaw);
|
||||
}
|
||||
|
||||
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", 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();
|
||||
}
|
||||
}
|
||||
|
||||
part.Shape.MediaRaw = part.Shape.Media.ToXml();
|
||||
}
|
||||
|
||||
protected void OnSceneObjectPartCopy(SceneObjectPart copy, SceneObjectPart original, bool userExposed)
|
||||
|
|
Loading…
Reference in New Issue