Esempio n. 1
0
        public IEnumerable <DiscoveryResult> DiscoverPath(string path, bool includeFiles)
        {
            IEnumerable <DiscoveryResult> result = Enumerable.Empty <DiscoveryResult>();

            try
            {
                var directories = Directory.GetDirectories(path)
                                  .Where(
                    dirPath => AccessUtility.HasAccess(dirPath)
                    )
                                  .Select(
                    dirPath => new DiscoveryResult(dirPath)
                    );

                result = result.Concat(directories);

                if (includeFiles)
                {
                    var files = Directory.GetFiles(path)
                                .Where(
                        filePath => AccessUtility.HasAccess(filePath)
                        )
                                .Select(
                        filePath => new DiscoveryResult(filePath)
                        );
                    result = result.Concat(files);
                }
            }
            catch (Exception exc)
            {
                _logger.LogError(1, exc, "Error listing directory and files");
            }

            return(result);
        }
        private DiscoveryResult RecursiveScan(DiscoveryResult parent)
        {
            var path        = parent.Path;
            var directories = Directory.GetDirectories(path)
                              .Where(filePath => AccessUtility.HasAccess(filePath))
                              .ToList().Select(filePath => new DiscoveryResult(filePath));

            foreach (var directory in directories)
            {
                RecursiveScan(directory);
                parent.AddChild(directory);
            }
            var files = Directory.GetFiles(path).ToList()
                        .Where(filePath => AccessUtility.HasAccess(filePath))
                        .Where(file =>
                               VideoFile.Extensions.Contains(Path.GetExtension(file), new ExtensionComparer())
                               )

                        .Select(filePath => new DiscoveryResult(filePath));

            foreach (var file in files)
            {
                parent.AddChild(file);
            }

            return(parent);
        }