Repository navigation
Expand file tree
/
Copy pathFileSystem.cs
More file actions
65 lines (50 loc) · 1.88 KB
/
Copy pathFileSystem.cs
File metadata and controls
65 lines (50 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.IO.Abstractions;
using System.Security.AccessControl;
namespace IsolatedFileSystem
{
/// <summary>
/// Implementation of <see cref="System.IO.Abstractions.IFileSystem"/>, that
/// allows to lock file system within specified physical folder.
/// </summary>
public class FileSystem : IFileSystem
{
private readonly string _rootFolderPath;
private readonly IFileSystem _physicalFileSystem = new System.IO.Abstractions.FileSystem();
/// <summary>
/// .ctor
/// </summary>
/// <param name="rootFolderPath">Root folder where file system will be locked</param>
public FileSystem(string rootFolderPath)
{
if (string.IsNullOrWhiteSpace(_rootFolderPath))
{
throw new ArgumentException("Root folder was not specified.");
}
_rootFolderPath = rootFolderPath;
if (!_physicalFileSystem.Directory.Exists(_rootFolderPath))
{
_physicalFileSystem.Directory.CreateDirectory(_rootFolderPath);
}
Path = new Path(_rootFolderPath, _physicalFileSystem);
}
#region Implementation of IFileSystem
/// <inheritdoc />
public IFile File { get; }
/// <inheritdoc />
public IDirectory Directory { get; }
/// <inheritdoc />
public IFileInfoFactory FileInfo { get; }
/// <inheritdoc />
public IFileStreamFactory FileStream { get; }
/// <inheritdoc />
public IPath Path { get; }
/// <inheritdoc />
public IDirectoryInfoFactory DirectoryInfo { get; }
/// <inheritdoc />
public IDriveInfoFactory DriveInfo { get; }
/// <inheritdoc />
public IFileSystemWatcherFactory FileSystemWatcher { get; }
#endregion
}
}