public List <BookMetadata> Import(string path)
        {
            var result = new List <BookMetadata>();

            if (path[path.Length - 1] == '\\')
            {
                throw new InvalidOperationException($"Path {path} can't end with trailing slash.");
            }

            var bookmarkFiles = Glob.Expand(path + @"\**\*.bmk.txt");

            foreach (var bookmarkFile in bookmarkFiles)
            {
                var folder = Path.GetDirectoryName(bookmarkFile.FullName);

                // check for the txt book
                var txtBookPath = bookmarkFile.FullName.Replace(".bmk.txt", ".txt");
                if (!File.Exists(txtBookPath))
                {
                    Logger.Warn($"Couldn't import book for bookmark file {bookmarkFile.FullName}");
                    continue;
                }

                result.Add(new BookMetadata
                {
                    BookImportType = GetBookImportType(folder),
                    BookmarksPath  = bookmarkFile.FullName,
                    BookPath       = txtBookPath,
                    BookName       = Path.GetFileName(Path.GetDirectoryName(bookmarkFile.FullName))
                });
            }

            return(result);
        }
示例#2
0
        public static IEnumerable <IngestionItem> EnumerateIngestionFiles(
            IngestionInfo ingestionInfo,
            bool parseMetadataFromFile,
            IEnumerable <string>?ingestionCandidatePaths = null,
            string?basePath = null)
        {
            if (ingestionInfo.BasePath is string)
            {
                basePath = basePath is string
                           ?Path.Combine(basePath, ingestionInfo.BasePath)
                               : ingestionInfo.BasePath;
            }

            basePath = ResolveFullPath(basePath ?? ".");

            if (ingestionCandidatePaths is null)
            {
                ingestionCandidatePaths = Glob.Expand(
                    basePath: basePath,
                    pattern: ingestionInfo.PathGlob);
            }

            return(ingestionCandidatePaths
                   .Select(path => (
                               FullPath: path,
                               Match: ingestionInfo.PathFilter?.Match(path)))
                   .Where(item => item.Match is null || item.Match.Success)
                   .Select(item => IngestionItem.FromFileSystem(
                               basePath,
                               item.FullPath,
                               item.Match,
                               parseDuration: parseMetadataFromFile)));
        }
示例#3
0
        public AssetComponents GetGlobComponentsForAsset(IEnumerable <string> assetPaths, string basePath)
        {
            var files        = new List <string>();
            var excludes     = new List <string>();
            var dependencies = new List <string>();

            foreach (var path in assetPaths)
            {
                if (path.StartsWith("!"))
                {
                    excludes.AddRange(Glob.Expand(Path.Combine(basePath, path.Substring(1))).Select(f => f.FullName));
                }
                else if (path.StartsWith("+"))
                {
                    dependencies.AddRange(Glob.Expand(Path.Combine(basePath, path.Substring(1))).Select(f => f.FullName));
                }
                else
                {
                    files.AddRange(Glob.Expand(Path.Combine(basePath, path)).Select(f => f.FullName));
                }
            }

            excludes.AddRange(dependencies);

            var components = new AssetComponents();

            dependencies.ForEach(o => components.Dependencies.Add(() => ReadFile(o)));
            files.Except(excludes).ForEach(o => components.Files.Add(() => ReadFile(o)));

            return(components);
        }
示例#4
0
        public void CanCancel()
        {
            var glob = new Glob(TestDir + @"\dir1\*", FileSystem);

            glob.Cancel();
            var fs = glob.Expand().ToList();

            Assert.Empty(fs);
        }
        private static IEnumerable <string> GetFileNames(IEnumerable <string> fileSpecs)
        {
            IEnumerable <string> fileNames = Enumerable.Empty <string>();

            foreach (string fileSpec in fileSpecs)
            {
                fileNames = fileNames.Concat(Glob.Expand(fileSpec).Select(fsi => fsi.FullName));
            }

            return(fileNames);
        }
示例#6
0
        private static IEnumerable <string> ExpandGlobPatterns(IEnumerable <string> globPatterns)
        {
            var glob      = new Glob();
            var fileNames = new List <string>();

            foreach (var pattern in globPatterns)
            {
                var paths = glob.Expand(pattern);

                fileNames.AddRange(paths.Select(path => path.FullName));
            }

            return(fileNames);
        }
        static List <string> expandGlobPatterns(string[] globPatterns)
        {
            List <string> fileNames = new List <string>();

            foreach (string pattern in globPatterns)
            {
                var paths = Glob.Expand(pattern);

                foreach (var path in paths)
                {
                    fileNames.Add(path.FullName);
                }
            }

            return(fileNames);
        }
示例#8
0
        public IEnumerable <Result> ProcessFiles(
            string globPattern,
            bool showRelativePaths)
        {
            var absoluteBaseDir = Path.GetFullPath(".");
            var pathTransformer = showRelativePaths
                ? ToRelativePath(absoluteBaseDir)
                : Identity;
            var glob = new Glob(globPattern, _fileSystem)
            {
                ErrorLog = HandeGlobError
            };

            return(glob
                   .Expand()
                   .Cast <FileInfoBase>()
                   .Select(fileInfo => fileInfo.FullName)
                   .Select(fullName => (fullName, transformedFileName: pathTransformer(fullName)))
                   .Select(ProcessFile)
                   .ToList());
        }
示例#9
0
        static List <File> expandGlobPatternsForInclude(Dictionary <string, List <string> > includes)
        {
            List <File> files = new List <File>();

            foreach (var inc in includes)
            {
                foreach (var pattern in inc.Value)
                {
                    var globPaths = Glob.Expand(pattern);

                    foreach (var globPath in globPaths)
                    {
                        files.Add(new File()
                        {
                            OutputPath = inc.Key, FilePath = globPath.FullName
                        });
                    }
                }
            }

            return(files);
        }
        public override IEnumerable <SourcingResult> Generate(SourcingContext context)
        {
            var glob  = context.TemplateRoot.FullName + _globPattern;
            var files = Glob.Expand(glob);

            foreach (var file in files)
            {
                // Maybe should throw here?
                if (!File.Exists(file.FullName))
                {
                    continue;
                }

                var fileRelativePath = file.FullName.Replace(context.TemplateRoot.FullName, "");
                yield return(new SourcingResult
                {
                    FilePath = fileRelativePath,
                    FileName = fileRelativePath,
                    Provider = new OpenFileStreamProvider(file.FullName)
                });
            }
        }
示例#11
0
        public void Should_expand_a_pattern_to_its_absolute_path()
        {
            // Arrange
            Glob empty      = null;
            Glob sampleFile = Path.GetTempFileName();
            Glob root       = Path.Combine("C:\\", "websites", "coolapp.com", "src", "wwwroot");

            // Act
            var case1 = ((Glob)@"..\Views").Expand(root);
            var case2 = new Glob("../../index.html").Expand(root);
            var case3 = ((Glob)"..\\file.tmp").Expand(@"%TEMP%\foo", true);
            var case4 = ((Glob)"../").Expand(@"%TEMP%\foo", expandVariables: false);
            var case5 = empty.Expand(root);
            var case6 = sampleFile.Expand(root);

            // Assert
            case1.ShouldEndWith(@"src\Views");
            case2.ShouldEndWith("coolapp.com\\index.html");
            case3.ShouldContain(Environment.ExpandEnvironmentVariables("%TEMP%"));
            case4.ShouldBe("%TEMP%");
            case5.ShouldBe(root);
            case6.ShouldBe(sampleFile);
        }
示例#12
0
        public static IEnumerable <FileSystemInfoBase> Expand(IEnumerable <string> globs, IErrorReporter reporter)
        {
            var files = new List <FileSystemInfoBase>();

            foreach (var glob in globs)
            {
                foreach (var path in Glob.Expand(glob))
                {
                    if (!files.Contains(path))
                    {
                        files.Add(path);
                    }
                }
            }

            if (files.Count == 0)
            {
                reporter.ErrorLine(IcoErrorCode.FileNotFound, "No files matched the inputs.");
                return(null);
            }

            return(files);
        }
示例#13
0
        public Nuspec GetNuGetPackageInformation()
        {
            Nuspec nuspec = null;
            var    nuget  = _slnx.nuget;

            if (nuget != null)
            {
                var    id = SafeExpandAndTrimEnvironmentVariables(nuget.id, SlnxName);
                var    excludePackages           = nuget.excludePackagesSpecified && nuget.excludePackages;
                var    excludeProjects           = nuget.excludeProjectsSpecified && nuget.excludeProjects;
                var    versionString             = SafeExpandAndTrimEnvironmentVariables(nuget.version, null);
                var    targetConfig              = SafeExpandAndTrimEnvironmentVariables(nuget.targetConfig, "Release");
                var    readmeFile                = SafeExpandAndTrimEnvironmentVariables(nuget.readme, null);
                string additionalInformation     = null;
                var    additionalInformationList = nuget.info?.Any?.Select(x => x.OuterXml);

                if (additionalInformationList != null)
                {
                    additionalInformation = SafeExpandEnvironmentVariables(string.Join(Environment.NewLine, additionalInformationList));
                }

                nuspec = new Nuspec(id, versionString, readmeFile, additionalInformation);

                if (!excludeProjects)
                {
                    foreach (var p in Projects)
                    {
                        if (p.IsPackable)
                        {
                            nuspec.AddLibraryElement(p.Framework, p.GetAssemblyPath(targetConfig));
                            var pdb = p.GetPdbPath(targetConfig);
                            if (File.Exists(pdb))
                            {
                                nuspec.AddLibraryElement(p.Framework, pdb);
                            }
                        }
                    }
                }

                if (!excludePackages)
                {
                    foreach (var package in Packages)
                    {
                        var packageIsReferenced = Projects
                                                  .Where(refProject => refProject.IsPackable)
                                                  .Any(refProject =>
                                                       refProject.AllPackageReferences.Any(refPackage => refPackage.Identity.Id.Equals(package.Identity.Id, StringComparison.OrdinalIgnoreCase))
                                                       );

                        if (packageIsReferenced)
                        {
                            nuspec.AddDependeciesPacket(package);
                        }
                        else
                        {
                            _logger?.Info($"The package {package} has no reference in packable projects. It will be excluded from the NuSpec dependencies.");
                        }
                    }
                }

                if (nuget.content != null)
                {
                    foreach (var item in nuget.content)
                    {
                        var value = SafeExpandAndTrimEnvironmentVariables(item.Value);
                        Assert(!string.IsNullOrEmpty(value), $"The value of the item element is not set");
                        Assert(item.targetFramework != null || item.targetFolder != null, $"The targetFramework or the targetFolder attribute in the item element must be set. The value of the element is: {item.Value}");
                        Assert((item.targetFramework != null && item.targetFolder == null) || (item.targetFramework == null && item.targetFolder != null), $"The targetFramework and the targetFolder attribute cannot be both set on an item. The value of the element is: {item.Value}");

                        var filtered = Glob.Expand(value);

                        Assert(filtered.Any(), $"The provided content item-path in the <nuget> element did not match any file.\n{item.Value}");

                        foreach (var f in filtered)
                        {
                            if (item.targetFramework != null)
                            {
                                nuspec.AddLibraryElement(item.targetFramework, f.FullName);
                            }
                            if (item.targetFolder != null)
                            {
                                nuspec.AddGenericFile(item.targetFolder, f.FullName);
                            }
                        }
                    }
                }
            }
            return(nuspec);
        }
示例#14
0
文件: Tests.cs 项目: iobajwa/Glob.cs
        public void CanUseStaticMethods()
        {
            var fs = Glob.Expand(FixPath(TestDir + @"\dir1\abc"), ignoreCase: true, dirOnly: false, fileSystem: FileSystem).Select(f => f.FullName).ToList();

            AssertEqual(fs, @"\dir1\abc");
        }
示例#15
0
 /* Generic Utils */
 public static FileSystemInfoBase[] Expand(string pattern)
 {
     return(Glob.Expand(pattern.Replace('/', '\\')).ToArray());
 }
示例#16
0
 private static IEnumerable <IFileSystemInfo> GetFileByExtensionFromFolder(string folderPath, string filePattern)
 {
     return(Glob.Expand(folderPath + @"\" + filePattern));
 }