|
13 | 13 | using Microsoft.AspNetCore.Hosting;
|
14 | 14 | using Microsoft.AspNetCore.Http;
|
15 | 15 | using Microsoft.Extensions.DependencyInjection;
|
16 |
| -using Microsoft.Extensions.FileProviders; |
17 | 16 | using Microsoft.Extensions.Hosting;
|
18 | 17 | using Microsoft.Extensions.Logging;
|
19 |
| -using Microsoft.Extensions.Primitives; |
20 | 18 | using Westwind.AspNetCore.LiveReload;
|
21 |
| -using IFileInfo = Microsoft.Extensions.FileProviders.IFileInfo; |
22 | 19 |
|
23 | 20 | namespace Documentation.Builder.Http;
|
24 | 21 |
|
@@ -184,74 +181,3 @@ private static async Task<IResult> ServeDocumentationFile(ReloadableGeneratorSta
|
184 | 181 | }
|
185 | 182 | }
|
186 | 183 | }
|
187 |
| - |
188 |
| - |
189 |
| -public sealed class EmbeddedOrPhysicalFileProvider : IFileProvider, IDisposable |
190 |
| -{ |
191 |
| - private readonly EmbeddedFileProvider _embeddedProvider = new(typeof(BuildContext).Assembly, "Elastic.Markdown._static"); |
192 |
| - private readonly PhysicalFileProvider? _staticFilesInDocsFolder; |
193 |
| - |
194 |
| - private readonly PhysicalFileProvider? _staticWebFilesDuringDebug; |
195 |
| - |
196 |
| - public EmbeddedOrPhysicalFileProvider(BuildContext context) |
197 |
| - { |
198 |
| - var documentationStaticFiles = Path.Combine(context.DocumentationSourceDirectory.FullName, "_static"); |
199 |
| -#if DEBUG |
200 |
| - // this attempts to serve files directly from their source rather than the embedded resources during development. |
201 |
| - // this allows us to change js/css files without restarting the webserver |
202 |
| - var solutionRoot = Paths.GetSolutionDirectory(); |
203 |
| - if (solutionRoot != null) |
204 |
| - { |
205 |
| - |
206 |
| - var debugWebFiles = Path.Combine(solutionRoot.FullName, "src", "Elastic.Markdown", "_static"); |
207 |
| - _staticWebFilesDuringDebug = new PhysicalFileProvider(debugWebFiles); |
208 |
| - } |
209 |
| -#else |
210 |
| - _staticWebFilesDuringDebug = null; |
211 |
| -#endif |
212 |
| - if (context.ReadFileSystem.Directory.Exists(documentationStaticFiles)) |
213 |
| - _staticFilesInDocsFolder = new PhysicalFileProvider(documentationStaticFiles); |
214 |
| - } |
215 |
| - |
216 |
| - private T? FirstYielding<T>(string arg, Func<string, PhysicalFileProvider, T?> predicate) => |
217 |
| - Yield(arg, predicate, _staticWebFilesDuringDebug) ?? Yield(arg, predicate, _staticFilesInDocsFolder); |
218 |
| - |
219 |
| - private static T? Yield<T>(string arg, Func<string, PhysicalFileProvider, T?> predicate, PhysicalFileProvider? provider) |
220 |
| - { |
221 |
| - if (provider is null) |
222 |
| - return default; |
223 |
| - var result = predicate(arg, provider); |
224 |
| - return result ?? default; |
225 |
| - } |
226 |
| - |
227 |
| - public IDirectoryContents GetDirectoryContents(string subpath) |
228 |
| - { |
229 |
| - var contents = FirstYielding(subpath, static (a, p) => p.GetDirectoryContents(a)); |
230 |
| - if (contents is null || !contents.Exists) |
231 |
| - contents = _embeddedProvider.GetDirectoryContents(subpath); |
232 |
| - return contents; |
233 |
| - } |
234 |
| - |
235 |
| - public IFileInfo GetFileInfo(string subpath) |
236 |
| - { |
237 |
| - var path = subpath.Replace($"{Path.DirectorySeparatorChar}_static", ""); |
238 |
| - var fileInfo = FirstYielding(path, static (a, p) => p.GetFileInfo(a)); |
239 |
| - if (fileInfo is null || !fileInfo.Exists) |
240 |
| - fileInfo = _embeddedProvider.GetFileInfo(subpath); |
241 |
| - return fileInfo; |
242 |
| - } |
243 |
| - |
244 |
| - public IChangeToken Watch(string filter) |
245 |
| - { |
246 |
| - var changeToken = FirstYielding(filter, static (f, p) => p.Watch(f)); |
247 |
| - if (changeToken is null or NullChangeToken) |
248 |
| - changeToken = _embeddedProvider.Watch(filter); |
249 |
| - return changeToken; |
250 |
| - } |
251 |
| - |
252 |
| - public void Dispose() |
253 |
| - { |
254 |
| - _staticFilesInDocsFolder?.Dispose(); |
255 |
| - _staticWebFilesDuringDebug?.Dispose(); |
256 |
| - } |
257 |
| -} |
0 commit comments