Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

Commit 6e46bc4

Browse files
committed
Fixed more xml warnings and some cleanup with resharper.
1 parent 48d28d2 commit 6e46bc4

File tree

3 files changed

+130
-11
lines changed

3 files changed

+130
-11
lines changed

src/Nancy/IO/RequestStream.cs

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.IO;
5+
using System.Threading.Tasks;
56

67
/// <summary>
78
/// A <see cref="Stream"/> decorator that can handle moving the stream out from memory and on to disk when the contents reaches a certain length.
@@ -10,6 +11,9 @@ public class RequestStream : Stream
1011
{
1112
internal const int BufferSize = 4096;
1213

14+
/// <summary>
15+
/// The default switchover threshold
16+
/// </summary>
1317
public static long DEFAULT_SWITCHOVER_THRESHOLD = 81920;
1418

1519
private bool disableStreamSwitching;
@@ -71,24 +75,33 @@ public RequestStream(Stream stream, long expectedLength, long thresholdLength, b
7175

7276
if (!this.stream.CanSeek)
7377
{
74-
this.MoveToWritableStream();
78+
var task = this.MoveToWritableStream();
79+
80+
task.Wait();
81+
82+
if (task.IsFaulted)
83+
{
84+
throw new InvalidOperationException("Unable to copy stream", task.Exception);
85+
}
7586
}
7687

7788
this.stream.Position = 0;
7889
}
7990

91+
/// <summary>
92+
/// Finalizes an instance of the <see cref="RequestStream"/> class.
93+
/// </summary>
8094
~RequestStream()
8195
{
8296
this.Dispose(false);
8397
}
8498

85-
private void MoveToWritableStream()
99+
private Task MoveToWritableStream()
86100
{
87101
var sourceStream = this.stream;
88-
89102
this.stream = new MemoryStream(BufferSize);
90103

91-
sourceStream.CopyTo(this.stream);
104+
return sourceStream.CopyToAsync(this);
92105
}
93106

94107
/// <summary>
@@ -143,7 +156,7 @@ public override long Length
143156
/// <remarks>The stream is moved to disk when either the length of the contents or expected content length exceeds the threshold specified in the constructor.</remarks>
144157
public bool IsInMemory
145158
{
146-
get { return !(this.stream.GetType() == typeof(FileStream)); }
159+
get { return this.stream.GetType() != typeof(FileStream); }
147160
}
148161

149162
/// <summary>
@@ -195,6 +208,10 @@ public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, As
195208
}
196209
#endif
197210

211+
/// <summary>
212+
/// Releases the unmanaged resources used by the <see cref="T:System.IO.Stream" /> and optionally releases the managed resources.
213+
/// </summary>
214+
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
198215
protected override void Dispose(bool disposing)
199216
{
200217
if (this.isSafeToDisposeStream)
@@ -246,26 +263,59 @@ public override void Flush()
246263
this.stream.Flush();
247264
}
248265

266+
/// <summary>
267+
/// Creates a new request stream from a stream.
268+
/// </summary>
269+
/// <param name="stream">The stream.</param>
270+
/// <returns>A request stream instance</returns>
249271
public static RequestStream FromStream(Stream stream)
250272
{
251273
return FromStream(stream, 0, DEFAULT_SWITCHOVER_THRESHOLD, false);
252274
}
253275

276+
/// <summary>
277+
/// Creates a new request stream from a stream.
278+
/// </summary>
279+
/// <param name="stream">The stream.</param>
280+
/// <param name="expectedLength">The expected length.</param>
281+
/// <returns>A request stream instance</returns>
254282
public static RequestStream FromStream(Stream stream, long expectedLength)
255283
{
256284
return FromStream(stream, expectedLength, DEFAULT_SWITCHOVER_THRESHOLD, false);
257285
}
258286

287+
/// <summary>
288+
/// Creates a new request stream from a stream.
289+
/// </summary>
290+
/// <param name="stream">The stream.</param>
291+
/// <param name="expectedLength">The expected length.</param>
292+
/// <param name="thresholdLength">Length of the threshold.</param>
293+
/// <returns>A request stream instance</returns>
259294
public static RequestStream FromStream(Stream stream, long expectedLength, long thresholdLength)
260295
{
261296
return FromStream(stream, expectedLength, thresholdLength, false);
262297
}
263298

299+
/// <summary>
300+
/// Creates a new request stream from a stream.
301+
/// </summary>
302+
/// <param name="stream">The stream.</param>
303+
/// <param name="expectedLength">The expected length.</param>
304+
/// <param name="disableStreamSwitching">if set to <c>true</c> [disable stream switching].</param>
305+
/// <returns>A request stream instance</returns>
264306
public static RequestStream FromStream(Stream stream, long expectedLength, bool disableStreamSwitching)
265307
{
266308
return FromStream(stream, expectedLength, DEFAULT_SWITCHOVER_THRESHOLD, disableStreamSwitching);
267309
}
268310

311+
/// <summary>
312+
/// Creates a new request stream from a stream.
313+
/// </summary>
314+
/// <param name="stream">The stream.</param>
315+
/// <param name="expectedLength">The expected length.</param>
316+
/// <param name="thresholdLength">Length of the threshold.</param>
317+
/// <param name="disableStreamSwitching">if set to <c>true</c> [disable stream switching].</param>
318+
/// <returns>A request stream instance</returns>
269319
public static RequestStream FromStream(Stream stream, long expectedLength, long thresholdLength, bool disableStreamSwitching)
270320
{
271321
return new RequestStream(stream, expectedLength, thresholdLength, disableStreamSwitching);

src/Nancy/Json/JavaScriptConverter.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,60 @@ namespace Nancy.Json
3131
using System;
3232
using System.Collections.Generic;
3333

34+
/// <summary>
35+
/// Abstracr base class for javascript converter operations.
36+
/// </summary>
3437
public abstract class JavaScriptConverter
3538
{
36-
protected JavaScriptConverter () { }
39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="JavaScriptConverter"/> class.
41+
/// </summary>
42+
protected JavaScriptConverter () { }
3743

38-
public abstract IEnumerable<Type> SupportedTypes { get; }
44+
/// <summary>
45+
/// Gets the supported types.
46+
/// </summary>
47+
/// <value>
48+
/// The supported types.
49+
/// </value>
50+
public abstract IEnumerable<Type> SupportedTypes { get; }
3951

52+
/// <summary>
53+
/// Deserializes the specified dictionary.
54+
/// </summary>
55+
/// <param name="dictionary">The dictionary.</param>
56+
/// <param name="type">The type.</param>
57+
/// <returns></returns>
4058
public virtual object Deserialize(IDictionary<string, object> dictionary, Type type)
4159
{
4260
return Deserialize(dictionary, type, null);
4361
}
4462

45-
public abstract object Deserialize (IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer);
63+
/// <summary>
64+
/// Deserializes the specified dictionary.
65+
/// </summary>
66+
/// <param name="dictionary">The dictionary.</param>
67+
/// <param name="type">The type.</param>
68+
/// <param name="serializer">The serializer.</param>
69+
/// <returns></returns>
70+
public abstract object Deserialize (IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer);
4671

72+
/// <summary>
73+
/// Serializes the specified object.
74+
/// </summary>
75+
/// <param name="obj">The object.</param>
76+
/// <returns></returns>
4777
public IDictionary<string, object> Serialize(object obj)
4878
{
4979
return Serialize(obj, null);
50-
}
80+
}
5181

82+
/// <summary>
83+
/// Serializes the specified object.
84+
/// </summary>
85+
/// <param name="obj">The object.</param>
86+
/// <param name="serializer">The serializer.</param>
87+
/// <returns></returns>
5288
public abstract IDictionary<string, object> Serialize (object obj, JavaScriptSerializer serializer);
5389
}
5490
}

src/Nancy/Json/JavaScriptPrimitiveConverter.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,55 @@
33
using System;
44
using System.Collections.Generic;
55

6+
/// <summary>
7+
/// Operations for converting javascript primitives.
8+
/// </summary>
69
public abstract class JavaScriptPrimitiveConverter
710
{
11+
/// <summary>
12+
/// Gets the supported types.
13+
/// </summary>
14+
/// <value>
15+
/// The supported types.
16+
/// </value>
817
public abstract IEnumerable<Type> SupportedTypes { get; }
918

19+
/// <summary>
20+
/// Deserializes the specified primitive value.
21+
/// </summary>
22+
/// <param name="primitiveValue">The primitive value.</param>
23+
/// <param name="type">The type.</param>
24+
/// <returns></returns>
1025
public virtual object Deserialize(object primitiveValue, Type type)
1126
{
12-
return Deserialize(primitiveValue, type, null);
27+
return this.Deserialize(primitiveValue, type, null);
1328
}
1429

30+
/// <summary>
31+
/// Deserializes the specified primitive value.
32+
/// </summary>
33+
/// <param name="primitiveValue">The primitive value.</param>
34+
/// <param name="type">The type.</param>
35+
/// <param name="serializer">The serializer.</param>
36+
/// <returns></returns>
1537
public abstract object Deserialize(object primitiveValue, Type type, JavaScriptSerializer serializer);
1638

39+
/// <summary>
40+
/// Serializes the specified object.
41+
/// </summary>
42+
/// <param name="obj">The object.</param>
43+
/// <returns></returns>
1744
public virtual object Serialize(object obj)
1845
{
19-
return Serialize(obj, null);
46+
return this.Serialize(obj, null);
2047
}
2148

49+
/// <summary>
50+
/// Serializes the specified object.
51+
/// </summary>
52+
/// <param name="obj">The object.</param>
53+
/// <param name="serializer">The serializer.</param>
54+
/// <returns></returns>
2255
public abstract object Serialize(object obj, JavaScriptSerializer serializer);
2356
}
2457
}

0 commit comments

Comments
 (0)