From ac07d853b89d9b2bda2dd058f7f9ea94211a26f1 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 3 Aug 2010 15:58:17 +0100 Subject: [PATCH] remove duplicated serialization code --- OpenSim/Framework/PrimitiveBaseShape.cs | 38 ++++++++---- .../World/Media/Moap/MoapModule.cs | 58 +------------------ 2 files changed, 29 insertions(+), 67 deletions(-) diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs index de7e42d700..685599ac40 100644 --- a/OpenSim/Framework/PrimitiveBaseShape.cs +++ b/OpenSim/Framework/PrimitiveBaseShape.cs @@ -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 mediaEntries = new List(); 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()); + } } } } \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs index 339a979f75..52acf8141e 100644 --- a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs +++ b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs @@ -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)