Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        public static ArrayList DAVGetData(WebUtil objWebUtil, string strRoot)
        {
            ArrayList objResult = new ArrayList();

            if (strRoot == "" || strRoot == null)
            {
                strRoot = "http://groups.msn.com";
            }

            // Build the query.
            string folderQuery = null;

            folderQuery += "<?xml version='1.0' encoding='UTF-8' ?>";
            folderQuery += "<a:propfind xmlns:a='DAV:' xmlns:b='urn:schemas-microsoft-com:datatypes'>";
            folderQuery += "<a:prop>";
            folderQuery += "<a:name/>";
            folderQuery += "<a:parentname/>";
            folderQuery += "<a:href/>";
            folderQuery += "<a:ishidden/>";
            folderQuery += "<a:isreadonly/>";
            folderQuery += "<a:getcontenttype/>";
            folderQuery += "<a:contentclass/>";
            folderQuery += "<a:getcontentlanguage/>";
            folderQuery += "<a:creationdate/>";
            folderQuery += "<a:lastaccessed/>";
            folderQuery += "<a:getlastmodified/>";
            folderQuery += "<a:getcontentlength/>";
            folderQuery += "<a:iscollection/>";
            folderQuery += "<a:isstructureddocument/>";
            folderQuery += "<a:defaultdocument/>";
            folderQuery += "<a:displayname/>";
            folderQuery += "<a:isroot/>";
            folderQuery += "<a:resourcetype/>";
            folderQuery += "</a:prop>";
            folderQuery += "</a:propfind>";

            // Declare locals.
            HttpWebRequest  request  = null;
            HttpWebResponse response = null;

            // We need to try a few times to hit the server

            // Get the response
            int iTryCount = 2;

            while (iTryCount > 0 && response == null)
            {
                try
                {
                    // Setup the request
                    request                 = (HttpWebRequest)WebRequest.Create(strRoot);
                    request.Method          = "PROPFIND";
                    request.CookieContainer = new CookieContainer();
                    request.CookieContainer.Add(objWebUtil.cookies);
                    request.AllowAutoRedirect = false;
                    request.UserAgent         = "Microsoft Data Access Internet Publishing Provider DAV";
                    request.Headers.Add("PROPFIND", folderQuery);
                    request.Headers.Add("Depth", "1");
                    request.Headers.Add("Translate", "f");

                    // Get the response
                    response = (HttpWebResponse)request.GetResponse();
                }
                catch (WebException e)
                {
                    if (iTryCount == 1)
                    {
                        throw e;
                    }
                }
                iTryCount--;
            }

            string strResult = new StreamReader(response.GetResponseStream()).ReadToEnd();

            //Console.WriteLine(strResult);

            // Store the response cookies
            objWebUtil.cookies.Add(response.Cookies);

            // Get the xml dom from the string
            XmlDocument xmldoc = new XmlDocument();

            // For some reason, I can't get multiple namespaces to work in this parser.
            // I'm going to cheat and simply eliminate them from the xml before I parse.
            // Ugly, but works.

            strResult = strResult.Replace("a:", "");
            strResult = strResult.Replace("b:", "");

            //Console.WriteLine(strResult);

            xmldoc.LoadXml(strResult);


            XmlNodeList nlist = xmldoc.SelectNodes("//response");

            for (int i = 0; i < nlist.Count; i++)
            {
                XmlNode n = nlist[i];

                string strName = HttpUtility.UrlDecode(n.SelectSingleNode("href").InnerText);

                if (strName.ToLower() != strRoot.ToLower())
                {
                    DavItem objDavItem = new DavItem();

                    objDavItem.strName        = strName;
                    objDavItem.strDisplayName = n.SelectSingleNode("propstat/prop/displayname").InnerText;
                    objDavItem.fIsCollection  = (n.SelectSingleNode("propstat/prop/iscollection").InnerText == "1");
                    objDavItem.fIsHidden      = (n.SelectSingleNode("propstat/prop/ishidden").InnerText == "1");
                    objDavItem.iContentLength = Convert.ToInt32(n.SelectSingleNode("propstat/prop/getcontentlength").InnerText);
                    objDavItem.strContentType = n.SelectSingleNode("propstat/prop/getcontenttype").InnerText;
                    objDavItem.dtCreated      = Convert.ToDateTime(n.SelectSingleNode("propstat/prop/creationdate").InnerText);
                    objDavItem.dtModified     = Convert.ToDateTime(n.SelectSingleNode("propstat/prop/getlastmodified").InnerText);

                    objResult.Add(objDavItem);
                }
            }


            return(objResult);
        }