Exemplo n.º 1
0
        public void RequestFolderContents(UUID folder, UUID owner, bool folders, bool items,
                                          InventorySortOrder order)
        {
            FetchInventoryDescendentsPacket fetch = new FetchInventoryDescendentsPacket();

            fetch.AgentData.AgentID   = frame.AgentID;
            fetch.AgentData.SessionID = frame.SessionID;

            fetch.InventoryData.FetchFolders = folders;
            fetch.InventoryData.FetchItems   = items;
            fetch.InventoryData.FolderID     = folder;
            fetch.InventoryData.OwnerID      = owner;
            fetch.InventoryData.SortOrder    = (int)order;

            proxy.InjectPacket(fetch, Direction.Outgoing);
        }
Exemplo n.º 2
0
Arquivo: CliInt.cs Projeto: zadark/par
        /// <summary>
        /// Request a folder's content.
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="folders"></param>
        /// <param name="items"></param>
        /// <param name="order"></param>
        public void RequestFolderContents(UUID folder, bool folders, bool items, InventorySortOrder order)
        {
            //empty the dictionnary containing current folder items by name
            currentFolderItems = new Dictionary <string, InventoryItem>();
            //reset the number of descendants received
            nbdescendantsreceived = 0;
            //build a packet to request the content
            FetchInventoryDescendentsPacket fetch = new FetchInventoryDescendentsPacket();

            fetch.AgentData.AgentID   = frame.AgentID;
            fetch.AgentData.SessionID = frame.SessionID;

            fetch.InventoryData.FetchFolders = folders;
            fetch.InventoryData.FetchItems   = items;
            fetch.InventoryData.FolderID     = folder;
            fetch.InventoryData.OwnerID      = frame.AgentID; //is it correct?
            fetch.InventoryData.SortOrder    = (int)order;

            //send packet to SL
            proxy.InjectPacket(fetch, Direction.Outgoing);
        }
Exemplo n.º 3
0
        public void RequestFolderContents(LLUUID folder, LLUUID owner, bool folders, bool items, 
            InventorySortOrder order)
        {
            FetchInventoryDescendentsPacket fetch = new FetchInventoryDescendentsPacket();
            fetch.AgentData.AgentID = _Client.Self.AgentID;
            fetch.AgentData.SessionID = _Client.Self.SessionID;

            fetch.InventoryData.FetchFolders = folders;
            fetch.InventoryData.FetchItems = items;
            fetch.InventoryData.FolderID = folder;
            fetch.InventoryData.OwnerID = owner;
            fetch.InventoryData.SortOrder = (int)order;

            _Client.Network.SendPacket(fetch);
        }
Exemplo n.º 4
0
        public List<InventoryBase> FolderContents(LLUUID folder, LLUUID owner, bool folders, bool items,
            InventorySortOrder order, int timeoutMS)
        {
            List<InventoryBase> objects = null;
            AutoResetEvent fetchEvent = new AutoResetEvent(false);

            FolderUpdatedCallback callback =
                delegate(LLUUID folderID)
                {
                    if (folderID == folder)
                        fetchEvent.Set();
                };

            OnFolderUpdated += callback;

            RequestFolderContents(folder, owner, folders, items, order);
            if (fetchEvent.WaitOne(timeoutMS, false))
                objects = _Store.GetContents(folder);

            OnFolderUpdated -= callback;

            return objects;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get contents of a folder
        /// </summary>
        /// <param name="folder">The <seealso cref="UUID"/> of the folder to search</param>
        /// <param name="owner">The <seealso cref="UUID"/> of the folders owner</param>
        /// <param name="folders">true to retrieve folders</param>
        /// <param name="items">true to retrieve items</param>
        /// <param name="order">sort order to return results in</param>
        /// <param name="timeoutMS">a integer representing the number of milliseconds to wait for results</param>
        /// <returns>A list of inventory items matching search criteria within folder</returns>
        /// <seealso cref="InventoryManager.RequestFolderContents"/>
        /// <remarks>InventoryFolder.DescendentCount will only be accurate if both folders and items are
        /// requested</remarks>
        public List<InventoryBase> FolderContents(UUID folder, UUID owner, bool folders, bool items,
            InventorySortOrder order, int timeoutMS)
        {
            List<InventoryBase> objects = null;
            AutoResetEvent fetchEvent = new AutoResetEvent(false);

            EventHandler<FolderUpdatedEventArgs> callback =
                delegate(object sender, FolderUpdatedEventArgs e)
                {
                    if (e.FolderID == folder
                        && _Store[folder] is InventoryFolder)
                    {
                        // InventoryDescendentsHandler only stores DescendendCount if both folders and items are fetched.
                        if (_Store.GetContents(folder).Count >= ((InventoryFolder)_Store[folder]).DescendentCount)
                        {

                            fetchEvent.Set();
                        }
                    }
                    else
                    {
                        fetchEvent.Set();
                    }
                };

            FolderUpdated += callback;

            RequestFolderContents(folder, owner, folders, items, order);
            if (fetchEvent.WaitOne(timeoutMS, false))
                objects = _Store.GetContents(folder);

            FolderUpdated -= callback;

            return objects;
        }
Exemplo n.º 6
0
    //request a folder content
    public void RequestFolderContents(UUID folder, bool folders, bool items,
        InventorySortOrder order)
    {
        //empty the dictionnary containing current folder items by name
        currentFolderItems = new Dictionary<string, ItemData>();
        //reset the number of descendants received
        nbdescendantsreceived = 0;
        //build a packet to request the content
        FetchInventoryDescendentsPacket fetch = new FetchInventoryDescendentsPacket();
        fetch.AgentData.AgentID = frame.AgentID;
        fetch.AgentData.SessionID = frame.SessionID;

        fetch.InventoryData.FetchFolders = folders;
        fetch.InventoryData.FetchItems = items;
        fetch.InventoryData.FolderID = folder;
        fetch.InventoryData.OwnerID = frame.AgentID; //is it correct?
        fetch.InventoryData.SortOrder = (int)order;

        //send packet to SL
        proxy.InjectPacket(fetch, Direction.Outgoing);
    }
Exemplo n.º 7
0
        /// <summary>
        /// Request the contents of an inventory folder, <paramref name="callback"/> is fired when all of the contents are retrieved.
        /// <paramref name="partialCallback"/> is fired as the contents trickle in from the server. 
        /// </summary>
        /// <param name="folder">The folder to search</param>
        /// <param name="owner">The folder owners <seealso cref="UUID"/></param>
        /// <param name="folders">true to return <seealso cref="InventoryManager.InventoryFolder"/>s contained in folder</param>
        /// <param name="items">true to return <seealso cref="InventoryManager.InventoryItem"/>s containd in folder</param>
        /// <param name="order">the sort order to return items in</param>
        /// <param name="callback">The callback to fire when all the contents are received.</param>
        /// <param name="partialCallback">The callback to fire as the contents are received.</param>
        /// <seealso cref="InventoryManager.FolderContents"/>
        public void RequestFolderContents(UUID folder, UUID owner, bool folders, bool items, InventorySortOrder order, FolderContentsCallback callback, PartialContentsCallback partialCallback)
        {
            DescendentsRequest request = new DescendentsRequest(folder, callback);
            request.PartialCallback = partialCallback;
            lock (_DescendentsRequests)
                _DescendentsRequests.Add(request);

            // Send the packet:
            FetchInventoryDescendentsPacket fetch = new FetchInventoryDescendentsPacket();
            fetch.AgentData.AgentID = _Agents.AgentID;
            fetch.AgentData.SessionID = _Agents.SessionID;

            fetch.InventoryData.FetchFolders = folders;
            fetch.InventoryData.FetchItems = items;
            fetch.InventoryData.FolderID = folder;
            fetch.InventoryData.OwnerID = owner;
            fetch.InventoryData.SortOrder = (int)order;

            _Network.SendPacket(fetch);
        }
Exemplo n.º 8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="folder"></param>
 /// <param name="owner"></param>
 /// <param name="folders"></param>
 /// <param name="items"></param>
 /// <param name="order"></param>
 /// <param name="callback"></param>
 public void RequestFolderContents(UUID folder, UUID owner, bool folders, bool items, InventorySortOrder order, FolderContentsCallback callback)
 {
     RequestFolderContents(folder, owner, folders, items, order, callback, null);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Get contents of a folder
        /// </summary>
        /// <param name="folder">The <seealso cref="UUID"/> of the folder to search</param>
        /// <param name="owner">The <seealso cref="UUID"/> of the folders owner</param>
        /// <param name="folders">true to retrieve folders</param>
        /// <param name="items">true to retrieve items</param>
        /// <param name="order">sort order to return results in</param>
        /// <param name="timeout">a TimeSpan representing the amount of time to wait for results</param>
        /// <param name="folderContents">A list of FolderData representing the folders contained in the parent folder.</param>
        /// <param name="itemContents">A list of ItemData representing the items contained in the parent folder.</param>
        /// <returns><code>true</code> if successful, <code>false</code> if timed out</returns>
        /// <seealso cref="InventoryManager.RequestFolderContents"/>
        public bool FolderContents(UUID folder, UUID owner, bool folders, bool items,
            InventorySortOrder order, TimeSpan timeout, out List<ItemData> itemContents, out List<FolderData> folderContents)
        {
            AutoResetEvent lockEvent = new AutoResetEvent(false);
            List<FolderData> _folders = null;
            List<ItemData> _items = null;
            FolderContentsCallback callback = new FolderContentsCallback(
                delegate(UUID folderID, List<ItemData> __items, List<FolderData> __folders)
                {
                    if (folderID == folder)
                    {
                        _folders = __folders;
                        _items = __items;
                        lockEvent.Set();
                    }
                });
            RequestFolderContents(folder, owner, folders, items, order, callback);

            bool success = lockEvent.WaitOne(timeout, false);
            itemContents = _items;
            folderContents = _folders;
            return success;
        }
Exemplo n.º 10
0
        public void RequestFolderContentsCap(List<InventoryFolder> batch, Uri url, bool fetchFolders, bool fetchItems, InventorySortOrder order)
        {
            try
            {
                CapsClient request = new CapsClient(url);
                request.OnComplete += (client, result, error) =>
                {
                    try
                    {
                        if (error != null)
                        {
                            throw error;
                        }

                        OSDMap resultMap = ((OSDMap)result);
                        if (resultMap.ContainsKey("folders"))
                        {
                            OSDArray fetchedFolders = (OSDArray)resultMap["folders"];
                            for (int fetchedFolderNr = 0; fetchedFolderNr < fetchedFolders.Count; fetchedFolderNr++)
                            {
                                OSDMap res = (OSDMap)fetchedFolders[fetchedFolderNr];
                                InventoryFolder fetchedFolder = null;

                                if (_Store.Contains(res["folder_id"])
                                    && _Store[res["folder_id"]] is InventoryFolder)
                                {
                                    fetchedFolder = (InventoryFolder)_Store[res["folder_id"]];
                                }
                                else
                                {
                                    fetchedFolder = new InventoryFolder(res["folder_id"]);
                                    _Store[res["folder_id"]] = fetchedFolder;
                                }
                                fetchedFolder.DescendentCount = res["descendents"];
                                fetchedFolder.Version = res["version"];
                                fetchedFolder.OwnerID = res["owner_id"];
                                _Store.GetNodeFor(fetchedFolder.UUID).NeedsUpdate = false;

                                // Do we have any descendants
                                if (fetchedFolder.DescendentCount > 0)
                                {
                                    // Fetch descendent folders
                                    if (res["categories"] is OSDArray)
                                    {
                                        OSDArray folders = (OSDArray)res["categories"];
                                        for (int i = 0; i < folders.Count; i++)
                                        {
                                            OSDMap descFolder = (OSDMap)folders[i];
                                            InventoryFolder folder;
                                            UUID folderID = descFolder.ContainsKey("category_id") ? descFolder["category_id"] : descFolder["folder_id"];
                                            if (!_Store.Contains(folderID))
                                            {
                                                folder = new InventoryFolder(folderID);
                                                folder.ParentUUID = descFolder["parent_id"];
                                                _Store[folderID] = folder;
                                            }
                                            else
                                            {
                                                folder = (InventoryFolder)_Store[folderID];
                                            }

                                            folder.OwnerID = descFolder["agent_id"];
                                            folder.ParentUUID = descFolder["parent_id"];
                                            folder.Name = descFolder["name"];
                                            folder.Version = descFolder["version"];
                                            folder.PreferredType = (FolderType)(int)descFolder["type_default"];
                                        }

                                        // Fetch descendent items
                                        OSDArray items = (OSDArray)res["items"];
                                        for (int i = 0; i < items.Count; i++)
                                        {
                                            InventoryItem item = InventoryItem.FromOSD(items[i]);
                                            _Store[item.UUID] = item;
                                        }
                                    }
                                }

                                OnFolderUpdated(new FolderUpdatedEventArgs(res["folder_id"], true));
                            }
                        }
                    }
                    catch (Exception exc)
                    {
                        Logger.Log(string.Format("Failed to fetch inventory descendants: {0}\n{1}", exc.Message, exc.StackTrace.ToString()), Helpers.LogLevel.Warning, Client);
                        foreach (var f in batch)
                        {
                            OnFolderUpdated(new FolderUpdatedEventArgs(f.UUID, false));
                        }
                        return;
                    }

                };

                // Construct request
                OSDArray requestedFolders = new OSDArray(1);
                foreach (var f in batch)
                {
                    OSDMap requestedFolder = new OSDMap(1);
                    requestedFolder["folder_id"] = f.UUID;
                    requestedFolder["owner_id"] = f.OwnerID;
                    requestedFolder["fetch_folders"] = fetchFolders;
                    requestedFolder["fetch_items"] = fetchItems;
                    requestedFolder["sort_order"] = (int)order;

                    requestedFolders.Add(requestedFolder);
                }
                OSDMap req = new OSDMap(1);
                req["folders"] = requestedFolders;

                request.BeginGetResponse(req, OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
            }
            catch (Exception ex)
            {
                Logger.Log(string.Format("Failed to fetch inventory descendants: {0}\n{1}", ex.Message, ex.StackTrace.ToString()), Helpers.LogLevel.Warning, Client);
                foreach (var f in batch)
                {
                    OnFolderUpdated(new FolderUpdatedEventArgs(f.UUID, false));
                }
                return;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Request the contents of an inventory folder using HTTP capabilities
        /// </summary>
        /// <param name="folderID">The folder to search</param>
        /// <param name="ownerID">The folder owners <seealso cref="UUID"/></param>
        /// <param name="fetchFolders">true to return <seealso cref="InventoryManager.InventoryFolder"/>s contained in folder</param>
        /// <param name="fetchItems">true to return <seealso cref="InventoryManager.InventoryItem"/>s containd in folder</param>
        /// <param name="order">the sort order to return items in</param>
        /// <seealso cref="InventoryManager.FolderContents"/>
        public void RequestFolderContentsCap(UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems,
            InventorySortOrder order)
        {
            Uri url = null;
            string cap = ownerID == Client.Self.AgentID ? "FetchInventoryDescendents2" : "FetchLibDescendents2";
            if (Client.Network.CurrentSim.Caps == null ||
                null == (url = Client.Network.CurrentSim.Caps.CapabilityURI(cap)))
            {
                Logger.Log(cap + " capability not available in the current sim", Helpers.LogLevel.Warning, Client);
                OnFolderUpdated(new FolderUpdatedEventArgs(folderID, false));
                return;
            }

            InventoryFolder folder = new InventoryFolder(folderID);
            folder.OwnerID = ownerID;
            folder.UUID = folderID;
            RequestFolderContentsCap(new List<InventoryFolder>() { folder }, url, fetchFolders, fetchItems, order);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Request the contents of an inventory folder
        /// </summary>
        /// <param name="folder">The folder to search</param>
        /// <param name="owner">The folder owners <seealso cref="UUID"/></param>
        /// <param name="folders">true to return <seealso cref="InventoryManager.InventoryFolder"/>s contained in folder</param>
        /// <param name="items">true to return <seealso cref="InventoryManager.InventoryItem"/>s containd in folder</param>
        /// <param name="order">the sort order to return items in</param>
        /// <seealso cref="InventoryManager.FolderContents"/>
        public void RequestFolderContents(UUID folder, UUID owner, bool folders, bool items,
            InventorySortOrder order)
        {
            string cap = owner == Client.Self.AgentID ? "FetchInventoryDescendents2" : "FetchLibDescendents2";

            if (Client.Settings.HTTP_INVENTORY &&
                Client.Network.CurrentSim.Caps != null &&
                Client.Network.CurrentSim.Caps.CapabilityURI(cap) != null)
            {
                RequestFolderContentsCap(folder, owner, folders, items, order);
                return;
            }

            FetchInventoryDescendentsPacket fetch = new FetchInventoryDescendentsPacket();
            fetch.AgentData.AgentID = Client.Self.AgentID;
            fetch.AgentData.SessionID = Client.Self.SessionID;

            fetch.InventoryData.FetchFolders = folders;
            fetch.InventoryData.FetchItems = items;
            fetch.InventoryData.FolderID = folder;
            fetch.InventoryData.OwnerID = owner;
            fetch.InventoryData.SortOrder = (int)order;

            Client.Network.SendPacket(fetch);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Request the contents of an inventory folder using HTTP capabilities
        /// </summary>
        /// <param name="folderID">The folder to search</param>
        /// <param name="ownerID">The folder owners <seealso cref="UUID"/></param>
        /// <param name="fetchFolders">true to return <seealso cref="InventoryManager.InventoryFolder"/>s contained in folder</param>
        /// <param name="fetchItems">true to return <seealso cref="InventoryManager.InventoryItem"/>s containd in folder</param>
        /// <param name="order">the sort order to return items in</param>
        /// <seealso cref="InventoryManager.FolderContents"/>
        public void RequestFolderContentsCap(UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems,
            InventorySortOrder order)
        {
            Uri url = null;

            if (Client.Network.CurrentSim.Caps == null ||
                null == (url = Client.Network.CurrentSim.Caps.CapabilityURI("FetchInventoryDescendents2")))
            {
                Logger.Log("FetchInventoryDescendents2 capability not available in the current sim", Helpers.LogLevel.Warning, Client);
                OnFolderUpdated(new FolderUpdatedEventArgs(folderID, false));
                return;
            }

            try
            {
                CapsClient request = new CapsClient(url);
                request.OnComplete += (client, result, error) =>
                {
                    try
                    {
                        if (error != null)
                        {
                            throw error;
                        }

                        OSDArray fetchedFolders = (OSDArray)((OSDMap)result)["folders"];
                        for (int fetchedFolderNr = 0; fetchedFolderNr < fetchedFolders.Count; fetchedFolderNr++)
                        {
                            OSDMap res = (OSDMap)fetchedFolders[fetchedFolderNr];
                            InventoryFolder fetchedFolder = null;

                            if (_Store.Contains(res["folder_id"])
                                && _Store[res["folder_id"]] is InventoryFolder)
                            {
                                fetchedFolder = (InventoryFolder)_Store[res["folder_id"]];
                            }
                            else
                            {
                                fetchedFolder = new InventoryFolder(res["folder_id"]);
                                _Store[res["folder_id"]] = fetchedFolder;
                            }
                            fetchedFolder.DescendentCount = res["descendents"];
                            fetchedFolder.Version = res["version"];
                            fetchedFolder.OwnerID = res["owner_id"];
                            _Store.GetNodeFor(fetchedFolder.UUID).NeedsUpdate = false;

                            // Do we have any descendants
                            if (fetchedFolder.DescendentCount > 0)
                            {
                                // Fetch descendent folders
                                if (res["categories"] is OSDArray)
                                {
                                    OSDArray folders = (OSDArray)res["categories"];
                                    for (int i = 0; i < folders.Count; i++)
                                    {
                                        OSDMap descFolder = (OSDMap)folders[i];
                                        InventoryFolder folder;
                                        if (!_Store.Contains(descFolder["category_id"]))
                                        {
                                            folder = new InventoryFolder(descFolder["category_id"]);
                                            folder.ParentUUID = descFolder["parent_id"];
                                            _Store[descFolder["category_id"]] = folder;
                                        }
                                        else
                                        {
                                            folder = (InventoryFolder)_Store[descFolder["category_id"]];
                                        }

                                        folder.OwnerID = descFolder["agent_id"];
                                        folder.ParentUUID = descFolder["parent_id"];
                                        folder.Name = descFolder["name"];
                                        folder.Version = descFolder["version"];
                                        folder.PreferredType = (AssetType)(int)descFolder["type_default"];
                                    }

                                    // Fetch descendent items
                                    OSDArray items = (OSDArray)res["items"];
                                    for (int i = 0; i < items.Count; i++)
                                    {
                                        InventoryItem item = InventoryItem.FromOSD(items[i]);
                                       _Store[item.UUID] = item;
                                    }
                                }
                            }

                            OnFolderUpdated(new FolderUpdatedEventArgs(res["folder_id"], true));
                        }
                    }
                    catch (Exception exc)
                    {
                        Logger.Log(string.Format("Failed to fetch inventory descendants for folder id {0}: {1}\n{2}", folderID, exc.Message, exc.StackTrace.ToString()), Helpers.LogLevel.Warning, Client);
                        OnFolderUpdated(new FolderUpdatedEventArgs(folderID, false));
                        return;
                    }

                };

                // Construct request
                OSDMap requestedFolder = new OSDMap(1);
                requestedFolder["folder_id"] = folderID;
                requestedFolder["owner_id"] = ownerID;
                requestedFolder["fetch_folders"] = fetchFolders;
                requestedFolder["fetch_items"] = fetchItems;
                requestedFolder["sort_order"] = (int)order;

                OSDArray requestedFolders = new OSDArray(1);
                requestedFolders.Add(requestedFolder);
                OSDMap req = new OSDMap(1);
                req["folders"] = requestedFolders;

                request.BeginGetResponse(req, OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
            }
            catch (Exception ex)
            {
                Logger.Log(string.Format("Failed to fetch inventory descendants for folder id {0}: {1}\n{2}", folderID, ex.Message, ex.StackTrace.ToString()), Helpers.LogLevel.Warning, Client);
                OnFolderUpdated(new FolderUpdatedEventArgs(folderID, false));
                return;
            }
        }
        /// <summary>
        /// Request the contents of an inventory folder using HTTP capabilities
        /// </summary>
        /// <param name="folderID">The folder to search</param>
        /// <param name="ownerID">The folder owners <seealso cref="UUID"/></param>
        /// <param name="fetchFolders">true to return <seealso cref="InventoryManager.InventoryFolder"/>s contained in folder</param>
        /// <param name="fetchItems">true to return <seealso cref="InventoryManager.InventoryItem"/>s containd in folder</param>
        /// <param name="order">the sort order to return items in</param>
        /// <seealso cref="InventoryManager.FolderContents"/>
        public void RequestFolderContentsCap(UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems,
            InventorySortOrder order)
        {
            Uri url = null;

            if (Client.Network.CurrentSim.Caps == null ||
                null == (url = Client.Network.CurrentSim.Caps.CapabilityURI("FetchInventoryDescendents2")))
            {
                Logger.Log("FetchInventoryDescendents2 capability not available in the current sim", Helpers.LogLevel.Warning, Client);
                OnFolderUpdated(new FolderUpdatedEventArgs(folderID, false));
                return;
            }

            try
            {
                CapsClient request = new CapsClient(url);
                request.OnComplete += (client, result, error) =>
                {
                    try
                    {
                        if (error != null) throw error;

                        OSDArray fetchedFolders = (OSDArray)((OSDMap)result)["folders"];
                        for (int fetchedFolderNr = 0; fetchedFolderNr < fetchedFolders.Count; fetchedFolderNr++)
                        {
                            OSDMap res = (OSDMap)fetchedFolders[fetchedFolderNr];
                            InventoryFolder fetchedFolder = null;

                            if (_Store.Contains(res["folder_id"])
                                && _Store[res["folder_id"]] is InventoryFolder)
                            {
                                fetchedFolder = (InventoryFolder)_Store[res["folder_id"]];
                            }
                            else
                            {
                                fetchedFolder = new InventoryFolder(res["folder_id"]);
                                _Store[res["folder_id"]] = fetchedFolder;
                            }
                            fetchedFolder.DescendentCount = res["descendents"];
                            fetchedFolder.Version = res["version"];
                            fetchedFolder.OwnerID = res["owner_id"];
                            _Store.GetNodeFor(fetchedFolder.UUID).NeedsUpdate = false;

                            // Do we have any descendants
                            if (fetchedFolder.DescendentCount > 0)
                            {
                                // Fetch descendent folders
                                if (res["categories"] is OSDArray)
                                {
                                    OSDArray folders = (OSDArray)res["categories"];
                                    for (int i = 0; i < folders.Count; i++)
                                    {
                                        OSDMap descFolder = (OSDMap)folders[i];
                                        InventoryFolder folder;
                                        if (!_Store.Contains(descFolder["category_id"]))
                                        {
                                            folder = new InventoryFolder(descFolder["category_id"]);
                                            folder.ParentUUID = descFolder["parent_id"];
                                            _Store[descFolder["category_id"]] = folder;
                                        }
                                        else
                                        {
                                            folder = (InventoryFolder)_Store[descFolder["category_id"]];
                                        }

                                        folder.OwnerID = descFolder["agent_id"];
                                        folder.ParentUUID = descFolder["parent_id"];
                                        folder.Name = descFolder["name"];
                                        folder.Version = descFolder["version"];
                                        folder.PreferredType = (AssetType)(int)descFolder["type_default"];
                                    }

                                    // Fetch descendent items
                                    OSDArray items = (OSDArray)res["items"];
                                    for (int i = 0; i < items.Count; i++)
                                    {
                                        OSDMap descItem = (OSDMap)items[i];
                                        InventoryType type = (InventoryType)descItem["inv_type"].AsInteger();
                                        if (type == InventoryType.Texture && (AssetType)descItem["type"].AsInteger() == AssetType.Object)
                                        {
                                            type = InventoryType.Attachment;
                                        }
                                        InventoryItem item = CreateInventoryItem(type, descItem["item_id"]);

                                        item.ParentUUID = descItem["parent_id"];
                                        item.Name = descItem["name"];
                                        item.Description = descItem["desc"];
                                        item.OwnerID = descItem["agent_id"];
                                        item.AssetUUID = descItem["asset_id"];
                                        item.AssetType = (AssetType)descItem["type"].AsInteger();
                                        item.CreationDate =  Utils.UnixTimeToDateTime(descItem["created_at"]);
                                        item.Flags = descItem["flags"];

                                        OSDMap perms = (OSDMap)descItem["permissions"];
                                        item.CreatorID = perms["creator_id"];
                                        item.LastOwnerID = perms["last_owner_id"];
                                        item.Permissions = new Permissions(perms["base_mask"], perms["everyone_mask"], perms["group_mask"], perms["next_owner_mask"], perms["owner_mask"]);
                                        item.GroupOwned = perms["is_owner_group"];
                                        item.GroupID = perms["group_id"];

                                        OSDMap sale = (OSDMap)descItem["sale_info"];
                                        item.SalePrice = sale["sale_price"];
                                        item.SaleType = (SaleType)sale["sale_type"].AsInteger();

                                        _Store[item.UUID] = item;
                                    }
                                }
                            }

                            OnFolderUpdated(new FolderUpdatedEventArgs(res["folder_id"], true));
                        }
                    }
                    catch (Exception exc)
                    {
                        Logger.Log(string.Format("Failed to fetch inventory descendants for folder id {0}: {1}\n{2}", folderID, exc.Message, exc.StackTrace.ToString()), Helpers.LogLevel.Warning, Client);
                        OnFolderUpdated(new FolderUpdatedEventArgs(folderID, false));
                        return;
                    }

                };

                // Construct request
                OSDMap requestedFolder = new OSDMap(1);
                requestedFolder["folder_id"] = folderID;
                requestedFolder["owner_id"] = ownerID;
                requestedFolder["fetch_folders"] = fetchFolders;
                requestedFolder["fetch_items"] = fetchItems;
                requestedFolder["sort_order"] = (int)order;

                OSDArray requestedFolders = new OSDArray(1);
                requestedFolders.Add(requestedFolder);
                OSDMap req = new OSDMap(1);
                req["folders"] = requestedFolders;

                request.BeginGetResponse(req, OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
            }
            catch (Exception ex)
            {
                Logger.Log(string.Format("Failed to fetch inventory descendants for folder id {0}: {1}\n{2}", folderID, ex.Message, ex.StackTrace.ToString()), Helpers.LogLevel.Warning, Client);
                OnFolderUpdated(new FolderUpdatedEventArgs(folderID, false));
                return;
            }
        }
Exemplo n.º 15
0
        public void RequestFolderContents(UUID folder, UUID owner, bool folders, bool items,
            InventorySortOrder order)
        {
            FetchInventoryDescendentsPacket fetch = new FetchInventoryDescendentsPacket();
            fetch.AgentData.AgentID = frame.AgentID;
            fetch.AgentData.SessionID = frame.SessionID;

            fetch.InventoryData.FetchFolders = folders;
            fetch.InventoryData.FetchItems = items;
            fetch.InventoryData.FolderID = folder;
            fetch.InventoryData.OwnerID = owner;
            fetch.InventoryData.SortOrder = (int)order;

            proxy.InjectPacket(fetch, Direction.Outgoing);
        }