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

Commit

Permalink
Fixed more xml warnings and some cleanup with resharper.
Browse files Browse the repository at this point in the history
  • Loading branch information
cemremengu committed Aug 30, 2016
1 parent 48d28d2 commit 6e46bc4
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 11 deletions.
60 changes: 55 additions & 5 deletions src/Nancy/IO/RequestStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.IO;
using System.Threading.Tasks;

/// <summary>
/// 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.
Expand All @@ -10,6 +11,9 @@ public class RequestStream : Stream
{
internal const int BufferSize = 4096;

/// <summary>
/// The default switchover threshold
/// </summary>
public static long DEFAULT_SWITCHOVER_THRESHOLD = 81920;

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

if (!this.stream.CanSeek)
{
this.MoveToWritableStream();
var task = this.MoveToWritableStream();

This comment has been minimized.

Copy link
@davidallyoung

davidallyoung Jan 14, 2017

Contributor

I think this change was an accidental merge error that overwrites @khellang PR #2534 before this. It should not be calling task.Wait() as it can result in a deadlock. Am I mistaken on this?


task.Wait();

if (task.IsFaulted)
{
throw new InvalidOperationException("Unable to copy stream", task.Exception);
}
}

this.stream.Position = 0;
}

/// <summary>
/// Finalizes an instance of the <see cref="RequestStream"/> class.
/// </summary>
~RequestStream()
{
this.Dispose(false);
}

private void MoveToWritableStream()
private Task MoveToWritableStream()
{
var sourceStream = this.stream;

this.stream = new MemoryStream(BufferSize);

sourceStream.CopyTo(this.stream);
return sourceStream.CopyToAsync(this);
}

/// <summary>
Expand Down Expand Up @@ -143,7 +156,7 @@ public override long Length
/// <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>
public bool IsInMemory
{
get { return !(this.stream.GetType() == typeof(FileStream)); }
get { return this.stream.GetType() != typeof(FileStream); }
}

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

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

/// <summary>
/// Creates a new request stream from a stream.
/// </summary>
/// <param name="stream">The stream.</param>
/// <returns>A request stream instance</returns>
public static RequestStream FromStream(Stream stream)
{
return FromStream(stream, 0, DEFAULT_SWITCHOVER_THRESHOLD, false);
}

/// <summary>
/// Creates a new request stream from a stream.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="expectedLength">The expected length.</param>
/// <returns>A request stream instance</returns>
public static RequestStream FromStream(Stream stream, long expectedLength)
{
return FromStream(stream, expectedLength, DEFAULT_SWITCHOVER_THRESHOLD, false);
}

/// <summary>
/// Creates a new request stream from a stream.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="expectedLength">The expected length.</param>
/// <param name="thresholdLength">Length of the threshold.</param>
/// <returns>A request stream instance</returns>
public static RequestStream FromStream(Stream stream, long expectedLength, long thresholdLength)
{
return FromStream(stream, expectedLength, thresholdLength, false);
}

/// <summary>
/// Creates a new request stream from a stream.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="expectedLength">The expected length.</param>
/// <param name="disableStreamSwitching">if set to <c>true</c> [disable stream switching].</param>
/// <returns>A request stream instance</returns>
public static RequestStream FromStream(Stream stream, long expectedLength, bool disableStreamSwitching)
{
return FromStream(stream, expectedLength, DEFAULT_SWITCHOVER_THRESHOLD, disableStreamSwitching);
}

/// <summary>
/// Creates a new request stream from a stream.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="expectedLength">The expected length.</param>
/// <param name="thresholdLength">Length of the threshold.</param>
/// <param name="disableStreamSwitching">if set to <c>true</c> [disable stream switching].</param>
/// <returns>A request stream instance</returns>
public static RequestStream FromStream(Stream stream, long expectedLength, long thresholdLength, bool disableStreamSwitching)
{
return new RequestStream(stream, expectedLength, thresholdLength, disableStreamSwitching);
Expand Down
44 changes: 40 additions & 4 deletions src/Nancy/Json/JavaScriptConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,60 @@ namespace Nancy.Json
using System;
using System.Collections.Generic;

/// <summary>
/// Abstracr base class for javascript converter operations.
/// </summary>
public abstract class JavaScriptConverter
{
protected JavaScriptConverter () { }
/// <summary>
/// Initializes a new instance of the <see cref="JavaScriptConverter"/> class.
/// </summary>
protected JavaScriptConverter () { }

public abstract IEnumerable<Type> SupportedTypes { get; }
/// <summary>
/// Gets the supported types.
/// </summary>
/// <value>
/// The supported types.
/// </value>
public abstract IEnumerable<Type> SupportedTypes { get; }

/// <summary>
/// Deserializes the specified dictionary.
/// </summary>
/// <param name="dictionary">The dictionary.</param>
/// <param name="type">The type.</param>
/// <returns></returns>
public virtual object Deserialize(IDictionary<string, object> dictionary, Type type)
{
return Deserialize(dictionary, type, null);
}

public abstract object Deserialize (IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer);
/// <summary>
/// Deserializes the specified dictionary.
/// </summary>
/// <param name="dictionary">The dictionary.</param>
/// <param name="type">The type.</param>
/// <param name="serializer">The serializer.</param>
/// <returns></returns>
public abstract object Deserialize (IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer);

/// <summary>
/// Serializes the specified object.
/// </summary>
/// <param name="obj">The object.</param>
/// <returns></returns>
public IDictionary<string, object> Serialize(object obj)
{
return Serialize(obj, null);
}
}

/// <summary>
/// Serializes the specified object.
/// </summary>
/// <param name="obj">The object.</param>
/// <param name="serializer">The serializer.</param>
/// <returns></returns>
public abstract IDictionary<string, object> Serialize (object obj, JavaScriptSerializer serializer);
}
}
37 changes: 35 additions & 2 deletions src/Nancy/Json/JavaScriptPrimitiveConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,55 @@
using System;
using System.Collections.Generic;

/// <summary>
/// Operations for converting javascript primitives.
/// </summary>
public abstract class JavaScriptPrimitiveConverter
{
/// <summary>
/// Gets the supported types.
/// </summary>
/// <value>
/// The supported types.
/// </value>
public abstract IEnumerable<Type> SupportedTypes { get; }

/// <summary>
/// Deserializes the specified primitive value.
/// </summary>
/// <param name="primitiveValue">The primitive value.</param>
/// <param name="type">The type.</param>
/// <returns></returns>
public virtual object Deserialize(object primitiveValue, Type type)
{
return Deserialize(primitiveValue, type, null);
return this.Deserialize(primitiveValue, type, null);
}

/// <summary>
/// Deserializes the specified primitive value.
/// </summary>
/// <param name="primitiveValue">The primitive value.</param>
/// <param name="type">The type.</param>
/// <param name="serializer">The serializer.</param>
/// <returns></returns>
public abstract object Deserialize(object primitiveValue, Type type, JavaScriptSerializer serializer);

/// <summary>
/// Serializes the specified object.
/// </summary>
/// <param name="obj">The object.</param>
/// <returns></returns>
public virtual object Serialize(object obj)
{
return Serialize(obj, null);
return this.Serialize(obj, null);
}

/// <summary>
/// Serializes the specified object.
/// </summary>
/// <param name="obj">The object.</param>
/// <param name="serializer">The serializer.</param>
/// <returns></returns>
public abstract object Serialize(object obj, JavaScriptSerializer serializer);
}
}

0 comments on commit 6e46bc4

Please sign in to comment.