aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-02-17 15:39:18 +0000
committerJustin Clarke Casey2009-02-17 15:39:18 +0000
commit229b69e044ca81233f248ff623b22516136bb3c6 (patch)
tree6c8d1d8f145b5bb2ec7745fe1209b1d3221496c3 /OpenSim
parent* Ignored a bunch of genned files (diff)
downloadopensim-SC_OLD-229b69e044ca81233f248ff623b22516136bb3c6.zip
opensim-SC_OLD-229b69e044ca81233f248ff623b22516136bb3c6.tar.gz
opensim-SC_OLD-229b69e044ca81233f248ff623b22516136bb3c6.tar.bz2
opensim-SC_OLD-229b69e044ca81233f248ff623b22516136bb3c6.tar.xz
* 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
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/InventoryItemBase.cs2
-rw-r--r--OpenSim/Framework/InventoryNodeBase.cs2
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs42
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs34
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs23
-rw-r--r--OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs22
6 files changed, 89 insertions, 36 deletions
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
65 /// <summary> 65 /// <summary>
66 /// The description of the inventory item (must be less than 64 characters) 66 /// The description of the inventory item (must be less than 64 characters)
67 /// </summary> 67 /// </summary>
68 private string _description; 68 private string _description = string.Empty;
69 69
70 /// <summary> 70 /// <summary>
71 /// 71 ///
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
42 get { return m_name; } 42 get { return m_name; }
43 set { m_name = value; } 43 set { m_name = value; }
44 } 44 }
45 private string m_name; 45 private string m_name = string.Empty;
46 46
47 /// <summary> 47 /// <summary>
48 /// A UUID containing the ID for the inventory node itself 48 /// 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
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 protected TarArchiveWriter archive = new TarArchiveWriter(); 47 protected TarArchiveWriter archive = new TarArchiveWriter();
48 protected CommunicationsManager commsManager;
49 protected Dictionary<UUID, int> assetUuids = new Dictionary<UUID, int>(); 48 protected Dictionary<UUID, int> assetUuids = new Dictionary<UUID, int>();
50 49
50 private InventoryArchiverModule m_module;
51 private CachedUserInfo m_userInfo; 51 private CachedUserInfo m_userInfo;
52 private string m_invPath; 52 private string m_invPath;
53 53
@@ -60,12 +60,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
60 /// Constructor 60 /// Constructor
61 /// </summary> 61 /// </summary>
62 public InventoryArchiveWriteRequest( 62 public InventoryArchiveWriteRequest(
63 CachedUserInfo userInfo, string invPath, string savePath, CommunicationsManager commsManager) 63 InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, string savePath)
64 : this( 64 : this(
65 module,
65 userInfo, 66 userInfo,
66 invPath, 67 invPath,
67 new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress), 68 new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress))
68 commsManager)
69 { 69 {
70 } 70 }
71 71
@@ -73,19 +73,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
73 /// Constructor 73 /// Constructor
74 /// </summary> 74 /// </summary>
75 public InventoryArchiveWriteRequest( 75 public InventoryArchiveWriteRequest(
76 CachedUserInfo userInfo, string invPath, Stream saveStream, CommunicationsManager commsManager) 76 InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, Stream saveStream)
77 { 77 {
78 m_module = module;
78 m_userInfo = userInfo; 79 m_userInfo = userInfo;
79 m_invPath = invPath; 80 m_invPath = invPath;
80 m_saveStream = saveStream; 81 m_saveStream = saveStream;
81 this.commsManager = commsManager;
82 } 82 }
83 83
84 protected void ReceivedAllAssets(IDictionary<UUID, AssetBase> assetsFound, ICollection<UUID> assetsNotFoundUuids) 84 protected void ReceivedAllAssets(IDictionary<UUID, AssetBase> assetsFound, ICollection<UUID> assetsNotFoundUuids)
85 { 85 {
86 AssetsArchiver assetsArchiver = new AssetsArchiver(assetsFound); 86 AssetsArchiver assetsArchiver = new AssetsArchiver(assetsFound);
87 assetsArchiver.Archive(archive); 87 assetsArchiver.Archive(archive);
88 archive.WriteTar(m_saveStream); 88
89 Exception reportedException = null;
90 bool succeeded = true;
91
92 try
93 {
94 archive.WriteTar(m_saveStream);
95 }
96 catch (IOException e)
97 {
98 reportedException = e;
99 succeeded = false;
100 }
101
102 m_module.TriggerInventoryArchiveSaved(succeeded, m_userInfo, m_invPath, m_saveStream, reportedException);
89 } 103 }
90 104
91 protected void saveInvItem(InventoryItemBase inventoryItem, string path) 105 protected void saveInvItem(InventoryItemBase inventoryItem, string path)
@@ -115,9 +129,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
115 writer.WriteString(inventoryItem.Owner.ToString()); 129 writer.WriteString(inventoryItem.Owner.ToString());
116 writer.WriteEndElement(); 130 writer.WriteEndElement();
117 writer.WriteStartElement("Description"); 131 writer.WriteStartElement("Description");
118 if (inventoryItem.Description.Length > 0) 132 writer.WriteString(inventoryItem.Description);
119 writer.WriteString(inventoryItem.Description);
120 else writer.WriteString("No Description");
121 writer.WriteEndElement(); 133 writer.WriteEndElement();
122 writer.WriteStartElement("AssetType"); 134 writer.WriteStartElement("AssetType");
123 writer.WriteString(inventoryItem.AssetType.ToString()); 135 writer.WriteString(inventoryItem.AssetType.ToString());
@@ -191,7 +203,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
191 // 203 //
192 // FIXME: FetchInventory should probably be assumed to by async anyway, since even standalones might 204 // FIXME: FetchInventory should probably be assumed to by async anyway, since even standalones might
193 // use a remote inventory service, though this is vanishingly rare at the moment. 205 // use a remote inventory service, though this is vanishingly rare at the moment.
194 if (null == commsManager.UserAdminService) 206 if (null == m_module.CommsManager.UserAdminService)
195 { 207 {
196 m_log.ErrorFormat( 208 m_log.ErrorFormat(
197 "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}", 209 "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}",
@@ -242,7 +254,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
242 } 254 }
243 else 255 else
244 { 256 {
245 m_log.InfoFormat( 257 m_log.DebugFormat(
246 "[INVENTORY ARCHIVER]: Found item {0} {1} at {2}", 258 "[INVENTORY ARCHIVER]: Found item {0} {1} at {2}",
247 inventoryItem.Name, inventoryItem.ID, m_invPath); 259 inventoryItem.Name, inventoryItem.ID, m_invPath);
248 260
@@ -252,7 +264,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
252 } 264 }
253 else 265 else
254 { 266 {
255 m_log.InfoFormat( 267 m_log.DebugFormat(
256 "[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}", 268 "[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}",
257 inventoryFolder.Name, inventoryFolder.ID, m_invPath); 269 inventoryFolder.Name, inventoryFolder.ID, m_invPath);
258 270
@@ -260,7 +272,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
260 saveInvDir(inventoryFolder, ""); 272 saveInvDir(inventoryFolder, "");
261 } 273 }
262 274
263 new AssetsRequest(assetUuids.Keys, commsManager.AssetCache, ReceivedAllAssets).Execute(); 275 new AssetsRequest(assetUuids.Keys, m_module.CommsManager.AssetCache, ReceivedAllAssets).Execute();
264 } 276 }
265 } 277 }
266} 278}
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 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System;
28using System.Collections.Generic; 29using System.Collections.Generic;
29using System.IO; 30using System.IO;
30using System.Reflection; 31using System.Reflection;
@@ -38,7 +39,7 @@ using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes; 39using OpenSim.Region.Framework.Scenes;
39 40
40namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver 41namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
41{ 42{
42 /// <summary> 43 /// <summary>
43 /// This module loads and saves OpenSimulator inventory archives 44 /// This module loads and saves OpenSimulator inventory archives
44 /// </summary> 45 /// </summary>
@@ -50,10 +51,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
50 51
51 public bool IsSharedModule { get { return true; } } 52 public bool IsSharedModule { get { return true; } }
52 53
54 public event InventoryArchiveSaved OnInventoryArchiveSaved;
55
53 /// <summary> 56 /// <summary>
54 /// The file to load and save inventory if no filename has been specified 57 /// The file to load and save inventory if no filename has been specified
55 /// </summary> 58 /// </summary>
56 protected const string DEFAULT_INV_BACKUP_FILENAME = "user-inventory_iar.tar.gz"; 59 protected const string DEFAULT_INV_BACKUP_FILENAME = "user-inventory_iar.tar.gz";
57 60
58 /// <value> 61 /// <value>
59 /// All scenes that this module knows about 62 /// All scenes that this module knows about
@@ -63,14 +66,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
63 /// <value> 66 /// <value>
64 /// The comms manager we will use for all comms requests 67 /// The comms manager we will use for all comms requests
65 /// </value> 68 /// </value>
66 private CommunicationsManager m_commsManager; 69 protected internal CommunicationsManager CommsManager;
67 70
68 public void Initialise(Scene scene, IConfigSource source) 71 public void Initialise(Scene scene, IConfigSource source)
69 { 72 {
70 if (m_scenes.Count == 0) 73 if (m_scenes.Count == 0)
71 { 74 {
72 scene.RegisterModuleInterface<IInventoryArchiverModule>(this); 75 scene.RegisterModuleInterface<IInventoryArchiverModule>(this);
73 m_commsManager = scene.CommsManager; 76 CommsManager = scene.CommsManager;
74 77
75 scene.AddCommand( 78 scene.AddCommand(
76 this, "load iar", 79 this, "load iar",
@@ -89,6 +92,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
89 public void PostInitialise() {} 92 public void PostInitialise() {}
90 93
91 public void Close() {} 94 public void Close() {}
95
96 /// <summary>
97 /// Trigger the inventory archive saved event.
98 /// </summary>
99 protected internal void TriggerInventoryArchiveSaved(
100 bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException)
101 {
102 InventoryArchiveSaved handlerInventoryArchiveSaved = OnInventoryArchiveSaved;
103 if (handlerInventoryArchiveSaved != null)
104 handlerInventoryArchiveSaved(succeeded, userInfo, invPath, saveStream, reportedException);
105 }
92 106
93 public void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream) 107 public void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream)
94 { 108 {
@@ -99,7 +113,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
99 if (userInfo != null) 113 if (userInfo != null)
100 { 114 {
101 InventoryArchiveReadRequest request = 115 InventoryArchiveReadRequest request =
102 new InventoryArchiveReadRequest(userInfo, invPath, loadStream, m_commsManager); 116 new InventoryArchiveReadRequest(userInfo, invPath, loadStream, CommsManager);
103 UpdateClientWithLoadedNodes(userInfo, request.Execute()); 117 UpdateClientWithLoadedNodes(userInfo, request.Execute());
104 } 118 }
105 } 119 }
@@ -112,7 +126,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
112 CachedUserInfo userInfo = GetUserInfo(firstName, lastName); 126 CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
113 127
114 if (userInfo != null) 128 if (userInfo != null)
115 new InventoryArchiveWriteRequest(userInfo, invPath, saveStream, m_commsManager).Execute(); 129 new InventoryArchiveWriteRequest(this, userInfo, invPath, saveStream).Execute();
116 } 130 }
117 } 131 }
118 132
@@ -125,7 +139,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
125 if (userInfo != null) 139 if (userInfo != null)
126 { 140 {
127 InventoryArchiveReadRequest request = 141 InventoryArchiveReadRequest request =
128 new InventoryArchiveReadRequest(userInfo, invPath, loadPath, m_commsManager); 142 new InventoryArchiveReadRequest(userInfo, invPath, loadPath, CommsManager);
129 UpdateClientWithLoadedNodes(userInfo, request.Execute()); 143 UpdateClientWithLoadedNodes(userInfo, request.Execute());
130 } 144 }
131 } 145 }
@@ -138,7 +152,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
138 CachedUserInfo userInfo = GetUserInfo(firstName, lastName); 152 CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
139 153
140 if (userInfo != null) 154 if (userInfo != null)
141 new InventoryArchiveWriteRequest(userInfo, invPath, savePath, m_commsManager).Execute(); 155 new InventoryArchiveWriteRequest(this, userInfo, invPath, savePath).Execute();
142 } 156 }
143 } 157 }
144 158
@@ -208,7 +222,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
208 /// <returns></returns> 222 /// <returns></returns>
209 protected CachedUserInfo GetUserInfo(string firstName, string lastName) 223 protected CachedUserInfo GetUserInfo(string firstName, string lastName)
210 { 224 {
211 UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(firstName, lastName); 225 UserProfileData userProfile = CommsManager.UserService.GetUserProfile(firstName, lastName);
212 226
213 if (null == userProfile) 227 if (null == userProfile)
214 { 228 {
@@ -216,7 +230,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
216 return null; 230 return null;
217 } 231 }
218 232
219 CachedUserInfo userInfo = m_commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID); 233 CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
220 if (null == userInfo) 234 if (null == userInfo)
221 { 235 {
222 m_log.ErrorFormat( 236 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 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.IO;
29using System.Text; 30using System.Text;
31using System.Threading;
30using NUnit.Framework; 32using NUnit.Framework;
31using OpenMetaverse; 33using OpenMetaverse;
32using OpenSim.Data; 34using OpenSim.Data;
@@ -42,10 +44,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
42 [TestFixture] 44 [TestFixture]
43 public class InventoryArchiverTests 45 public class InventoryArchiverTests
44 { 46 {
47 private EventWaitHandle m_waitHandle = new AutoResetEvent(false);
48
49 private void SaveCompleted(
50 bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException)
51 {
52 m_waitHandle.Set();
53 }
54
45 /// <summary> 55 /// <summary>
46 /// Test saving a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet). 56 /// Test saving a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet).
47 /// </summary> 57 /// </summary>
48 [Test] 58 [Test]
49 public void TestSaveIarV0p1() 59 public void TestSaveIarV0p1()
50 { 60 {
51 //log4net.Config.XmlConfigurator.Configure(); 61 //log4net.Config.XmlConfigurator.Configure();
@@ -94,16 +104,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
94 item1.Name = "My Little Dog"; 104 item1.Name = "My Little Dog";
95 item1.AssetID = asset1.FullID; 105 item1.AssetID = asset1.FullID;
96 item1.Folder = userInfo.RootFolder.FindFolderByPath("Objects").ID; 106 item1.Folder = userInfo.RootFolder.FindFolderByPath("Objects").ID;
97 scene.AddInventoryItem(userId, item1); 107 scene.AddInventoryItem(userId, item1);
98
99 /*
100 108
101 MemoryStream archiveWriteStream = new MemoryStream(); 109 MemoryStream archiveWriteStream = new MemoryStream();
102 110 archiverModule.OnInventoryArchiveSaved += SaveCompleted;
103 scene.EventManager.OnOarFileSaved += SaveCompleted; 111
104 archiverModule.ArchiveRegion(archiveWriteStream); 112 archiverModule.ArchiveInventory(userFirstName, userLastName, "Objects", archiveWriteStream);
105 m_waitHandle.WaitOne(60000, true); 113 m_waitHandle.WaitOne(60000, true);
106 114
115 /*
107 byte[] archive = archiveWriteStream.ToArray(); 116 byte[] archive = archiveWriteStream.ToArray();
108 MemoryStream archiveReadStream = new MemoryStream(archive); 117 MemoryStream archiveReadStream = new MemoryStream(archive);
109 TarArchiveReader tar = new TarArchiveReader(archiveReadStream); 118 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 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System;
28using System.IO; 29using System.IO;
30using OpenSim.Framework.Communications.Cache;
29 31
30namespace OpenSim.Region.Framework.Interfaces 32namespace OpenSim.Region.Framework.Interfaces
31{ 33{
32 public interface IInventoryArchiverModule 34 /// <summary>
35 /// Used for the OnInventoryArchiveSaved event.
36 /// </summary>
37 /// <param name="succeeded">true if the save succeeded, false otherwise</param>
38 /// <param name="userInfo">The user for whom the save was conducted</param>
39 /// <param name="invPath">The inventory path saved</param>
40 /// <param name="savePath">The stream to which the archive was saved</param>
41 /// <param name="reportedException">Contains the exception generated if the save did not succeed</param>
42 public delegate void InventoryArchiveSaved(
43 bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException);
44
45 public interface IInventoryArchiverModule
33 { 46 {
34 /// <summary> 47 /// <summary>
48 /// Fired when an archive inventory save has been completed.
49 /// </summary>
50 event InventoryArchiveSaved OnInventoryArchiveSaved;
51
52 /// <summary>
35 /// Dearchive a user's inventory folder from the given stream 53 /// Dearchive a user's inventory folder from the given stream
36 /// </summary> 54 /// </summary>
37 /// <param name="firstName"></param> 55 /// <param name="firstName"></param>