From 3f3c4e182fa950f2eb8ba18ab6fcdea013668947 Mon Sep 17 00:00:00 2001 From: Jim Radford Date: Wed, 7 Oct 2009 03:47:02 +0000 Subject: [PATCH] LIBOMV-576 Merged ClientHelpers and Helpers classes, ClientHelpers methods can once again be directly accessed through the static Helpers class. git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3130 52acb1d6-8a22-11de-b505-999d5b087335 --- OpenMetaverse/ClientHelpers.cs | 50 ------------------- OpenMetaverse/Helpers.cs | 45 +++++++++++++++-- Programs/PrimWorkshop/frmBrowser.cs | 4 +- Programs/PrimWorkshop/frmPrimWorkshop.cs | 2 +- .../Commands/Prims/ExportCommand.cs | 2 +- .../Commands/Prims/ImportCommand.cs | 2 +- 6 files changed, 47 insertions(+), 58 deletions(-) delete mode 100644 OpenMetaverse/ClientHelpers.cs diff --git a/OpenMetaverse/ClientHelpers.cs b/OpenMetaverse/ClientHelpers.cs deleted file mode 100644 index 8ca5b07b..00000000 --- a/OpenMetaverse/ClientHelpers.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace OpenMetaverse -{ - public static class ClientHelpers - { - /// - /// Converts a list of primitives to an object that can be serialized - /// with the LLSD system - /// - /// Primitives to convert to a serializable object - /// An object that can be serialized with LLSD - public static StructuredData.OSD PrimListToOSD(List prims) - { - StructuredData.OSDMap map = new OpenMetaverse.StructuredData.OSDMap(prims.Count); - - for (int i = 0; i < prims.Count; i++) - map.Add(prims[i].LocalID.ToString(), prims[i].GetOSD()); - - return map; - } - - /// - /// Deserializes OSD in to a list of primitives - /// - /// Structure holding the serialized primitive list, - /// must be of the SDMap type - /// A list of deserialized primitives - public static List OSDToPrimList(StructuredData.OSD osd) - { - if (osd.Type != StructuredData.OSDType.Map) - throw new ArgumentException("LLSD must be in the Map structure"); - - StructuredData.OSDMap map = (StructuredData.OSDMap)osd; - List prims = new List(map.Count); - - foreach (KeyValuePair kvp in map) - { - Primitive prim = Primitive.FromOSD(kvp.Value); - prim.LocalID = UInt32.Parse(kvp.Key); - prims.Add(prim); - } - - return prims; - } - } -} diff --git a/OpenMetaverse/Helpers.cs b/OpenMetaverse/Helpers.cs index b1427901..c136dee3 100644 --- a/OpenMetaverse/Helpers.cs +++ b/OpenMetaverse/Helpers.cs @@ -301,8 +301,8 @@ namespace OpenMetaverse } catch (Exception ex) { - //Logger.Log(String.Format("Zerodecoding error: i={0}, srclen={1}, bodylen={2}, zerolen={3}\n{4}\n{5}", - // i, srclen, bodylen, zerolen, Utils.BytesToHexString(src, srclen, null), ex), LogLevel.Error); + Logger.Log(String.Format("Zerodecoding error: i={0}, srclen={1}, bodylen={2}, zerolen={3}\n{4}\n{5}", + i, srclen, bodylen, zerolen, Utils.BytesToHexString(src, srclen, null), ex), LogLevel.Error); throw new IndexOutOfRangeException(String.Format("Zerodecoding error: i={0}, srclen={1}, bodylen={2}, zerolen={3}\n{4}\n{5}", i, srclen, bodylen, zerolen, Utils.BytesToHexString(src, srclen, null)), ex.InnerException); } @@ -479,6 +479,45 @@ namespace OpenMetaverse } return null; - } + } + /// + /// Converts a list of primitives to an object that can be serialized + /// with the LLSD system + /// + /// Primitives to convert to a serializable object + /// An object that can be serialized with LLSD + public static StructuredData.OSD PrimListToOSD(List prims) + { + StructuredData.OSDMap map = new OpenMetaverse.StructuredData.OSDMap(prims.Count); + + for (int i = 0; i < prims.Count; i++) + map.Add(prims[i].LocalID.ToString(), prims[i].GetOSD()); + + return map; + } + + /// + /// Deserializes OSD in to a list of primitives + /// + /// Structure holding the serialized primitive list, + /// must be of the SDMap type + /// A list of deserialized primitives + public static List OSDToPrimList(StructuredData.OSD osd) + { + if (osd.Type != StructuredData.OSDType.Map) + throw new ArgumentException("LLSD must be in the Map structure"); + + StructuredData.OSDMap map = (StructuredData.OSDMap)osd; + List prims = new List(map.Count); + + foreach (KeyValuePair kvp in map) + { + Primitive prim = Primitive.FromOSD(kvp.Value); + prim.LocalID = UInt32.Parse(kvp.Key); + prims.Add(prim); + } + + return prims; + } } } diff --git a/Programs/PrimWorkshop/frmBrowser.cs b/Programs/PrimWorkshop/frmBrowser.cs index 4c654746..75942d17 100644 --- a/Programs/PrimWorkshop/frmBrowser.cs +++ b/Programs/PrimWorkshop/frmBrowser.cs @@ -328,7 +328,7 @@ namespace PrimWorkshop textures = 0; // Write the LLSD to the hard drive in XML format - string output = OSDParser.SerializeLLSDXmlString(ClientHelpers.PrimListToOSD(primList)); + string output = OSDParser.SerializeLLSDXmlString(Helpers.PrimListToOSD(primList)); try { // Create a temporary directory @@ -499,7 +499,7 @@ namespace PrimWorkshop // Decode the .prims file string raw = File.ReadAllText(primFile); OSD osd = OSDParser.DeserializeLLSDXml(raw); - return ClientHelpers.OSDToPrimList(osd); + return Helpers.OSDToPrimList(osd); } catch (Exception e) { diff --git a/Programs/PrimWorkshop/frmPrimWorkshop.cs b/Programs/PrimWorkshop/frmPrimWorkshop.cs index 4cf302c5..cc324eb7 100644 --- a/Programs/PrimWorkshop/frmPrimWorkshop.cs +++ b/Programs/PrimWorkshop/frmPrimWorkshop.cs @@ -275,7 +275,7 @@ namespace PrimWorkshop if (osd != null && osd.Type == OSDType.Map) { - List primList = ClientHelpers.OSDToPrimList(osd); + List primList = Helpers.OSDToPrimList(osd); Prims = new List(primList.Count); for (int i = 0; i < primList.Count; i++) diff --git a/Programs/examples/TestClient/Commands/Prims/ExportCommand.cs b/Programs/examples/TestClient/Commands/Prims/ExportCommand.cs index 4fe4d46b..dd3cc310 100644 --- a/Programs/examples/TestClient/Commands/Prims/ExportCommand.cs +++ b/Programs/examples/TestClient/Commands/Prims/ExportCommand.cs @@ -100,7 +100,7 @@ namespace OpenMetaverse.TestClient Logger.Log(uuid.ToString(), Helpers.LogLevel.Warning, Client); } - string output = OSDParser.SerializeLLSDXmlString(ClientHelpers.PrimListToOSD(prims)); + string output = OSDParser.SerializeLLSDXmlString(Helpers.PrimListToOSD(prims)); try { File.WriteAllText(file, output); } catch (Exception e) { return e.Message; } diff --git a/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs b/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs index 5e20abbe..5c2755f4 100644 --- a/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs +++ b/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs @@ -63,7 +63,7 @@ namespace OpenMetaverse.TestClient try { xml = File.ReadAllText(filename); } catch (Exception e) { return e.Message; } - try { prims = ClientHelpers.OSDToPrimList(OSDParser.DeserializeLLSDXml(xml)); } + try { prims = Helpers.OSDToPrimList(OSDParser.DeserializeLLSDXml(xml)); } catch (Exception e) { return "Failed to deserialize " + filename + ": " + e.Message; } // Build an organized structure from the imported prims