forked from ITHit/UserFileSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtualDrive.cs
More file actions
85 lines (75 loc) · 2.76 KB
/
Copy pathVirtualDrive.cs
File metadata and controls
85 lines (75 loc) · 2.76 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using log4net;
using ITHit.FileSystem.Samples.Common;
using ITHit.FileSystem.Samples.Common.Windows;
using ITHit.FileSystem;
namespace VirtualFileSystem
{
/// <summary>
/// Processes OS file system calls,
/// synchronizes the user file system to the remote storage and back,
/// monitors files pinning and unpinning in the local file system,
/// monitores changes in the remote storage.
/// </summary>
internal class VirtualDrive : VirtualDriveBase
{
/// <summary>
/// Monitors changes in the remote storage, notifies the client and updates the user file system.
/// </summary>
internal RemoteStorageMonitor RemoteStorageMonitor;
/// <inheritdoc/>
public VirtualDrive(string license, string userFileSystemRootPath, Settings settings, ILog log)
: base(license, userFileSystemRootPath, settings, log)
{
string remoteStorageRootPath = Mapping.MapPath(userFileSystemRootPath);
RemoteStorageMonitor = new RemoteStorageMonitor(remoteStorageRootPath, this, log);
}
/// <inheritdoc/>
public override async Task<IVirtualFileSystemItem> GetVirtualFileSystemItemAsync(string userFileSystemPath, FileSystemItemTypeEnum itemType, ILogger logger)
{
if (itemType == FileSystemItemTypeEnum.File)
{
return new VirtualFile(userFileSystemPath, this, logger);
}
else
{
return new VirtualFolder(userFileSystemPath, this, logger);
}
}
/// <summary>
/// Enables or disables full synchronization service, user file sytem monitor and remote storage monitor.
/// </summary>
/// <param name="enabled">Pass true to start synchronization. Pass false - to stop.</param>
public override async Task SetEnabledAsync(bool enabled)
{
await base.SetEnabledAsync(enabled);
if (enabled)
{
await RemoteStorageMonitor.StartAsync();
}
else
{
await RemoteStorageMonitor.StopAsync();
}
}
private bool disposedValue;
protected override void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
RemoteStorageMonitor.Dispose();
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
disposedValue = true;
}
base.Dispose(disposing);
}
}
}