Nuget Nuget

Creek.FileRepository

An easy way to hook up various file storage mechanisms, following the repository pattern with a factory.

This is available on NuGet - just click one of the buttons above, or search for Creek.FileRepository in Visual Studio.

How to use a repository

appsettings.json

To utilise a repository you'll need to set up the relevant section in your appsettings.json, for example this section for an SFTP repository:

"SftpRepository": {
    "host": "my-server.local",
    "port": 22,
    "username": "usernamegoeshere",
    "password": "passwordgoeshere",
    "remoteDirectoryPath": "/home/username/foldername"
  }

You can load this into your standard config in a dotnet core app, or manually load it with something like:

private static IConfiguration InitConfiguration()
{
    IConfigurationRoot configBuilder = new ConfigurationBuilder()
        .AddJsonFile("appsettings.json")
        .Build();
    return configBuilder;
}

Loading the repository

Use the enum of RepositoryTypes to select the repository you want, then use the factory to instantiate it.

Factory.RepositoryType repositoryType = Factory.RepositoryType.Sftp;
IFileRepository fileRepository = Factory.GetFileRepository(repositoryType, config);

CRUD operations

Create

RepoFile repoFile = new RepoFile();

// .. Make changes to a Stream contentStream property here

repoFile = repoFile.GenerateFile(filename, contentStream);

await fileRepository.CreateFileAsync(repoFile);

Read

RepoFile repoFile = await fileRepository.ReadFileAsync(filename);

Update

// .. Make changes to the file's Content property here

await fileRepository.UpdateFileAsync(repoFile);

Delete

await fileRepository.DeleteFileAsync(filename);

Storage Repositories

The following storage mechanisms are included:

  • Disk [in progress]
  • MongoDB [in progress]
  • S3 [in progress]
  • SFTP
  • SQL [in progress]

The appsettings sections for each one that isn't in progress are included below.

SFTP

"SftpRepository": {
    "host": "",
    "port": 22,
    "username": "",
    "password": "",
    "remoteDirectoryPath": "/"
  }
S
Description
No description provided
Readme GPL-3.0 84 KiB
Languages
C# 100%