IRowReceiveRelation RecursiveFromDirectory(DirectoryInfo di)
        {
            if (ExcludeFolderNames?.Length > 0)
            {
                //TODO: case insensitive
                if (ExcludeFolderNames.Contains(di.Name))
                {
                    return(null);
                }
            }
            var rh = DirectoryRow(di);

            rh.Relations.Add("files", Files(di));
            var folders = new List <IRowReceiveRelation>();

            rh.Relations.Add("folders", folders);
            foreach (var folder in di.EnumerateDirectories())
            {
                var dir = RecursiveFromDirectory(folder);
                if (dir != null)
                {
                    folders.Add(dir);
                }
            }
            return(rh);
        }
示例#2
0
        IRowReceiveHierarchicalParent[] RecursiveFromDirectory(DirectoryInfo di, IRowReceive parent)
        {
            if (ExcludeFolderNames?.Length > 0)
            {
                //TODO: case insensitive
                if (ExcludeFolderNames.Contains(di.Name))
                {
                    return(null);
                }
            }

            var ret = new List <IRowReceiveHierarchicalParent>();

            //var di = new DirectoryInfo(FolderName);
            try
            {
                var rh = DirectoryRow(di);
                if (parent != null)
                {
                    rh.Parent = parent as IRowReceiveHierarchicalParent;
                }

                ret.Add(rh);

                var files = Files(di, rh);

                if (files?.Length > 0)
                {
                    ret.AddRange(files);
                }
                rh.Values.Add("nrfiles", files?.Length);

                foreach (var dir in di.EnumerateDirectories())
                {
                    var filesFolders = RecursiveFromDirectory(dir, rh);
                    if (filesFolders?.Length > 0)
                    {
                        ret.AddRange(filesFolders.Where(it => it != null).ToArray());
                    }
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                string message = ex.Message;
                //@class.Log(LogLevel.Warning,0,$"unauthorized {message}",ex,null);
                message += "text";
            }
            return(ret.ToArray());
        }