/// <summary> /// This is the recursive method. I've separated them in this way so that /// we do not have to waste cycles on any first-case-only processing. /// </summary> private void traverseInventory(InventoryRequestData rdata, InventoryFolderBase folder, int pi) { int fk = 0; InventoryFolderBase ffound = null; InventoryItemBase ifound = null; Rest.Log.DebugFormat("{0} Traverse Folder : {1} {2} [{3}]", MsgId, folder.ID, folder.Name, pi); foreach (InventoryFolderBase f in rdata.folders) { if (f.ParentID == folder.ID && (f.Name == rdata.Parameters[pi] || f.ID.ToString() == rdata.Parameters[pi])) { fk++; ffound = f; } } // If this is the last element in the parameter sequence, then // it is reasonable to check for an item. All intermediate nodes // MUST be folders. if (pi == rdata.Parameters.Length-1) { // Only if there are any items, and there pretty much always are. if (rdata.items != null) { foreach (InventoryItemBase i in rdata.items) { if (i.Folder == folder.ID && (i.Name == rdata.Parameters[pi] || i.ID.ToString() == rdata.Parameters[pi])) { fk++; ifound = i; } } } } if (fk == 1) { if (ffound != null) { if (pi < rdata.Parameters.Length-1) { traverseInventory(rdata, ffound, pi+1); } else { formatInventory(rdata, ffound, String.Empty); } return; } else { // Fetching an Item has a special significance. In this // case we also want to fetch the associated asset. // To make it interesting, we'll do this via redirection. string asseturl = String.Format("http://{0}:{1}/{2}{3}{4}", rdata.hostname, rdata.port, "admin/assets",Rest.UrlPathSeparator,ifound.AssetID.ToString()); rdata.Redirect(asseturl,Rest.PERMANENT); Rest.Log.DebugFormat("{0} Never Reached", MsgId); } } else if (fk > 1) { rdata.Fail(Rest.HttpStatusCodeConflict, String.Format("ambiguous element ({0}) in path specified: <{1}>", pi, rdata.path)); } Rest.Log.DebugFormat("{0} Inventory does not contain item/folder: <{1}>", MsgId, rdata.path); rdata.Fail(Rest.HttpStatusCodeNotFound,String.Format("no such item/folder : {0}", rdata.Parameters[pi])); }