Skip to content

Commit

Permalink
Merge branch 'v4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Dec 26, 2012
2 parents 3787e3d + 79e45f4 commit 75d3d27
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/DotNetOpenAuth.Core/Messaging/HttpRequestInfo.cs
Expand Up @@ -80,7 +80,7 @@ public class HttpRequestInfo : HttpRequestBase {
this.form = new NameValueCollection();
this.queryString = HttpUtility.ParseQueryString(requestUri.Query);
this.serverVariables = new NameValueCollection();
this.cookies = new HttpCookieCollection();
this.cookies = new HttpCookieCollection();

Reporting.RecordRequestStatistics(this);
}
Expand Down
68 changes: 34 additions & 34 deletions src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
Expand Up @@ -22,8 +22,8 @@ namespace DotNetOpenAuth.Messaging {
using System.Runtime.Serialization.Json;
using System.Security;
using System.Security.Cryptography;
using System.Threading;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using System.Xml;
Expand All @@ -41,13 +41,6 @@ public static class MessagingUtilities {
/// <remarks>The random number generator is thread-safe.</remarks>
internal static readonly RandomNumberGenerator CryptoRandomDataGenerator = new RNGCryptoServiceProvider();

/// <summary>
/// Gets a random number generator for use on the current thread only.
/// </summary>
internal static Random NonCryptoRandomDataGenerator {
get { return ThreadSafeRandom.RandomNumberGenerator; }
}

/// <summary>
/// The uppercase alphabet.
/// </summary>
Expand Down Expand Up @@ -157,6 +150,13 @@ internal enum CompressionMethod {
Gzip,
}

/// <summary>
/// Gets a random number generator for use on the current thread only.
/// </summary>
internal static Random NonCryptoRandomDataGenerator {
get { return ThreadSafeRandom.RandomNumberGenerator; }
}

/// <summary>
/// Transforms an OutgoingWebResponse to an MVC-friendly ActionResult.
/// </summary>
Expand Down Expand Up @@ -2014,6 +2014,32 @@ internal enum CompressionMethod {
}
}

/// <summary>
/// A thread-safe, non-crypto random number generator.
/// </summary>
private static class ThreadSafeRandom {
/// <summary>
/// The initializer of all new <see cref="Random"/> instances.
/// </summary>
private static readonly Random threadRandomInitializer = new Random();

/// <summary>
/// A thread-local instance of <see cref="Random"/>
/// </summary>
private static readonly ThreadLocal<Random> threadRandom = new ThreadLocal<Random>(delegate {
lock (threadRandomInitializer) {
return new Random(threadRandomInitializer.Next());
}
});

/// <summary>
/// Gets a random number generator for use on the current thread only.
/// </summary>
public static Random RandomNumberGenerator {
get { return threadRandom.Value; }
}
}

/// <summary>
/// A class to convert a <see cref="Comparison&lt;T&gt;"/> into an <see cref="IComparer&lt;T&gt;"/>.
/// </summary>
Expand Down Expand Up @@ -2048,31 +2074,5 @@ private class ComparisonHelper<T> : IComparer<T> {

#endregion
}

/// <summary>
/// A thread-safe, non-crypto random number generator.
/// </summary>
private static class ThreadSafeRandom {
/// <summary>
/// The initializer of all new <see cref="Random"/> instances.
/// </summary>
private static readonly Random threadRandomInitializer = new Random();

/// <summary>
/// A thread-local instance of <see cref="Random"/>
/// </summary>
private static readonly ThreadLocal<Random> threadRandom = new ThreadLocal<Random>(delegate {
lock (threadRandomInitializer) {
return new Random(threadRandomInitializer.Next());
}
});

/// <summary>
/// Gets a random number generator for use on the current thread only.
/// </summary>
public static Random RandomNumberGenerator {
get { return threadRandom.Value; }
}
}
}
}
2 changes: 2 additions & 0 deletions src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs
Expand Up @@ -32,6 +32,7 @@ internal class CoordinatingHttpRequestInfo : HttpRequestInfo {
/// <param name="messageFactory">The message factory.</param>
/// <param name="messageData">The message data.</param>
/// <param name="recipient">The recipient.</param>
/// <param name="cookies">Cookies included in the incoming request.</param>
internal CoordinatingHttpRequestInfo(
Channel channel,
IMessageFactory messageFactory,
Expand All @@ -52,6 +53,7 @@ internal class CoordinatingHttpRequestInfo : HttpRequestInfo {
/// that will not generate any message.
/// </summary>
/// <param name="recipient">The recipient.</param>
/// <param name="cookies">Cookies included in the incoming request.</param>
internal CoordinatingHttpRequestInfo(MessageReceivingEndpoint recipient, HttpCookieCollection cookies)
: base(GetHttpVerb(recipient), recipient != null ? recipient.Location : new Uri("http://host/path"), cookies: cookies) {
this.recipient = recipient;
Expand Down
Expand Up @@ -23,6 +23,7 @@ internal class CoordinatingOutgoingWebResponse : OutgoingWebResponse {
/// </summary>
/// <param name="message">The direct response message to send to the remote channel. This message will be cloned.</param>
/// <param name="receivingChannel">The receiving channel.</param>
/// <param name="sendingChannel">The sending channel.</param>
internal CoordinatingOutgoingWebResponse(IProtocolMessage message, CoordinatingChannel receivingChannel, CoordinatingChannel sendingChannel) {
Requires.NotNull(message, "message");
Requires.NotNull(receivingChannel, "receivingChannel");
Expand Down

0 comments on commit 75d3d27

Please sign in to comment.