InventoryDownloadBehaviour.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. using OpenMetaverse;
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Diagnostics;
  31. using System.Threading;
  32. using System.Linq;
  33. using pCampBot.Interfaces;
  34. namespace pCampBot
  35. {
  36. /// <summary>
  37. /// Do nothing
  38. /// </summary>
  39. public class InventoryDownloadBehaviour : AbstractBehaviour
  40. {
  41. private bool m_initialized;
  42. private int m_Requests = 2;
  43. private Stopwatch m_StopWatch = new Stopwatch();
  44. private List<UUID> m_processed = new List<UUID>();
  45. public InventoryDownloadBehaviour()
  46. {
  47. AbbreviatedName = "inv";
  48. Name = "Inventory";
  49. }
  50. public override void Action()
  51. {
  52. if (!m_initialized)
  53. {
  54. m_initialized = true;
  55. Bot.Client.Settings.HTTP_INVENTORY = true;
  56. Bot.Client.Settings.FETCH_MISSING_INVENTORY = true;
  57. Bot.Client.Inventory.FolderUpdated += Inventory_FolderUpdated;
  58. Console.WriteLine("Lib owner is " + Bot.Client.Inventory.Store.LibraryRootNode.Data.OwnerID);
  59. m_StopWatch.Start();
  60. Bot.Client.Inventory.RequestFolderContents(Bot.Client.Inventory.Store.RootFolder.UUID, Bot.Client.Self.AgentID, true, true, InventorySortOrder.ByDate);
  61. Bot.Client.Inventory.RequestFolderContents(Bot.Client.Inventory.Store.LibraryRootNode.Data.UUID, Bot.Client.Inventory.Store.LibraryRootNode.Data.OwnerID, true, true, InventorySortOrder.ByDate);
  62. }
  63. Thread.Sleep(1000);
  64. Console.WriteLine("Total items: " + Bot.Client.Inventory.Store.Items.Count + "; Total requests: " + m_Requests + "; Time: " + m_StopWatch.Elapsed);
  65. }
  66. void Inventory_FolderUpdated(object sender, FolderUpdatedEventArgs e)
  67. {
  68. if (e.Success)
  69. {
  70. //Console.WriteLine("Folder " + e.FolderID + " updated");
  71. bool fetch = false;
  72. lock (m_processed)
  73. {
  74. if (!m_processed.Contains(e.FolderID))
  75. {
  76. m_processed.Add(e.FolderID);
  77. fetch = true;
  78. }
  79. }
  80. if (fetch)
  81. {
  82. List<InventoryFolder> m_foldersToFetch = new List<InventoryFolder>();
  83. foreach (InventoryBase item in Bot.Client.Inventory.Store.GetContents(e.FolderID))
  84. {
  85. if (item is InventoryFolder)
  86. {
  87. InventoryFolder f = new InventoryFolder(item.UUID);
  88. f.OwnerID = item.OwnerID;
  89. m_foldersToFetch.Add(f);
  90. }
  91. }
  92. if (m_foldersToFetch.Count > 0)
  93. {
  94. m_Requests += 1;
  95. Bot.Client.Inventory.RequestFolderContentsCap(m_foldersToFetch, Bot.Client.Network.CurrentSim.Caps.CapabilityURI("FetchInventoryDescendents2"), true, true, InventorySortOrder.ByDate);
  96. }
  97. }
  98. if (Bot.Client.Inventory.Store.Items.Count >= 15739)
  99. {
  100. m_StopWatch.Stop();
  101. Console.WriteLine("Stop! Total items: " + Bot.Client.Inventory.Store.Items.Count + "; Total requests: " + m_Requests + "; Time: " + m_StopWatch.Elapsed);
  102. }
  103. }
  104. }
  105. public override void Interrupt()
  106. {
  107. m_interruptEvent.Set();
  108. }
  109. }
  110. }