/// <summary>
        /// Gets everything (folders and items) inside a folder
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="folderID"></param>
        /// <returns></returns>
        public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
        {
            InventoryFolderImpl folder = null;
            InventoryCollection inv = new InventoryCollection();
            inv.UserID = m_Library.Owner;

            if (folderID != m_Library.ID)
            {
                folder = m_Library.FindFolder(folderID);
                if (folder == null)
                {
                    inv.Folders = new List<InventoryFolderBase>();
                    inv.Items = new List<InventoryItemBase>();
                    return inv;
                }
            }
            else
                folder = m_Library;

            inv.Folders = folder.RequestListOfFolders();
            inv.Items = folder.RequestListOfItems();

            m_log.DebugFormat("[LIBRARY MODULE]: Got content for folder {0}", folder.Name);
            return inv;
        }
Exemple #2
0
        public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
        {
            InventoryCollection inv = null;
            InventoryCollection c;
            if (m_Inventories.TryGetValue(userID, out inv))
            {
                c = new InventoryCollection();
                c.UserID = userID;

                c.Folders = inv.Folders.FindAll(delegate(InventoryFolderBase f)
                {
                    return f.ParentID == folderID;
                });
                c.Items = inv.Items.FindAll(delegate(InventoryItemBase i)
                {
                    return i.Folder == folderID;
                });
                return c;
            }
            return null;
        }
        public virtual InventoryCollection GetUserInventory(UUID userID)
        {
            InventoryCollection userInventory = new InventoryCollection();
            userInventory.UserID = userID;
            userInventory.Folders = new List<InventoryFolderBase>();
            userInventory.Items = new List<InventoryItemBase>();

            List<InventoryFolderBase> skel = GetInventorySkeleton(userID);
            if (skel != null)
            {
                foreach (InventoryFolderBase f in skel)
                {
                    InventoryCollection c = GetFolderContent(userID, f.ID);
                    if (c != null && c.Items != null && c.Items.Count > 0)
                        userInventory.Items.AddRange(c.Items);
                    if (c != null && c.Folders != null && c.Folders.Count > 0)
                        userInventory.Folders.AddRange(c.Folders);
                }
            }
            m_log.DebugFormat("[XINVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
                userID, userInventory.Folders.Count, userInventory.Items.Count);
            return userInventory;
        }
 private static InventoryNodeBase CheckIDInInventoryCollection(InventoryCollection ic, UUID uuid)
 {
     foreach (InventoryFolderBase ifb in ic.Folders) 
     {
         if (ifb.ID == uuid)
             return ifb;
     }
     foreach (InventoryItemBase iib in ic.Items)
     {
         if (iib.ID == uuid)
             return iib;
     }
     return null;
 }
        /// <summary>
        /// Handle the caps inventory descendents fetch.
        ///
        /// Since the folder structure is sent to the client on login, I believe we only need to handle items.
        /// Diva comment 8/13/2009: what if someone gave us a folder in the meantime??
        /// </summary>
        /// <param name="agentID"></param>
        /// <param name="folderID"></param>
        /// <param name="ownerID"></param>
        /// <param name="fetchFolders"></param>
        /// <param name="fetchItems"></param>
        /// <param name="sortOrder"></param>
        /// <returns>null if the inventory look up failed</returns>
        public InventoryCollection HandleFetchInventoryDescendentsCAPS(UUID agentID, UUID folderID, UUID ownerID,
                                                   bool fetchFolders, bool fetchItems, int sortOrder, out int version)
        {
            m_log.DebugFormat(
                "[INVENTORY CACHE]: Fetching folders ({0}), items ({1}) from {2} for agent {3}",
                fetchFolders, fetchItems, folderID, agentID);

            // FIXME MAYBE: We're not handling sortOrder!

            // TODO: This code for looking in the folder for the library should be folded back into the
            // CachedUserInfo so that this class doesn't have to know the details (and so that multiple libraries, etc.
            // can be handled transparently).
            InventoryFolderImpl fold;
            if (LibraryService != null && LibraryService.LibraryRootFolder != null)
                if ((fold = LibraryService.LibraryRootFolder.FindFolder(folderID)) != null)
                {
                    version = 0;
                    InventoryCollection ret = new InventoryCollection();
                    ret.Folders = new List<InventoryFolderBase>();
                    ret.Items = fold.RequestListOfItems();

                    return ret;
                }

            InventoryCollection contents = new InventoryCollection();

            if (folderID != UUID.Zero)
            {
                contents = InventoryService.GetFolderContent(agentID, folderID); 
                InventoryFolderBase containingFolder = new InventoryFolderBase();
                containingFolder.ID = folderID;
                containingFolder.Owner = agentID;
                containingFolder = InventoryService.GetFolder(containingFolder);
                version = containingFolder.Version;
            }
            else
            {
                // Lost itemsm don't really need a version
                version = 1;
            }

            return contents;

        }
Exemple #6
0
        // Shamelessly copied from LLClientView
        private void DescendantsCallBack(InventoryCollection inv)
        {
            // Send InventoryDescendentsPacket(s)

            Console.WriteLine("[InventoryClient]: Received InventoryCollection");
            InventoryFolderBase fb = null;
            bool fetchFolders = false, fetchItems = false;
            lock (pendingRequests)
            {
                fb = pendingRequests[0];
                pendingRequests.RemoveAt(0);
                fetchFolders = pendingRequestsFetchFoldersFlag[0];
                pendingRequestsFetchFoldersFlag.RemoveAt(0);
                fetchItems = pendingRequestsFetchItemsFlag[0];
                pendingRequestsFetchItemsFlag.RemoveAt(0);
            }
            if (fb == null)
            {
                Console.WriteLine("[InventoryClient]: Request not found ??? ");
                return;
            }

            List<InventoryItemBase> items = inv.Items;
            List<InventoryFolderBase> folders = inv.Folders;

            //// Add them to our local cache -- DON'T, they're already there
            //foreach (InventoryItemBase item in items)
            //{
            //    AddToCache(item);
            //}

            // An inventory descendents packet consists of a single agent section and an inventory details
            // section for each inventory item.  The size of each inventory item is approximately 550 bytes.
            // In theory, UDP has a maximum packet size of 64k, so it should be possible to send descendent
            // packets containing metadata for in excess of 100 items.  But in practice, there may be other
            // factors (e.g. firewalls) restraining the maximum UDP packet size.  See,
            //
            // http://opensimulator.org/mantis/view.php?id=226
            //
            // for one example of this kind of thing.  In fact, the Linden servers appear to only send about
            // 6 to 7 items at a time, so let's stick with 6
            int MAX_ITEMS_PER_PACKET = 6;

            //Ckrinke This variable is not used, so comment out to remove the warning from the compiler (3-21-08)
            //Ckrinke            uint FULL_MASK_PERMISSIONS = 2147483647;

            int itemsSent = 0;
            InventoryDescendentsPacket descend = new InventoryDescendentsPacket();
            if (fetchItems)
            {
                descend.Header.Zerocoded = true;
                descend.AgentData.AgentID = inv.UserID;
                descend.AgentData.OwnerID = inv.UserID;
                descend.AgentData.FolderID = fb.ID;
                descend.AgentData.Version = 1;

                if (items.Count < MAX_ITEMS_PER_PACKET)
                {
                    descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count];
                }
                else
                {
                    descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET];
                }

                // Descendents must contain the *total* number of descendents (plus folders, whether we
                // fetch them or not), not the number of entries we send in this packet. For consistency,
                // I'll use it for folder-requests, too, although I wasn't able to get one with
                // FetchFolders = true.
                // TODO this should be checked with FetchFolders = true
                descend.AgentData.Descendents = items.Count + folders.Count;

                int count = 0;
                int i = 0;
                foreach (InventoryItemBase item in items)
                {
                    descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock();
                    descend.ItemData[i].ItemID = item.ID;
                    descend.ItemData[i].AssetID = item.AssetID;
                    descend.ItemData[i].CreatorID = item.CreatorIdAsUuid;
                    descend.ItemData[i].BaseMask = item.BasePermissions;
                    descend.ItemData[i].Description = StringToPacketBytes(item.Description);
                    descend.ItemData[i].EveryoneMask = item.EveryOnePermissions;
                    descend.ItemData[i].OwnerMask = item.CurrentPermissions;
                    descend.ItemData[i].FolderID = item.Folder;
                    descend.ItemData[i].InvType = (sbyte)item.InvType;
                    descend.ItemData[i].Name = StringToPacketBytes(item.Name);
                    descend.ItemData[i].NextOwnerMask = item.NextPermissions;
                    descend.ItemData[i].OwnerID = item.Owner;
                    descend.ItemData[i].Type = (sbyte)item.AssetType;

                    descend.ItemData[i].GroupID = item.GroupID;
                    descend.ItemData[i].GroupOwned = item.GroupOwned;
                    descend.ItemData[i].GroupMask = item.GroupPermissions;
                    descend.ItemData[i].CreationDate = item.CreationDate;
                    descend.ItemData[i].SalePrice = item.SalePrice;
                    descend.ItemData[i].SaleType = item.SaleType;
                    descend.ItemData[i].Flags = item.Flags;

                    descend.ItemData[i].CRC =
                        Helpers.InventoryCRC(descend.ItemData[i].CreationDate, descend.ItemData[i].SaleType,
                                             descend.ItemData[i].InvType, descend.ItemData[i].Type,
                                             descend.ItemData[i].AssetID, descend.ItemData[i].GroupID,
                                             descend.ItemData[i].SalePrice,
                                             descend.ItemData[i].OwnerID, descend.ItemData[i].CreatorID,
                                             descend.ItemData[i].ItemID, descend.ItemData[i].FolderID,
                                             descend.ItemData[i].EveryoneMask,
                                             descend.ItemData[i].Flags, descend.ItemData[i].OwnerMask,
                                             descend.ItemData[i].GroupMask, item.CurrentPermissions);

                    i++;
                    count++;
                    itemsSent++;
                    if (i == MAX_ITEMS_PER_PACKET)
                    {
                        descend.Header.Zerocoded = true;
                        AddNullFolderBlockToDecendentsPacket(ref descend);
                        proxy.InjectPacket(descend, Direction.Incoming);
                        //OutPacket(descend, ThrottleOutPacketType.Asset);

                        if ((items.Count - count) > 0)
                        {
                            descend = new InventoryDescendentsPacket();
                            descend.Header.Zerocoded = true;
                            descend.AgentData.AgentID = inv.UserID;
                            descend.AgentData.OwnerID = inv.UserID;
                            descend.AgentData.FolderID = fb.ID;
                            descend.AgentData.Version = 1;

                            if ((items.Count - count) < MAX_ITEMS_PER_PACKET)
                            {
                                descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count - count];
                            }
                            else
                            {
                                descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET];
                            }
                            descend.AgentData.Descendents = items.Count + folders.Count;
                            i = 0;
                        }
                    }
                }

                if (0 < i && i < MAX_ITEMS_PER_PACKET)
                {
                    AddNullFolderBlockToDecendentsPacket(ref descend);
                    proxy.InjectPacket(descend, Direction.Incoming);
                    ///OutPacket(descend, ThrottleOutPacketType.Asset);
                }
            }

            //send subfolders
            if (fetchFolders)
            {
                descend = new InventoryDescendentsPacket();
                descend.Header.Zerocoded = true;
                descend.AgentData.AgentID = inv.UserID;
                descend.AgentData.OwnerID = inv.UserID;
                descend.AgentData.FolderID = fb.ID;
                descend.AgentData.Version = 1;

                if (folders.Count < MAX_ITEMS_PER_PACKET)
                {
                    descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders.Count];
                }
                else
                {
                    descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET];
                }

                // Not sure if this scenario ever actually occurs, but nonetheless we include the items
                // count even if we're not sending item data for the same reasons as above.
                descend.AgentData.Descendents = items.Count + folders.Count;

                int i = 0;
                int count = 0;
                foreach (InventoryFolderBase folder in folders)
                {
                    descend.FolderData[i] = new InventoryDescendentsPacket.FolderDataBlock();
                    descend.FolderData[i].FolderID = folder.ID;
                    descend.FolderData[i].Name = StringToPacketBytes(folder.Name);
                    descend.FolderData[i].ParentID = folder.ParentID;
                    descend.FolderData[i].Type = (sbyte)folder.Type;

                    i++;
                    count++;
                    itemsSent++;
                    if (i == MAX_ITEMS_PER_PACKET)
                    {
                        AddNullItemBlockToDescendentsPacket(ref descend);
                        proxy.InjectPacket(descend, Direction.Incoming);
                        //OutPacket(descend, ThrottleOutPacketType.Asset);

                        if ((folders.Count - count) > 0)
                        {
                            descend = new InventoryDescendentsPacket();
                            if ((folders.Count - count) < MAX_ITEMS_PER_PACKET)
                            {
                                descend.FolderData =
                                    new InventoryDescendentsPacket.FolderDataBlock[folders.Count - count];
                            }
                            else
                            {
                                descend.FolderData =
                                    new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET];
                            }
                            descend.AgentData.Descendents = items.Count + folders.Count;
                            i = 0;
                        }
                    }
                }

                if (0 < i && i < MAX_ITEMS_PER_PACKET)
                {
                    AddNullItemBlockToDescendentsPacket(ref descend);
                    proxy.InjectPacket(descend, Direction.Incoming);
                    //OutPacket(descend, ThrottleOutPacketType.Asset);
                }
            }

            if (itemsSent == 0)
            {
                // no items found.
                descend = new InventoryDescendentsPacket();
                descend.Header.Zerocoded = true;
                descend.AgentData.AgentID = inv.UserID;
                descend.AgentData.OwnerID = inv.UserID;
                descend.AgentData.FolderID = fb.ID;
                descend.AgentData.Version = 1;
                descend.AgentData.Descendents = 0;
                AddNullItemBlockToDescendentsPacket(ref descend);
                AddNullFolderBlockToDecendentsPacket(ref descend);
                proxy.InjectPacket(descend, Direction.Incoming);
                //OutPacket(descend, ThrottleOutPacketType.Asset);
            }
        }
        /// <summary>
        /// Gets the items inside a folder
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="folderID"></param>
        /// <returns></returns>
        public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID)
        {
            InventoryCollection inventory = new InventoryCollection();
            inventory.UserID = userID;

            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "GetInventoryNode" },
                { "ItemID", folderID.ToString() },
                { "OwnerID", userID.ToString() },
                { "IncludeFolders", "0" },
                { "IncludeItems", "1" },
                { "ChildrenOnly", "1" }
            };

            OSDMap response = WebUtils.PostToService(m_serverUrl, requestArgs);
            if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
            {
                OSDArray items = (OSDArray)response["Items"];
                return GetItemsFromResponse(items);
            }
            else
            {
                m_log.Warn("[SIMIAN INVENTORY CONNECTOR]: Error fetching folder " + folderID + " for " + userID + ": " +
                    response["Message"].AsString());
                return new List<InventoryItemBase>(0);
            }
        }
        public BackendResponse TryCreateInventory(Uri owner, InventoryFolderWithChildren rootFolder)
        {
            BackendResponse ret;

            lock (inventories)
            {
                if (!inventories.ContainsKey(owner))
                {
                    InventoryCollection collection = new InventoryCollection();
                    collection.UserID = rootFolder.Owner;
                    collection.Folders = new Dictionary<UUID, InventoryFolderWithChildren>();
                    collection.Folders.Add(rootFolder.ID, rootFolder);
                    collection.Items = new Dictionary<UUID, InventoryItemBase>();

                    inventories.Add(owner, collection);

                    ret = BackendResponse.Success;
                }
                else
                {
                    ret = BackendResponse.Failure;
                }
            }

            if (ret == BackendResponse.Success)
            {
                string path = Path.Combine(DEFAULT_INVENTORY_DIR, rootFolder.Owner.ToString());
                try
                {
                    // Create the directory for this agent
                    Directory.CreateDirectory(path);

                    // Create an index.txt containing the UUID and URI for this agent
                    string[] index = new string[] { rootFolder.Owner.ToString(), owner.ToString() };
                    File.WriteAllLines(Path.Combine(path, "index.txt"), index);

                    // Create the root folder file
                    SaveFolder(rootFolder);
                }
                catch (Exception ex)
                {
                    m_log.Error("[SIMPLEINVENTORYSTORAGE]: " + ex.Message);
                    ret = BackendResponse.Failure;
                }
            }

            server.MetricsProvider.LogInventoryCreateInventory(EXTENSION_NAME, ret, DateTime.Now);
            return ret;
        }
        public BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents)
        {
            contents = null;
            BackendResponse ret;

            InventoryCollection collection;
            InventoryFolderWithChildren folder;

            if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder))
            {
                contents = new InventoryCollection();
                contents.UserID = collection.UserID;
                contents.Folders = new Dictionary<UUID, InventoryFolderWithChildren>();
                contents.Items = new Dictionary<UUID, InventoryItemBase>();

                foreach (InventoryNodeBase invBase in folder.Children.Values)
                {
                    if (invBase is InventoryItemBase)
                    {
                        InventoryItemBase invItem = invBase as InventoryItemBase;
                        contents.Items.Add(invItem.ID, invItem);
                    }
                    else
                    {
                        InventoryFolderWithChildren invFolder = invBase as InventoryFolderWithChildren;
                        contents.Folders.Add(invFolder.ID, invFolder);
                    }
                }

                ret = BackendResponse.Success;
            }
            else
            {
                ret = BackendResponse.NotFound;
            }

            server.MetricsProvider.LogInventoryFetchFolderContents(EXTENSION_NAME, ret, owner, folderID, DateTime.Now);
            return ret;
        }
        public virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
        {
            InventoryCollection[] invColl = new InventoryCollection[folderIDs.Length];
            int i = 0;
            foreach (UUID fid in folderIDs)
            {
                invColl[i++] = GetFolderContent(principalID, fid);
            }

            return invColl;

        }
        public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
        {
            Dictionary<string,object> ret = MakeRequest("GETFOLDERCONTENT",
                    new Dictionary<string,object> {
                        { "PRINCIPAL", principalID.ToString() },
                        { "FOLDER", folderID.ToString() }
                    });

            if (ret == null)
                return null;

            if (ret.Count == 0)
                return null;

            
            InventoryCollection inventory = new InventoryCollection();
            inventory.Folders = new List<InventoryFolderBase>();
            inventory.Items = new List<InventoryItemBase>();
            inventory.UserID = principalID;
            
            Dictionary<string,object> folders =
                    (Dictionary<string,object>)ret["FOLDERS"];
            Dictionary<string,object> items =
                    (Dictionary<string,object>)ret["ITEMS"];

            foreach (Object o in folders.Values)
                inventory.Folders.Add(BuildFolder((Dictionary<string,object>)o));
            foreach (Object o in items.Values)
                inventory.Items.Add(BuildItem((Dictionary<string,object>)o));

            return inventory;
        }
        public InventoryCollection GetUserInventory(UUID userID)
        {
            m_log.Error("[SIMIAN INVENTORY CONNECTOR]: Obsolete GetUserInventory called for " + userID);

            InventoryCollection inventory = new InventoryCollection();
            inventory.UserID = userID;
            inventory.Folders = new List<InventoryFolderBase>();
            inventory.Items = new List<InventoryItemBase>();

            return inventory;
        }
        public virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs)
        {
            InventoryItemBase[] itemArr = new InventoryItemBase[itemIDs.Length];
            try
            {
                Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEITEMS",
                        new Dictionary<string, object> {
                            { "PRINCIPAL", principalID.ToString() },
                            { "ITEMS", String.Join(",", itemIDs) },
                            { "COUNT", itemIDs.Length.ToString() }
                        });

                if (!CheckReturn(resultSet))
                    return null;

                int i = 0;
                foreach (KeyValuePair<string, object> kvp in resultSet)
                {
                    InventoryCollection inventory = new InventoryCollection();
                    if (kvp.Key.StartsWith("item_"))
                    {
                        if (kvp.Value is Dictionary<string, object>)
                            itemArr[i++] = BuildItem((Dictionary<string, object>)kvp.Value);
                        else
                            itemArr[i++] = null;
                    }
                }
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleItems: {0}", e.Message);
            }

            return itemArr;
        }
Exemple #14
0
            void WriteObject_InventoryCollection(InventoryCollection ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
            {
                if (((object)ob) == null)
                {
                    if (isNullable)
                        WriteNullTagLiteral(element, namesp);
                    return;
                }

                System.Type type = ob.GetType();
                if (type == typeof(InventoryCollection))
                { }
                else
                {
                    throw CreateUnknownTypeException(ob);
                }

                if (writeWrappingElem)
                {
                    WriteStartElement(element, namesp, ob);
                }

                if (needType) WriteXsiType("InventoryCollection", "");

                if (ob.@Folders != null)
                {
                    WriteStartElement("Folders", "", ob.@Folders);
                    foreach (InventoryFolderWithChildren folder in ob.Folders.Values)
                    {
                        WriteObject_InventoryFolder(folder, "InventoryFolderBase", "", true, false, true);
                    }
                    WriteEndElement(ob.@Folders);
                }
                if (ob.@Items != null)
                {
                    WriteStartElement("Items", "", ob.@Items);
                    foreach (InventoryItemBase item in ob.Items.Values)
                    {
                        WriteObject_InventoryItem(item, "InventoryItemBase", "", true, false, true);
                    }
                    WriteEndElement(ob.@Items);
                }
                WriteObject_UUID(ob.@UserID, "UserID", "", false, false, true);
                if (writeWrappingElem) WriteEndElement(ob);
            }
Exemple #15
0
        public InventoryCollection FetchDescendants(InventoryFolderBase fb)
        {
            m_log.Info("[HGStandaloneInvService]: Processing request for folder " + fb.ID);

            // Uncomment me to simulate a slow responding inventory server
            //Thread.Sleep(16000);

            InventoryCollection invCollection = new InventoryCollection();

            List<InventoryItemBase> items = m_inventoryService.RequestFolderItems(fb.ID);
            List<InventoryFolderBase> folders = m_inventoryService.RequestSubFolders(fb.ID);

            invCollection.UserID = fb.Owner;
            invCollection.Folders = folders;
            invCollection.Items = items;

            m_log.DebugFormat("[HGStandaloneInvService]: Found {0} items and {1} folders", items.Count, folders.Count);

            return invCollection;
        }
        /// <summary>
        /// Gets everything (folders and items) inside a folder
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="folderID"></param>
        /// <returns></returns>
        public InventoryCollection GetFolderContent(string userID, UUID folderID, UUID sessionID)
        {
            try
            {
                // normal case
                return SynchronousRestSessionObjectPoster<Guid, InventoryCollection>.BeginPostObject(
                    "POST", m_ServerURI + "/GetFolderContent/", folderID.Guid, sessionID.ToString(), userID.ToString());
            }
            catch (TimeoutException e)
            {
                m_log.ErrorFormat(
                    "[INVENTORY CONNECTOR]: GetFolderContent operation to {0} for {1} timed out {2} {3}.",
                    m_ServerURI, folderID, e.Source, e.Message);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetFolderContent operation failed for {0}, {1} {2} (old server?).",
                    folderID, e.Source, e.Message);
            }

            InventoryCollection nullCollection = new InventoryCollection();
            nullCollection.Folders = new List<InventoryFolderBase>();
            nullCollection.Items = new List<InventoryItemBase>();
            nullCollection.UserID = new UUID(userID);
            return nullCollection;
        }
        /// <summary>
        /// Return a user's entire inventory
        /// </summary>
        /// <param name="rawUserID"></param>
        /// <returns>The user's inventory.  If an inventory cannot be found then an empty collection is returned.</returns>
        public InventoryCollection GetUserInventory(Guid rawUserID)
        {
            UUID userID = new UUID(rawUserID);

            m_log.InfoFormat("[GRID AGENT INVENTORY]: Processing request for inventory of {0}", userID);

            // Uncomment me to simulate a slow responding inventory server
            //Thread.Sleep(16000);

            InventoryCollection invCollection = new InventoryCollection();

            List<InventoryFolderBase> allFolders = GetInventorySkeleton(userID);

            if (null == allFolders)
            {
                m_log.WarnFormat("[GRID AGENT INVENTORY]: No inventory found for user {0}", rawUserID);

                return invCollection;
            }

            List<InventoryItemBase> allItems = new List<InventoryItemBase>();

            foreach (InventoryFolderBase folder in allFolders)
            {
                List<InventoryItemBase> items = RequestFolderItems(folder.ID);

                if (items != null)
                {
                    allItems.InsertRange(0, items);
                }
            }

            invCollection.UserID = userID;
            invCollection.Folders = allFolders;
            invCollection.Items = allItems;

            //            foreach (InventoryFolderBase folder in invCollection.Folders)
            //            {
            //                m_log.DebugFormat("[GRID AGENT INVENTORY]: Sending back folder {0} {1}", folder.Name, folder.ID);
            //            }
            //
            //            foreach (InventoryItemBase item in invCollection.Items)
            //            {
            //                m_log.DebugFormat("[GRID AGENT INVENTORY]: Sending back item {0} {1}, folder {2}", item.Name, item.ID, item.Folder);
            //            }

            m_log.InfoFormat(
                "[GRID AGENT INVENTORY]: Sending back inventory response to user {0} containing {1} folders and {2} items",
                invCollection.UserID, invCollection.Folders.Count, invCollection.Items.Count);

            return invCollection;
        }
        public override InventoryCollection GetUserInventory(UUID userID)
        {
            m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
            InventoryCollection userInventory = new InventoryCollection();
            userInventory.UserID = userID;
            userInventory.Folders = new List<InventoryFolderBase>();
            userInventory.Items = new List<InventoryItemBase>();

            XInventoryFolder suitcase = GetSuitcaseXFolder(userID);

            List<XInventoryFolder> tree = GetFolderTree(userID, suitcase.folderID);
            if (tree == null || (tree != null && tree.Count == 0))
            {
                SetAsNormalFolder(suitcase);
                userInventory.Folders.Add(ConvertToOpenSim(suitcase));
                return userInventory;
            }

            List<InventoryItemBase> items;
            foreach (XInventoryFolder f in tree)
            {
                // Add the items of this subfolder
                items = GetFolderItems(userID, f.folderID);
                if (items != null && items.Count > 0)
                {
                    userInventory.Items.AddRange(items);
                }

                // Add the folder itself
                userInventory.Folders.Add(ConvertToOpenSim(f));
            }

            items = GetFolderItems(userID, suitcase.folderID);
            if (items != null && items.Count > 0)
            {
                userInventory.Items.AddRange(items);
            }

            SetAsNormalFolder(suitcase);
            userInventory.Folders.Add(ConvertToOpenSim(suitcase));

            m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
                userID, userInventory.Folders.Count, userInventory.Items.Count);
            return userInventory;
        }
        public BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory)
        {
            inventory = null;
            BackendResponse ret;

            if (inventories.TryGetValue(owner, out inventory))
                ret = BackendResponse.Success;
            else
                ret = BackendResponse.NotFound;

            server.MetricsProvider.LogInventoryFetchInventory(EXTENSION_NAME, ret, owner, DateTime.Now);
            return ret;
        }
Exemple #20
0
 public void Cache(UUID userID, InventoryCollection inv)
 {
     m_Inventories.AddOrUpdate(userID, inv, 120);
 }
        void LoadFiles(string folder)
        {
            // Try to create the directory if it doesn't already exist
            if (!Directory.Exists(folder))
            {
                try { Directory.CreateDirectory(folder); }
                catch (Exception ex)
                {
                    m_log.Warn("[SIMPLEINVENTORYSTORAGE]: " + ex.Message);
                    return;
                }
            }

            try
            {
                string[] agentFolders = Directory.GetDirectories(DEFAULT_INVENTORY_DIR);

                for (int i = 0; i < agentFolders.Length; i++)
                {
                    string foldername = agentFolders[i];
                    string indexPath = Path.Combine(foldername, "index.txt");
                    UUID ownerID = UUID.Zero;
                    Uri owner = null;

                    try
                    {
                        string[] index = File.ReadAllLines(indexPath);
                        ownerID = UUID.Parse(index[0]);
                        owner = new Uri(index[1]);
                    }
                    catch (Exception ex)
                    {
                        m_log.WarnFormat("[SIMPLEINVENTORYSTORAGE]: Failed loading the index file {0}: {1}", indexPath, ex.Message);
                    }

                    if (ownerID != UUID.Zero && owner != null)
                    {
                        // Initialize the active gestures list for this agent
                        activeGestures.Add(owner, new List<InventoryItemBase>());

                        InventoryCollection collection = new InventoryCollection();
                        collection.UserID = ownerID;

                        // Load all of the folders for this agent
                        string[] folders = Directory.GetFiles(foldername, "*.folder", SearchOption.TopDirectoryOnly);
                        collection.Folders = new Dictionary<UUID,InventoryFolderWithChildren>(folders.Length);

                        for (int j = 0; j < folders.Length; j++)
                        {
                            InventoryFolderWithChildren invFolder = (InventoryFolderWithChildren)folderSerializer.Deserialize(
                                new FileStream(folders[j], FileMode.Open, FileAccess.Read));
                            collection.Folders[invFolder.ID] = invFolder;
                        }

                        // Iterate over the folders collection, adding children to their parents
                        foreach (InventoryFolderWithChildren invFolder in collection.Folders.Values)
                        {
                            InventoryFolderWithChildren parent;
                            if (collection.Folders.TryGetValue(invFolder.ParentID, out parent))
                                parent.Children[invFolder.ID] = invFolder;
                        }

                        // Load all of the items for this agent
                        string[] files = Directory.GetFiles(foldername, "*.item", SearchOption.TopDirectoryOnly);
                        collection.Items = new Dictionary<UUID, InventoryItemBase>(files.Length);

                        for (int j = 0; j < files.Length; j++)
                        {
                            InventoryItemBase invItem = (InventoryItemBase)itemSerializer.Deserialize(
                                new FileStream(files[j], FileMode.Open, FileAccess.Read));
                            collection.Items[invItem.ID] = invItem;

                            // Add items to their parent folders
                            InventoryFolderWithChildren parent;
                            if (collection.Folders.TryGetValue(invItem.Folder, out parent))
                                parent.Children[invItem.ID] = invItem;

                            // Add active gestures to our list
                            if (invItem.InvType == (int)InventoryType.Gesture && invItem.Flags != 0)
                                activeGestures[owner].Add(invItem);
                        }

                        inventories.Add(owner, collection);
                    }
                }
            }
            catch (Exception ex)
            {
                m_log.ErrorFormat("[SIMPLEINVENTORYSTORAGE]: Failed loading inventory from {0}: {1}", folder, ex.Message);
            }
        }
        public virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
        {
            InventoryCollection[] inventoryArr = new InventoryCollection[folderIDs.Length];
            // m_log.DebugFormat("[XXX]: In GetMultipleFoldersContent {0}", String.Join(",", folderIDs));
            try
            {
                Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEFOLDERSCONTENT",
                        new Dictionary<string, object> {
                            { "PRINCIPAL", principalID.ToString() },
                            { "FOLDERS", String.Join(",", folderIDs) },
                            { "COUNT", folderIDs.Length.ToString() }
                        });

                if (!CheckReturn(resultSet))
                    return null;

                int i = 0;
                foreach (KeyValuePair<string, object> kvp in resultSet)
                {
                    InventoryCollection inventory = new InventoryCollection();
                    if (kvp.Key.StartsWith("F_"))
                    {
                        UUID fid = UUID.Zero;
                        if (UUID.TryParse(kvp.Key.Substring(2), out fid) && fid == folderIDs[i])
                        {
                            inventory.Folders = new List<InventoryFolderBase>();
                            inventory.Items = new List<InventoryItemBase>();

                            Dictionary<string, object> ret = (Dictionary<string, object>)kvp.Value;

                            if (ret.ContainsKey("FID"))
                            {
                                if (!UUID.TryParse(ret["FID"].ToString(), out inventory.FolderID))
                                    m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Could not parse folder id {0}", ret["FID"].ToString());
                            }
                            else
                                m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: FID key not present in response");

                            inventory.Version = -1;
                            if (ret.ContainsKey("VERSION"))
                                Int32.TryParse(ret["VERSION"].ToString(), out inventory.Version);
                            if (ret.ContainsKey("OWNER"))
                                UUID.TryParse(ret["OWNER"].ToString(), out inventory.OwnerID);

                            //m_log.DebugFormat("[XXX]: Received {0} ({1}) {2} {3}", inventory.FolderID, fid, inventory.Version, inventory.OwnerID);

                            Dictionary<string, object> folders =
                                    (Dictionary<string, object>)ret["FOLDERS"];
                            Dictionary<string, object> items =
                                    (Dictionary<string, object>)ret["ITEMS"];

                            foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
                            {
                                inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
                            }
                            foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
                            {
                                inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
                            }

                            inventoryArr[i] = inventory;
                        }
                        else
                        {
                            m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Folder id does not match. Expected {0} got {1}",
                                folderIDs[i], fid);
                            m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: {0} {1}", String.Join(",", folderIDs), String.Join(",", resultSet.Keys));
                        }

                        i += 1;
                    }
                }
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleFoldersContent: {0}", e.Message);
            }

            return inventoryArr;
        }
        public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
        {
            InventoryCollection coll = null;

            if (!IsWithinSuitcaseTree(principalID, folderID))
                return new InventoryCollection();

            coll = base.GetFolderContent(principalID, folderID);

            if (coll == null)
            {
                m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID);
                coll = new InventoryCollection();
            }
            return coll;
        }
Exemple #24
0
        private void GetInventoryCallBack(InventoryCollection inv)
        {
            List<InventoryItemBase> items = inv.Items;
            List<InventoryFolderBase> folders = inv.Folders;

            // Add them to our local cache
            foreach (InventoryItemBase item in items)
            {
                AddToCache(item);
            }

            UUID rootID = UUID.Zero;
            ArrayList AgentInventoryArray = new ArrayList();
            Hashtable TempHash;
            foreach (InventoryFolderBase InvFolder in folders)
            {
                if (InvFolder.ParentID == UUID.Zero)
                {
                    rootID = InvFolder.ID;
                }
                TempHash = new Hashtable();
                TempHash["name"] = InvFolder.Name;
                TempHash["parent_id"] = InvFolder.ParentID.ToString();
                TempHash["version"] = (Int32)InvFolder.Version;
                TempHash["type_default"] = (Int32)InvFolder.Type;
                TempHash["folder_id"] = InvFolder.ID.ToString();
                AgentInventoryArray.Add(TempHash);
            }

            InventoryRoot = new LoginService.InventoryData(AgentInventoryArray, rootID);
        }
        public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
        {
            InventoryCollection inventory = new InventoryCollection();
            inventory.Folders = new List<InventoryFolderBase>();
            inventory.Items = new List<InventoryItemBase>();
            inventory.OwnerID = principalID;

            try
            {
                Dictionary<string,object> ret = MakeRequest("GETFOLDERCONTENT",
                        new Dictionary<string,object> {
                            { "PRINCIPAL", principalID.ToString() },
                            { "FOLDER", folderID.ToString() }
                        });

                if (!CheckReturn(ret))
                    return null;

                Dictionary<string,object> folders = ret.ContainsKey("FOLDERS") ?
                    (Dictionary<string,object>)ret["FOLDERS"] : null;
                Dictionary<string,object> items = ret.ContainsKey("ITEMS") ?
                    (Dictionary<string, object>)ret["ITEMS"] : null;

                if (folders != null)
                    foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
                        inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
                if (items != null)
                    foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
                        inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetFolderContent: {0}", e.Message);
            }

            return inventory;
        }
        public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
        {
            // Uncomment me to simulate a slow responding inventory server
            //Thread.Sleep(16000);

            InventoryCollection invCollection = new InventoryCollection();

            List<InventoryItemBase> items = GetFolderItems(userID, folderID);
            List<InventoryFolderBase> folders = RequestSubFolders(folderID);

            invCollection.UserID = userID;
            invCollection.Folders = folders;
            invCollection.Items = items;

            m_log.DebugFormat("[INVENTORY SERVICE]: Found {0} items and {1} folders in folder {2}", items.Count, folders.Count, folderID);

            return invCollection;
        }
        public virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs)
        {
            //m_log.DebugFormat("[XXX]: In GetMultipleItems {0}", String.Join(",", itemIDs));

            InventoryItemBase[] itemArr = new InventoryItemBase[itemIDs.Length];
            // Try to get them from the cache
            List<UUID> pending = new List<UUID>();
            InventoryItemBase item = null;
            int i = 0;
            foreach (UUID id in itemIDs)
            {
                if (m_ItemCache.TryGetValue(id, out item))
                    itemArr[i++] = item;
                else
                    pending.Add(id);
            }

            if (pending.Count == 0) // we're done, everything was in the cache
                return itemArr;

            try
            {
                Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEITEMS",
                        new Dictionary<string, object> {
                            { "PRINCIPAL", principalID.ToString() },
                            { "ITEMS", String.Join(",", pending.ToArray()) },
                            { "COUNT", pending.Count.ToString() }
                        });

                if (!CheckReturn(resultSet))
                {
                    if (i == 0)
                        return null;
                    else
                        return itemArr;
                }

                // carry over index i where we left above
                foreach (KeyValuePair<string, object> kvp in resultSet)
                {
                    InventoryCollection inventory = new InventoryCollection();
                    if (kvp.Key.StartsWith("item_"))
                    {
                        if (kvp.Value is Dictionary<string, object>)
                        {
                            item = BuildItem((Dictionary<string, object>)kvp.Value);
                            m_ItemCache.AddOrUpdate(item.ID, item, CACHE_EXPIRATION_SECONDS);
                            itemArr[i++] = item;
                        }
                        else
                            itemArr[i++] = null;
                    }
                }
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleItems: {0}", e.Message);
            }

            return itemArr;
        }
 public override InventoryCollection GetFolderContent(UUID userID, UUID folderID)
 {
     UUID sessionID = GetSessionID(userID);
     try
     {
         return m_RemoteConnector.GetFolderContent(userID.ToString(), folderID, sessionID);
     }
     catch (Exception e)
     {
         m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetFolderContent operation failed, {0} {1}",
             e.Source, e.Message);
     }
     InventoryCollection nullCollection = new InventoryCollection();
     nullCollection.Folders = new List<InventoryFolderBase>();
     nullCollection.Items = new List<InventoryItemBase>();
     nullCollection.UserID = userID;
     return nullCollection;
 }
        public virtual InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
        {
            // This method doesn't receive a valud principal id from the
            // connector. So we disregard the principal and look
            // by ID.
            //
            m_log.DebugFormat("[XINVENTORY SERVICE]: Fetch contents for folder {0}", folderID.ToString());
            InventoryCollection inventory = new InventoryCollection();
            inventory.UserID = principalID;
            inventory.Folders = new List<InventoryFolderBase>();
            inventory.Items = new List<InventoryItemBase>();

            XInventoryFolder[] folders = m_Database.GetFolders(
                    new string[] { "parentFolderID"},
                    new string[] { folderID.ToString() });

            foreach (XInventoryFolder x in folders)
            {
                //m_log.DebugFormat("[XINVENTORY]: Adding folder {0} to response", x.folderName);
                inventory.Folders.Add(ConvertToOpenSim(x));
            }

            XInventoryItem[] items = m_Database.GetItems(
                    new string[] { "parentFolderID"},
                    new string[] { folderID.ToString() });

            foreach (XInventoryItem i in items)
            {
                //m_log.DebugFormat("[XINVENTORY]: Adding item {0} to response", i.inventoryName);
                inventory.Items.Add(ConvertToOpenSim(i));
            }

            return inventory;
        }
        /// <summary>
        /// Callback used by the inventory server GetInventory request
        /// </summary>
        /// <param name="userID"></param>
        private void InventoryResponse(InventoryCollection response)
        {
            UUID userID = response.UserID;
            InventoryReceiptCallback callback = null;
            lock (m_RequestingInventory)
            {
                if (m_RequestingInventory.ContainsKey(userID))
                {
                    callback = m_RequestingInventory[userID];
                    m_RequestingInventory.Remove(userID);
                    lock (m_RequestTime)
                    {
                        if (m_RequestTime.ContainsKey(userID))
                        {
                            m_RequestTime.Remove(userID);
                        }
                    }
                }
                else
                {
                    m_log.WarnFormat(
                        "[INVENTORY CONNECTOR]: " +
                        "Received inventory response for {0} for which we do not have a record of requesting!",
                        userID);
                    return;
                }
            }

            m_log.InfoFormat("[INVENTORY CONNECTOR]: " +
                             "Received inventory response for user {0} containing {1} folders and {2} items",
                             userID, response.Folders.Count, response.Items.Count);

            InventoryFolderImpl rootFolder = null;

            ICollection<InventoryFolderImpl> folders = new List<InventoryFolderImpl>();
            ICollection<InventoryItemBase> items = new List<InventoryItemBase>();

            foreach (InventoryFolderBase folder in response.Folders)
            {
                if (folder.ParentID == UUID.Zero)
                {
                    rootFolder = new InventoryFolderImpl(folder);
                    folders.Add(rootFolder);

                    break;
                }
            }

            if (rootFolder != null)
            {
                foreach (InventoryFolderBase folder in response.Folders)
                {
                    if (folder.ID != rootFolder.ID)
                    {
                        folders.Add(new InventoryFolderImpl(folder));
                    }
                }

                foreach (InventoryItemBase item in response.Items)
                {
                    items.Add(item);
                }
            }
            else
            {
                m_log.ErrorFormat("[INVENTORY CONNECTOR]: Did not get back an inventory containing a root folder for user {0}", userID);
            }

            callback(folders, items);

        }