From 229b69e044ca81233f248ff623b22516136bb3c6 Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Tue, 17 Feb 2009 15:39:18 +0000
Subject: * Establish InventoryArchiveSaved event for unit tests * This is done
on the inventory archiver module directly rather than Scene.EventManager -
the module seems the more appropriate location
---
OpenSim/Framework/InventoryItemBase.cs | 2 +-
OpenSim/Framework/InventoryNodeBase.cs | 2 +-
.../Archiver/InventoryArchiveWriteRequest.cs | 42 ++++++++++++++--------
.../Inventory/Archiver/InventoryArchiverModule.cs | 34 ++++++++++++------
.../Archiver/Tests/InventoryArchiverTests.cs | 23 ++++++++----
.../Interfaces/IInventoryArchiverModule.cs | 22 ++++++++++--
6 files changed, 89 insertions(+), 36 deletions(-)
(limited to 'OpenSim')
diff --git a/OpenSim/Framework/InventoryItemBase.cs b/OpenSim/Framework/InventoryItemBase.cs
index ecc2d76..21683c4 100644
--- a/OpenSim/Framework/InventoryItemBase.cs
+++ b/OpenSim/Framework/InventoryItemBase.cs
@@ -65,7 +65,7 @@ namespace OpenSim.Framework
///
/// The description of the inventory item (must be less than 64 characters)
///
- private string _description;
+ private string _description = string.Empty;
///
///
diff --git a/OpenSim/Framework/InventoryNodeBase.cs b/OpenSim/Framework/InventoryNodeBase.cs
index 6f61ab5..57ec516 100644
--- a/OpenSim/Framework/InventoryNodeBase.cs
+++ b/OpenSim/Framework/InventoryNodeBase.cs
@@ -42,7 +42,7 @@ namespace OpenSim.Framework
get { return m_name; }
set { m_name = value; }
}
- private string m_name;
+ private string m_name = string.Empty;
///
/// A UUID containing the ID for the inventory node itself
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
index d916eba..456831d 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
@@ -45,9 +45,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected TarArchiveWriter archive = new TarArchiveWriter();
- protected CommunicationsManager commsManager;
protected Dictionary assetUuids = new Dictionary();
+ private InventoryArchiverModule m_module;
private CachedUserInfo m_userInfo;
private string m_invPath;
@@ -60,12 +60,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// Constructor
///
public InventoryArchiveWriteRequest(
- CachedUserInfo userInfo, string invPath, string savePath, CommunicationsManager commsManager)
+ InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, string savePath)
: this(
+ module,
userInfo,
invPath,
- new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress),
- commsManager)
+ new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress))
{
}
@@ -73,19 +73,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// Constructor
///
public InventoryArchiveWriteRequest(
- CachedUserInfo userInfo, string invPath, Stream saveStream, CommunicationsManager commsManager)
+ InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, Stream saveStream)
{
+ m_module = module;
m_userInfo = userInfo;
m_invPath = invPath;
- m_saveStream = saveStream;
- this.commsManager = commsManager;
+ m_saveStream = saveStream;
}
protected void ReceivedAllAssets(IDictionary assetsFound, ICollection assetsNotFoundUuids)
{
AssetsArchiver assetsArchiver = new AssetsArchiver(assetsFound);
assetsArchiver.Archive(archive);
- archive.WriteTar(m_saveStream);
+
+ Exception reportedException = null;
+ bool succeeded = true;
+
+ try
+ {
+ archive.WriteTar(m_saveStream);
+ }
+ catch (IOException e)
+ {
+ reportedException = e;
+ succeeded = false;
+ }
+
+ m_module.TriggerInventoryArchiveSaved(succeeded, m_userInfo, m_invPath, m_saveStream, reportedException);
}
protected void saveInvItem(InventoryItemBase inventoryItem, string path)
@@ -115,9 +129,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
writer.WriteString(inventoryItem.Owner.ToString());
writer.WriteEndElement();
writer.WriteStartElement("Description");
- if (inventoryItem.Description.Length > 0)
- writer.WriteString(inventoryItem.Description);
- else writer.WriteString("No Description");
+ writer.WriteString(inventoryItem.Description);
writer.WriteEndElement();
writer.WriteStartElement("AssetType");
writer.WriteString(inventoryItem.AssetType.ToString());
@@ -191,7 +203,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
//
// FIXME: FetchInventory should probably be assumed to by async anyway, since even standalones might
// use a remote inventory service, though this is vanishingly rare at the moment.
- if (null == commsManager.UserAdminService)
+ if (null == m_module.CommsManager.UserAdminService)
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}",
@@ -242,7 +254,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
else
{
- m_log.InfoFormat(
+ m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Found item {0} {1} at {2}",
inventoryItem.Name, inventoryItem.ID, m_invPath);
@@ -252,7 +264,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
else
{
- m_log.InfoFormat(
+ m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}",
inventoryFolder.Name, inventoryFolder.ID, m_invPath);
@@ -260,7 +272,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
saveInvDir(inventoryFolder, "");
}
- new AssetsRequest(assetUuids.Keys, commsManager.AssetCache, ReceivedAllAssets).Execute();
+ new AssetsRequest(assetUuids.Keys, m_module.CommsManager.AssetCache, ReceivedAllAssets).Execute();
}
}
}
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
index 786cbeb..1997562 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
@@ -25,6 +25,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
@@ -38,7 +39,7 @@ using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
-{
+{
///
/// This module loads and saves OpenSimulator inventory archives
///
@@ -50,10 +51,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
public bool IsSharedModule { get { return true; } }
+ public event InventoryArchiveSaved OnInventoryArchiveSaved;
+
///
/// The file to load and save inventory if no filename has been specified
///
- protected const string DEFAULT_INV_BACKUP_FILENAME = "user-inventory_iar.tar.gz";
+ protected const string DEFAULT_INV_BACKUP_FILENAME = "user-inventory_iar.tar.gz";
///
/// All scenes that this module knows about
@@ -63,14 +66,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
///
/// The comms manager we will use for all comms requests
///
- private CommunicationsManager m_commsManager;
+ protected internal CommunicationsManager CommsManager;
public void Initialise(Scene scene, IConfigSource source)
{
if (m_scenes.Count == 0)
{
scene.RegisterModuleInterface(this);
- m_commsManager = scene.CommsManager;
+ CommsManager = scene.CommsManager;
scene.AddCommand(
this, "load iar",
@@ -89,6 +92,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
public void PostInitialise() {}
public void Close() {}
+
+ ///
+ /// Trigger the inventory archive saved event.
+ ///
+ protected internal void TriggerInventoryArchiveSaved(
+ bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException)
+ {
+ InventoryArchiveSaved handlerInventoryArchiveSaved = OnInventoryArchiveSaved;
+ if (handlerInventoryArchiveSaved != null)
+ handlerInventoryArchiveSaved(succeeded, userInfo, invPath, saveStream, reportedException);
+ }
public void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream)
{
@@ -99,7 +113,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
if (userInfo != null)
{
InventoryArchiveReadRequest request =
- new InventoryArchiveReadRequest(userInfo, invPath, loadStream, m_commsManager);
+ new InventoryArchiveReadRequest(userInfo, invPath, loadStream, CommsManager);
UpdateClientWithLoadedNodes(userInfo, request.Execute());
}
}
@@ -112,7 +126,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null)
- new InventoryArchiveWriteRequest(userInfo, invPath, saveStream, m_commsManager).Execute();
+ new InventoryArchiveWriteRequest(this, userInfo, invPath, saveStream).Execute();
}
}
@@ -125,7 +139,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
if (userInfo != null)
{
InventoryArchiveReadRequest request =
- new InventoryArchiveReadRequest(userInfo, invPath, loadPath, m_commsManager);
+ new InventoryArchiveReadRequest(userInfo, invPath, loadPath, CommsManager);
UpdateClientWithLoadedNodes(userInfo, request.Execute());
}
}
@@ -138,7 +152,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null)
- new InventoryArchiveWriteRequest(userInfo, invPath, savePath, m_commsManager).Execute();
+ new InventoryArchiveWriteRequest(this, userInfo, invPath, savePath).Execute();
}
}
@@ -208,7 +222,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
///
protected CachedUserInfo GetUserInfo(string firstName, string lastName)
{
- UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(firstName, lastName);
+ UserProfileData userProfile = CommsManager.UserService.GetUserProfile(firstName, lastName);
if (null == userProfile)
{
@@ -216,7 +230,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
return null;
}
- CachedUserInfo userInfo = m_commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
+ CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
if (null == userInfo)
{
m_log.ErrorFormat(
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
index bc5e564..d1956b4 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
@@ -26,7 +26,9 @@
*/
using System;
+using System.IO;
using System.Text;
+using System.Threading;
using NUnit.Framework;
using OpenMetaverse;
using OpenSim.Data;
@@ -42,10 +44,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
[TestFixture]
public class InventoryArchiverTests
{
+ private EventWaitHandle m_waitHandle = new AutoResetEvent(false);
+
+ private void SaveCompleted(
+ bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException)
+ {
+ m_waitHandle.Set();
+ }
+
///
/// Test saving a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet).
///
- [Test]
+ [Test]
public void TestSaveIarV0p1()
{
//log4net.Config.XmlConfigurator.Configure();
@@ -94,16 +104,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
item1.Name = "My Little Dog";
item1.AssetID = asset1.FullID;
item1.Folder = userInfo.RootFolder.FindFolderByPath("Objects").ID;
- scene.AddInventoryItem(userId, item1);
-
- /*
+ scene.AddInventoryItem(userId, item1);
MemoryStream archiveWriteStream = new MemoryStream();
-
- scene.EventManager.OnOarFileSaved += SaveCompleted;
- archiverModule.ArchiveRegion(archiveWriteStream);
+ archiverModule.OnInventoryArchiveSaved += SaveCompleted;
+
+ archiverModule.ArchiveInventory(userFirstName, userLastName, "Objects", archiveWriteStream);
m_waitHandle.WaitOne(60000, true);
+ /*
byte[] archive = archiveWriteStream.ToArray();
MemoryStream archiveReadStream = new MemoryStream(archive);
TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
diff --git a/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs b/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs
index 0e1e851..652dbf8 100644
--- a/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs
@@ -25,13 +25,31 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+using System;
using System.IO;
+using OpenSim.Framework.Communications.Cache;
namespace OpenSim.Region.Framework.Interfaces
-{
- public interface IInventoryArchiverModule
+{
+ ///
+ /// Used for the OnInventoryArchiveSaved event.
+ ///
+ /// true if the save succeeded, false otherwise
+ /// The user for whom the save was conducted
+ /// The inventory path saved
+ /// The stream to which the archive was saved
+ /// Contains the exception generated if the save did not succeed
+ public delegate void InventoryArchiveSaved(
+ bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException);
+
+ public interface IInventoryArchiverModule
{
///
+ /// Fired when an archive inventory save has been completed.
+ ///
+ event InventoryArchiveSaved OnInventoryArchiveSaved;
+
+ ///
/// Dearchive a user's inventory folder from the given stream
///
///
--
cgit v1.1