aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot/Behaviours/InventoryDownloadBehaviour.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tools/pCampBot/Behaviours/InventoryDownloadBehaviour.cs')
-rw-r--r--OpenSim/Tools/pCampBot/Behaviours/InventoryDownloadBehaviour.cs121
1 files changed, 121 insertions, 0 deletions
diff --git a/OpenSim/Tools/pCampBot/Behaviours/InventoryDownloadBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/InventoryDownloadBehaviour.cs
new file mode 100644
index 0000000..521415c
--- /dev/null
+++ b/OpenSim/Tools/pCampBot/Behaviours/InventoryDownloadBehaviour.cs
@@ -0,0 +1,121 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using OpenMetaverse;
29using System;
30using System.Collections.Generic;
31using System.Diagnostics;
32using System.Threading;
33using System.Linq;
34using pCampBot.Interfaces;
35
36namespace pCampBot
37{
38 /// <summary>
39 /// Do nothing
40 /// </summary>
41 public class InventoryDownloadBehaviour : AbstractBehaviour
42 {
43 private bool m_initialized;
44 private int m_Requests = 2;
45 private Stopwatch m_StopWatch = new Stopwatch();
46 private List<UUID> m_processed = new List<UUID>();
47
48 public InventoryDownloadBehaviour()
49 {
50 AbbreviatedName = "inv";
51 Name = "Inventory";
52 }
53
54 public override void Action()
55 {
56 if (!m_initialized)
57 {
58 m_initialized = true;
59 Bot.Client.Settings.HTTP_INVENTORY = true;
60 Bot.Client.Settings.FETCH_MISSING_INVENTORY = true;
61 Bot.Client.Inventory.FolderUpdated += Inventory_FolderUpdated;
62 Console.WriteLine("Lib owner is " + Bot.Client.Inventory.Store.LibraryRootNode.Data.OwnerID);
63 m_StopWatch.Start();
64 Bot.Client.Inventory.RequestFolderContents(Bot.Client.Inventory.Store.RootFolder.UUID, Bot.Client.Self.AgentID, true, true, InventorySortOrder.ByDate);
65 Bot.Client.Inventory.RequestFolderContents(Bot.Client.Inventory.Store.LibraryRootNode.Data.UUID, Bot.Client.Inventory.Store.LibraryRootNode.Data.OwnerID, true, true, InventorySortOrder.ByDate);
66 }
67
68 Thread.Sleep(1000);
69 Console.WriteLine("Total items: " + Bot.Client.Inventory.Store.Items.Count + "; Total requests: " + m_Requests + "; Time: " + m_StopWatch.Elapsed);
70
71 }
72
73 void Inventory_FolderUpdated(object sender, FolderUpdatedEventArgs e)
74 {
75 if (e.Success)
76 {
77 //Console.WriteLine("Folder " + e.FolderID + " updated");
78 bool fetch = false;
79 lock (m_processed)
80 {
81 if (!m_processed.Contains(e.FolderID))
82 {
83 m_processed.Add(e.FolderID);
84 fetch = true;
85 }
86 }
87
88 if (fetch)
89 {
90 List<InventoryFolder> m_foldersToFetch = new List<InventoryFolder>();
91 foreach (InventoryBase item in Bot.Client.Inventory.Store.GetContents(e.FolderID))
92 {
93 if (item is InventoryFolder)
94 {
95 InventoryFolder f = new InventoryFolder(item.UUID);
96 f.OwnerID = item.OwnerID;
97 m_foldersToFetch.Add(f);
98 }
99 }
100 if (m_foldersToFetch.Count > 0)
101 {
102 m_Requests += 1;
103 Bot.Client.Inventory.RequestFolderContentsCap(m_foldersToFetch, Bot.Client.Network.CurrentSim.Caps.CapabilityURI("FetchInventoryDescendents2"), true, true, InventorySortOrder.ByDate);
104 }
105 }
106
107 if (Bot.Client.Inventory.Store.Items.Count >= 15739)
108 {
109 m_StopWatch.Stop();
110 Console.WriteLine("Stop! Total items: " + Bot.Client.Inventory.Store.Items.Count + "; Total requests: " + m_Requests + "; Time: " + m_StopWatch.Elapsed);
111 }
112 }
113
114 }
115
116 public override void Interrupt()
117 {
118 m_interruptEvent.Set();
119 }
120 }
121} \ No newline at end of file