/// <summary> /// Find inventory items by path. /// </summary> /// <param name="baseFolder">The folder to begin the search in.</param> /// <param name="inventoryOwner">The object owner's <seealso cref="UUID"/></param> /// <param name="pathArray">A string array representing a path already split into individual folder names.</param> /// <param name="callback">The callback to fire when the path has been found.</param> public void RequestFindObjectByPath(UUID baseFolder, UUID inventoryOwner, string[] pathArray, FindObjectByPathCallback callback) { // Create the RequestFolderContents callback: FolderContentsCallback contentsCallback = ConstructFindContentsHandler(String.Join("/", pathArray), pathArray, 0, callback); // Start the search RequestFolderContents(baseFolder, inventoryOwner, true, true, InventorySortOrder.ByName, contentsCallback); }
/// <summary> /// This constructs the callback that RequestFindObjectByPath needs to call RequestFolderContents. /// We need to put it in its own method because the callback will need to create another callback for /// recursing into child folders. /// <param name="path">Used for display purposes only.</param> /// <param name="pathArray"></param> /// <param name="level"></param> /// <param name="callback"></param> /// </summary> private FolderContentsCallback ConstructFindContentsHandler(string path, string[] pathArray, int level, FindObjectByPathCallback callback) { return new FolderContentsCallback( delegate(UUID folder, List<ItemData> items, List<FolderData> folders) { foreach (FolderData folderData in folders) { if (folderData.Name == pathArray[level]) { if (level == pathArray.Length - 1) { Logger.DebugLog("Finished path search of " + path, _Client); // This is the last node in the path, fire the callback and clean up callback(path, folderData.UUID); } else { // Construct the callback that will be called to recurse into the child folder. FolderContentsCallback contentsCallback = ConstructFindContentsHandler(path, pathArray, level + 1, callback); RequestFolderContents(folderData.UUID, folderData.OwnerID, true, true, InventorySortOrder.ByName, contentsCallback); } } } foreach (ItemData item in items) { if (item.Name == pathArray[level]) { if (level == pathArray.Length - 1) { Logger.DebugLog("Finished path search of " + path, _Client); // This is the last node in the path, fire the callback and clean up callback(path, item.UUID); } else { Logger.Log("Path search attempted to request the contents of an item.", Helpers.LogLevel.Warning, _Client); callback(path, UUID.Zero); } } } }); }
/// <summary> /// Find inventory items by path /// </summary> /// <param name="baseFolder">The folder to begin the search in</param> /// <param name="inventoryOwner">The object owners <seealso cref="UUID"/></param> /// <param name="path">A string path to search, folders/objects separated by a '/'</param> /// <param name="callback">The callback to fire when the path has been found.</param> public void RequestFindObjectByPath(UUID baseFolder, UUID inventoryOwner, string path, FindObjectByPathCallback callback) { if (path == null || path.Length == 0) throw new ArgumentException("Empty path is not supported"); string[] pathArray = path.Split('/'); RequestFindObjectByPath(baseFolder, inventoryOwner, pathArray, callback); }