forked from ITHit/UserFileSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserFolder.cs
More file actions
90 lines (79 loc) · 3.92 KB
/
UserFolder.cs
File metadata and controls
90 lines (79 loc) · 3.92 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
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ITHit.FileSystem;
using ITHit.FileSystem.Samples.Common;
namespace VirtualFileSystem
{
/// <summary>
/// Represents a folder in the remote storage. Provides methods for enumerating this folder children,
/// creating files and folders and updating this folder information (creatin date, modification date, attributes, etc.).
/// </summary>
/// <remarks>You will change methods of this class to read/write data from/to your remote storage.</remarks>
internal class UserFolder : UserFileSystemItem, IUserFolder
{
/// <summary>
/// Creates instance of this class.
/// </summary>
/// <param name="userfileSystemFolderPath">Path of this folder in the user file system.</param>
/// <param name="lockInfo">Information about file lock. Pass null if the item is not locked.</param>
public UserFolder(string userfileSystemFolderPath) : base(userfileSystemFolderPath)
{
}
/// <summary>
/// Gets list of files and folders in this folder in the remote storage.
/// </summary>
/// <param name="pattern">Search pattern.</param>
/// <returns>
/// List of files and folders located in this folder in the remote
/// storage that correstonds with the provided search pattern.
/// </returns>
public async Task<IEnumerable<FileSystemItemBasicInfo>> EnumerateChildrenAsync(string pattern)
{
// This method has a 60 sec timeout.
// To process longer requests modify the IFolder.GetChildrenAsync() implementation.
IEnumerable<FileSystemInfo> remoteStorageChildren = new DirectoryInfo(RemoteStoragePath).EnumerateFileSystemInfos(pattern);
List<FileSystemItemBasicInfo> userFileSystemChildren = new List<FileSystemItemBasicInfo>();
foreach (FileSystemInfo remoteStorageItem in remoteStorageChildren)
{
FileSystemItemBasicInfo itemInfo = Mapping.GetUserFileSysteItemBasicInfo(remoteStorageItem);
userFileSystemChildren.Add(itemInfo);
}
return userFileSystemChildren;
}
/// <summary>
/// Creates a file in the remote storage.
/// </summary>
/// <param name="fileInfo">Information about the new file.</param>
/// <param name="content">New file content.</param>
/// <returns>New ETag returned from the remote storage.</returns>
public async Task<string> CreateFileAsync(IFileBasicInfo fileInfo, Stream content)
{
string itemPath = Path.Combine(RemoteStoragePath, fileInfo.Name);
return await CreateOrUpdateFileAsync(itemPath, fileInfo, FileMode.CreateNew, content);
}
/// <summary>
/// Creates a folder in the remote storage.
/// </summary>
/// <param name="folderInfo">Information about the new folder.</param>
/// <returns>New ETag returned from the remote storage.</returns>
public async Task<string> CreateFolderAsync(IFolderBasicInfo folderInfo)
{
string itemPath = Path.Combine(RemoteStoragePath, folderInfo.Name);
return await CreateOrUpdateFolderAsync(itemPath, folderInfo, FileMode.CreateNew);
}
/// <summary>
/// Updates folder in the remote storage.
/// </summary>
/// <param name="folderInfo">New folder information.</param>
/// <param name="lockInfo">Information about the lock. Caller passes null if the item is not locked.</param>
/// <returns>New ETag returned from the remote storage.</returns>
public async Task<string> UpdateAsync(IFolderBasicInfo folderInfo, ServerLockInfo lockInfo = null)
{
return await CreateOrUpdateFolderAsync(RemoteStoragePath, folderInfo, FileMode.Open);
}
}
}