/
Metadata.cs
324 lines (296 loc) · 12.3 KB
/
Metadata.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// <auto-generated>
// Auto-generated by StoneAPI, do not modify.
// </auto-generated>
namespace Dropbox.Api.Files
{
using sys = System;
using col = System.Collections.Generic;
using re = System.Text.RegularExpressions;
using enc = Dropbox.Api.Stone;
/// <summary>
/// <para>Metadata for a file or folder.</para>
/// </summary>
/// <seealso cref="DeleteBatchResultData" />
/// <seealso cref="DeleteResult" />
/// <seealso cref="DeletedMetadata" />
/// <seealso cref="FileMetadata" />
/// <seealso cref="FolderMetadata" />
/// <seealso cref="GetCopyReferenceResult" />
/// <seealso cref="LockFileResult" />
/// <seealso cref="RelocationBatchResultData" />
/// <seealso cref="RelocationResult" />
/// <seealso cref="SaveCopyReferenceResult" />
/// <seealso cref="SearchMatch" />
public class Metadata
{
#pragma warning disable 108
/// <summary>
/// <para>The encoder instance.</para>
/// </summary>
internal static enc.StructEncoder<Metadata> Encoder = new MetadataEncoder();
/// <summary>
/// <para>The decoder instance.</para>
/// </summary>
internal static enc.StructDecoder<Metadata> Decoder = new MetadataDecoder();
/// <summary>
/// <para>Initializes a new instance of the <see cref="Metadata" /> class.</para>
/// </summary>
/// <param name="name">The last component of the path (including extension). This never
/// contains a slash.</param>
/// <param name="pathLower">The lowercased full path in the user's Dropbox. This always
/// starts with a slash. This field will be null if the file or folder is not
/// mounted.</param>
/// <param name="pathDisplay">The cased path to be used for display purposes only. In
/// rare instances the casing will not correctly match the user's filesystem, but this
/// behavior will match the path provided in the Core API v1, and at least the last
/// path component will have the correct casing. Changes to only the casing of paths
/// won't be returned by <see
/// cref="Dropbox.Api.Files.Routes.FilesAppRoutes.ListFolderContinueAsync" /> <see
/// cref="Dropbox.Api.Files.Routes.FilesUserRoutes.ListFolderContinueAsync" />. This
/// field will be null if the file or folder is not mounted.</param>
/// <param name="parentSharedFolderId">Please use <see
/// cref="Dropbox.Api.Files.FileSharingInfo.ParentSharedFolderId" /> or <see
/// cref="Dropbox.Api.Files.FolderSharingInfo.ParentSharedFolderId" /> instead.</param>
/// <param name="previewUrl">The preview URL of the file.</param>
protected Metadata(string name,
string pathLower = null,
string pathDisplay = null,
string parentSharedFolderId = null,
string previewUrl = null)
{
if (name == null)
{
throw new sys.ArgumentNullException("name");
}
if (parentSharedFolderId != null)
{
if (!re.Regex.IsMatch(parentSharedFolderId, @"\A(?:[-_0-9a-zA-Z:]+)\z"))
{
throw new sys.ArgumentOutOfRangeException("parentSharedFolderId", @"Value should match pattern '\A(?:[-_0-9a-zA-Z:]+)\z'");
}
}
this.Name = name;
this.PathLower = pathLower;
this.PathDisplay = pathDisplay;
this.ParentSharedFolderId = parentSharedFolderId;
this.PreviewUrl = previewUrl;
}
/// <summary>
/// <para>Initializes a new instance of the <see cref="Metadata" /> class.</para>
/// </summary>
/// <remarks>This is to construct an instance of the object when
/// deserializing.</remarks>
[sys.ComponentModel.EditorBrowsable(sys.ComponentModel.EditorBrowsableState.Never)]
public Metadata()
{
}
/// <summary>
/// <para>Gets a value indicating whether this instance is File</para>
/// </summary>
public bool IsFile
{
get
{
return this is FileMetadata;
}
}
/// <summary>
/// <para>Gets this instance as a <see cref="FileMetadata" />, or <c>null</c>.</para>
/// </summary>
public FileMetadata AsFile
{
get
{
return this as FileMetadata;
}
}
/// <summary>
/// <para>Gets a value indicating whether this instance is Folder</para>
/// </summary>
public bool IsFolder
{
get
{
return this is FolderMetadata;
}
}
/// <summary>
/// <para>Gets this instance as a <see cref="FolderMetadata" />, or <c>null</c>.</para>
/// </summary>
public FolderMetadata AsFolder
{
get
{
return this as FolderMetadata;
}
}
/// <summary>
/// <para>Gets a value indicating whether this instance is Deleted</para>
/// </summary>
public bool IsDeleted
{
get
{
return this is DeletedMetadata;
}
}
/// <summary>
/// <para>Gets this instance as a <see cref="DeletedMetadata" />, or
/// <c>null</c>.</para>
/// </summary>
public DeletedMetadata AsDeleted
{
get
{
return this as DeletedMetadata;
}
}
/// <summary>
/// <para>The last component of the path (including extension). This never contains a
/// slash.</para>
/// </summary>
public string Name { get; protected set; }
/// <summary>
/// <para>The lowercased full path in the user's Dropbox. This always starts with a
/// slash. This field will be null if the file or folder is not mounted.</para>
/// </summary>
public string PathLower { get; protected set; }
/// <summary>
/// <para>The cased path to be used for display purposes only. In rare instances the
/// casing will not correctly match the user's filesystem, but this behavior will match
/// the path provided in the Core API v1, and at least the last path component will
/// have the correct casing. Changes to only the casing of paths won't be returned by
/// <see cref="Dropbox.Api.Files.Routes.FilesAppRoutes.ListFolderContinueAsync" /> <see
/// cref="Dropbox.Api.Files.Routes.FilesUserRoutes.ListFolderContinueAsync" />. This
/// field will be null if the file or folder is not mounted.</para>
/// </summary>
public string PathDisplay { get; protected set; }
/// <summary>
/// <para>Please use <see cref="Dropbox.Api.Files.FileSharingInfo.ParentSharedFolderId"
/// /> or <see cref="Dropbox.Api.Files.FolderSharingInfo.ParentSharedFolderId" />
/// instead.</para>
/// </summary>
public string ParentSharedFolderId { get; protected set; }
/// <summary>
/// <para>The preview URL of the file.</para>
/// </summary>
public string PreviewUrl { get; protected set; }
#region Encoder class
/// <summary>
/// <para>Encoder for <see cref="Metadata" />.</para>
/// </summary>
private class MetadataEncoder : enc.StructEncoder<Metadata>
{
/// <summary>
/// <para>Encode fields of given value.</para>
/// </summary>
/// <param name="value">The value.</param>
/// <param name="writer">The writer.</param>
public override void EncodeFields(Metadata value, enc.IJsonWriter writer)
{
if (value is FileMetadata)
{
WriteProperty(".tag", "file", writer, enc.StringEncoder.Instance);
FileMetadata.Encoder.EncodeFields((FileMetadata)value, writer);
return;
}
if (value is FolderMetadata)
{
WriteProperty(".tag", "folder", writer, enc.StringEncoder.Instance);
FolderMetadata.Encoder.EncodeFields((FolderMetadata)value, writer);
return;
}
if (value is DeletedMetadata)
{
WriteProperty(".tag", "deleted", writer, enc.StringEncoder.Instance);
DeletedMetadata.Encoder.EncodeFields((DeletedMetadata)value, writer);
return;
}
WriteProperty("name", value.Name, writer, enc.StringEncoder.Instance);
if (value.PathLower != null)
{
WriteProperty("path_lower", value.PathLower, writer, enc.StringEncoder.Instance);
}
if (value.PathDisplay != null)
{
WriteProperty("path_display", value.PathDisplay, writer, enc.StringEncoder.Instance);
}
if (value.ParentSharedFolderId != null)
{
WriteProperty("parent_shared_folder_id", value.ParentSharedFolderId, writer, enc.StringEncoder.Instance);
}
if (value.PreviewUrl != null)
{
WriteProperty("preview_url", value.PreviewUrl, writer, enc.StringEncoder.Instance);
}
}
}
#endregion
#region Decoder class
/// <summary>
/// <para>Decoder for <see cref="Metadata" />.</para>
/// </summary>
private class MetadataDecoder : enc.UnionDecoder<Metadata>
{
/// <summary>
/// <para>Create a new instance of type <see cref="Metadata" />.</para>
/// </summary>
/// <returns>The struct instance.</returns>
protected override Metadata Create()
{
return new Metadata();
}
/// <summary>
/// <para>Decode based on given tag.</para>
/// </summary>
/// <param name="tag">The tag.</param>
/// <param name="reader">The json reader.</param>
/// <returns>The decoded object.</returns>
protected override Metadata Decode(string tag, enc.IJsonReader reader)
{
switch (tag)
{
case "file":
return FileMetadata.Decoder.DecodeFields(reader);
case "folder":
return FolderMetadata.Decoder.DecodeFields(reader);
case "deleted":
return DeletedMetadata.Decoder.DecodeFields(reader);
default:
throw new sys.InvalidOperationException();
}
}
/// <summary>
/// <para>Set given field.</para>
/// </summary>
/// <param name="value">The field value.</param>
/// <param name="fieldName">The field name.</param>
/// <param name="reader">The json reader.</param>
protected override void SetField(Metadata value, string fieldName, enc.IJsonReader reader)
{
switch (fieldName)
{
case "name":
value.Name = enc.StringDecoder.Instance.Decode(reader);
break;
case "path_lower":
value.PathLower = enc.StringDecoder.Instance.Decode(reader);
break;
case "path_display":
value.PathDisplay = enc.StringDecoder.Instance.Decode(reader);
break;
case "parent_shared_folder_id":
value.ParentSharedFolderId = enc.StringDecoder.Instance.Decode(reader);
break;
case "preview_url":
value.PreviewUrl = enc.StringDecoder.Instance.Decode(reader);
break;
default:
reader.Skip();
break;
}
}
}
#endregion
}
}