コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public List <FileModel> GetDoucuments()
        {
            var orgXmlStr = GetOrg();

            ProcessOn?.BeginInvoke("获取组织结构", 0, null, null);
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(orgXmlStr);
            var groupItems = xmlDoc.SelectNodes("//GroupItem");
            var fileModels = new List <FileModel>();

            foreach (XmlNode item in groupItems)
            {
                var id = item.Attributes["Id"].Value;
                if (id == "0")
                {
                    continue;
                }
                _currentPath = Path.Combine(_rootPath, item.Attributes["Name"].Value);
                var files = GetFiles(ownderid: id, item.Attributes["Name"].Value);
                fileModels.AddRange(files);
            }
            return(fileModels);
        }
コード例 #2
0
        /// <summary>
        /// 获取文件信息
        /// </summary>
        /// <param name="ownderid"></param>
        /// <param name="floderid"></param>
        /// <param name="floderName"></param>
        /// <returns></returns>
        public List <FileModel> GetFiles(string ownderid, string ownderName, string floderid = "0")
        {
            #region 创建目录

            var path = CreateFolder(ownderName);

            #endregion

            #region 获取文件

            var fileModels = new List <FileModel>();
            if (ownderid == "0")
            {
                return(fileModels);
            }
            var url = $"{IPAddress}/ufInterface?opr=folderfiles&ownerid={ownderid}" +
                      $"&folderid={floderid}&count=2048&sortid=1&sortstyle=1&isfiletx=0" +
                      $"&hash2={HashKey}";
            var rst    = GetHttp(url, _outtime);
            var xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(rst);
            var dataNode = xmlDoc.SelectSingleNode("Data");
            if (dataNode != null)// 这里是第一次请求获取所有目录,不会涉及文件
            {
                foreach (XmlNode item in dataNode.ChildNodes)
                {
                    var id    = item.Attributes["Id"].Value;
                    var pid   = item.Attributes["FatherId"].Value;
                    var name  = item.FirstChild.InnerText;
                    var bitem = new FileModel
                    {
                        Id       = id,
                        ParentId = pid,
                        Name     = name,
                        Type     = 0
                    };
                    if (id != "0") // 获取下当前目的文件
                    {
                        bitem.Children.AddRange(GetFiles(ownderid, name, id));
                    }
                    var child    = item.SelectSingleNode("Childs");
                    var children = child.SelectNodes("Item");
                    if (children != null)
                    {
                        foreach (XmlNode citem in children)
                        {
                            var cid = citem.Attributes["Id"].Value;
                            if (cid != "0")
                            {
                                var on = Path.Combine(ownderName, citem.SelectSingleNode("Path").InnerText);
                                bitem.Children.AddRange(GetFiles(ownderid, on, cid));
                            }
                        }
                    }
                    fileModels.Add(bitem);
                }
            }
            else
            {
                var folders = xmlDoc.SelectNodes("//Folder");
                foreach (XmlNode folder in folders)
                {
                    var name = folder.Attributes["Name"].Value;
                    var p    = new FileModel()
                    {
                        Name = name,
                        Type = 0,
                    };
                    var fileItems = folder.SelectSingleNode("FileItems");
                    foreach (XmlNode item in fileItems.ChildNodes)
                    {
                        ProcessOn?.BeginInvoke($"获取文件:{item.Attributes["Name"].Value}", 0, null, null);
                        var fileModel = new FileModel
                        {
                            Id   = item.Attributes["FileKey"].Value,
                            Name = item.Attributes["Name"].Value,
                            Type = 1,
                            Size = item.Attributes["Size"].Value,
                        };

                        System.Diagnostics.Debugger.Log(0, "dwonload", item.Attributes["Name"].Value);
                        fileModel.FilePath = Download(fileModel.Id, path);
                        p.Children.Add(fileModel);
                    }
                    // subfolder
                    var subfolders = folder.SelectSingleNode("SubFolders");
                    foreach (XmlNode item in subfolders)
                    {
                        var sid = item.Attributes["Id"].Value;
                        var on  = Path.Combine(ownderName, item.InnerText);
                        p.Children.AddRange(GetFiles(ownderid, on, sid));
                    }
                    fileModels.Add(p);
                }
            }
            #endregion

            return(fileModels);
        }