Dreamine.Web 1.0.0.0
WPF와 Blazor를 한 코드 흐름으로 연결하고 반복적인 MVVM 코드를 줄이는 오픈소스 FullKit 공식 웹 애플리케이션입니다.
로딩중...
검색중...
일치하는것 없음
DocViewModel.cs
이 파일의 문서화 페이지로 가기
1using System.IO;
2using Dreamine.MVVM.ViewModels;
5using Markdig;
6
8
17public class DocViewModel : ViewModelBase
18{
27 private readonly ILibraryStore _store;
36 private readonly string _xmlDocRoot;
37
46 private static readonly MarkdownPipeline _pipeline =
47 new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
48
57 public LibraryInfo? Library { get; private set; }
66 public List<DocMember> Members { get; private set; } = [];
67
76 public bool IsKorean { get; set; } = true;
77
86 public string? ReadmeHtml { get; private set; }
87
96 public string? MermaidDiagram { get; private set; }
97
106 public bool HasDiagram { get; private set; }
107
116 public string DiagramUrl { get; private set; } = string.Empty;
117
126 public IEnumerable<DocMember> Types =>
127 Members.Where(m => m.Kind == DocMemberKind.Type).OrderBy(m => m.ShortName);
128
137 public IEnumerable<IGrouping<string?, DocMember>> MembersByType =>
138 Members.Where(m => m.Kind != DocMemberKind.Type)
139 .OrderBy(m => m.TypeName).ThenBy(m => m.Kind).ThenBy(m => m.ShortName)
140 .GroupBy(m => m.TypeName);
141
159 {
160 _store = store;
161 _xmlDocRoot = Path.Combine(AppContext.BaseDirectory, "wwwroot", "xmldocs");
162 }
163
188 public async Task LoadAsync(string libraryId)
189 {
190 Library = await _store.GetAsync(libraryId);
191 Members = [];
192 ReadmeHtml = null;
193 MermaidDiagram = null;
194 HasDiagram = false;
195
196 if (Library is null) return;
197
198 var docDir = Path.Combine(_xmlDocRoot, Library.Name);
199
200 // XML API 문서
201 var xmlPath = Path.Combine(docDir, $"{Library.Name}.xml");
202 if (File.Exists(xmlPath))
203 Members = XmlDocParser.Parse(xmlPath);
204 else if (!string.IsNullOrEmpty(Library.XmlDocPath) && File.Exists(Library.XmlDocPath))
205 Members = XmlDocParser.Parse(Library.XmlDocPath);
206
207 // README
208 LoadReadme(docDir);
209
210 // Mermaid 다이어그램 (우선)
211 var mermaidPath = Path.Combine(docDir, "diagram.mermaid");
212 if (File.Exists(mermaidPath))
213 {
214 MermaidDiagram = File.ReadAllText(mermaidPath).Trim();
215 HasDiagram = true;
216 }
217 else
218 {
219 // SVG fallback
220 var svgPath = Path.Combine(docDir, "diagram.svg");
221 if (File.Exists(svgPath))
222 {
223 HasDiagram = true;
224 DiagramUrl = $"/xmldocs/{Library.Name}/diagram.svg";
225 }
226 }
227 }
228
237 public void RefreshReadme()
238 {
239 if (Library is not null)
240 LoadReadme(Path.Combine(_xmlDocRoot, Library.Name));
241 }
242
259 private void LoadReadme(string docDir)
260 {
261 string? mdPath = null;
262
263 if (IsKorean)
264 {
265 var ko1 = Path.Combine(docDir, "README_KO.md");
266 var ko2 = Path.Combine(docDir, "README_ko.md");
267 if (File.Exists(ko1)) mdPath = ko1;
268 else if (File.Exists(ko2)) mdPath = ko2;
269 }
270
271 if (mdPath is null)
272 {
273 var en = Path.Combine(docDir, "README.md");
274 if (File.Exists(en)) mdPath = en;
275 }
276
277 ReadmeHtml = mdPath is not null
278 ? Markdown.ToHtml(File.ReadAllText(mdPath), _pipeline)
279 : null;
280 }
281}
static List< DocMember > Parse(string xmlPath)
static readonly MarkdownPipeline _pipeline
readonly ILibraryStore _store
async Task LoadAsync(string libraryId)
IEnumerable< IGrouping< string?, DocMember > > MembersByType
IEnumerable< DocMember > Types