This repository has been archived by the owner on Nov 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 166
/
Files.Async.cs
306 lines (232 loc) · 14.2 KB
/
Files.Async.cs
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
using System.Collections.Generic;
using System.IO;
using DropNet.Models;
using RestSharp;
using System;
using DropNet.Exceptions;
namespace DropNet
{
public partial class DropNetClient
{
public void GetMetaDataAsync(Action<MetaData> success, Action<DropboxException> failure, String hash = null, Boolean list = false, Boolean include_deleted = false)
{
GetMetaDataAsync(String.Empty, success, failure, hash, list, include_deleted);
}
public void GetMetaDataAsync(String path, Action<MetaData> success, Action<DropboxException> failure, String hash = null, Boolean list = false, Boolean include_deleted = false)
{
if (path != "" && !path.StartsWith("/")) path = "/" + path;
var request = _requestHelper.CreateMetadataRequest(path, Root, hash, list, include_deleted);
ExecuteAsync(ApiType.Base, request, success, failure);
}
/// <summary>
/// Restores a file path to a previous revision.
/// </summary>
/// <param name="rev">The revision of the file to restore.</param>
/// <param name="path">The path to the file.</param>
/// <param name="success">Success call back</param>
/// <param name="failure">Failure call back </param>
public void RestoreAsync(string rev, string path, Action<MetaData> success, Action<DropboxException> failure)
{
var request = _requestHelper.CreateRestoreRequest(rev, path, Root);
ExecuteAsync(ApiType.Base, request, success, failure);
}
public void SearchAsync(string searchString, Action<List<MetaData>> success, Action<DropboxException> failure)
{
SearchAsync(searchString, string.Empty, 1000, success, failure);
}
public void SearchAsync(string searchString, int fileLimit, Action<List<MetaData>> success, Action<DropboxException> failure)
{
SearchAsync(searchString, string.Empty, fileLimit, success, failure);
}
public void SearchAsync(string searchString, string path, Action<List<MetaData>> success, Action<DropboxException> failure)
{
SearchAsync(searchString, path, 1000, success, failure);
}
public void SearchAsync(string searchString, string path, int fileLimit, Action<List<MetaData>> success, Action<DropboxException> failure)
{
if (fileLimit > 1000)
fileLimit = 1000;
var request = _requestHelper.CreateSearchRequest(searchString, path, Root, fileLimit);
ExecuteAsync(ApiType.Base, request, success, failure);
}
public void GetFileAsync(string path, Action<IRestResponse> success, Action<DropboxException> failure)
{
if (!path.StartsWith("/")) path = "/" + path;
var request = _requestHelper.CreateGetFileRequest(path, Root);
ExecuteAsync(ApiType.Content, request, success, failure);
}
public void GetFileAsync(string path, long startByte, long endByte, string rev, Action<IRestResponse> success, Action<DropboxException> failure)
{
if (!path.StartsWith("/")) path = "/" + path;
var request = _requestHelper.CreateGetFileRequest(path, Root, startByte, endByte, rev);
ExecuteAsync(ApiType.Content, request, success, failure);
}
#if !WINDOWS_PHONE && !MONOTOUCH
public void UploadFileAsync(string path, FileInfo localFile, Action<MetaData> success, Action<DropboxException> failure, bool overwrite = true, string parentRevision = null)
{
//Get the file stream
byte[] bytes;
using (var fs = new FileStream(localFile.FullName, FileMode.Open, FileAccess.Read))
{
using (var br = new BinaryReader(fs))
{
long numBytes = localFile.Length;
bytes = br.ReadBytes((int)numBytes);
}
}
UploadFileAsync(path, localFile.Name, bytes, success, failure, overwrite, parentRevision);
}
#endif
public void UploadFileAsync(string path, string filename, byte[] fileData, Action<MetaData> success, Action<DropboxException> failure, bool overwrite = true, string parentRevision = null)
{
if (path != "" && !path.StartsWith("/")) path = "/" + path;
var request = _requestHelper.CreateUploadFileRequest(path, filename, fileData, Root, overwrite, parentRevision);
ExecuteAsync(ApiType.Content, request, success, failure);
}
public void UploadFileAsync(string path, string filename, Stream fileStream, Action<MetaData> success, Action<DropboxException> failure, bool overwrite = true, string parentRevision = null)
{
if (path != "" && !path.StartsWith("/")) path = "/" + path;
var request = _requestHelper.CreateUploadFileRequest(path, filename, fileStream, Root, overwrite, parentRevision);
ExecuteAsync(ApiType.Content, request, success, failure);
}
public void UploadChunkedFileAsync(Func<long, byte[]> chunkNeeded, string path, Action<MetaData> success, Action<DropboxException> failure, Action<ChunkedUploadProgress> progress = null, bool overwrite = true, string parentRevision = null, long? fileSize = null, long? maxRetries = null)
{
var chunkedUploader = new DropNet.Helpers.ChunkedUploadHelper(this, chunkNeeded, path, success, failure, progress, overwrite, parentRevision, fileSize, maxRetries);
chunkedUploader.Start();
}
public void StartChunkedUploadAsync(byte[] fileData, Action<ChunkedUpload> success, Action<DropboxException> failure)
{
var request = _requestHelper.CreateChunkedUploadRequest(fileData);
ExecuteAsync(ApiType.Content, request, success, failure);
}
public void AppendChunkedUploadAsync(ChunkedUpload upload, byte[] fileData, Action<ChunkedUpload> success, Action<DropboxException> failure)
{
var request = _requestHelper.CreateAppendChunkedUploadRequest(upload, fileData);
ExecuteAsync(ApiType.Content, request, success, failure);
}
public void CommitChunkedUploadAsync(ChunkedUpload upload, string path, Action<MetaData> success, Action<DropboxException> failure, bool overwrite = true, string parentRevision = null)
{
var request = _requestHelper.CreateCommitChunkedUploadRequest(upload, path, Root, overwrite, parentRevision);
ExecuteAsync(ApiType.Content, request, success, failure);
}
public void DeleteAsync(string path, Action<IRestResponse> success, Action<DropboxException> failure)
{
if (path != "" && !path.StartsWith("/")) path = "/" + path;
var request = _requestHelper.CreateDeleteFileRequest(path, Root);
ExecuteAsync(ApiType.Base, request, success, failure);
}
public void CopyAsync(string fromPath, string toPath, Action<IRestResponse> success, Action<DropboxException> failure)
{
if (!fromPath.StartsWith("/")) fromPath = "/" + fromPath;
if (!toPath.StartsWith("/")) toPath = "/" + toPath;
var request = _requestHelper.CreateCopyFileRequest(fromPath, toPath, Root);
ExecuteAsync(ApiType.Base, request, success, failure);
}
public void CopyFromCopyRefAsync(string fromCopyRef, string toPath, Action<IRestResponse> success, Action<DropboxException> failure)
{
if (!toPath.StartsWith("/")) toPath = "/" + toPath;
var request = _requestHelper.CreateCopyFileFromCopyRefRequest(fromCopyRef, toPath, Root);
ExecuteAsync(ApiType.Base, request, success, failure);
}
public void MoveAsync(string fromPath, string toPath, Action<IRestResponse> success, Action<DropboxException> failure)
{
if (!fromPath.StartsWith("/")) fromPath = "/" + fromPath;
if (!toPath.StartsWith("/")) toPath = "/" + toPath;
var request = _requestHelper.CreateMoveFileRequest(fromPath, toPath, Root);
ExecuteAsync(ApiType.Base, request, success, failure);
}
public void CreateFolderAsync(string path, Action<MetaData> success, Action<DropboxException> failure)
{
if (!path.StartsWith("/")) path = "/" + path;
var request = _requestHelper.CreateCreateFolderRequest(path, Root);
ExecuteAsync(ApiType.Base, request, success, failure);
}
public void GetShareAsync(string path, Action<ShareResponse> success, Action<DropboxException> failure)
{
GetShareAsync(path, true, success, failure);
}
public void GetShareAsync(string path, bool shortUrl, Action<ShareResponse> success, Action<DropboxException> failure)
{
if (!path.StartsWith("/")) path = "/" + path;
var request = _requestHelper.CreateShareRequest(path, Root, shortUrl);
ExecuteAsync(ApiType.Base, request, success, failure);
}
public void GetMediaAsync(string path, Action<ShareResponse> success, Action<DropboxException> failure)
{
if (!path.StartsWith("/")) path = "/" + path;
var request = _requestHelper.CreateMediaRequest(path, Root);
ExecuteAsync(ApiType.Base, request, success, failure);
}
/// <summary>
/// A long-poll endpoint to wait for changes on an account. In conjunction with /delta, this call gives you a low-latency way to monitor an account for file changes.
/// </summary>
/// <param name="cursor">The value returned from the prior call to GetDelta.</param>
/// <param name="failure"></param>
/// <param name="success"></param>
/// <param name="timeout">An optional integer indicating a timeout, in seconds.
/// The default value is 30 seconds, which is also the minimum allowed value. The maximum is 480 seconds.</param>
public void GetLongpollDeltaAsync(string cursor, Action<LongpollDeltaResult> success,
Action<DropboxException> failure, int timeout = 30)
{
var request = _requestHelper.CreateLongpollDeltaRequest(cursor, timeout);
ExecuteAsync<LongpollDeltaResult>(ApiType.Notify, request, success, failure);
}
/// <summary>
/// The beta delta function, gets updates for a given folder
/// </summary>
/// <param name="IKnowThisIsBetaOnly"></param>
/// <param name="cursor">The value returned from the prior call to GetDelta or an empty string</param>
/// <param name="success"></param>
/// <param name="failure"></param>
public void GetDeltaAsync(bool IKnowThisIsBetaOnly, string cursor, Action<DeltaPage> success, Action<DropboxException> failure)
{
if (!IKnowThisIsBetaOnly) return;
var request = _requestHelper.CreateDeltaRequest(cursor, null, null, false);
ExecuteAsync<DeltaPage>(ApiType.Base, request, success, failure);
}
/// <summary>
/// The beta delta function, gets updates for a given folder
/// </summary>
/// <param name="IKnowThisIsBetaOnly"></param>
/// <param name="cursor">The value returned from the prior call to GetDelta or an empty string</param>
/// <param name="pathPrefix">If present, this parameter filters the response to only include entries at or under the specified path</param>
/// <param name="locale">If present the metadata returned will have its size field translated based on the given locale</param>
/// <param name="includeMediaInfo">If true, each file will include a photo_info dictionary for photos and a video_info dictionary for videos with additional media info. When include_media_info is specified, files will only appear in delta responses when the media info is ready. If you use the include_media_info parameter, you must continue to pass the same value on subsequent calls using the returned cursor.</param>
/// <param name="success"></param>
/// <param name="failure"></param>
public void GetDeltaAsync(bool IKnowThisIsBetaOnly, string cursor, string pathPrefix,
string locale, bool includeMediaInfo, Action<DeltaPage> success, Action<DropboxException> failure)
{
if (!IKnowThisIsBetaOnly) return;
if (!pathPrefix.StartsWith("/")) pathPrefix = "/" + pathPrefix;
var request = _requestHelper.CreateDeltaRequest(cursor, pathPrefix, locale, includeMediaInfo);
ExecuteAsync<DeltaPage>(ApiType.Base, request, success, failure);
}
public void GetThumbnailAsync(MetaData file, Action<byte[]> success, Action<DropboxException> failure)
{
GetThumbnailAsync(file.Path, ThumbnailSize.Small, success, failure);
}
public void GetThumbnailAsync(MetaData file, ThumbnailSize size, Action<byte[]> success, Action<DropboxException> failure)
{
GetThumbnailAsync(file.Path, size, success, failure);
}
public void GetThumbnailAsync(string path, Action<byte[]> success, Action<DropboxException> failure)
{
GetThumbnailAsync(path, ThumbnailSize.Small, success, failure);
}
public void GetThumbnailAsync(string path, ThumbnailSize size, Action<byte[]> success, Action<DropboxException> failure)
{
if (!path.StartsWith("/")) path = "/" + path;
var request = _requestHelper.CreateThumbnailRequest(path, size, Root);
ExecuteAsync(ApiType.Content, request,
response => success(response.RawBytes),
failure);
}
public void GetCopyRefAsync(string path, Action<CopyRefResponse> success, Action<DropboxException> failure)
{
if (!path.StartsWith("/")) path = "/" + path;
var request = _requestHelper.CreateCopyRefRequest(path, Root);
ExecuteAsync(ApiType.Base, request, success, failure);
}
}
}