/// <summary> /// Get an iFolder Entry /// </summary> /// <param name="c">The Collection Object</param> /// <param name="n">The Node Object</param> /// <returns>An iFolderEntry Object</returns> private static iFolderEntry GetEntry(Collection c, Node n) { iFolderEntry entry = new iFolderEntry(); entry.ID = n.ID; entry.Name = n.Name; entry.iFolderID = c.ID; try { entry.ParentID = (n.Properties.GetSingleProperty(PropertyTags.Parent).Value as Relationship).NodeID; } catch { // ignore } // file node if (n.IsBaseType(NodeTypes.FileNodeType)) { FileNode fileNode = (FileNode)FileNode.NodeFactory(c, n); entry.Path = fileNode.GetRelativePath(); entry.LastModified = fileNode.LastWriteTime; entry.Size = fileNode.Length; } // dir node else if (n.IsBaseType(NodeTypes.DirNodeType)) { DirNode dirNode = (DirNode)DirNode.NodeFactory(c, n); entry.Path = dirNode.GetRelativePath(); entry.LastModified = dirNode.CreationTime; entry.IsDirectory = true; entry.IsRoot = dirNode.IsRoot; entry.HasChildren = dirNode.HasChildren(c); entry.Size = (long)dirNode.GetSize(c); } // bad node else { throw new EntryDoesNotExistException(n.ID); } return(entry); }
/// <summary> /// Get iFolder Entries by Name /// </summary> /// <param name="ifolderID">The ID of the iFolder.</param> /// <param name="parentID">The ID of the Parent Entry.</param> /// <param name="operation">The Search Operation</param> /// <param name="pattern">The Search Pattern</param> /// <param name="index">The Search Start Index</param> /// <param name="max">The Search Max Count of Results</param> /// <param name="accessID">The Access User ID.</param> /// <returns>A Set of iFolderEntry Objects</returns> public static iFolderEntrySet GetEntriesByName(string ifolderID, string parentID, SearchOperation operation, string pattern, int index, int max, string accessID) { Store store = Store.GetStore(); Collection c = store.GetCollectionByID(ifolderID); if (c == null) { throw new iFolderDoesNotExistException(ifolderID); } // impersonate iFolder.Impersonate(c, accessID); // path string path; if ((parentID == null) || ifolderID.Equals(parentID)) { path = c.Name + "/"; } else { Node n = c.GetNodeByID(parentID); DirNode dirNode = (DirNode)DirNode.NodeFactory(c, n); path = dirNode.GetRelativePath() + "/"; } // match the pattern Regex regex = null; if ((pattern != null) && (pattern.Length > 0)) { switch (operation) { case SearchOperation.BeginsWith: pattern = "^" + pattern; break; case SearchOperation.EndsWith: pattern = pattern + "$"; break; case SearchOperation.Equals: pattern = "^" + pattern + "$"; break; case SearchOperation.Contains: default: break; } regex = new Regex(pattern, RegexOptions.IgnoreCase); } // find children deep ICSList children = c.Search(PropertyTags.FileSystemPath, path, SearchOp.Begins); // sort the list ArrayList sortList = new ArrayList(); foreach (ShallowNode sn in children) { if ((regex == null) || regex.Match(sn.Name).Success) { sortList.Add(sn); } } sortList.Sort(new EntryComparer()); // build the result list ArrayList list = new ArrayList(); int i = 0; foreach (ShallowNode sn in sortList) { if (sn.IsBaseType(NodeTypes.FileNodeType) || sn.IsBaseType(NodeTypes.DirNodeType)) { if ((i >= index) && (((max <= 0) || i < (max + index)))) { Node n = c.GetNodeByID(sn.ID); list.Add(iFolderEntry.GetEntry(c, n)); } ++i; } } return(new iFolderEntrySet((iFolderEntry[])list.ToArray(typeof(iFolderEntry)), i)); }