forked from ITHit/UserFileSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserFile.cs
More file actions
65 lines (58 loc) · 2.66 KB
/
UserFile.cs
File metadata and controls
65 lines (58 loc) · 2.66 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.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using ITHit.FileSystem;
using ITHit.FileSystem.Samples.Common;
namespace VirtualFileSystem
{
/// <summary>
/// Represents a file in the remote storage.
/// </summary>
/// <remarks>You will change methods of this class to read/write data from/to your remote storage.</remarks>
internal class UserFile : UserFileSystemItem, IUserFile
{
/// <summary>
/// Creates instance of this class.
/// </summary>
/// <param name="userFileSystemFilePath">Path of this file in the user file system.</param>
/// <param name="lockInfo">Information about file lock. Pass null if the item is not locked.</param>
public UserFile(string userFileSystemFilePath) : base(userFileSystemFilePath)
{
}
/// <summary>
/// Reads file content from the remote storage.
/// </summary>
/// <param name="offset">Offset in bytes in file content to start reading from.</param>
/// <param name="length">Lenth in bytes of the file content to read.</param>
/// <returns>File content that corresponds to the provided offset and length.</returns>
public async Task<byte[]> ReadAsync(long offset, long length)
{
// This method has a 60 sec timeout.
// To process longer requests modify the IFolder.TransferDataAsync() implementation.
await using (FileStream stream = File.OpenRead(RemoteStoragePath))
{
stream.Seek(offset, SeekOrigin.Begin);
byte[] buffer = new byte[length];
int bytesRead = await stream.ReadAsync(buffer, 0, (int)length);
return buffer;
}
}
public async Task<bool> ValidateDataAsync(long offset, long length)
{
return true;
}
/// <summary>
/// Updates file in the remote storage.
/// </summary>
/// <param name="fileInfo">New information about the file, such as creation date, modification date, attributes, etc.</param>
/// <param name="content">New file content or null if the file content is not modified.</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(IFileBasicInfo fileInfo, Stream content = null, ServerLockInfo lockInfo = null)
{
return await CreateOrUpdateFileAsync(RemoteStoragePath, fileInfo, FileMode.Open, content);
}
}
}