|
1 | 1 | using Microsoft.Extensions.Logging;
|
| 2 | +using Microsoft.Extensions.Options; |
| 3 | +using Microsoft.TeamFoundation.TestManagement.WebApi; |
| 4 | +using Microsoft.TeamFoundation.Wiki.WebApi; |
2 | 5 | using System;
|
3 | 6 | using System.Collections.Generic;
|
4 | 7 | using System.IO;
|
| 8 | +using System.Linq; |
5 | 9 |
|
6 | 10 | namespace azuredevops_export_wiki
|
7 | 11 | {
|
8 |
| - internal class SingleFileScanner : IWikiDirectoryScanner |
| 12 | + internal class SingleFileScanner : WikiOptionFilesScanner |
9 | 13 | {
|
10 | 14 | private readonly string singleFilePath;
|
11 |
| - private ILogger logger; |
12 | 15 |
|
13 |
| - public SingleFileScanner(string filePath, ILogger logger) |
| 16 | + public SingleFileScanner(string filePath, string wikiPath, Options options, ILogger logger) |
| 17 | + : base(wikiPath, options, logger) |
14 | 18 | {
|
15 | 19 | this.singleFilePath = filePath;
|
16 |
| - this.logger = logger; |
17 | 20 | }
|
18 | 21 |
|
19 |
| - public IList<MarkdownFile> Scan() |
| 22 | + public override IList<MarkdownFile> Scan() |
20 | 23 | {
|
21 |
| - var filePath = Path.GetFullPath(singleFilePath); |
22 |
| - var directory = new DirectoryInfo(Path.GetFullPath(filePath)); |
| 24 | + var allFiles = base.Scan(); |
| 25 | + var current = allFiles.FirstOrDefault(m => m.FileRelativePath.Contains(singleFilePath)); |
| 26 | + var idx = allFiles.IndexOf(current); |
23 | 27 |
|
24 |
| - if (!File.Exists(filePath)) |
| 28 | + if (current is null || idx == -1) |
25 | 29 | {
|
26 |
| - logger.Log($"Single-File [-s] {filePath} specified not found" + filePath, LogLevel.Error); |
| 30 | + logger.Log($"Single-File [-s] {singleFilePath} specified not found" + singleFilePath, LogLevel.Error); |
27 | 31 | throw new ArgumentException($"{singleFilePath} not found");
|
28 | 32 | }
|
| 33 | + var result = new List<MarkdownFile>() { current }; |
29 | 34 |
|
30 |
| - var relativePath = filePath.Substring(directory.FullName.Length); |
| 35 | + if (allFiles.Count > idx) |
| 36 | + { |
| 37 | + foreach (var item in allFiles.Skip(idx + 1)) |
| 38 | + { |
| 39 | + if (item.Level > current.Level) |
| 40 | + { |
| 41 | + result.Add(item); |
| 42 | + } |
| 43 | + else |
| 44 | + break; |
| 45 | + } |
| 46 | + } |
31 | 47 |
|
32 |
| - return new List<MarkdownFile>() { |
33 |
| - new MarkdownFile(new FileInfo(filePath), relativePath, 0, "/") |
34 |
| - }; |
| 48 | + return result; |
35 | 49 | }
|
36 | 50 |
|
37 | 51 | }
|
|
0 commit comments