Skip to content

Commit 6cc73f6

Browse files
committed
Added shared folder endpoints. Code refactoring to improve json parsing performance
1 parent a525151 commit 6cc73f6

File tree

178 files changed

+33866
-6458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+33866
-6458
lines changed

Dropbox.Api/ApiException.cs

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ namespace Dropbox.Api
1515
/// implementation if there is an error processing the request.
1616
/// </summary>
1717
/// <typeparam name="TError">The type of the error.</typeparam>
18-
public sealed class ApiException<TError> : Exception, IEncodable<ApiException<TError>>
19-
where TError : IEncodable<TError>, new()
18+
public sealed class ApiException<TError> : Exception
2019
{
2120
/// <summary>
2221
/// Initializes a new instance of the <see cref="ApiException{TError}"/> class.
2322
/// </summary>
24-
/// <remarks>This constructor is only used when deserializing from JSON.</remarks>
23+
/// <remarks>This constructor is only used when decoded from JSON.</remarks>
2524
public ApiException()
2625
: this(default(TError))
2726
{
@@ -56,6 +55,7 @@ public ApiException(TError errorResponse, string message, Exception inner)
5655
: base(message, inner)
5756
{
5857
this.ErrorResponse = errorResponse;
58+
this.ErrorMessage = message;
5959
}
6060

6161
/// <summary>
@@ -67,31 +67,78 @@ public ApiException(TError errorResponse, string message, Exception inner)
6767
public TError ErrorResponse { get; private set; }
6868

6969
/// <summary>
70-
/// Encodes the object using the supplied encoder.
70+
/// Gets the exception message.
7171
/// </summary>
72-
/// <param name="encoder">The encoder being used to serialize the object.</param>
73-
/// <exception cref="System.NotImplementedException"></exception>
74-
void IEncodable<ApiException<TError>>.Encode(IEncoder encoder)
72+
public override string Message
7573
{
76-
throw new NotSupportedException("Exceptions cannot be encoded");
74+
get { return this.ErrorMessage; }
7775
}
7876

7977
/// <summary>
80-
/// Decodes on object using the supplied decoder.
78+
/// Gets or sets the error message.
8179
/// </summary>
82-
/// <param name="decoder">The decoder used to deserialize the object.</param>
83-
/// <returns>
84-
/// The deserialized object. Note: this is not necessarily the current instance.
85-
/// </returns>
86-
/// <exception cref="System.NotImplementedException"></exception>
87-
ApiException<TError> IEncodable<ApiException<TError>>.Decode(IDecoder decoder)
80+
private string ErrorMessage { get; set; }
81+
82+
/// <summary>
83+
/// Decode from given json using given decoder.
84+
/// </summary>
85+
/// <param name="json">The json.</param>
86+
/// <param name="errorDecoder">The error json.</param>
87+
/// <returns>The <see cref="ApiException{TError}"/></returns>
88+
internal static ApiException<TError> Decode(string json, IDecoder<TError> errorDecoder)
89+
{
90+
return JsonReader.Read(json, new ApiExceptionDecoder(errorDecoder));
91+
}
92+
93+
/// <summary>
94+
/// The exception decoder.
95+
/// </summary>
96+
private class ApiExceptionDecoder : StructDecoder<ApiException<TError>>
8897
{
89-
using (var obj = decoder.GetObject())
98+
/// <summary>
99+
/// The error decoder.
100+
/// </summary>
101+
private readonly IDecoder<TError> errorDecoder;
102+
103+
/// <summary>
104+
/// Initializes a new instance of the <see cref="ApiExceptionDecoder"/> class.
105+
/// </summary>
106+
/// <param name="errorDecoder">The error decoder.</param>
107+
public ApiExceptionDecoder(IDecoder<TError> errorDecoder)
90108
{
91-
this.ErrorResponse = obj.GetFieldObject<TError>("error");
109+
this.errorDecoder = errorDecoder;
92110
}
93111

94-
return this;
112+
/// <summary>
113+
/// Create a struct instance.
114+
/// </summary>
115+
/// <returns>The struct instance.</returns>
116+
protected override ApiException<TError> Create()
117+
{
118+
return new ApiException<TError>();
119+
}
120+
121+
/// <summary>
122+
/// Set given field.
123+
/// </summary>
124+
/// <param name="value">The field value.</param>
125+
/// <param name="fieldName">The field name.</param>
126+
/// <param name="reader">The reader.</param>
127+
protected override void SetField(ApiException<TError> value, string fieldName, IJsonReader reader)
128+
{
129+
switch (fieldName)
130+
{
131+
case "error":
132+
value.ErrorResponse = this.errorDecoder.Decode(reader);
133+
break;
134+
case "error_summary":
135+
value.ErrorMessage = StringDecoder.Instance.Decode(reader);
136+
break;
137+
default:
138+
SkipProperty(reader);
139+
break;
140+
}
141+
}
95142
}
96143
}
97144
}
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
// <auto-generated>
2+
// Auto-generated by BabelAPI, do not modify.
3+
// </auto-generated>
4+
5+
namespace Dropbox.Api.Async
6+
{
7+
using sys = System;
8+
using col = System.Collections.Generic;
9+
using re = System.Text.RegularExpressions;
10+
11+
using enc = Dropbox.Api.Babel;
12+
13+
/// <summary>
14+
/// <para>Result returned by methods that may either launch an asynchronous job or complete
15+
/// synchronously. Upon synchronous completion of the job, no additional information is
16+
/// returned.</para>
17+
/// </summary>
18+
public class LaunchEmptyResult
19+
{
20+
#pragma warning disable 108
21+
22+
/// <summary>
23+
/// <para>The encoder instance.</para>
24+
/// </summary>
25+
internal static enc.StructEncoder<LaunchEmptyResult> Encoder = new LaunchEmptyResultEncoder();
26+
27+
/// <summary>
28+
/// <para>The decoder instance.</para>
29+
/// </summary>
30+
internal static enc.StructDecoder<LaunchEmptyResult> Decoder = new LaunchEmptyResultDecoder();
31+
32+
/// <summary>
33+
/// <para>Initializes a new instance of the <see cref="LaunchEmptyResult" />
34+
/// class.</para>
35+
/// </summary>
36+
public LaunchEmptyResult()
37+
{
38+
}
39+
40+
/// <summary>
41+
/// <para>Gets a value indicating whether this instance is Complete</para>
42+
/// </summary>
43+
public bool IsComplete
44+
{
45+
get
46+
{
47+
return this is Complete;
48+
}
49+
}
50+
51+
/// <summary>
52+
/// <para>Gets this instance as a Complete, or <c>null</c>.</para>
53+
/// </summary>
54+
public Complete AsComplete
55+
{
56+
get
57+
{
58+
return this as Complete;
59+
}
60+
}
61+
62+
#region Encoder class
63+
64+
/// <summary>
65+
/// <para>Encoder for <see cref="LaunchEmptyResult" />.</para>
66+
/// </summary>
67+
private class LaunchEmptyResultEncoder : enc.StructEncoder<LaunchEmptyResult>
68+
{
69+
/// <summary>
70+
/// <para>Encode fields of given value.</para>
71+
/// </summary>
72+
/// <param name="value">The value.</param>
73+
/// <param name="writer">The writer.</param>
74+
public override void EncodeFields(LaunchEmptyResult value, enc.IJsonWriter writer)
75+
{
76+
if (value is Complete)
77+
{
78+
WriteProperty(".tag", "complete", writer, enc.StringEncoder.Instance);
79+
Complete.Encoder.EncodeFields((Complete)value, writer);
80+
return;
81+
}
82+
throw new sys.InvalidOperationException();
83+
}
84+
}
85+
86+
#endregion
87+
88+
#region Decoder class
89+
90+
/// <summary>
91+
/// <para>Decoder for <see cref="LaunchEmptyResult" />.</para>
92+
/// </summary>
93+
private class LaunchEmptyResultDecoder : enc.UnionDecoder<LaunchEmptyResult>
94+
{
95+
/// <summary>
96+
/// <para>Create a new instance of type <see cref="LaunchEmptyResult" />.</para>
97+
/// </summary>
98+
/// <returns>The struct instance.</returns>
99+
protected override LaunchEmptyResult Create()
100+
{
101+
return new LaunchEmptyResult();
102+
}
103+
104+
/// <summary>
105+
/// <para>Decode based on given tag.</para>
106+
/// </summary>
107+
/// <param name="tag">The tag.</param>
108+
/// <param name="reader">The json reader.</param>
109+
/// <returns>The decoded object.</returns>
110+
protected override LaunchEmptyResult Decode(string tag, enc.IJsonReader reader)
111+
{
112+
switch (tag)
113+
{
114+
case "complete":
115+
return Complete.Decoder.DecodeFields(reader);
116+
default:
117+
throw new sys.InvalidOperationException();
118+
}
119+
}
120+
}
121+
122+
#endregion
123+
124+
/// <summary>
125+
/// <para>The job finished synchronously and successfully.</para>
126+
/// </summary>
127+
public sealed class Complete : LaunchEmptyResult
128+
{
129+
#pragma warning disable 108
130+
131+
/// <summary>
132+
/// <para>The encoder instance.</para>
133+
/// </summary>
134+
internal static enc.StructEncoder<Complete> Encoder = new CompleteEncoder();
135+
136+
/// <summary>
137+
/// <para>The decoder instance.</para>
138+
/// </summary>
139+
internal static enc.StructDecoder<Complete> Decoder = new CompleteDecoder();
140+
141+
/// <summary>
142+
/// <para>Initializes a new instance of the <see cref="Complete" /> class.</para>
143+
/// </summary>
144+
private Complete()
145+
{
146+
}
147+
148+
/// <summary>
149+
/// <para>A singleton instance of Complete</para>
150+
/// </summary>
151+
public static readonly Complete Instance = new Complete();
152+
153+
#region Encoder class
154+
155+
/// <summary>
156+
/// <para>Encoder for <see cref="Complete" />.</para>
157+
/// </summary>
158+
private class CompleteEncoder : enc.StructEncoder<Complete>
159+
{
160+
/// <summary>
161+
/// <para>Encode fields of given value.</para>
162+
/// </summary>
163+
/// <param name="value">The value.</param>
164+
/// <param name="writer">The writer.</param>
165+
public override void EncodeFields(Complete value, enc.IJsonWriter writer)
166+
{
167+
}
168+
}
169+
170+
#endregion
171+
172+
#region Decoder class
173+
174+
/// <summary>
175+
/// <para>Decoder for <see cref="Complete" />.</para>
176+
/// </summary>
177+
private class CompleteDecoder : enc.StructDecoder<Complete>
178+
{
179+
/// <summary>
180+
/// <para>Create a new instance of type <see cref="Complete" />.</para>
181+
/// </summary>
182+
/// <returns>The struct instance.</returns>
183+
protected override Complete Create()
184+
{
185+
return new Complete();
186+
}
187+
188+
/// <summary>
189+
/// <para>Decode fields without ensuring start and end object.</para>
190+
/// </summary>
191+
/// <param name="reader">The json reader.</param>
192+
/// <returns>The decoded object.</returns>
193+
public override Complete DecodeFields(enc.IJsonReader reader)
194+
{
195+
return Complete.Instance;
196+
}
197+
}
198+
199+
#endregion
200+
}
201+
}
202+
}

0 commit comments

Comments
 (0)