private void SetMockRootPath(string path) { try { if (_fileProvider?.Root.Equals(path) == true) { return; } var fullPath = Path.IsPathRooted(path) ? path : Path.Combine(Directory.GetCurrentDirectory(), path); var fileProvider = new PhysicalFileProvider(fullPath, ExclusionFilters.Hidden | ExclusionFilters.System); _fileProvider?.Dispose(); _fileProvider = fileProvider; _logger.LogInformation("Mock path: {fullPath}", fullPath); } catch (Exception ex) { _logger.LogError(ex, "Error setting mock root path"); } }
public void Dispose() { if (fileProvider != null) { fileProvider.Dispose(); } }
/// <summary> /// Set the directory of the file provider /// </summary> /// <param name="webDirectory">New web directory</param> private void SetWebDirectory(string webDirectory) { lock (this) { _provider.Dispose(); _provider = new PhysicalFileProvider(webDirectory); } }
protected override void DisposeCore(bool disposing) { foreach (var kvp in _changeTokens) { kvp.Value.Dispose(); } _changeTokens.Clear(); _changeTokens = null; _innerFileProvider.Dispose(); }
/// <summary> /// Constructs a <see cref="UrlRewriteFileProvider"/> with the given options. /// </summary> public UrlWriteSpaStaticFileProvider(IServiceProvider serviceProvider, UrlRewriteSpaStaticFilesOptions options) { if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (string.IsNullOrEmpty(options.RootPath)) { throw new ArgumentException($"The {nameof(options.RootPath)} property of {nameof(options)} cannot be null or empty.", paramName: nameof(options)); } var env = serviceProvider.GetRequiredService <IWebHostEnvironment>(); var httpContextAccessor = serviceProvider.GetRequiredService <IHttpContextAccessor>(); var absoluteRootPath = Path.Combine(env.ContentRootPath, options.RootPath); if (Directory.Exists(absoluteRootPath)) { #pragma warning disable CA2000 // Dispose objects before losing scope var physicalFileProvider = new PhysicalFileProvider(absoluteRootPath); #pragma warning restore CA2000 // Dispose objects before losing scope try { this.fileProvider = new UrlRewriteFileProvider(physicalFileProvider, httpContextAccessor, options); } catch (Exception) { physicalFileProvider.Dispose(); throw; } } }
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> public void Dispose() { _memoryCache?.Dispose(); _physicalFileProvider?.Dispose(); }
public void Dispose() { _fileProvider.Dispose(); _fileSystem.Dispose(); }
public void Dispose() { _fileProvider?.Dispose(); _cache?.Dispose(); }
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> public void Dispose() { _memoryCache?.Dispose(); _fileProvider?.Dispose(); }
public void Dispose() { fileProvider?.Dispose(); }
/// <summary> /// Does the work. /// </summary> /// <param name="services">The services.</param> /// <param name="cancellation">The cancellation.</param> /// <returns></returns> public async override Task DoWorkAsync(IServiceProvider services, CancellationToken cancellation) { if (_initialDelay.HasValue) { await Task.Delay(_initialDelay.Value, cancellation); } using (var scope = services.CreateScope()) { var logger = scope.ServiceProvider.GetRequiredService <ILogger <FileWatcherBackgroundOperation> >(); if (string.IsNullOrEmpty(_directoryToWatch) || !Directory.Exists(_directoryToWatch)) { logger.LogWarning("'ImageDirectory' directory not found from configuration"); return; } PhysicalFileProvider fileProvider = null; try { fileProvider = new PhysicalFileProvider(_directoryToWatch, ExclusionFilters.Sensitive); logger.LogInformation("Starting to watch for '{filterGlobb}' inside '{directoryToWatch}'", _filterGlobb, _directoryToWatch); int counter = 0; while (!cancellation.IsCancellationRequested) { IChangeToken change_token = fileProvider.Watch(_filterGlobb); if (change_token == null) { break; } var tcs = new TaskCompletionSource <int>(); (IDisposable change, IDisposable cancel)regs = (null, null); try { regs.cancel = cancellation.Register((token) => { tcs.TrySetCanceled((CancellationToken)token); }, cancellation, false); regs.change = change_token.RegisterChangeCallback(async state => { counter++; int?result; int fail_count = _failRetryCount.GetValueOrDefault(1); do { result = _onChangeFunction?.Invoke(counter, _directoryToWatch, _filterGlobb); logger.LogInformation("'{filterGlobb}' changed {counter} of times, scheduled action with {result}", _filterGlobb, counter, result.GetValueOrDefault(-1)); await Task.Delay((_failRetryCount.GetValueOrDefault(1) - fail_count) << 9, cancellation); }while (--fail_count > 0 && result.GetValueOrDefault(-1) != 0); ((TaskCompletionSource <int>)state).TrySetResult(counter); }, tcs); var cntr = await tcs.Task.ConfigureAwait(false); await Task.Delay(250, cancellation); } catch (TaskCanceledException ex) { logger.LogWarning(ex, "cancelled"); } finally { regs.change?.Dispose(); regs.change = null; regs.cancel?.Dispose(); regs.cancel = null; } } } catch (Exception) { throw; } finally { fileProvider?.Dispose(); } } }
public void Dispose() { _fileProvider.Dispose(); }