示例#1
0
 public LoadExtensionsInDirectory(
     IDirectoryAccessor directory,
     IReadOnlyList <FileInfo> additionalDependencies = null)
 {
     Directory = directory;
     AdditionalDependencies = additionalDependencies ?? Array.Empty <FileInfo>();
 }
示例#2
0
 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;
 }
示例#3
0
        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));
            }
        }
示例#4
0
 public static void WriteAllText(
     this IDirectoryAccessor directoryAccessor,
     string relativePath,
     string text) =>
 directoryAccessor.WriteAllText(
     new RelativeFilePath(relativePath),
     text);
示例#5
0
        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));
        }
示例#6
0
文件: Startup.cs 项目: yarligayan/try
        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);
            }
        }
示例#7
0
        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);
        }
示例#8
0
        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);
            }
        }
示例#9
0
 public RemoteMailboxProperties(IStoreSession storeSession, IDirectoryAccessor directoryAccessor)
 {
     ArgumentValidator.ThrowIfNull("storeSession", storeSession);
     ArgumentValidator.ThrowIfNull("directoryAccessor", directoryAccessor);
     this.storeSession      = storeSession;
     this.directoryAccessor = directoryAccessor;
 }
示例#10
0
        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));
        }
示例#11
0
        public Package2(
            PackageDescriptor descriptor,
            IDirectoryAccessor directoryAccessor)
        {
            _descriptor = descriptor ?? throw new ArgumentNullException(nameof(descriptor));

            DirectoryAccessor = directoryAccessor ?? throw new ArgumentNullException(nameof(directoryAccessor));
        }
示例#12
0
        public static IDirectoryAccessor GetDirectoryAccessorFor(this IDirectoryAccessor directory, DirectoryInfo directoryInfo)
        {
            var relative = PathUtilities.GetRelativePath(
                directory.GetFullyQualifiedRoot().FullName,
                directoryInfo.FullName);

            return(directory.GetDirectoryAccessorForRelativePath(new RelativeDirectoryPath(relative)));
        }
示例#13
0
 public static Task <IDisposable> TryCreateAsync(IDirectoryAccessor directoryAccessor)
 {
     if (directoryAccessor == null)
     {
         throw new ArgumentNullException(nameof(directoryAccessor));
     }
     return(TryCreateAsync(directoryAccessor.GetFullyQualifiedFilePath(LockFileName)));
 }
示例#14
0
 public PublishOptions(
     IDirectoryAccessor rootDirectory,
     IDirectoryAccessor targetDirectory = null,
     PublishFormat format = PublishFormat.Markdown) : base(rootDirectory)
 {
     Format          = format;
     TargetDirectory = targetDirectory ?? rootDirectory;
 }
示例#15
0
        public static void EnsureDirectoryExists(this IDirectoryAccessor directoryAccessor, RelativePath path)
        {
            var relativeDirectoryPath = path.Match(
                directory => directory,
                file => file.Directory
                );

            directoryAccessor.EnsureDirectoryExists(relativeDirectoryPath);
        }
示例#16
0
 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;
 }
示例#17
0
        public static Task <IDisposable> TryLockAsync(this IDirectoryAccessor directoryAccessor)
        {
            if (directoryAccessor == null)
            {
                throw new ArgumentNullException(nameof(directoryAccessor));
            }

            return(FileLock.TryCreateAsync(directoryAccessor));
        }
示例#18
0
 public PublishOptions(
     IDirectoryAccessor rootDirectory,
     IDirectoryAccessor targetDirectory = null,
     PublishFormat format = PublishFormat.Markdown)
 {
     RootDirectory   = rootDirectory ?? throw new System.ArgumentNullException(nameof(rootDirectory));
     Format          = format;
     TargetDirectory = targetDirectory ?? rootDirectory;
 }
示例#19
0
 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);
         }
     }
 }
示例#20
0
        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)));
 }
示例#24
0
        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);
        }
示例#26
0
        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);
        }
示例#27
0
        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}");
            }
        }
示例#28
0
        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));
        }
示例#30
0
        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);
        }