public ArrayList AddGroup( string strGroup, int iCount, bool fRepeat, string strSort, bool fDesc, bool fRecurse, string strRoot, string strPre, string strPost, int iDepth, int iCurrentDepth ) { ArrayList objDavData; // Read the group information objDavData = DavUtil.DAVGetData(m_objWebUtil, strGroup); int fileCount = 0; int directoryCount = 0; for (int i = 0; i < objDavData.Count; i++) { DavItem objDavItem = (DavItem)objDavData[i]; if (objDavItem.fIsCollection) { directoryCount++; } if (objDavItem.strContentType == "image/jpeg") { fileCount++; } } // Get a working list for the result ArrayList objWorkingList = new ArrayList(); // Process the files in this directory if there are no subdirectorys, or // the root files are request if (fileCount > 0 && (strRoot == "heavy" || strRoot == "even" || directoryCount == 0)) { for (int i = 0; i < objDavData.Count; i++) { DavItem objDavItem = (DavItem)objDavData[i]; if (objDavItem.strContentType == "image/jpeg") { ImageFile objImageFile = new ImageFile(); objImageFile.strName = objDavItem.strName; objImageFile.strPre = strPre; objImageFile.strPost = strPost; objImageFile.lSize = objDavItem.iContentLength; objImageFile.dtCreated = objDavItem.dtCreated; objImageFile.dtModified = objDavItem.dtModified; objWorkingList.Add(objImageFile); } } // Evenly weighted files in a directory are filtered down to the same level // as those in subdirectories before being included if (strRoot == "even") { SortImageList(objWorkingList, strSort); objWorkingList = SelectFromList(objWorkingList, iCount, fRepeat, strSort, fDesc); } } // Get all the subdirectories that match the mask if (fRecurse && directoryCount > 0) { for (int i = 0; i < objDavData.Count; i++) { DavItem objDavItem = (DavItem)objDavData[i]; if (objDavItem.fIsCollection) { ArrayList objGroupFiles = AddGroup(objDavItem.strName, iCount, fRepeat, strSort, fDesc, fRecurse, strRoot, strPre, strPost, iDepth, iCurrentDepth + 1); for (int j = 0; j < objGroupFiles.Count; j++) { objWorkingList.Add(objGroupFiles[j]); } } } } // Normalize and sort only those that are deeper than the requested depth if (iCurrentDepth >= iDepth) { SortImageList(objWorkingList, strSort); return(SelectFromList(objWorkingList, iCount, fRepeat, strSort, fDesc)); } else { return(objWorkingList); } }
private ArrayList ProcessNodes( XmlTextReader xml, int iCount, bool fRepeat, string strSort, bool fDesc, string strPre, string strPost) { ArrayList objWorkingList = new ArrayList(); while (xml.NodeType != XmlNodeType.EndElement) { if (xml.NodeType != XmlNodeType.Element) { throw new Exception("Malformed photolist"); } if (xml.Name == "imagefile") { ImageFile objImageFile; string strName; //Datetime dtModified; //Datetime dtCreated; // Read in any pre or post transition attribute string strImageFilePre = GetDefaultAttribute(xml.GetAttribute("pre"), strPre); string strImageFilePost = GetDefaultAttribute(xml.GetAttribute("post"), strPost); // Advance the parser to read the name xml.Read(); strName = xml.Value; // Read in some file information // Create the object for the image file objImageFile = new ImageFile(); objImageFile.strName = strName; //objImageFile.dtCreated = File.GetCreationTime(strName); //objImageFile.dtModified = File.GetLastWriteTime(strName); //objImageFile.lSize = (new FileInfo(strName)).Length; objImageFile.strPre = strImageFilePre; objImageFile.strPost = strImageFilePost; // Add to the list objWorkingList.Add(objImageFile); // Advance the parser to read the end element xml.Read(); } else if (xml.Name == "photolist" || xml.Name == "photolistfile") { // Get the count, sorting attributes string strPLPre = GetDefaultAttribute(xml.GetAttribute("pre"), strPre); string strPLPost = GetDefaultAttribute(xml.GetAttribute("post"), strPost); int iPLCount = GetCount(xml.GetAttribute("count")); string strPLSort = xml.GetAttribute("sort"); bool fPLDesc = (xml.GetAttribute("desc") == "1"); bool fPLRepeat = (xml.GetAttribute("repeat") == "1"); // Get the xml for the embedded data XmlTextReader objXmlEmbedded; if (xml.Name == "photolist") { objXmlEmbedded = xml; } else { // Advance to the file name xml.Read(); // Read in the items objXmlEmbedded = new XmlTextReader(xml.Value); objXmlEmbedded.WhitespaceHandling = WhitespaceHandling.None; // Read the first node and verify that it is a photolist if (!(objXmlEmbedded.Read() && objXmlEmbedded.NodeType == XmlNodeType.Element && objXmlEmbedded.Name == "photolist")) { throw new Exception("Invalid photolist"); } // Advance the parser to point at the end element xml.Read(); } // Read to the first element in the list objXmlEmbedded.Read(); // Get the items in the embedded photo list ArrayList objPhotoListItems = ProcessNodes(objXmlEmbedded, iPLCount, fPLRepeat, strPLSort, fPLDesc, strPLPre, strPLPost); // Add them (in order) to the working list for (int i = 0; i < objPhotoListItems.Count; i++) { objWorkingList.Add(objPhotoListItems[i]); } } else if (xml.Name == "directory") { string strDirPre = GetDefaultAttribute(xml.GetAttribute("pre"), strPre); string strDirPost = GetDefaultAttribute(xml.GetAttribute("pre"), strPost); string strDirDirMask = GetDefaultAttribute(xml.GetAttribute("dirmask"), "*"); string strDirFileMask = GetDefaultAttribute(xml.GetAttribute("filemask"), "*.jpg"); bool fDirRecurse = (xml.GetAttribute("recurse") == "1"); int iDirCount = GetCount(xml.GetAttribute("count")); bool fDirRepeat = (xml.GetAttribute("repeat") == "1"); string strDirSort = GetDefaultAttribute(xml.GetAttribute("sort"), "listed"); bool fDirDesc = (xml.GetAttribute("desc") == "1"); string strDirRoot = GetDefaultAttribute(xml.GetAttribute("root"), "even"); int iDirDepth = GetDepth(xml.GetAttribute("depth")); // Read to the directory name xml.Read(); string strDirectory = xml.Value; // Create a list for the items ArrayList objDirImageList = AddDirectory(strDirectory, iDirCount, fDirRepeat, strDirSort, fDirDesc, fDirRecurse, strDirRoot, strDirPre, strDirPost, strDirDirMask, strDirFileMask, iDirDepth, 0); // Add them (in order) to the working list for (int i = 0; i < objDirImageList.Count; i++) { objWorkingList.Add(objDirImageList[i]); } // Advance to the close tag xml.Read(); } else if (xml.Name == "group") { string strGroupPre = GetDefaultAttribute(xml.GetAttribute("pre"), strPre); string strGroupPost = GetDefaultAttribute(xml.GetAttribute("pre"), strPost); bool fGroupRecurse = (xml.GetAttribute("recurse") == "1"); int iGroupCount = GetCount(xml.GetAttribute("count")); bool fGroupRepeat = (xml.GetAttribute("repeat") == "1"); string strGroupSort = GetDefaultAttribute(xml.GetAttribute("sort"), "listed"); bool fGroupDesc = (xml.GetAttribute("desc") == "1"); string strGroupRoot = GetDefaultAttribute(xml.GetAttribute("root"), "even"); int iGroupDepth = GetDepth(xml.GetAttribute("depth")); // Read to the group name xml.Read(); string strGroup = xml.Value; // Create a list for the items ArrayList objDirImageList = AddGroup(strGroup, iGroupCount, fGroupRepeat, strGroupSort, fGroupDesc, fGroupRecurse, strGroupRoot, strGroupPre, strGroupPost, iGroupDepth, 0); // Add them (in order) to the working list for (int i = 0; i < objDirImageList.Count; i++) { objWorkingList.Add(objDirImageList[i]); } // Advance to the close tag xml.Read(); } else { throw new Exception("Unknown command: " + xml.Name); } // Advance the parser to the next element xml.Read(); } // Sort the list SortImageList(objWorkingList, strSort); // Select from the list return(SelectFromList(objWorkingList, iCount, fRepeat, strSort, fDesc)); }
public ArrayList AddDirectory( string strDirectory, int iCount, bool fRepeat, string strSort, bool fDesc, bool fRecurse, string strRoot, string strPre, string strPost, string strDirMask, string strFileMask, int iDepth, int iCurrentDepth ) { // Get the directory information DirectoryInfo di = new DirectoryInfo(strDirectory); // Read all the directories that match the mask DirectoryInfo[] dis = di.GetDirectories(strDirMask); // Get a working list for the result ArrayList objWorkingList = new ArrayList(); // Process the files in this directory if there are no subdirectorys, or // the root files are request // Get the image files in the root (this directory) that match the mask if (strRoot == "heavy" || strRoot == "even" || dis.Length == 0) { // Get all the files FileInfo[] fis = di.GetFiles(strFileMask); for (int i = 0; i < fis.Length; i++) { ImageFile objImageFile = new ImageFile(); objImageFile.strName = strDirectory + fis[i].Name; objImageFile.strPre = strPre; objImageFile.strPost = strPost; objImageFile.lSize = fis[i].Length; objWorkingList.Add(objImageFile); } // Evenly weighted files in a directory are filtered down to the same level // as those in subdirectories before being included if (strRoot == "even") { SortImageList(objWorkingList, strSort); objWorkingList = SelectFromList(objWorkingList, iCount, fRepeat, strSort, fDesc); } } // Get all the subdirectories that match the mask if (fRecurse) { for (int i = 0; i < dis.Length; i++) { ArrayList objDirectoryFiles = AddDirectory(strDirectory + dis[i].Name + "\\", iCount, fRepeat, strSort, fDesc, fRecurse, strRoot, strPre, strPost, strDirMask, strFileMask, iDepth, iCurrentDepth + 1); for (int j = 0; j < objDirectoryFiles.Count; j++) { objWorkingList.Add(objDirectoryFiles[j]); } } } // Normalize and sort only those that are deeper than the requested depth if (iCurrentDepth >= iDepth) { SortImageList(objWorkingList, strSort); return(SelectFromList(objWorkingList, iCount, fRepeat, strSort, fDesc)); } else { return(objWorkingList); } }