public void MigrateFromPattern(string cwd, List <string> patterns, List <string> excludePatterns, string outputFolder)
        {
            var files = FileGlob.GetFiles(cwd, patterns, excludePatterns).ToList();

            if (files.Count == 0)
            {
                Console.WriteLine("No file found from the glob pattern provided.");
            }

            //var ph = ProgressHelper.CreateStartedInstance(files.Count(), "Migrating Files");

            if (string.IsNullOrEmpty(outputFolder))
            {
                Parallel.ForEach(files, file =>
                {
                    MigrateFile(file, file);
                    //ph.Increase();
                });
                return;
            }

            Parallel.ForEach(files, file =>
            {
                var name       = Path.GetFileName(file);
                var outputFile = Path.Combine(outputFolder, name);
                MigrateFile(file, outputFile);
            });
        }
예제 #2
0
        public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping)
        {
            if (fileMapping == null)
            {
                return(null);
            }

            if (fileMapping.Expanded)
            {
                return(fileMapping);
            }

            var expandedFileMapping = new FileMapping();

            foreach (var item in fileMapping.Items)
            {
                // Use local variable to avoid different items influencing each other
                var cwd     = Path.Combine(baseDirectory, item.CurrentWorkingDirectory ?? string.Empty);
                var options = GetMatchOptionsFromItem(item);
                var files   = FileGlob.GetFiles(cwd, item.Files, item.Exclude, options).ToArray();
                if (files.Length == 0)
                {
                    Logger.LogInfo($"No files are found with glob pattern {item.Files.ToDelimitedString() ?? "<none>"}, excluding {item.Exclude.ToDelimitedString() ?? "<none>"}, under working directory {baseDirectory ?? "<current>"}");
                }
                expandedFileMapping.Add(
                    new FileMappingItem
                {
                    CurrentWorkingDirectory = cwd,
                    Files = new FileItems(files),
                });
            }

            expandedFileMapping.Expanded = true;
            return(expandedFileMapping);
        }
예제 #3
0
        private void MigrateFromPattern(string cwd, List <string> patterns, List <string> excludePatterns, string outputFolder)
        {
            var files = FileGlob.GetFiles(cwd, patterns, excludePatterns).ToList();

            if (files.Count == 0)
            {
                Console.WriteLine("No file found from the glob pattern provided.");
            }

            if (string.IsNullOrEmpty(outputFolder))
            {
                foreach (var file in files)
                {
                    MigrateFile(file, file);
                }
            }
            else
            {
                foreach (var file in files)
                {
                    var name       = Path.GetFileName(file);
                    var outputFile = Path.Combine(outputFolder, name);
                    MigrateFile(file, outputFile);
                }
            }
        }
예제 #4
0
        private static void FindVariation(string folder, string glob)
        {
            var files     = FileGlob.GetFiles(folder, new[] { glob }, new string[0]);
            var oldProxy  = GetMarkProxy(CreateDomain("old", "old.config"));
            var newDomain = CreateDomain("new", "new/new.config");
            var newProxy  = GetMarkProxy(newDomain);

            foreach (var file in files)
            {
                var markdown    = File.ReadAllText(file);
                var oldTreeJson = oldProxy.Parse(markdown);
                var newTreeJson = newProxy.Parse(markdown);
                Compare(file, oldTreeJson, newTreeJson);
            }
        }
예제 #5
0
        public ParseResult Exec(RunningContext context)
        {
            var outputFile = Path.Combine(_options.OutputFolder ?? Environment.CurrentDirectory, _options.Name ?? "externalreference.rpk");

            try
            {
                var baseUri = new Uri(_options.BaseUrl);
                if (!baseUri.IsAbsoluteUri)
                {
                    return(new ParseResult(ResultLevel.Error, "BaseUrl should be absolute url."));
                }
                var source = _options.Source.TrimEnd('/', '\\');
                using (var package = _options.AppendMode ? ExternalReferencePackageWriter.Append(outputFile, baseUri) : ExternalReferencePackageWriter.Create(outputFile, baseUri))
                {
                    var files = FileGlob.GetFiles(source, new string[] { _options.Glob }, null).ToList();
                    if (_options.FlatMode)
                    {
                        package.AddFiles(string.Empty, files);
                    }
                    else
                    {
                        foreach (var g in from f in files
                                 group f by Path.GetDirectoryName(f) into g
                                 select new
                        {
                            Folder = g.Key.Substring(source.Length).Replace('\\', '/').Trim('/'),
                            Files = g.ToList(),
                        })
                        {
                            if (g.Folder.Length == 0)
                            {
                                package.AddFiles(string.Empty, g.Files);
                            }
                            else
                            {
                                package.AddFiles(g.Folder + "/", g.Files);
                            }
                        }
                    }
                }
                return(ParseResult.SuccessResult);
            }
            catch (Exception ex)
            {
                return(new ParseResult(ResultLevel.Error, ex.ToString()));
            }
        }
예제 #6
0
        public void Exec(SubCommandRunningContext context)
        {
            var outputFile = Path.Combine(_options.OutputFolder ?? Environment.CurrentDirectory, _options.Name ?? "externalreference.rpk");
            var baseUri    = new Uri(_options.BaseUrl);

            if (!baseUri.IsAbsoluteUri)
            {
                throw new InvalidOptionException("BaseUrl should be absolute url.", "BaseUrl");
            }

            var source = _options.Source.TrimEnd('/', '\\');

            using (var package = _options.AppendMode ? ExternalReferencePackageWriter.Append(outputFile, baseUri) : ExternalReferencePackageWriter.Create(outputFile, baseUri))
            {
                var files = FileGlob.GetFiles(source, new string[] { _options.Glob }, null).ToList();
                if (_options.FlatMode)
                {
                    ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, string.Empty, files);
                }
                else
                {
                    foreach (var g in from f in files
                             group f by Path.GetDirectoryName(f) into g
                             select new
                    {
                        Folder = g.Key.Substring(source.Length).Replace('\\', '/').Trim('/'),
                        Files = g.ToList(),
                    })
                    {
                        if (g.Folder.Length == 0)
                        {
                            ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, string.Empty, g.Files);
                        }
                        else
                        {
                            ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, g.Folder + "/", g.Files);
                        }
                    }
                }
            }
        }
예제 #7
0
파일: GlobUtility.cs 프로젝트: ye-man/docfx
        public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping)
        {
            if (fileMapping == null)
            {
                return(null);
            }
            if (fileMapping.Expanded)
            {
                return(fileMapping);
            }

            var expandedFileMapping = new FileMapping();

            foreach (var item in fileMapping.Items)
            {
                var src       = Path.Combine(baseDirectory, item.SourceFolder ?? string.Empty);
                var options   = GetMatchOptionsFromItem(item);
                var fileItems = new FileItems(FileGlob.GetFiles(src, item.Files, item.Exclude, options));
                if (fileItems.Count == 0)
                {
                    var currentSrcFullPath = string.IsNullOrEmpty(src) ? Directory.GetCurrentDirectory() : Path.GetFullPath(src);
                    Logger.LogInfo($"No files are found with glob pattern {StringExtension.ToDelimitedString(item.Files) ?? "<none>"}, excluding {StringExtension.ToDelimitedString(item.Exclude) ?? "<none>"}, under directory \"{currentSrcFullPath}\"");
                    CheckPatterns(item.Files);
                }
                if (item.Exclude != null)
                {
                    CheckPatterns(item.Exclude);
                }
                expandedFileMapping.Add(
                    new FileMappingItem
                {
                    SourceFolder      = src,
                    Files             = fileItems,
                    DestinationFolder = item.DestinationFolder
                });
            }

            expandedFileMapping.Expanded = true;
            return(expandedFileMapping);
        }
예제 #8
0
파일: Program.cs 프로젝트: zyj0021/docfx
        private List <string> GetAllFiles()
        {
            // just guess: the bigger files contains more apis/types.
            var files = (from file in FileGlob.GetFiles(_baseDirectory, new string[] { _globPattern }, null)
                         let fi = new FileInfo(file)
                                  orderby fi.Length
                                  select file).ToList();

            if (files.Count > 0)
            {
                Console.WriteLine("Loading comment id from:");
                foreach (var file in files)
                {
                    Console.WriteLine(file);
                }
            }
            else
            {
                Console.WriteLine("File not found.");
            }
            return(files);
        }
예제 #9
0
        public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping)
        {
            if (fileMapping == null)
            {
                return(null);
            }

            if (fileMapping.Expanded)
            {
                return(fileMapping);
            }

            var expandedFileMapping = new FileMapping();

            foreach (var item in fileMapping.Items)
            {
                // Use local variable to avoid different items influencing each other
                var src     = Path.Combine(baseDirectory, item.SourceFolder ?? string.Empty);
                var options = GetMatchOptionsFromItem(item);
                var files   = FileGlob.GetFiles(src, item.Files, item.Exclude, options).ToArray();
                if (files.Length == 0)
                {
                    var currentSrcFullPath = string.IsNullOrEmpty(src) ? Directory.GetCurrentDirectory() : Path.GetFullPath(src);
                    Logger.LogInfo($"No files are found with glob pattern {item.Files.ToDelimitedString() ?? "<none>"}, excluding {item.Exclude.ToDelimitedString() ?? "<none>"}, under directory \"{currentSrcFullPath}\"");
                    CheckPatterns(item.Files);
                }
                expandedFileMapping.Add(
                    new FileMappingItem
                {
                    SourceFolder      = src,
                    Files             = new FileItems(files),
                    DestinationFolder = item.DestinationFolder
                });
            }

            expandedFileMapping.Expanded = true;
            return(expandedFileMapping);
        }
예제 #10
0
        public void TestGlobGetFilesShouldAbleToGetFiles()
        {
            // - Root/
            //   |- A.cs
            //   |- B.cs
            //   |- C/
            //   |  |- D.cs
            //   |- E/
            //   |  |- F.cs
            //   |  |- G.csproj
            //   |  |- H/
            //   |  |   |- I.jpg
            //   |- J/
            //   |  |- K.md
            //   |- M/
            //      |- N.md
            //      |- L/
            //         |- O.md
            // - .Hidden/
            var files = new string[]
            {
                "Root/A.cs",
                "Root/B.cs",
                "Root/C/D.cs",
                "Root/E/F.cs",
                "Root/E/G.csproj",
                "Root/E/H/I.jpg",
                "Root/J/K.md",
                "Root/M/N.md",
                "Root/M/L/O.md",
                ".Hidden/",
            };

            CreateFilesOrFolders(_workingDirectory, files);
            var result = FileGlob.GetFiles(
                _workingDirectory,
                new string[] { "**.md" },
                null).ToArray();

            Assert.Equal(3, result.Length);
            result = FileGlob.GetFiles(
                _workingDirectory,
                null,
                new string[] { "**.md" }).ToArray();
            Assert.Empty(result);
            result = FileGlob.GetFiles(
                _workingDirectory,
                new string[] { "**" },
                new string[] { "**.md" }).ToArray();
            Assert.Equal(6, result.Length);
            result = FileGlob.GetFiles(
                _workingDirectory,
                new string[] { "**.md" },
                new string[] { "**{J,L}/**" }).ToArray();
            Assert.Single(result);
            result = FileGlob.GetFiles(
                _workingDirectory,
                new string[] { "**.md", "**.csproj" },
                new string[] { "**J/**", "**/M/**" }).ToArray();
            Assert.Single(result);
            result = FileGlob.GetFiles(
                _workingDirectory + "/Root",
                new string[] { "[EJ]/*.{md,cs,csproj}" },
                new string[] { "**.cs" }).ToArray();
            Assert.Equal(2, result.Length);
        }