Skip to content

RainsSoft/VirtualPath

 
 

Repository files navigation

VirtualPath .NET Library

A simple abstraction layer over file system like APIs

Currently implemented:

Installation

Nuget: install-package VirtualPath

Usage

Direct instanciation of provider:

using(var storage = new InMemoryVirtualPathProvider())
{
	var file = storage.GetFile("/info.txt");
	var info = file.ReadAllText();
}

Using VirtualPathProvider factory:

// general usage:
var storage = VirtualPathProvider.Open(providerName, config);

// Exemples:
VirtualPathProvider.Open("Memory")
VirtualPathProvider.Open("FileSystem", "C:\\Temp\\")
VirtualPathProvider.Open("FTP", "host=ftp.company.com;username=login;password=password")
VirtualPathProvider.Open("SFTP", "host=ftp.company.com;username=login;password=password")
VirtualPathProvider.Open("Dropbox", "apikey=;apisecret=;usertoken=;usersecret=")

You can also pass anonymous objects to specify constructor parameters:

var config = new { host = "ftp.company.com", username = "login", password = "password" };
VirtualPathProvider.Open("FTP", config);

Factory behavior:

  • If you pass a string:
    • split it on ';' then build IDict<string,string> by splitting on '=',
    • if no key => wildcard key (works for single parameter constructors like FileSystem)
  • If passing an object, build a IDict<string,object> from properties

Finding the constructor:

  • filter constructors with matching parameter count
  • if one result: return constructor
  • filter remaining constructors on parameter names
  • if one result: return constructor
  • filter remaining on parameter types (including conversions if passed strings)
  • if one result: return constructor

Available providerNames:

  • InMemoryVirtualPathProvider: Memory
  • FileSystemVirtualPathProvider: FileSystem, FS
  • FtpVirtualPathProvider: AlexFTPS, FTP
  • SftpVirtualPathProvider: SshNet, SFTP
  • DropboxVirtualPathProvider: DropNet, Dropbox
  • ZipVirtualPathProvider: Zip, DotNetZip

Todo

  • FTPS by providerName
  • CIFS credentials in FileSystem
  • WebDAV
  • Cross provider methods
    • CopyFile(string virtualPath, IVirtualFile file)
    • MoveFile(string virtualPath, IVirtualFile file)
    • etc

Futures (?)

  • Directory Move / Copy ?
  • Amazon S3
  • Google Drive
  • Transactional PathProvider (InMemory commiting to FileSystem for example)

Tanks

About

A simple abstraction layer over file system like APIs for .NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 98.8%
  • Other 1.2%