* refactor: break out sog original xml serialization to a separate class

0.6.5-rc1
Justin Clarke Casey 2009-05-08 18:05:54 +00:00
parent fcfc97a4bf
commit 9f39a490b5
5 changed files with 67 additions and 60 deletions

View File

@ -1816,7 +1816,7 @@ namespace OpenSim.Region.Framework.Scenes
{
UUID assetID = UUID.Zero;
string sceneObjectXml = objectGroup.ToXmlString();
string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(objectGroup);
// Get the user info of the item destination
//
@ -2040,7 +2040,7 @@ namespace OpenSim.Region.Framework.Scenes
"[ATTACHMENT]: Updating asset for attachment {0}, attachpoint {1}",
grp.UUID, grp.GetAttachmentPoint());
string sceneObjectXml = objectGroup.ToXmlString();
string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(objectGroup);
CachedUserInfo userInfo =
CommsManager.UserProfileCacheService.GetUserDetails(agentID);
@ -2111,7 +2111,7 @@ namespace OpenSim.Region.Framework.Scenes
itemID = UUID.Zero;
if (grp != null)
{
string sceneObjectXml = grp.ToXmlString();
string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp);
CachedUserInfo userInfo =
CommsManager.UserProfileCacheService.GetUserDetails(AgentId);

View File

@ -44,6 +44,7 @@ using OpenSim.Framework.Communications.Clients;
using OpenSim.Framework.Console;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes.Scripting;
using OpenSim.Region.Framework.Scenes.Serialization;
using OpenSim.Region.Physics.Manager;
using Timer=System.Timers.Timer;
using TPFlags = OpenSim.Framework.Constants.TeleportFlags;
@ -3383,7 +3384,7 @@ namespace OpenSim.Region.Framework.Scenes
break;
case 2: // Sell a copy
string sceneObjectXml = group.ToXmlString();
string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(group);
CachedUserInfo userInfo =
CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);

View File

@ -655,50 +655,6 @@ namespace OpenSim.Region.Framework.Scenes
#endregion
public string ToXmlString()
{
using (StringWriter sw = new StringWriter())
{
using (XmlTextWriter writer = new XmlTextWriter(sw))
{
ToXml(writer);
}
return sw.ToString();
}
}
public void ToXml(XmlTextWriter writer)
{
//m_log.DebugFormat("[SOG]: Starting serialization of {0}", Name);
//int time = System.Environment.TickCount;
writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
writer.WriteStartElement(String.Empty, "RootPart", String.Empty);
m_rootPart.ToXml(writer);
writer.WriteEndElement();
writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
lock (m_parts)
{
foreach (SceneObjectPart part in m_parts.Values)
{
if (part.UUID != m_rootPart.UUID)
{
writer.WriteStartElement(String.Empty, "Part", String.Empty);
part.ToXml(writer);
writer.WriteEndElement();
}
}
}
writer.WriteEndElement(); // OtherParts
SaveScriptedState(writer);
writer.WriteEndElement(); // SceneObjectGroup
//m_log.DebugFormat("[SOG]: Finished serialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
}
public string ToXmlString2()
{
using (StringWriter sw = new StringWriter())
@ -714,7 +670,6 @@ namespace OpenSim.Region.Framework.Scenes
public void ToXml2(XmlTextWriter writer)
{
//m_log.DebugFormat("[SOG]: Starting serialization of SOG {0} to XML2", Name);
//int time = System.Environment.TickCount;
@ -738,12 +693,10 @@ namespace OpenSim.Region.Framework.Scenes
writer.WriteEndElement(); // End of SceneObjectGroup
//m_log.DebugFormat("[SOG]: Finished serialization of SOG {0} to XML2, {1}ms", Name, System.Environment.TickCount - time);
}
private void SaveScriptedState(XmlTextWriter writer)
public void SaveScriptedState(XmlTextWriter writer)
{
XmlDocument doc = new XmlDocument();
Dictionary<UUID,string> states = new Dictionary<UUID,string>();
@ -774,7 +727,6 @@ namespace OpenSim.Region.Framework.Scenes
}
writer.WriteEndElement(); // End of GroupScriptStates
}
}
/// <summary>

View File

@ -90,7 +90,7 @@ namespace OpenSim.Region.Framework.Scenes
{
if (ent is SceneObjectGroup)
{
stream.WriteLine(((SceneObjectGroup) ent).ToXmlString());
stream.WriteLine(SceneObjectSerializer.ToOriginalXmlFormat((SceneObjectGroup)ent));
primCount++;
}
}

View File

@ -64,7 +64,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
//m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
//int time = System.Environment.TickCount;
SceneObjectGroup so = new SceneObjectGroup();
SceneObjectGroup sceneObject = new SceneObjectGroup();
// libomv.types changes UUID to Guid
serialization = serialization.Replace("<UUID>", "<Guid>");
@ -94,7 +94,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
{
sr = new StringReader(parts[0].InnerXml);
reader = new XmlTextReader(sr);
so.SetRootPart(SceneObjectPart.FromXml(fromUserInventoryItemID, reader));
sceneObject.SetRootPart(SceneObjectPart.FromXml(fromUserInventoryItemID, reader));
reader.Close();
sr.Close();
}
@ -107,7 +107,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
reader = new XmlTextReader(sr);
SceneObjectPart part = SceneObjectPart.FromXml(reader);
linkNum = part.LinkNum;
so.AddPart(part);
sceneObject.AddPart(part);
part.LinkNum = linkNum;
part.TrimPermissions();
part.StoreUndoState();
@ -117,7 +117,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
// Script state may, or may not, exist. Not having any, is NOT
// ever a problem.
so.LoadScriptState(doc);
sceneObject.LoadScriptState(doc);
}
catch (Exception e)
{
@ -127,7 +127,61 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
//m_log.DebugFormat("[SERIALIZER]: Finished deserialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
return so;
}
return sceneObject;
}
/// <summary>
/// Serialize a scene object to the original xml format
/// </summary>
/// <param name="sceneObject"></param>
/// <returns></returns>
public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
{
using (StringWriter sw = new StringWriter())
{
using (XmlTextWriter writer = new XmlTextWriter(sw))
{
ToOriginalXmlFormat(sceneObject, writer);
}
return sw.ToString();
}
}
/// <summary>
/// Serialize a scene object to the original xml format
/// </summary>
/// <param name="sceneObject"></param>
/// <returns></returns>
public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer)
{
//m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", Name);
//int time = System.Environment.TickCount;
writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
writer.WriteStartElement(String.Empty, "RootPart", String.Empty);
sceneObject.RootPart.ToXml(writer);
writer.WriteEndElement();
writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
lock (sceneObject.Children)
{
foreach (SceneObjectPart part in sceneObject.Children.Values)
{
if (part.UUID != sceneObject.RootPart.UUID)
{
writer.WriteStartElement(String.Empty, "Part", String.Empty);
part.ToXml(writer);
writer.WriteEndElement();
}
}
}
writer.WriteEndElement(); // OtherParts
sceneObject.SaveScriptedState(writer);
writer.WriteEndElement(); // SceneObjectGroup
//m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
}
}
}