コード例 #1
0
 internal PatternGroup(IEnumerable <string> includePatterns)
 {
     IncludeLiterals = Enumerable.Empty <string>();
     IncludePatterns = includePatterns;
     ExcludePatterns = Enumerable.Empty <string>();
     _matcher.AddIncludePatterns(IncludePatterns);
 }
コード例 #2
0
ファイル: IncludeFilesResolver.cs プロジェクト: wtgodbe/cli
        private static IEnumerable <FilePatternMatch> GetIncludeFilesCore(
            string sourceBasePath,
            List <string> includePatterns,
            List <string> excludePatterns,
            List <string> includeFiles,
            List <string> builtInsInclude,
            List <string> builtInsExclude)
        {
            var literalIncludedFiles = new List <string>();

            if (includeFiles != null)
            {
                // literal included files are added at the last, but the search happens early
                // so as to make the process fail early in case there is missing file. fail early
                // helps to avoid unnecessary globing for performance optimization
                foreach (var literalRelativePath in includeFiles)
                {
                    var fullPath = Path.GetFullPath(Path.Combine(sourceBasePath, literalRelativePath));

                    if (!File.Exists(fullPath))
                    {
                        throw new InvalidOperationException(string.Format("Can't find file {0}", literalRelativePath));
                    }

                    literalIncludedFiles.Add(fullPath);
                }
            }

            // Globbing
            var matcher = new Matcher();

            if (builtInsInclude != null)
            {
                matcher.AddIncludePatterns(builtInsInclude);
            }
            if (includePatterns != null)
            {
                matcher.AddIncludePatterns(includePatterns);
            }
            if (builtInsExclude != null)
            {
                matcher.AddExcludePatterns(builtInsExclude);
            }
            if (excludePatterns != null)
            {
                matcher.AddExcludePatterns(excludePatterns);
            }

            return(matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(sourceBasePath))).Files);
        }
コード例 #3
0
        private Task LoadDirectoryFiles()
        {
            string rootDir = null;

            if (_initParams.rootUri != null)
            {
                rootDir = _initParams.rootUri.ToAbsolutePath();
            }
            else if (!string.IsNullOrEmpty(_initParams.rootPath))
            {
                rootDir = PathUtils.NormalizePath(_initParams.rootPath);
            }

            if (string.IsNullOrEmpty(rootDir))
            {
                return(Task.CompletedTask);
            }

            var matcher  = new Matcher();
            var included = _initParams.initializationOptions.includeFiles;

            matcher.AddIncludePatterns(included != null && included.Length > 0 ? included : new[] { "**/*" });
            matcher.AddExcludePatterns(_initParams.initializationOptions.excludeFiles ?? Enumerable.Empty <string>());

            var dib         = new DirectoryInfoWrapper(new DirectoryInfo(rootDir));
            var matchResult = matcher.Execute(dib);

            _server.LogMessage(MessageType.Log, $"Loading files from {rootDir}");
            return(LoadFromDirectoryAsync(rootDir, matchResult));
        }
コード例 #4
0
        private bool ProcessGlob()
        {
            this.Log.AddInfo(string.Format(Util.CLEANUP_Processing, this.Version.ToString(3)));
            try
            {
                if (this._glob.Contains(".."))
                {
                    this.Log.AddWarning(Util.EXCEPTION + " - " + Util.EXCEPTION_GlobDotDotNotSupportedInCleanup);
                }
                else
                {
                    var globs = new Matcher(StringComparison.InvariantCultureIgnoreCase);
                    globs.AddIncludePatterns(this._glob.Split(';'));
                    var files = globs.GetResultsInFullPath(Globals.ApplicationMapPath).ToArray();
                    FileSystemUtils.DeleteFiles(files);
                }
            }
            catch (Exception ex)
            {
                this.Log.AddWarning(string.Format(Util.CLEANUP_ProcessError, ex.Message));
            }

            this.Log.AddInfo(string.Format(Util.CLEANUP_ProcessComplete, this.Version.ToString(3)));
            return(true);
        }
コード例 #5
0
        private static IEnumerable <string> GetCompileFullPaths(XElement compile, string includeOrRemovePattern, string csProjRoot)
        {
            if (string.IsNullOrEmpty(csProjRoot))
            {
                csProjRoot = "./";
            }

            // solve macro
            includeOrRemovePattern = includeOrRemovePattern.Replace("$(ProjectDir)", csProjRoot).Replace("$(MSBuildProjectDirectory)", csProjRoot);

            var matcher = new Matcher(StringComparison.OrdinalIgnoreCase);

            matcher.AddIncludePatterns(includeOrRemovePattern.Split(';'));
            var exclude = compile?.Attribute("Exclude")?.Value;

            if (exclude != null)
            {
                matcher.AddExcludePatterns(exclude.Split(';'));
            }

            foreach (var path in matcher.GetResultsInFullPath(csProjRoot))
            {
                yield return(path);
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: jim-dale/VideoTools
        private static void ProcessInputDirectory(AppContext appContext)
        {
            var patterns = appContext.SearchPatterns.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            var matcher = new Matcher();

            matcher.AddIncludePatterns(patterns);

            var files = matcher.GetResultsInFullPath(appContext.InputDirectory);

            foreach (var file in files)
            {
                try
                {
                    using (Log.Logger.BeginTimedOperation("Process file", file))
                    {
                        var fileContext = new FileContext(appContext, file);

                        fileContext.ProcessFile();
                    }
                }
                catch (Exception exception)
                {
                    Log.Error(exception, "Failed to process {Path}", file);
                }
            }
        }
コード例 #7
0
ファイル: SendToRemoteCommand.cs プロジェクト: zachwieja/RTVS
        public async Task <bool> TryHandleCommandAsync(IImmutableSet <IProjectTree> nodes, long commandId, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut)
        {
            _appShell.AssertIsOnMainThread();
            if (commandId != RPackageCommandId.icmdSendToRemote)
            {
                return(false);
            }

            var    properties = _configuredProject.Services.ExportProvider.GetExportedValue <ProjectProperties>();
            string projectDir = Path.GetDirectoryName(_configuredProject.UnconfiguredProject.FullPath);

            string fileFilterString = await properties.GetFileFilterAsync();

            Matcher matcher = new Matcher(StringComparison.OrdinalIgnoreCase);

            matcher.AddIncludePatterns(fileFilterString.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries));

            List <string> filteredFiles = new List <string>();

            filteredFiles.AddRange(matcher.GetMatchedFiles(nodes.GetAllFolderPaths(_configuredProject.UnconfiguredProject)));

            // Add any file that user specifically selected. This can contain a file ignored by the filter.
            filteredFiles.AddRange(nodes.Where(n => n.IsFile()).Select(n => n.FilePath));

            string projectName = properties.GetProjectName();
            string remotePath  = await properties.GetRemoteProjectPathAsync();

            if (filteredFiles.Count > 0)
            {
                await SendToRemoteAsync(filteredFiles.Distinct(), projectDir, projectName, remotePath);
            }

            return(true);
        }
コード例 #8
0
        private async Task SendProjectAsync(EnvDTE.Project project, string remotePath, string filterString)
        {
            ProgressOutputWriter.WriteLine("Preparing to transfer project.");

            var projectDir  = Path.GetDirectoryName(project.FullName);
            var projectName = Path.GetFileNameWithoutExtension(project.FullName);

            string[] filterSplitter = { ";" };
            Matcher  matcher        = new Matcher(StringComparison.InvariantCultureIgnoreCase);

            matcher.AddIncludePatterns(filterString.Split(filterSplitter, StringSplitOptions.RemoveEmptyEntries));

            ProgressOutputWriter.WriteLine($"Remote destination: {remotePath}");
            ProgressOutputWriter.WriteLine($"File filter applied: {filterString}");
            ProgressOutputWriter.WriteLine("Compressing project files for transfer: ");

            var compressedFilePath = FileSystem.CompressDirectory(projectDir, matcher, new Progress <string>((p) => {
                ProgressOutputWriter.WriteLine($"Compressing: {p}");
            }), CancellationToken.None);

            using (var fts = new FileTransferSession(Session, FileSystem)) {
                ProgressOutputWriter.Write("Transferring project to remote host...");
                var remoteFile = await fts.SendFileAsync(compressedFilePath);

                await Session.EvaluateAsync <string>($"rtvs:::save_to_project_folder({remoteFile.Id}, {projectName.ToRStringLiteral()}, '{remotePath.ToRPath()}')", REvaluationKind.Normal);
            }

            ProgressOutputWriter.WriteLine(" done.");
        }
コード例 #9
0
ファイル: ForEachFile.cs プロジェクト: jim-dale/CropScan
        public void Run(string path, string include, string exclude, Action <string> action)
        {
            var matcher = new Matcher(StringComparison.OrdinalIgnoreCase);

            if (string.IsNullOrEmpty(include))
            {
                matcher.AddInclude("**/*");
            }
            else
            {
                var tmp = include.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                matcher.AddIncludePatterns(tmp);
            }
            if (string.IsNullOrEmpty(exclude) == false)
            {
                var tmp = exclude.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                matcher.AddExcludePatterns(tmp);
            }

            var files = matcher.GetResultsInFullPath(path)
                        .ToList();

            if (files.Any())
            {
                foreach (var file in files)
                {
                    action?.Invoke(file);
                }
            }
        }
コード例 #10
0
ファイル: CLI.cs プロジェクト: mika-f/Unity-VariationPackager
        private static string CreateUnityPackage(IPackage meta, IPackageVariation variation)
        {
            var matcher = new Matcher();

            matcher.AddIncludePatterns(variation.UnityPackage.Includes);
            matcher.AddExclude("**/*.meta");
            if (variation.UnityPackage.Excludes != null)
            {
                matcher.AddExcludePatterns(variation.UnityPackage.Excludes);
            }

            var rootDirectory = new DirectoryInfoWrapper(new DirectoryInfo(Application.dataPath));
            var assets        = matcher.Execute(rootDirectory).Files.Select(w => $"Assets/{w.Path}");

            var destDirectory = Path.Combine(Application.dataPath, meta.Describe.Output);

            if (!Directory.Exists(destDirectory))
            {
                Directory.CreateDirectory(destDirectory);
            }

            var destName  = string.IsNullOrWhiteSpace(variation.UnityPackage.Name) ? $"{meta.Name}.unitypackage" : $"{variation.UnityPackage.Name}.unitypackage";
            var publishTo = Path.Combine(destDirectory, destName);

            if (File.Exists(publishTo))
            {
                File.Delete(publishTo);
            }

            AssetDatabase.ExportPackage(assets.ToArray(), publishTo, ExportPackageOptions.Default);

            return(publishTo);
        }
コード例 #11
0
        private async Task SendProjectAsync(EnvDTE.Project project, string remotePath, string filterString, CancellationToken cancellationToken)
        {
            Console.WriteLine(Resources.Info_PreparingProjectForTransfer);

            var projectDir  = Path.GetDirectoryName(project.FullName);
            var projectName = Path.GetFileNameWithoutExtension(project.FullName);

            string[] filterSplitter = { ";" };
            Matcher  matcher        = new Matcher(StringComparison.InvariantCultureIgnoreCase);

            matcher.AddIncludePatterns(filterString.Split(filterSplitter, StringSplitOptions.RemoveEmptyEntries));

            Console.WriteLine(Resources.Info_RemoteDestination.FormatInvariant(remotePath));
            Console.WriteLine(Resources.Info_FileTransferFilter.FormatInvariant(filterString));
            Console.WriteLine(Resources.Info_CompressingFiles);

            var compressedFilePath = FileSystem.CompressDirectory(projectDir, matcher, new Progress <string>((p) => {
                Console.WriteLine(Resources.Info_LocalFilePath.FormatInvariant(p));
                string dest = p.MakeRelativePath(projectDir).ProjectRelativePathToRemoteProjectPath(remotePath, projectName);
                Console.WriteLine(Resources.Info_RemoteFilePath.FormatInvariant(dest));
            }), CancellationToken.None);

            using (var fts = new DataTransferSession(Session, FileSystem)) {
                Console.WriteLine(Resources.Info_TransferringFiles);
                var remoteFile = await fts.SendFileAsync(compressedFilePath, true, null, cancellationToken);

                await Session.EvaluateAsync <string>($"rtvs:::save_to_project_folder({remoteFile.Id}, {projectName.ToRStringLiteral()}, '{remotePath.ToRPath()}')", REvaluationKind.Normal, cancellationToken);
            }

            Console.WriteLine(Resources.Info_TransferringFilesDone);
        }
コード例 #12
0
        static string[] GetFilePathsFromGlobPatterns(string rootPath, string[] globPatterns)
        {
            var matcher = new Matcher(StringComparison.CurrentCultureIgnoreCase);

            matcher.AddExcludePatterns(globPatterns.Where(globPattern => globPattern.StartsWith(GLOB_EXCLUDE_CHAR.ToString())).Select(globPattern => globPattern.TrimStart(GLOB_EXCLUDE_CHAR)));
            matcher.AddIncludePatterns(globPatterns.Where(globPattern => !globPattern.StartsWith(GLOB_EXCLUDE_CHAR.ToString())));
            return(matcher.GetResultsInFullPath(rootPath).ToArray());
        }
コード例 #13
0
        public ICollection <MigrationInfo> Load(ICollection <IFileProvider> fileProviders, string pattern)
        {
            var matcher = new Matcher(StringComparison.OrdinalIgnoreCase);

            matcher.AddIncludePatterns(new[] { pattern });

            return(fileProviders.SelectMany(x => LoadDirectory(x, matcher)).ToArray());
        }
コード例 #14
0
        public static Matcher CreateMatcher(IEnumerable <string> include, IEnumerable <string> exclude)
        {
            var fileMatcher = new Matcher(StringComparison.OrdinalIgnoreCase);

            fileMatcher.AddIncludePatterns(include.Any() ? include : AllFilesList);
            fileMatcher.AddExcludePatterns(exclude);
            return(fileMatcher);
        }
コード例 #15
0
ファイル: SourceFileMatcher.cs プロジェクト: jmarolf/format
        private SourceFileMatcher(string[] include, string[] exclude)
        {
            Include = include.ToImmutableArray();
            Exclude = exclude.ToImmutableArray();

            _matcher = new Matcher(StringComparison.OrdinalIgnoreCase);
            _matcher.AddIncludePatterns(Include);
            _matcher.AddExcludePatterns(Exclude);
        }
コード例 #16
0
        public GlobMatcher(IEnumerable <string> includes, IEnumerable <string> excludes)
        {
            var matcher = new Matcher();

            matcher.AddIncludePatterns(includes);
            matcher.AddExcludePatterns(excludes);

            _matcher = matcher;
        }
コード例 #17
0
        public virtual IEnumerable <string> Find(string directoryPath, IEnumerable <string> excludePatterns, IEnumerable <string> includePatterns)
        {
            var matcher = new Matcher();

            matcher.AddExcludePatterns(excludePatterns ?? Enumerable.Empty <string>());
            matcher.AddIncludePatterns(includePatterns ?? Enumerable.Empty <string>());

            return(matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(directoryPath))).Files.Select(file => file.Path));
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: endeffects/TextTemplating
        private int Execute(IReadOnlyList <string> include, bool preprocess)
        {
            var matcher = new Matcher();

            if (include.Count == 0)
            {
                matcher.AddInclude(@"**\*.tt");
            }
            else
            {
                matcher.AddIncludePatterns(include);
            }

            var engine    = new Engine();
            var templates = matcher.GetResultsInFullPath(_appEnv.ApplicationBasePath);

            foreach (var template in templates)
            {
                Console.WriteLine("Processing '{0}'...", template);
                var host     = new CommandLineEngineHost();
                var fileName = Path.GetFileNameWithoutExtension(template);
                var content  = File.ReadAllText(template);

                string transformedText;
                if (preprocess)
                {
                    var relativeDir    = Path.GetDirectoryName(template).Substring(_appEnv.ApplicationBasePath.Length);
                    var classNamespace = _appEnv.ApplicationName;
                    if (relativeDir.Length != 0)
                    {
                        classNamespace += '.' + relativeDir.Replace(Path.DirectorySeparatorChar, '.');
                    }

                    string   language;
                    string[] references;
                    transformedText = engine.PreprocessTemplate(
                        content,
                        host,
                        fileName,
                        classNamespace,
                        out language,
                        out references);
                }
                else
                {
                    transformedText = engine.ProcessTemplate(content, host);
                }


                var output = Path.ChangeExtension(template, host.FileExtension);
                Console.WriteLine("Writing '{0}'...", output);
                File.WriteAllText(output, transformedText);
            }

            return(0);
        }
コード例 #19
0
        public static Matcher AddIncludePatterns(this Matcher result, string includes)
        {
            if (string.IsNullOrWhiteSpace(includes) == false)
            {
                var patterns = includes.Split(';', StringSplitOptions.RemoveEmptyEntries);
                result.AddIncludePatterns(patterns);
            }

            return(result);
        }
コード例 #20
0
        //-----------------------------------------------------------
        static void Main(string[] args)
        {
            var opts = ParseArgs(args);

            var matcher = new Matcher(StringComparison.InvariantCultureIgnoreCase);

            matcher.AddIncludePatterns(new string[] { opts.InputPattern });

            var matches = matcher.Execute(new DirectoryInfoWrapper(opts.WorkingDir))
                          .Files
                          .Select(f => Path.GetFullPath(f.Path, opts.WorkingDir.FullName))
                          .ToArray();

            // These are probably already returned sorted
            Array.Sort(matches);

            foreach (var f in matches)
            {
                Console.WriteLine(f);
            }

            var images = matches
                         .Select(f => new Image(ImageDataFactory.Create(f)))
                         .ToArray();

            if (images.Length < 1)
            {
                ErrorExit("No images found for include pattern.");
            }

            var writer = new PdfWriter(opts.OutPath);
            var pdf    = new PdfDocument(writer);
            var doc    = new Document(pdf);

            doc.SetMargins(0, 0, 0, 0);

            // Take size of first image as the page size
            float imgWidth  = images[0].GetImageWidth();
            float imgHeight = images[0].GetImageHeight();

            pdf.SetDefaultPageSize(new(new(0, 0, imgWidth, imgHeight) ) );

            foreach (var img in images)
            {
                img.SetMargins(0, 0, 0, 0);
                img.SetPadding(0);

                img.SetWidth(pdf.GetDefaultPageSize().GetWidth());
                img.SetAutoScaleHeight(true);

                doc.Add(img);
            }

            pdf.Close();
        }
コード例 #21
0
        private static Matcher GetMatcher(string[] includePatterns, string[] excludePatterns)
        {
            Matcher matcher = new Matcher();

            matcher.AddIncludePatterns(includePatterns.IsNullOrEmpty() ? new[] { "**/*" } : includePatterns);
            if (!excludePatterns.IsNullOrEmpty())
            {
                matcher.AddExcludePatterns(excludePatterns);
            }
            return(matcher);
        }
コード例 #22
0
        /// <summary>
        /// Returns a list of files matching the specified globbing patterns. Patterns starting with
        /// `!` are interpreted as exclude patterns.
        /// </summary>
        public IEnumerable <FileInfoBase> Files(IEnumerable <string> globs)
        {
            var matcher         = new Matcher();
            var includePatterns = globs.Where(s => s.Length > 0 && s[0] != '!');
            var excludePatterns = globs.Where(s => s.Length > 0 && s[0] == '!').Select(s => s.Substring(1));

            matcher.AddIncludePatterns(includePatterns);
            matcher.AddExcludePatterns(excludePatterns);
            var results = matcher.Execute(Root);

            return(results.Files.Select(f => File(f.Path)));
        }
コード例 #23
0
        private void OnDebug()
        {
            var matcher = new Matcher();

            matcher.AddExclude("**/*.meta");
            matcher.AddIncludePatterns(_includes);
            matcher.AddExcludePatterns(_excludes);

            var rootDirectory = new DirectoryInfoWrapper(new DirectoryInfo(Application.dataPath));

            _matches.Clear();
            _matches.AddRange(matcher.Execute(rootDirectory).Files.Select(w => $"Assets/{w.Path}"));
        }
コード例 #24
0
        private SourceFileMatcher(string[] include, string[] exclude)
        {
            _shouldMatchAll = include.Length == 0 && exclude.Length == 0;

            Include = include.Length > 0
                ? include.ToImmutableArray()
                : AllFilesList.ToImmutableArray();
            Exclude = exclude.ToImmutableArray();

            _matcher = new Matcher(StringComparison.OrdinalIgnoreCase);
            _matcher.AddIncludePatterns(Include);
            _matcher.AddExcludePatterns(Exclude);
        }
コード例 #25
0
        public ExitCode Run()
        {
            _logger.LogDebug("Identifying file to process in {Count} directories. {CountInclude} includes, {CountExclude} excludes were provided", _settings.Directories.Length, _settings.Includes?.Length ?? 0, _settings.Excludes?.Length ?? 0);

            Matcher globber = new Matcher(StringComparison.OrdinalIgnoreCase);

            if (_settings.Includes != null)
            {
                globber.AddIncludePatterns(_settings.Includes);
            }

            if (_settings.Excludes != null)
            {
                globber.AddExcludePatterns(_settings.Excludes);
            }

            if (!_settings.NoDefaultExcludes)
            {
                globber.AddExclude("**/obj/**.targets");
                globber.AddExclude("**/bin/**.targets");
            }

            foreach (string directory in _settings.Directories)
            {
                using (_logger.BeginScope(new Dictionary <string, object>
                {
                    { "Directory", directory }
                }))
                {
                    _logger.LogDebug("Searching for files in {Directory}", directory);

                    if (Directory.Exists(directory))
                    {
                        IEnumerable <string> files = globber.GetResultsInFullPath(directory);

                        foreach (string file in files)
                        {
                            HandleFile(_formatter, file);

                            ProcessedFiles++;
                        }
                    }
                    else
                    {
                        _logger.LogWarning("{Directory} was not found", directory);
                    }
                }
            }

            return(ExitCode.Ok);
        }
コード例 #26
0
        public static Matcher AddIncludePatterns(this Matcher result, string patterns, char separator, string defaultValue)
        {
            if (string.IsNullOrEmpty(patterns))
            {
                result.AddInclude(defaultValue);
            }
            else
            {
                var items = patterns.Split(new char[] { separator }, StringSplitOptions.RemoveEmptyEntries);
                result.AddIncludePatterns(items);
            }

            return(result);
        }
コード例 #27
0
ファイル: CLI.cs プロジェクト: mika-f/Unity-VariationPackager
        private static void CreateZipPackage(IPackage meta, IPackageVariation variation, string publishedTo)
        {
            var matcher = new Matcher();

            if (variation.Archive?.Includes != null)
            {
                matcher.AddIncludePatterns(variation.Archive.Includes);
            }
            if (variation.Archive?.Excludes != null)
            {
                matcher.AddExcludePatterns(variation.Archive.Excludes);
            }

            var rootDirectory = new DirectoryInfoWrapper(new DirectoryInfo(Application.dataPath));
            var assets        = matcher.Execute(rootDirectory).Files.Select(w => $"Assets/{w.Path}");

            var sb = new List <string>();

            sb.Add(string.IsNullOrWhiteSpace(variation.Archive?.Name) ? meta.Name : variation.Archive.Name);
            if (!string.IsNullOrWhiteSpace(variation.Name))
            {
                sb.Add(variation.Name);
            }
            sb.Add(meta.Version);
            var archiveName   = string.Join("-", sb);
            var destDirectory = Path.Combine(Application.dataPath, meta.Describe.Output, archiveName);

            if (!Directory.Exists(destDirectory))
            {
                Directory.CreateDirectory(destDirectory);
            }

            foreach (var asset in assets)
            {
                var baseDir = string.IsNullOrWhiteSpace(variation.Archive?.BaseDir) ? "" : $"Assets/{variation.Archive.BaseDir}";
                var destTo  = $"{destDirectory}/{(string.IsNullOrWhiteSpace(baseDir) ? asset : asset.Replace(baseDir, ""))}";
                if (!Directory.Exists(Path.GetDirectoryName(destTo)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(destTo) ?? string.Empty);
                }
                File.Copy(asset, destTo, true);
            }

            File.Copy(publishedTo, $"{destDirectory}/{Path.GetFileName(publishedTo)}", true);

            ZipFile.CreateFromDirectory(destDirectory, $"{destDirectory}.zip", CompressionLevel.Optimal, true);

            Directory.Delete(destDirectory, true);
        }
コード例 #28
0
 public int OnExecute()
 {
     try
     {
         if (Targets == null || Targets.Length == 0)
         {
             _Console.Error.WriteLine("one or more files must be specified");
             return(1);
         }
         var basedir = !string.IsNullOrEmpty(BaseDirectory) ? BaseDirectory : Directory.GetCurrentDirectory();
         var fromenc = TextConverter.GetEncodingFromString(FromEncoding);
         var toenc   = TextConverter.GetEncodingFromString(ToEncoding);
         var matcher = new Matcher(StringComparison.CurrentCultureIgnoreCase);
         matcher.AddIncludePatterns(Targets);
         if (Exclude != null && Exclude.Length != 0)
         {
             matcher.AddExcludePatterns(Exclude);
         }
         var baseDirInfo = new DirectoryInfoWrapper(new DirectoryInfo(basedir));
         var result      = matcher.Execute(baseDirInfo);
         if (!result.HasMatches)
         {
             _Console.Error.WriteLine("no file was matched");
             return(3);
         }
         _Logger.LogDebug("converting {0} to {1}, newline = {2}, no preamble = {3}", fromenc.WebName, toenc.WebName, Newline, NoPreamble);
         foreach (var fpath in result.Files.Select(x => x.Path))
         {
             if (DryRun)
             {
                 Console.WriteLine($"replacing file(dryrun): {fpath}");
                 continue;
             }
             else
             {
                 Console.WriteLine($"replacing file: {fpath}");
             }
             DoEncoding(Path.Combine(baseDirInfo.FullName, fpath), fromenc, toenc);
         }
         return(0);
     }
     catch (Exception e)
     {
         _Console.Error.WriteLine("converting file error:{0}", e);
         return(2);
     }
 }
コード例 #29
0
        private static IEnumerable <string> GetCompileFullPaths(XElement compile, string includeOrRemovePattern, string csProjRoot)
        {
            var matcher = new Matcher(StringComparison.OrdinalIgnoreCase);

            matcher.AddIncludePatterns(includeOrRemovePattern.Split(';'));
            var exclude = compile?.Attribute("Exclude")?.Value;

            if (exclude != null)
            {
                matcher.AddExcludePatterns(exclude.Split(';'));
            }

            foreach (var path in matcher.GetResultsInFullPath(csProjRoot))
            {
                yield return(path);
            }
        }
コード例 #30
0
        /// <summary>
        /// Based on the CLI args, find the matching files. Return just a distinct set in case there are duplicates matches
        /// </summary>
        private IEnumerable <string> GetFileList(IEnumerable <FileInfo> files, DirectoryInfo baseDir, IEnumerable <string> patterns)
        {
            var filePaths = files?.Select(x => x.FullName) ?? Array.Empty <string>();

            if (baseDir != null && patterns != null)
            {
                var matcher = new Matcher();
                matcher.AddIncludePatterns(patterns);
                var matchedFiles = matcher.GetResultsInFullPath(baseDir.FullName);

                // Union() removes duplicates from the return set, so we don't need to 'Distinct()' the collection ourselves.
                filePaths = filePaths.Union(matchedFiles);
            }

            // We still need to sort it though
            // (still need to Distinct, since user can pass in duplicate files via the '--file' arg)
            return(filePaths.Distinct().OrderBy(x => x));
        }