public LoadExtensionsInDirectory( IDirectoryAccessor directory, IReadOnlyList <FileInfo> additionalDependencies = null) { Directory = directory; AdditionalDependencies = additionalDependencies ?? Array.Empty <FileInfo>(); }
public StartupOptions( bool production = false, bool languageService = false, string key = null, string applicationInsightsKey = null, string id = null, string regionId = null, PackageSource addPackageSource = null, Uri uri = null, DirectoryInfo logPath = null, bool verbose = false, bool enablePreviewFeatures = false, string package = null, string packageVersion = null, ParseResult parseResult = null, ushort?port = null, IDirectoryAccessor rootDirectory = null) { _parseResult = parseResult; LogPath = logPath; Verbose = verbose; Id = id; Production = production; IsLanguageService = languageService; Key = key; ApplicationInsightsKey = applicationInsightsKey; RegionId = regionId; RootDirectory = rootDirectory ?? new FileSystemDirectoryAccessor(new DirectoryInfo(Directory.GetCurrentDirectory())); AddPackageSource = addPackageSource; Uri = uri; EnablePreviewFeatures = enablePreviewFeatures; Package = package; PackageVersion = packageVersion; Port = port; }
public static async Task LoadFromAssembliesInDirectory( this KernelExtensionLoader loader, IDirectoryAccessor directory, IKernel kernel, KernelInvocationContext context, IReadOnlyList <FileInfo> additionalDependencies = null) { if (directory.RootDirectoryExists()) { context.Publish(new DisplayedValueProduced($"Loading kernel extensions in directory {directory.GetFullyQualifiedRoot().FullName}", context.Command)); var extensionDlls = directory.GetAllFiles() .Where(file => file.Extension == ".dll") .Select(directory.GetFullyQualifiedFilePath); foreach (var extensionDll in extensionDlls) { await loader.LoadFromAssembly( extensionDll, kernel, context, additionalDependencies); } context.Publish(new DisplayedValueProduced($"Loaded kernel extensions in directory {directory.GetFullyQualifiedRoot().FullName}", context.Command)); } }
public static void WriteAllText( this IDirectoryAccessor directoryAccessor, string relativePath, string text) => directoryAccessor.WriteAllText( new RelativeFilePath(relativePath), text);
public static bool IsSubDirectoryOf(this IDirectoryAccessor potentialChild, IDirectoryAccessor directory) { var child = potentialChild.GetFullyQualifiedPath(_here).FullName; var parent = directory.GetFullyQualifiedPath(_here).FullName; return(IsBaseOf(parent, child, selfIsChild: false)); }
private void LaunchBrowser(IBrowserLauncher browserLauncher, IDirectoryAccessor directoryAccessor, Uri uri) { if (StartupOptions.Uri != null && !StartupOptions.Uri.IsAbsoluteUri) { uri = new Uri(uri, StartupOptions.Uri); } else if (StartupOptions.Uri == null) { var readmeFile = FindReadmeFileAtRoot(); if (readmeFile != null) { uri = new Uri(uri, readmeFile.ToString()); } } browserLauncher.LaunchBrowser(uri); RelativeFilePath FindReadmeFileAtRoot() { var files = directoryAccessor .GetAllFilesRecursively() .Where(f => StringComparer.InvariantCultureIgnoreCase.Compare(f.FileName, "readme.md") == 0 && IsRoot(f.Directory)) .ToList(); return(files.FirstOrDefault()); } bool IsRoot(RelativeDirectoryPath path) { var isRoot = path == null || path == RelativeDirectoryPath.Root; return(isRoot); } }
public async Task LoadExtensionsFromDirectory(IDirectoryAccessor directory, KernelInvocationContext context, IEnumerable <string> additionalDependencies = null) { var extensionsDirectory = directory.GetDirectoryAccessorForRelativePath(_assemblyExtensionsPath); await new KernelExtensionLoader().LoadFromAssembliesInDirectory(extensionsDirectory, context.HandlingKernel, context, additionalDependencies); }
public async Task DownloadToAsync(IDirectoryAccessor destinationRootDirectory, System.Threading.CancellationToken cancellation) { if (destinationRootDirectory.Access != IOAccess.FULL) { throw new NotSupportedException("Access denied"); } foreach (var fileTask in EnumerateFilesAsync()) { var file = await fileTask; var destinationFile = await destinationRootDirectory.GetFileAsync(new UPath(PATH_FORMAT, file.Name), cancellation); using (var destinationFileStream = await destinationFile.OpenAsync(FileOpenMode.NEW, cancellation)) using (var fileStream = await file.OpenAsync(FileOpenMode.OPEN_OR_NEW, cancellation)) { await fileStream.WriteToAsync(destinationFileStream, cancellation); } } foreach (var innerDir in EnumerateDirectoriesAsync(cancellation)) { var dir = await innerDir; var destinationDirectoryPath = new UPath(PATH_FORMAT, dir._rawData.path.RemoveFirst(_rawData.path)); var destinationDirectory = await destinationRootDirectory.GetDirectoryAsync(destinationDirectoryPath, cancellation); await destinationDirectory.EnsureCreatedAsync(cancellation); await dir.DownloadToAsync(destinationDirectory, cancellation); } }
public RemoteMailboxProperties(IStoreSession storeSession, IDirectoryAccessor directoryAccessor) { ArgumentValidator.ThrowIfNull("storeSession", storeSession); ArgumentValidator.ThrowIfNull("directoryAccessor", directoryAccessor); this.storeSession = storeSession; this.directoryAccessor = directoryAccessor; }
public static bool IsChildOf(this FileSystemInfo file, IDirectoryAccessor directory) { var parent = directory.GetFullyQualifiedPath(_here).FullName; var child = Path.GetDirectoryName(file.FullName); child = child.EndsWith('/') || child.EndsWith('\\') ? child : child + "/"; return(IsBaseOf(parent, child, selfIsChild: true)); }
public Package2( PackageDescriptor descriptor, IDirectoryAccessor directoryAccessor) { _descriptor = descriptor ?? throw new ArgumentNullException(nameof(descriptor)); DirectoryAccessor = directoryAccessor ?? throw new ArgumentNullException(nameof(directoryAccessor)); }
public static IDirectoryAccessor GetDirectoryAccessorFor(this IDirectoryAccessor directory, DirectoryInfo directoryInfo) { var relative = PathUtilities.GetRelativePath( directory.GetFullyQualifiedRoot().FullName, directoryInfo.FullName); return(directory.GetDirectoryAccessorForRelativePath(new RelativeDirectoryPath(relative))); }
public static Task <IDisposable> TryCreateAsync(IDirectoryAccessor directoryAccessor) { if (directoryAccessor == null) { throw new ArgumentNullException(nameof(directoryAccessor)); } return(TryCreateAsync(directoryAccessor.GetFullyQualifiedFilePath(LockFileName))); }
public PublishOptions( IDirectoryAccessor rootDirectory, IDirectoryAccessor targetDirectory = null, PublishFormat format = PublishFormat.Markdown) : base(rootDirectory) { Format = format; TargetDirectory = targetDirectory ?? rootDirectory; }
public static void EnsureDirectoryExists(this IDirectoryAccessor directoryAccessor, RelativePath path) { var relativeDirectoryPath = path.Match( directory => directory, file => file.Directory ); directoryAccessor.EnsureDirectoryExists(relativeDirectoryPath); }
public MarkdownProject( IDirectoryAccessor directoryAccessor, PackageRegistry packageRegistry, IDefaultCodeBlockAnnotations defaultAnnotations = null) { DirectoryAccessor = directoryAccessor ?? throw new ArgumentNullException(nameof(directoryAccessor)); _packageRegistry = packageRegistry ?? throw new ArgumentNullException(nameof(packageRegistry)); _defaultAnnotations = defaultAnnotations; }
public static Task <IDisposable> TryLockAsync(this IDirectoryAccessor directoryAccessor) { if (directoryAccessor == null) { throw new ArgumentNullException(nameof(directoryAccessor)); } return(FileLock.TryCreateAsync(directoryAccessor)); }
public PublishOptions( IDirectoryAccessor rootDirectory, IDirectoryAccessor targetDirectory = null, PublishFormat format = PublishFormat.Markdown) { RootDirectory = rootDirectory ?? throw new System.ArgumentNullException(nameof(rootDirectory)); Format = format; TargetDirectory = targetDirectory ?? rootDirectory; }
public async Task LoadFromAssembliesInDirectory(IDirectoryAccessor directory, IKernel kernel, PublishEvent publishEvent) { if (directory.RootDirectoryExists()) { var extensionDlls = directory.GetAllFiles().Where(file => file.Extension == ".dll").Select(file => directory.GetFullyQualifiedFilePath(file)); foreach (var extensionDll in extensionDlls) { await LoadFromAssembly(extensionDll, kernel, publishEvent); } } }
public DirectoryEngine(IDirectoryAccessor directoryAccessor, ICacheAccessor cacheAccessor, IExportAccessor exportAccessor) { _directoryAccessor = directoryAccessor ?? throw new ArgumentNullException(nameof(directoryAccessor)); _cacheAccessor = cacheAccessor ?? throw new ArgumentNullException(nameof(cacheAccessor)); _exportAccessor = exportAccessor ?? throw new ArgumentNullException(nameof(exportAccessor)); }
async Task validateContent(IDirectoryAccessor directory, string folderNames, string fileNames, System.Threading.CancellationToken cancellation) { var directories = directory.EnumerateDirectoriesAsync(cancellation).Select(d => d.Result.Name).ToArray(); var files = directory.EnumerateFilesAsync(cancellation).Select(f => f.Result.Name).ToArray(); var expectedFolders = folderNames?.Split(",") ?? new string[0]; var expectedFiles = fileNames?.Split(",") ?? new string[0]; Assert.Equal(expectedFolders, directories); Assert.Equal(expectedFiles, files); }
public LocalCodeFenceAnnotationsParser( IDirectoryAccessor directoryAccessor, PackageRegistry packageRegistry, IDefaultCodeBlockAnnotations defaultAnnotations = null) : base(defaultAnnotations, csharp => { AddProjectOption(csharp, directoryAccessor); AddSourceFileOption(csharp); }) { _directoryAccessor = directoryAccessor; _packageRegistry = packageRegistry ?? throw new ArgumentNullException(nameof(packageRegistry)); }
public static MarkdownPipelineBuilder UseCodeBlockAnnotations( this MarkdownPipelineBuilder pipeline, IDirectoryAccessor directoryAccessor, PackageRegistry packageRegistry, IDefaultCodeBlockAnnotations defaultAnnotations = null) { return(pipeline.UseCodeBlockAnnotations( new LocalCodeFenceAnnotationsParser( directoryAccessor, packageRegistry, defaultAnnotations))); }
public static PackageTool TryCreateFromDirectory(string name, IDirectoryAccessor directoryAccessor) { var tool = new PackageTool(name, directoryAccessor); if (tool.Exists()) { return(tool); } else { return(null); } }
public static Buffer GetBufferAsync( this AnnotatedCodeBlock block, IDirectoryAccessor directoryAccessor, MarkdownFile markdownFile) { if (block.Annotations is LocalCodeBlockAnnotations localOptions) { var absolutePath = directoryAccessor.GetFullyQualifiedPath(localOptions.SourceFile).FullName; var bufferId = new BufferId(absolutePath, block.Annotations.Region); return(new Buffer(bufferId, block.SourceCode)); } return(null); }
public AgentService(StartupOptions options = null, IDirectoryAccessor directoryAccessor = null) { _directoryAccessor = directoryAccessor; _options = options ?? new StartupOptions( production: false, languageService: false); var testServer = CreateTestServer(); _client = testServer.CreateClient(); _disposables.Add(testServer); _disposables.Add(_client); }
private static void VerifyAnnotationReferences( AnnotatedCodeBlock annotatedCodeBlock, IDirectoryAccessor markdownFileDir, IConsole console, MarkdownProcessingContext context) { Console.ResetColor(); console.Out.WriteLine(" Checking Markdown..."); var diagnostics = annotatedCodeBlock.Diagnostics.ToArray(); var hasDiagnostics = diagnostics.Any(); if (hasDiagnostics) { Console.ForegroundColor = ConsoleColor.Red; } else { Console.ForegroundColor = ConsoleColor.Green; } if (annotatedCodeBlock.Annotations is LocalCodeBlockAnnotations annotations) { var file = annotations?.SourceFile ?? annotations?.DestinationFile; var fullyQualifiedPath = file != null ? markdownFileDir.GetFullyQualifiedPath(file).FullName : "UNKNOWN"; var project = annotatedCodeBlock.ProjectOrPackageName() ?? "UNKNOWN"; var symbol = hasDiagnostics ? "X" : "✓"; var error = $" {symbol} Line {annotatedCodeBlock.Line + 1}:\t{fullyQualifiedPath} (in project {project})"; if (hasDiagnostics) { context.Errors.Add(error); } console.Out.WriteLine(error); } foreach (var diagnostic in diagnostics) { console.Out.WriteLine($"\t\t{diagnostic}"); } }
private static string WriteTargetFile(string content, RelativeFilePath relativePath, IDirectoryAccessor targetDirectoryAccessor, PublishOptions publishOptions, WriteOutput writeOutput) { var fullyQualifiedPath = targetDirectoryAccessor.GetFullyQualifiedPath(relativePath); targetDirectoryAccessor.EnsureDirectoryExists(relativePath); var targetPath = fullyQualifiedPath.FullName; if (publishOptions.Format == PublishFormat.HTML) { targetPath = Path.ChangeExtension(targetPath, ".html"); } writeOutput(targetPath, content); return(targetPath); }
public ExportProcessingEngine(IExportAccessor exportAccessor, IDirectoryAccessor directoryAccessor, IEmailAccessor emailAccessor, ICacheAccessor cache) { _exportAccessor = exportAccessor ?? throw new ArgumentNullException(nameof(exportAccessor)); _directoryAccessor = directoryAccessor ?? throw new ArgumentNullException(nameof(directoryAccessor)); _emailAccessor = emailAccessor ?? throw new ArgumentNullException(nameof(emailAccessor)); _cache = cache ?? throw new ArgumentNullException(nameof(cache)); }
private static void AddProjectOption( Command command, IDirectoryAccessor directoryAccessor, string projectFileExtension) { var projectOptionArgument = new Argument <FileInfo>( (SymbolResult result, out FileInfo projectFile) => { var projectPath = new RelativeFilePath(result.Tokens.Select(t => t.Value).Single()); if (directoryAccessor.FileExists(projectPath)) { projectFile = directoryAccessor.GetFullyQualifiedFilePath(projectPath); return(true); } result.ErrorMessage = $"Project not found: {projectPath.Value}"; projectFile = null; return(false); }) { Name = "project", Arity = ArgumentArity.ExactlyOne }; projectOptionArgument.SetDefaultValue(() => { var rootDirectory = directoryAccessor.GetFullyQualifiedPath(new RelativeDirectoryPath(".")); var projectFiles = directoryAccessor.GetAllFilesRecursively() .Where(file => directoryAccessor.GetFullyQualifiedPath(file.Directory).FullName == rootDirectory.FullName && file.Extension == projectFileExtension) .ToArray(); if (projectFiles.Length == 1) { return(directoryAccessor.GetFullyQualifiedPath(projectFiles.Single())); } return(null); }); var projectOption = new Option("--project") { Argument = projectOptionArgument }; command.Add(projectOption); }