Exemplo n.º 1
1
        public void Main(string[] args)
        {
            var matcher = new Matcher();
            matcher.AddInclude(@"**\*.cs");
            matcher.AddExclude(OutputFileName);

            var inputFiles = new List<string>();
            var latestChange = DateTime.MinValue;
            foreach (var f in matcher.GetResultsInFullPath(_projectDir))
            {
                inputFiles.Add(f);
                var change = File.GetLastWriteTimeUtc(f);
                if (change > latestChange)
                    latestChange = change;
            }

            var outputFile = Path.Combine(_projectDir, OutputFileName);
            if (!File.Exists(outputFile) || latestChange > File.GetLastWriteTimeUtc(outputFile))
            {
                Console.WriteLine("Rewriting async methods in " + _projectDir);
                var asyncCode = new Rewriter().RewriteAndMerge(inputFiles.ToArray());
                File.WriteAllText(outputFile, asyncCode);
            }
            else
            {
                Console.WriteLine("Skipping async rewriting, generated code up to date");
            }
        }
Exemplo n.º 2
1
		public virtual PatternMatchingResult Execute(DirectoryInfoBase directoryInfo)
		{
			var files = new List<FilePatternMatch>();
			foreach (var includePattern in _includePatterns)
			{
				var matcher = new Matcher();
				matcher.AddInclude(includePattern);
				matcher.AddExcludePatterns(_excludePatterns);
				var result = matcher.Execute(directoryInfo);
				if (result.Files.Any())
				{
					files.AddRange(result.Files);
				}
			}
			return new PatternMatchingResult(files);
		}
Exemplo n.º 3
0
        public static IEnumerable <(string Path, string Stem)> GetFileList(string basedir, string[] includes, string[] excludes, bool ignoreCase)
        {
            var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher(ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture);

            if (excludes != null)
            {
                foreach (var exclude in excludes)
                {
                    matcher.AddExclude(exclude);
                }
            }
            if (includes != null && includes.Length != 0)
            {
                foreach (var include in includes)
                {
                    matcher.AddInclude(include);
                }
            }
            else
            {
                matcher.AddInclude("**/*");
            }
            var di        = new DirectoryInfo(basedir);
            var diwrapper = new DirectoryInfoWrapper(di);
            var result    = matcher.Execute(diwrapper);

            if (!result.HasMatches)
            {
                return(Array.Empty <(string, string)>());
            }
            else
            {
                return(result.Files.Select(x => (x.Path, x.Stem)));
            }
        }
Exemplo n.º 4
0
        public void FindAndLoadSolutions(DotnetWorkspace workspace, string path)
        {
            var globalJsonMatches = new Matcher()
                .AddInclude("**/global.json")
                .Execute(new DirectoryInfoWrapper(new DirectoryInfo(path)));

            foreach (var file in globalJsonMatches.Files)
            {
                var globalJsonPath = Path.Combine(path, file.Path);

                Console.WriteLine($"Loading {globalJsonPath}");

                workspace.Solutions.Add(DotnetSolution.Load(globalJsonPath));
            }
        }
Exemplo n.º 5
0
        public void FindAndLoadProjects2(DotnetWorkspace workspace)
        {
            foreach (var solution in workspace.Solutions)
            {
                var scanPath = solution.GlobalJson.FolderPath;

                var projectJsonMatches = new Matcher()
                    .AddInclude("**/project.json")
                    .Execute(new DirectoryInfoWrapper(new DirectoryInfo(scanPath)));

                foreach (var file in projectJsonMatches.Files)
                {
                    var projectJsonPath = Path.Combine(scanPath, file.Path);
                    Console.WriteLine($"  Loading {projectJsonPath}");

                    var project = DotnetProject.Load(projectJsonPath);
                    project.Solution = solution;
                    solution.Projects.Add(project);
                }
            }
        }
        /// <summary>
        /// 获取配置
        /// </summary>
        /// <returns></returns>
        public IConfigurationRoot GetConfigurationRoot()
        {
            if (_configuration == null)
            {
                if (!Directory.Exists(_configRootFullPath))
                {
                    Directory.CreateDirectory(_configRootFullPath);
                }
                var configurationBuilder = new ConfigurationBuilder()
                                           .SetBasePath(_configRootFullPath);

                foreach (var jsonConfig in _configOptions.Json)
                {
                    var jsonFileMatcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher();
                    var jsonFiles       = jsonFileMatcher
                                          .AddInclude(jsonConfig.Include)
                                          .AddExclude(jsonConfig.Exclude)
                                          .GetResultsInFullPath(_configRootFullPath);

                    foreach (var jsonFile in jsonFiles)
                    {
                        configurationBuilder.AddJsonFile(jsonFile, jsonConfig.Optional, jsonConfig.ReloadOnChange);
                    }
                }

                if (_configOptions.Consul?.Enable ?? false)
                {
                    if (_configOptions.Consul.Name == null)
                    {
                        throw new ArgumentException("Name is required when reading from consul");
                    }
                    _consulCancellationTokenSource = new CancellationTokenSource();
                    configurationBuilder.AddConsul($"{_configOptions.Consul.Name}.{_env.EnvironmentName}", _consulCancellationTokenSource.Token);
                }

                _configuration = configurationBuilder.Build();
            }

            return(_configuration);
        }
Exemplo n.º 7
0
        public bool Build()
        {
            var projectFilesFinder = new Matcher();

            // Resolve all the project names
            var projectFilesToBuild = new List<string>();
            foreach (var pattern in _buildOptions.ProjectPatterns)
            {
                if (pattern.Contains("*"))
                {
                    // Requires globbing
                    projectFilesFinder.AddInclude(NormalizeGlobbingPattern(pattern));
                }
                else
                {
                    projectFilesToBuild.Add(pattern);
                }
            }

            var rootDirectory = Directory.GetCurrentDirectory();
            var patternSearchFolder = new DirectoryInfoWrapper(new DirectoryInfo(rootDirectory));
            var globbingProjects = projectFilesFinder.Execute(patternSearchFolder).Files.Select(file =>
                Path.Combine(rootDirectory, file.Path));
            projectFilesToBuild.AddRange(globbingProjects);

            var sw = Stopwatch.StartNew();

            var globalSucess = true;
            foreach (var project in projectFilesToBuild)
            {
                var buildSuccess = BuildInternal(project);
                globalSucess &= buildSuccess;
            }

            _buildOptions.Reports.Information.WriteLine($"Total build time elapsed: { sw.Elapsed }");
            _buildOptions.Reports.Information.WriteLine($"Total projects built: { projectFilesToBuild.Count }");

            return globalSucess;
        }
Exemplo n.º 8
0
        // Initially based on code from Reliak.FileSystemGlobbingExtensions (https://github.com/reliak/Reliak.FileSystemGlobbingExtensions)
        public static IEnumerable<IFile> GetFiles(IDirectory directory, IEnumerable<string> patterns)
        {
            Matcher matcher = new Matcher(StringComparison.Ordinal);

            // Expand braces
            IEnumerable<string> expandedPatterns = patterns
                .SelectMany(ExpandBraces)
                .Select(f => f.Replace("\\{", "{").Replace("\\}", "}")); // Unescape braces

            // Add the patterns, any that start with ! are exclusions
            foreach (string expandedPattern in expandedPatterns)
            {
                bool isExclude = expandedPattern[0] == '!';
                string finalPattern = isExclude ? expandedPattern.Substring(1) : expandedPattern;
                finalPattern = finalPattern
                    .Replace("\\!", "!") // Unescape negation
                    .Replace("\\", "/"); // Normalize slashes

                // No support for absolute paths
                if (System.IO.Path.IsPathRooted(finalPattern))
                {
                    throw new ArgumentException($"Rooted globbing patterns are not supported ({expandedPattern})", nameof(patterns));
                }

                // Add exclude or include pattern to matcher
                if (isExclude)
                {
                    matcher.AddExclude(finalPattern);
                }
                else
                {
                    matcher.AddInclude(finalPattern);
                }
            }

            DirectoryInfoBase directoryInfo = new DirectoryInfo(directory);
            PatternMatchingResult result = matcher.Execute(directoryInfo);
            return result.Files.Select(match => directory.GetFile(match.Path));
        }
Exemplo n.º 9
0
        public void FindAndLoadProjects1(DotnetWorkspace workspace)
        {
            foreach (var solution in workspace.Solutions)
            {
                if (!solution.GlobalJson.ProjectFolders.Any())
                {
                    Console.WriteLine($"NO 'projects' folders {solution.GlobalJson.FolderPath}");
                    continue;
                }
                foreach (var projectFolder in solution.GlobalJson.ProjectFolders)
                {
                    var scanPath = Path.Combine(solution.GlobalJson.FolderPath, projectFolder.Path);

                    if (!scanPath.StartsWith(solution.GlobalJson.FolderPath) ||
                        projectFolder.Path.StartsWith("."))
                    {
                        Console.WriteLine($"OUTSIDE FOLDER {solution.GlobalJson.FolderPath}:{projectFolder.Path}");
                        continue;
                    }

                    Console.WriteLine($"Scanning {solution.GlobalJson.FolderPath}:{projectFolder.Path}");

                    var projectJsonMatches = new Matcher()
                        .AddInclude("*/project.json")
                        .Execute(new DirectoryInfoWrapper(new DirectoryInfo(scanPath)));

                    foreach (var file in projectJsonMatches.Files)
                    {
                        var projectJsonPath = Path.Combine(scanPath, file.Path);
                        Console.WriteLine($"  Loading {projectJsonPath}");

                        var project = DotnetProject.Load(projectJsonPath);
                        project.Solution = solution;
                        solution.Projects.Add(project);
                    }
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Enumerate all the PowerShell (ps1, psm1, psd1) files in the workspace in a recursive manner.
        /// </summary>
        /// <returns>An enumerator over the PowerShell files found in the workspace.</returns>
        public IEnumerable <string> EnumeratePSFiles(
            string[] excludeGlobs,
            string[] includeGlobs,
            int maxDepth,
            bool ignoreReparsePoints
            )
        {
            if (WorkspacePath == null || !Directory.Exists(WorkspacePath))
            {
                yield break;
            }

            var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher();

            foreach (string pattern in includeGlobs)
            {
                matcher.AddInclude(pattern);
            }
            foreach (string pattern in excludeGlobs)
            {
                matcher.AddExclude(pattern);
            }

            var fsFactory = new WorkspaceFileSystemWrapperFactory(
                WorkspacePath,
                maxDepth,
                Utils.IsNetCore ? s_psFileExtensionsCoreFramework : s_psFileExtensionsFullFramework,
                ignoreReparsePoints,
                logger
                );
            var fileMatchResult = matcher.Execute(fsFactory.RootDirectory);

            foreach (FilePatternMatch item in fileMatchResult.Files)
            {
                yield return(Path.Combine(WorkspacePath, item.Path));
            }
        }
Exemplo n.º 11
0
        public string CompressDirectory(string path, Matcher matcher, IProgress<string> progress, CancellationToken ct) {
            string zipFilePath = Path.GetTempFileName();
            using (FileStream zipStream = new FileStream(zipFilePath, FileMode.Create)) 
            using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create)) {
                Queue<string> dirs = new Queue<string>();
                dirs.Enqueue(path);
                while (dirs.Count > 0) {
                    var dir = dirs.Dequeue();
                    var subdirs = Directory.GetDirectories(dir);
                    foreach(var subdir in subdirs) {
                        dirs.Enqueue(subdir);
                    }

                    var files = matcher.GetResultsInFullPath(dir);
                    foreach (var file in files) {
                        if (ct.IsCancellationRequested) {
                            return string.Empty;
                        }
                        progress?.Report(file);
                        string entryName = file.MakeRelativePath(dir).Replace('\\', '/');
                        archive.CreateEntryFromFile(file, entryName);
                    }
                }
            }
            return zipFilePath;
        }
Exemplo n.º 12
0
 /// <summary>
 /// Matches the file passed in with the patterns in the matcher without going to disk.
 /// </summary>
 /// <param name="matcher">The matcher that holds the patterns and pattern matching type.</param>
 /// <param name="file">The file to run the matcher against.</param>
 /// <returns>The match results.</returns>
 public static PatternMatchingResult Match(this Matcher matcher, string file)
 {
     return(Match(matcher, Directory.GetCurrentDirectory(), new List <string> {
         file
     }));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Matches the file passed in with the patterns in the matcher without going to disk.
 /// </summary>
 /// <param name="matcher">The matcher that holds the patterns and pattern matching type.</param>
 /// <param name="rootDir">The root directory for the matcher to match the file from.</param>
 /// <param name="file">The file to run the matcher against.</param>
 /// <returns>The match results.</returns>
 public static PatternMatchingResult Match(this Matcher matcher, string rootDir, string file)
 {
     return(Match(matcher, rootDir, new List <string> {
         file
     }));
 }
        public void Discover(ShapeTableBuilder builder)
        {
            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Start discovering shapes");
            }

            var harvesterInfos = _harvesters
                .Select(harvester => new { harvester, subPaths = harvester.SubPaths() })
                .ToList();

            var activeFeatures = _featureManager.GetEnabledFeaturesAsync().Result.ToList();
            var activeExtensions = Once(activeFeatures).ToList();

            var matcher = new Matcher();
            foreach (var extension in _shapeTemplateViewEngines.SelectMany(x => x.TemplateFileExtensions))
            {
                matcher.AddInclude(string.Format("*.{0}", extension));
            }

            var hits = activeExtensions.Select(extensionDescriptor =>
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Start discovering candidate views filenames");
                }

                var pathContexts = harvesterInfos.SelectMany(harvesterInfo => harvesterInfo.subPaths.Select(subPath =>
                {
                    var basePath = _fileSystem.Combine(extensionDescriptor.Location, extensionDescriptor.Id);
                    var virtualPath = _fileSystem.Combine(basePath, subPath);
                    var files = _fileSystem.ListFiles(virtualPath, matcher).ToReadOnlyCollection();

                    return new { harvesterInfo.harvester, basePath, subPath, virtualPath, files };
                })).ToList();

                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Done discovering candidate views filenames");
                }
                var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve =>
                {
                    return pathContext.files.Select(
                        file => new
                        {
                            fileName = Path.GetFileNameWithoutExtension(file.Name),
                            fileVirtualPath = "~/" + _fileSystem.Combine(pathContext.virtualPath, file.Name),
                            pathContext
                        });
                }));

                var shapeContexts = fileContexts.SelectMany(fileContext =>
                {
                    var harvestShapeInfo = new HarvestShapeInfo
                    {
                        SubPath = fileContext.pathContext.subPath,
                        FileName = fileContext.fileName,
                        TemplateVirtualPath = fileContext.fileVirtualPath
                    };
                    var harvestShapeHits = fileContext.pathContext.harvester.HarvestShape(harvestShapeInfo);
                    return harvestShapeHits.Select(harvestShapeHit => new { harvestShapeInfo, harvestShapeHit, fileContext });
                });

                return shapeContexts.Select(shapeContext => new { extensionDescriptor, shapeContext }).ToList();
            }).SelectMany(hits2 => hits2);


            foreach (var iter in hits)
            {
                // templates are always associated with the namesake feature of module or theme
                var hit = iter;
                var featureDescriptors = iter.extensionDescriptor.Features.Where(fd => fd.Id == hit.extensionDescriptor.Id);
                foreach (var featureDescriptor in featureDescriptors)
                {
                    if (_logger.IsEnabled(LogLevel.Debug))
                    {
                        _logger.LogDebug("Binding {0} as shape [{1}] for feature {2}",
                        hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                        iter.shapeContext.harvestShapeHit.ShapeType,
                        featureDescriptor.Id);
                    }
                    builder.Describe(iter.shapeContext.harvestShapeHit.ShapeType)
                        .From(new Feature { Descriptor = featureDescriptor })
                        .BoundAs(
                            hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                            shapeDescriptor => displayContext => RenderAsync(shapeDescriptor, displayContext, hit.shapeContext.harvestShapeInfo, hit.shapeContext.harvestShapeHit));
                }
            }

            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Done discovering shapes");
            }
        }
Exemplo n.º 15
0
        public IEnumerable<IFileInfo> ListFiles(string path, Matcher matcher)
        {
            var directory = GetDirectoryInfo(path);
            if (!directory.Exists)
            {
                return Enumerable.Empty<IFileInfo>();
            }

            return matcher.Execute(new DirectoryInfoWrapper(directory))
                .Files
                .Select(result => GetFileInfo(Combine(directory.FullName, result.Path)));
        }
Exemplo n.º 16
0
 /// <summary>
 /// Matches the files passed in with the patterns in the matcher without going to disk.
 /// </summary>
 /// <param name="matcher">The matcher that holds the patterns and pattern matching type.</param>
 /// <param name="files">The files to run the matcher against.</param>
 /// <returns>The match results.</returns>
 public static PatternMatchingResult Match(this Matcher matcher, IEnumerable <string>?files)
 {
     return(Match(matcher, Directory.GetCurrentDirectory(), files));
 }
Exemplo n.º 17
0
 public string CompressDirectory(string path) {
     Matcher matcher = new Matcher(StringComparison.OrdinalIgnoreCase);
     matcher.AddInclude("*.*");
     return CompressDirectory(path, matcher, new Progress<string>((p) => { }), CancellationToken.None);
 }
Exemplo n.º 18
0
 public IEnumerable<IFileInfo> ListFiles(string path, Matcher matcher)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 19
0
        private bool ScanForProjects()
        {
            _logger.LogInformation(string.Format("Scanning '{0}' for DNX projects", _env.Path));

            var anyProjects = false;

            // Single project in this folder
            var projectInThisFolder = Path.Combine(_env.Path, "project.json");

            if (File.Exists(projectInThisFolder))
            {
                if (_context.TryAddProject(projectInThisFolder))
                {
                    _logger.LogInformation(string.Format("Found project '{0}'.", projectInThisFolder));

                    anyProjects = true;
                }
            }
            else
            {
                IEnumerable<string> paths;
#if DNX451
                if (_options.Projects != "**/project.json")
                {
                    var matcher = new Matcher();
                    matcher.AddIncludePatterns(_options.Projects.Split(';'));
                    paths = matcher.GetResultsInFullPath(_env.Path);
                }
                else
                {
                    paths = _directoryEnumerator.SafeEnumerateFiles(_env.Path, "project.json");
                }
#else
                // The matcher works on CoreCLR but Omnisharp still targets aspnetcore50 instead of
                // dnxcore50
                paths = _directoryEnumerator.SafeEnumerateFiles(_env.Path, "project.json");
#endif
                foreach (var path in paths)
                {
                    string projectFile = null;

                    if (Path.GetFileName(path) == "project.json")
                    {
                        projectFile = path;
                    }
                    else
                    {
                        projectFile = Path.Combine(path, "project.json");
                        if (!File.Exists(projectFile))
                        {
                            projectFile = null;
                        }
                    }

                    if (string.IsNullOrEmpty(projectFile))
                    {
                        continue;
                    }

                    if (!_context.TryAddProject(projectFile))
                    {
                        continue;
                    }

                    _logger.LogInformation(string.Format("Found project '{0}'.", projectFile));

                    anyProjects = true;
                }
            }

            return anyProjects;
        }
Exemplo n.º 20
0
        internal static IEnumerable<PhysicalPackageFile> CollectAdditionalFiles(DirectoryInfoBase rootDirectory, IEnumerable<PackIncludeEntry> projectFileGlobs, string projectFilePath, IList<DiagnosticMessage> diagnostics)
        {
            foreach (var entry in projectFileGlobs)
            {
                // Evaluate the globs on the right
                var matcher = new Matcher();
                matcher.AddIncludePatterns(entry.SourceGlobs);
                var results = matcher.Execute(rootDirectory);
                var files = results.Files.ToList();

                // Check for illegal characters
                if (string.IsNullOrEmpty(entry.Target))
                {
                    diagnostics.Add(new DiagnosticMessage(
                        DiagnosticMonikers.NU1003,
                        $"Invalid '{ProjectFilesCollection.PackIncludePropertyName}' section. The target '{entry.Target}' is invalid, " +
                        "targets must either be a file name or a directory suffixed with '/'. " +
                        "The root directory of the package can be specified by using a single '/' character.",
                        projectFilePath,
                        DiagnosticMessageSeverity.Error,
                        entry.Line,
                        entry.Column));
                    continue;
                }

                if (entry.Target.Split('/').Any(s => s.Equals(".") || s.Equals("..")))
                {
                    diagnostics.Add(new DiagnosticMessage(
                        DiagnosticMonikers.NU1004,
                        $"Invalid '{ProjectFilesCollection.PackIncludePropertyName}' section. " +
                        $"The target '{entry.Target}' contains path-traversal characters ('.' or '..'). " +
                        "These characters are not permitted in target paths.",
                        projectFilePath,
                        DiagnosticMessageSeverity.Error,
                        entry.Line,
                        entry.Column));
                    continue;
                }

                // Check the arity of the left
                if (entry.Target.EndsWith("/"))
                {
                    var dir = entry.Target.Substring(0, entry.Target.Length - 1).Replace('/', Path.DirectorySeparatorChar);

                    foreach (var file in files)
                    {
                        yield return new PhysicalPackageFile()
                        {
                            SourcePath = Path.Combine(rootDirectory.FullName, PathUtility.GetPathWithDirectorySeparator(file.Path)),
                            TargetPath = Path.Combine(dir, PathUtility.GetPathWithDirectorySeparator(file.Stem))
                        };
                    }
                }
                else
                {
                    // It's a file. If the glob matched multiple things, we're sad :(
                    if (files.Count > 1)
                    {
                        // Arity mismatch!
                        string sourceValue = entry.SourceGlobs.Length == 1 ?
                            $"\"{entry.SourceGlobs[0]}\"" :
                            ("[" + string.Join(",", entry.SourceGlobs.Select(v => $"\"{v}\"")) + "]");
                        diagnostics.Add(new DiagnosticMessage(
                            DiagnosticMonikers.NU1005,
                            $"Invalid '{ProjectFilesCollection.PackIncludePropertyName}' section. " +
                            $"The target '{entry.Target}' refers to a single file, but the pattern {sourceValue} " +
                            "produces multiple files. To mark the target as a directory, suffix it with '/'.",
                            projectFilePath,
                            DiagnosticMessageSeverity.Error,
                            entry.Line,
                            entry.Column));
                    }
                    else
                    {
                        yield return new PhysicalPackageFile()
                        {
                            SourcePath = Path.Combine(rootDirectory.FullName, files[0].Path),
                            TargetPath = PathUtility.GetPathWithDirectorySeparator(entry.Target)
                        };
                    }
                }
            }
        }
Exemplo n.º 21
0
        private async Task SendProjectAsync(EnvDTE.Project project, string remotePath, string filterString, CancellationToken cancellationToken) {
            ProgressOutputWriter.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));

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

            var compressedFilePath = FileSystem.CompressDirectory(projectDir, matcher, new Progress<string>((p) => {
                ProgressOutputWriter.WriteLine(Resources.Info_LocalFilePath.FormatInvariant(p));
                string dest = p.MakeRelativePath(projectDir).ProjectRelativePathToRemoteProjectPath(remotePath, projectName);
                ProgressOutputWriter.WriteLine(Resources.Info_RemoteFilePath.FormatInvariant(dest));
            }), CancellationToken.None);
            
            using (var fts = new DataTransferSession(Session, FileSystem)) {
                ProgressOutputWriter.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);
            }

            ProgressOutputWriter.WriteLine(Resources.Info_TransferringFilesDone);
        }
Exemplo n.º 22
-1
        private async Task<IEnumerable<RecipeDescriptor>> HarvestRecipesAsync(ExtensionDescriptor extension)
        {
            var recipeLocation = _fileSystem.Combine(extension.Location, extension.Id, "Recipes");

            var recipeOptions = _recipeOptions.Value;

            List<RecipeDescriptor> recipeDescriptors = new List<RecipeDescriptor>();

            foreach(var recipeFileExtension in recipeOptions.RecipeFileExtensions)
            {
                var fileMatcher = new Matcher(System.StringComparison.OrdinalIgnoreCase);
                fileMatcher.AddInclude(recipeFileExtension.Key);

                var recipeFiles = _fileSystem.ListFiles(recipeLocation, fileMatcher);

                recipeDescriptors.AddRange(await recipeFiles.InvokeAsync(recipeFile => {
                    var recipeParser = _recipeParsers.First(x => x.GetType() == recipeFileExtension.Value);
                    using (var stream = recipeFile.CreateReadStream()) {
                        var recipe = recipeParser.ParseRecipe(stream);
                        recipe.Location = recipeFile.PhysicalPath.Replace(_fileSystem.RootPath, "").TrimStart(System.IO.Path.DirectorySeparatorChar);
                        return Task.FromResult(recipe);
                    }
                }, Logger));
            }

            return recipeDescriptors;
        }