Skip to content

Latest commit

 

History

History
64 lines (49 loc) · 1.93 KB

File metadata and controls

64 lines (49 loc) · 1.93 KB

WebDav storage

NuGet GitHub release (latest by date) GitHub

Description

AImplementation of file storage abstraction based on WebDav protocol.

Well suited for small applications that work in content and do not have their own persistent storage, as well as for storing files that are used by two or more instances.

Install

For use you needed install packages:

Install-Package Skidbladnir.Storage.WebDav

Using

Register FileStorage in IoC Container

public void ConfigureServices(IServiceCollection services)
{
    services.AddWebDavStorage(new WebDavStorageConfiguration(){
        Address = "https://my-webdav/",
        Username = "User",
        Password = "Pass"
        });
    service.AddHostedService<TestBackgroundService>(); //Add sample service
}

Resolve and use

public class TestBackgroundService : BackgroundService{
    private IStorage<WebDavStorageInfo> _storage;
    private ILogger<StartupModule> _logger;
    public TestBackgroundService(ILogger<StartupModule> logger , IStorage<WebDavStorageInfo> storage){
        _storage = storage;
        _logger = logger;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        var currentDir = await _storage.GetFilesAsync("");
        _logger.LogInformation("Files in root dir");
        foreach (var fileInfo in currentDir)
        {
            _logger.LogInformation("Filename: {FileName}\t\t Length: {Length}\t\t Date: {Date}",
                fileInfo.FileName,
                fileInfo.Size, fileInfo.CreatedDate);
        }
    }
}