From 93b26f89336d83f2eab43ced0081d60b1acf2d7f Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 26 Mar 2009 17:25:12 +0000 Subject: * iars: Serialize information about item creators to archive --- .../Framework/Serialization/ArchiveConstants.cs | 41 +++++++------ .../External/UserProfileSerializer.cs | 71 ++++++++++++++++++++++ .../Archiver/InventoryArchiveWriteRequest.cs | 10 ++- 3 files changed, 102 insertions(+), 20 deletions(-) create mode 100644 OpenSim/Framework/Serialization/External/UserProfileSerializer.cs (limited to 'OpenSim') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index d0a0985..8ce7b56 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -35,49 +35,54 @@ namespace OpenSim.Framework.Serialization /// public class ArchiveConstants { - /// + /// /// The location of the archive control file - /// + /// public static readonly string CONTROL_FILE_PATH = "archive.xml"; - /// + /// /// Path for the assets held in an archive - /// + /// public static readonly string ASSETS_PATH = "assets/"; - /// + /// /// Path for the inventory data - /// + /// public static readonly string INVENTORY_PATH = "inventory/"; - /// + /// /// Path for the prims file - /// + /// public static readonly string OBJECTS_PATH = "objects/"; - /// + /// /// Path for terrains. Technically these may be assets, but I think it's quite nice to split them out. - /// + /// public static readonly string TERRAINS_PATH = "terrains/"; - /// + /// /// Path for region settings. - /// + /// public static readonly string SETTINGS_PATH = "settings/"; + + /// + /// Path for user profiles + /// + public const string USERS_PATH = "users/"; - /// + /// /// The character the separates the uuid from extension information in an archived asset filename - /// + /// public static readonly string ASSET_EXTENSION_SEPARATOR = "_"; - /// + /// /// Used to separate components in an inventory node name - /// + /// public static readonly string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__"; - /// + /// /// Extensions used for asset types in the archive - /// + /// public static readonly IDictionary ASSET_TYPE_TO_EXTENSION = new Dictionary(); public static readonly IDictionary EXTENSION_TO_ASSET_TYPE = new Dictionary(); diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs new file mode 100644 index 0000000..fc76fb6 --- /dev/null +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs @@ -0,0 +1,71 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.IO; +using System.Xml; +using OpenSim.Framework; + +namespace OpenSim.Framework.Serialization.External +{ + /// + /// Serialize and deserialize region settings for an archive file format. + /// + /// We didn't use automatic .NET serialization since this is really + /// a file format rather than an object serialization. + public class UserProfileSerializer + { + public const int MAJOR_VERSION = 0; + public const int MINOR_VERSION = 1; + + public static string Serialize(UserProfileData profile) + { + StringWriter sw = new StringWriter(); + XmlTextWriter xtw = new XmlTextWriter(sw); + xtw.Formatting = Formatting.Indented; + xtw.WriteStartDocument(); + + xtw.WriteStartElement("user_profile"); + xtw.WriteAttributeString("major_version", MAJOR_VERSION.ToString()); + xtw.WriteAttributeString("minor_version", MINOR_VERSION.ToString()); + + xtw.WriteElementString("name", profile.Name); + xtw.WriteElementString("id", profile.ID); + xtw.WriteElementString("about", profile.AboutText); + + // Not sure if we're storing this yet, need to take a look +// xtw.WriteElementString("Url", profile.Url); + // or, indeed, interests + + xtw.WriteEndElement(); + + xtw.Close(); + sw.Close(); + + return sw.ToString(); + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index 208c49e..5a7d929 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs @@ -35,6 +35,7 @@ using log4net; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Framework.Serialization; +using OpenSim.Framework.Serialization.External; using OpenSim.Framework.Communications; using OpenSim.Framework.Communications.Cache; using OpenSim.Region.CoreModules.World.Archiver; @@ -346,10 +347,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver = m_module.CommsManager.UserProfileCacheService.GetUserDetails(creatorId); if (creator != null) - m_log.DebugFormat( - "[INVENTORY ARCHIVER]: Got creator {0} {1}", creator.UserProfile.Name, creator.UserProfile.ID); + { + m_archive.WriteFile( + ArchiveConstants.USERS_PATH + creator.UserProfile.Name + ".xml", + UserProfileSerializer.Serialize(creator.UserProfile)); + } else + { m_log.WarnFormat("[INVENTORY ARCHIVER]: Failed to get creator profile for {0}", creatorId); + } } } } -- cgit v1.1