示例#1
0
        public IList <FileInfo> Directory(string path, bool useCache = true)
        {
            if (!_systemio.DirectoryExists(path))
            {
                logger.LogError(path + " not found");
                throw new ArgumentException(path + " not found");
            }

            var result = new List <FileInfo>();

            if (useCache)
            {
                if (!_systemio.DirectoryExists(path + "/.archive"))
                {
                    _systemio.DirectoryCreateDirectory(path + "/.archive");
                }
            }

            var files = _systemio.DirectoryGetFiles(path);

            foreach (var file in files)
            {
                if (useCache)
                {
                    var fileInfo = _systemio.FileInfo(file);
                    if (_systemio.FileExists(path + "/.archive/" + fileInfo.Name))
                    {
                        result.Add(_fileInfoIO.Load(path + "/.archive/" + fileInfo.Name));
                        continue;
                    }
                    else
                    {
                        var infoObject = File(file);
                        result.Add(infoObject);
                        _fileInfoIO.Save(infoObject, path + "/.archive/" + fileInfo.Name);
                    }
                    continue;
                }

                result.Add(File(file));
            }

            return(result);
        }