Permalink
Browse files

- final whitespace correction

  • Loading branch information...
1 parent 1f8f114 commit 140af6c6cfdc034bb2e2e725bc107424c5311560 @desunit desunit committed Oct 18, 2012
Showing with 9,684 additions and 9,684 deletions.
  1. +79 −79 NuGet/ServiceStack.Host.AspNet/content/Content/js/ss-validation.js
  2. +79 −79 NuGet/ServiceStack.Host.Mvc/content/Content/js/ss-validation.js
  3. +12 −12 src/ServiceStack.Authentication.OpenId/GoogleOpenIdOAuthProvider.cs
  4. +12 −12 src/ServiceStack.Authentication.OpenId/MyOpenIdOAuthProvider.cs
  5. +296 −296 src/ServiceStack.Authentication.OpenId/OpenIdOAuthProvider.cs
  6. +36 −36 src/ServiceStack.Authentication.OpenId/Properties/AssemblyInfo.cs
  7. +83 −83 src/ServiceStack.Authentication.OpenId/ServiceStack.Authentication.OpenId.csproj
  8. +12 −12 src/ServiceStack.Authentication.OpenId/YahooOpenIdOAuthProvider.cs
  9. +3 −3 src/ServiceStack.Authentication.OpenId/packages.config
  10. +87 −87 src/ServiceStack.Common/ActionExecExtensions.cs
  11. +72 −72 src/ServiceStack.Common/AssertExtensions.cs
  12. +19 −19 src/ServiceStack.Common/ByteArrayExtensions.cs
  13. +57 −57 src/ServiceStack.Common/DictionaryExtensions.cs
  14. +43 −43 src/ServiceStack.Common/DirectoryInfoExtensions.cs
  15. +45 −45 src/ServiceStack.Common/DisposableExtensions.cs
  16. +109 −109 src/ServiceStack.Common/EnumExtensions.cs
  17. +106 −106 src/ServiceStack.Common/EnumerableExtensions.cs
  18. +144 −144 src/ServiceStack.Common/ExecExtensions.cs
  19. +71 −71 src/ServiceStack.Common/Expressions/DelegateFactory.cs
  20. +52 −52 src/ServiceStack.Common/Extensions/ActionExecExtensions.cs
  21. +56 −56 src/ServiceStack.Common/Extensions/AssertExtensions.cs
  22. +11 −11 src/ServiceStack.Common/Extensions/ByteArrayExtensions.cs
  23. +24 −24 src/ServiceStack.Common/Extensions/CollectionExtensions.cs
  24. +29 −29 src/ServiceStack.Common/Extensions/DictionaryExtensions.cs
  25. +32 −32 src/ServiceStack.Common/Extensions/EnumerableExtensions.cs
  26. +23 −23 src/ServiceStack.Common/Extensions/ITranslatorExtensions.cs
  27. +44 −44 src/ServiceStack.Common/Extensions/IntExtensions.cs
  28. +61 −61 src/ServiceStack.Common/Extensions/ReflectionExtensions.cs
  29. +103 −103 src/ServiceStack.Common/Extensions/StringExtensions.cs
  30. +37 −37 src/ServiceStack.Common/HostContext.cs
  31. +165 −165 src/ServiceStack.Common/IPAddressExtensions.cs
  32. +71 −71 src/ServiceStack.Common/IntExtensions.cs
  33. +32 −32 src/ServiceStack.Common/Messaging/ClientFactory.cs
  34. +36 −36 src/ServiceStack.Common/Messaging/IMessageHandler.cs
  35. +6 −6 src/ServiceStack.Common/Messaging/IMessageHandlerDisposer.cs
  36. +9 −9 src/ServiceStack.Common/Messaging/IMessageHandlerFactory.cs
  37. +53 −53 src/ServiceStack.Common/Messaging/InMemoryMessageQueueClient.cs
  38. +73 −73 src/ServiceStack.Common/Messaging/InMemoryTransientMessageFactory.cs
  39. +39 −39 src/ServiceStack.Common/Messaging/InMemoryTransientMessageService.cs
  40. +211 −211 src/ServiceStack.Common/Messaging/MessageHandler.cs
  41. +61 −61 src/ServiceStack.Common/Messaging/MessageHandlerFactory.cs
  42. +67 −67 src/ServiceStack.Common/Messaging/MessageQueueClientFactory.cs
  43. +107 −107 src/ServiceStack.Common/Messaging/Rcon/PacketProcessingClient.cs
  44. +141 −141 src/ServiceStack.Common/Messaging/TransientMessageServiceBase.cs
  45. +26 −26 src/ServiceStack.Common/Model.cs
  46. +12 −12 src/ServiceStack.Common/ModelConfig.cs
  47. +439 −439 src/ServiceStack.Common/Net30/ConcurrentDictionary.cs
  48. +237 −237 src/ServiceStack.Common/Net30/ConcurrentQueue.cs
  49. +96 −96 src/ServiceStack.Common/Net30/ObjectPool.cs
  50. +518 −518 src/ServiceStack.Common/Net30/SplitOrderedList.cs
  51. +361 −361 src/ServiceStack.Common/Net30/Tuple.cs
  52. +39 −39 src/ServiceStack.Common/Properties/AssemblyInfo.cs
  53. +111 −111 src/ServiceStack.Common/Reflection/PropertyAccessor.cs
  54. +168 −168 src/ServiceStack.Common/Reflection/StaticAccessors.cs
  55. +205 −205 src/ServiceStack.Common/ReflectionExtensions.cs
  56. +30 −30 src/ServiceStack.Common/RequestContextExtensions.cs
  57. +569 −569 src/ServiceStack.Common/ServiceClient.Web/AsyncServiceClient.cs
  58. +29 −29 src/ServiceStack.Common/ServiceClient.Web/AuthDtos.cs
  59. +32 −32 src/ServiceStack.Common/ServiceClient.Web/DictionaryExtensions.cs
  60. +47 −47 src/ServiceStack.Common/ServiceClient.Web/GenericProxy.cs
  61. +27 −27 src/ServiceStack.Common/ServiceClient.Web/HttpMethod.cs
  62. +13 −13 src/ServiceStack.Common/ServiceClient.Web/IDuplex.cs
  63. +13 −13 src/ServiceStack.Common/ServiceClient.Web/IDuplexCallback.cs
  64. +13 −13 src/ServiceStack.Common/ServiceClient.Web/IOneWay.cs
  65. +13 −13 src/ServiceStack.Common/ServiceClient.Web/ISyncReply.cs
  66. +21 −21 src/ServiceStack.Common/ServiceClient.Web/IWcfServiceClient.cs
  67. +81 −81 src/ServiceStack.Common/ServiceClient.Web/JsonRestClientAsync.cs
  68. +50 −50 src/ServiceStack.Common/ServiceClient.Web/JsonServiceClient.cs
  69. +78 −78 src/ServiceStack.Common/ServiceClient.Web/JsvRestClientAsync.cs
  70. +55 −55 src/ServiceStack.Common/ServiceClient.Web/JsvServiceClient.cs
  71. +996 −996 src/ServiceStack.Common/ServiceClient.Web/ServiceClientBase.cs
  72. +145 −145 src/ServiceStack.Common/ServiceClient.Web/Soap11ServiceClient.cs
  73. +394 −394 src/ServiceStack.Common/ServiceClient.Web/WcfServiceClient.cs
  74. +221 −221 src/ServiceStack.Common/ServiceClient.Web/WebRequestExtensions.cs
  75. +97 −97 src/ServiceStack.Common/ServiceClient.Web/WebRequestUtils.cs
  76. +113 −113 src/ServiceStack.Common/ServiceClient.Web/WebServiceException.cs
  77. +273 −273 src/ServiceStack.Common/ServiceClient.Web/XLinqExtensions.cs
  78. +80 −80 src/ServiceStack.Common/ServiceClient.Web/XmlRestClientAsync.cs
  79. +60 −60 src/ServiceStack.Common/ServiceClient.Web/XmlServiceClient.cs
  80. +46 −46 src/ServiceStack.Common/ServiceModel/DictionaryExtensions.cs
  81. +78 −78 src/ServiceStack.Common/ServiceModel/Serialization/DataContractDeserializer.cs
  82. +89 −89 src/ServiceStack.Common/ServiceModel/Serialization/JsonDataContractDeserializer.cs
  83. +75 −75 src/ServiceStack.Common/ServiceModel/Serialization/JsonDataContractSerializer.cs
  84. +40 −40 src/ServiceStack.Common/ServiceModel/Serialization/KeyValueDataContractDeserializer.cs
  85. +73 −73 src/ServiceStack.Common/ServiceModel/Serialization/XmlSerializableDeserializer.cs
  86. +41 −41 src/ServiceStack.Common/ServiceModel/Serialization/XmlSerializableSerializer.cs
  87. +113 −113 src/ServiceStack.Common/ServiceModel/Support/XmlSerializableWrapper.cs
  88. +1 −1 src/ServiceStack.Common/ServiceModel/Validation/ValidationError.cs
  89. +33 −33 src/ServiceStack.Common/ServiceModel/Validation/ValidationErrorField.cs
  90. +127 −127 src/ServiceStack.Common/ServiceModel/Validation/ValidationErrorResult.cs
  91. +298 −298 src/ServiceStack.Common/ServiceModel/XLinqExtensions.cs
  92. +100 −100 src/ServiceStack.Common/StreamExtensions.cs
Sorry, we could not display the entire diff because too many files (660) changed.
View
158 NuGet/ServiceStack.Host.AspNet/content/Content/js/ss-validation.js
@@ -1,79 +1,79 @@
-(function ($) {
-
- if (!$.ss) $.ss = {};
- if (!$.ss.validation)
- $.ss.validation = {
- overrideMessages: false,
- messages: {
- NotEmpty: "Required",
- NotNull: "Required",
- Email: "Invalid email",
- AlreadyExists: "Already exists"
- },
- errorFilter: function (errorMsg, errorCode, type) {
- return this.overrideMessages
- ? this.messages[errorCode] || errorMsg || splitCase(errorCode)
- : errorMsg || splitCase(errorCode);
- }
- };
-
- function splitCase(t) {
- return typeof t != 'string' ? t : t.replace( /([A-Z]|[0-9]+)/g , ' $1').replace( /_/g , ' ');
- };
-
- $.fn.applyErrors = function(responseStatus, opt) {
- this.clearErrors();
- if (!responseStatus) return this;
-
- this.addClass("error");
-
- var o = _.defaults({}, opt, $.ss.validation);
- if (opt && opt.messages) {
- o.overrideMessages = true;
- _.extend(o.messages, $.ss.validation.messages);
- }
-
- var filter = _.bind(o.errorFilter, o),
- errors = responseStatus.errors;
-
- console.log(errors, responseStatus);
-
- if (errors && errors.length) {
- var fieldMap = { };
- this.find("input").each(function() {
- var $el = $(this);
- var $prev = $el.prev(), $next = $el.next();
-
- if ($prev.hasClass("help-inline") || $prev.hasClass("help-block")) {
- fieldMap[(this.id || $el.attr("name")).toLowerCase()] = $prev;
- } else if ($next.hasClass("help-inline") || $next.hasClass("help-block")) {
- fieldMap[(this.id || $el.attr("name")).toLowerCase()] = $next;
- }
- });
- _.each(errors, function(error) {
- var $field = fieldMap[(error.fieldName||"").toLowerCase()];
- if (!$field) return;
-
- $field.parent().addClass("error");
- $field.html(filter(error.message, error.errorCode, "field"));
- $field.show();
- });
- } else {
- this.find(".error-summary").html(
- filter(responseStatus.message || splitCase(responseStatus.errorCode), responseStatus.errorCode, "summary")
- );
- }
- return this;
- };
-
- $.fn.clearErrors = function() {
- this.removeClass("error");
- this.find(".error>.help-inline, .error>.help-block").each(function () {
- $(this).html("");
- });
- return this.find(".error").each(function() {
- $(this).removeClass("error");
- });
- };
-
-})(window.jQuery);
+(function ($) {
+
+ if (!$.ss) $.ss = {};
+ if (!$.ss.validation)
+ $.ss.validation = {
+ overrideMessages: false,
+ messages: {
+ NotEmpty: "Required",
+ NotNull: "Required",
+ Email: "Invalid email",
+ AlreadyExists: "Already exists"
+ },
+ errorFilter: function (errorMsg, errorCode, type) {
+ return this.overrideMessages
+ ? this.messages[errorCode] || errorMsg || splitCase(errorCode)
+ : errorMsg || splitCase(errorCode);
+ }
+ };
+
+ function splitCase(t) {
+ return typeof t != 'string' ? t : t.replace( /([A-Z]|[0-9]+)/g , ' $1').replace( /_/g , ' ');
+ };
+
+ $.fn.applyErrors = function(responseStatus, opt) {
+ this.clearErrors();
+ if (!responseStatus) return this;
+
+ this.addClass("error");
+
+ var o = _.defaults({}, opt, $.ss.validation);
+ if (opt && opt.messages) {
+ o.overrideMessages = true;
+ _.extend(o.messages, $.ss.validation.messages);
+ }
+
+ var filter = _.bind(o.errorFilter, o),
+ errors = responseStatus.errors;
+
+ console.log(errors, responseStatus);
+
+ if (errors && errors.length) {
+ var fieldMap = { };
+ this.find("input").each(function() {
+ var $el = $(this);
+ var $prev = $el.prev(), $next = $el.next();
+
+ if ($prev.hasClass("help-inline") || $prev.hasClass("help-block")) {
+ fieldMap[(this.id || $el.attr("name")).toLowerCase()] = $prev;
+ } else if ($next.hasClass("help-inline") || $next.hasClass("help-block")) {
+ fieldMap[(this.id || $el.attr("name")).toLowerCase()] = $next;
+ }
+ });
+ _.each(errors, function(error) {
+ var $field = fieldMap[(error.fieldName||"").toLowerCase()];
+ if (!$field) return;
+
+ $field.parent().addClass("error");
+ $field.html(filter(error.message, error.errorCode, "field"));
+ $field.show();
+ });
+ } else {
+ this.find(".error-summary").html(
+ filter(responseStatus.message || splitCase(responseStatus.errorCode), responseStatus.errorCode, "summary")
+ );
+ }
+ return this;
+ };
+
+ $.fn.clearErrors = function() {
+ this.removeClass("error");
+ this.find(".error>.help-inline, .error>.help-block").each(function () {
+ $(this).html("");
+ });
+ return this.find(".error").each(function() {
+ $(this).removeClass("error");
+ });
+ };
+
+})(window.jQuery);
View
158 NuGet/ServiceStack.Host.Mvc/content/Content/js/ss-validation.js
@@ -1,79 +1,79 @@
-(function ($) {
-
- if (!$.ss) $.ss = {};
- if (!$.ss.validation)
- $.ss.validation = {
- overrideMessages: false,
- messages: {
- NotEmpty: "Required",
- NotNull: "Required",
- Email: "Invalid email",
- AlreadyExists: "Already exists"
- },
- errorFilter: function (errorMsg, errorCode, type) {
- return this.overrideMessages
- ? this.messages[errorCode] || errorMsg || splitCase(errorCode)
- : errorMsg || splitCase(errorCode);
- }
- };
-
- function splitCase(t) {
- return typeof t != 'string' ? t : t.replace( /([A-Z]|[0-9]+)/g , ' $1').replace( /_/g , ' ');
- };
-
- $.fn.applyErrors = function(responseStatus, opt) {
- this.clearErrors();
- if (!responseStatus) return this;
-
- this.addClass("error");
-
- var o = _.defaults({}, opt, $.ss.validation);
- if (opt && opt.messages) {
- o.overrideMessages = true;
- _.extend(o.messages, $.ss.validation.messages);
- }
-
- var filter = _.bind(o.errorFilter, o),
- errors = responseStatus.errors;
-
- console.log(errors, responseStatus);
-
- if (errors && errors.length) {
- var fieldMap = { };
- this.find("input").each(function() {
- var $el = $(this);
- var $prev = $el.prev(), $next = $el.next();
-
- if ($prev.hasClass("help-inline") || $prev.hasClass("help-block")) {
- fieldMap[(this.id || $el.attr("name")).toLowerCase()] = $prev;
- } else if ($next.hasClass("help-inline") || $next.hasClass("help-block")) {
- fieldMap[(this.id || $el.attr("name")).toLowerCase()] = $next;
- }
- });
- _.each(errors, function(error) {
- var $field = fieldMap[(error.fieldName||"").toLowerCase()];
- if (!$field) return;
-
- $field.parent().addClass("error");
- $field.html(filter(error.message, error.errorCode, "field"));
- $field.show();
- });
- } else {
- this.find(".error-summary").html(
- filter(responseStatus.message || splitCase(responseStatus.errorCode), responseStatus.errorCode, "summary")
- );
- }
- return this;
- };
-
- $.fn.clearErrors = function() {
- this.removeClass("error");
- this.find(".error>.help-inline, .error>.help-block").each(function () {
- $(this).html("");
- });
- return this.find(".error").each(function() {
- $(this).removeClass("error");
- });
- };
-
-})(window.jQuery);
+(function ($) {
+
+ if (!$.ss) $.ss = {};
+ if (!$.ss.validation)
+ $.ss.validation = {
+ overrideMessages: false,
+ messages: {
+ NotEmpty: "Required",
+ NotNull: "Required",
+ Email: "Invalid email",
+ AlreadyExists: "Already exists"
+ },
+ errorFilter: function (errorMsg, errorCode, type) {
+ return this.overrideMessages
+ ? this.messages[errorCode] || errorMsg || splitCase(errorCode)
+ : errorMsg || splitCase(errorCode);
+ }
+ };
+
+ function splitCase(t) {
+ return typeof t != 'string' ? t : t.replace( /([A-Z]|[0-9]+)/g , ' $1').replace( /_/g , ' ');
+ };
+
+ $.fn.applyErrors = function(responseStatus, opt) {
+ this.clearErrors();
+ if (!responseStatus) return this;
+
+ this.addClass("error");
+
+ var o = _.defaults({}, opt, $.ss.validation);
+ if (opt && opt.messages) {
+ o.overrideMessages = true;
+ _.extend(o.messages, $.ss.validation.messages);
+ }
+
+ var filter = _.bind(o.errorFilter, o),
+ errors = responseStatus.errors;
+
+ console.log(errors, responseStatus);
+
+ if (errors && errors.length) {
+ var fieldMap = { };
+ this.find("input").each(function() {
+ var $el = $(this);
+ var $prev = $el.prev(), $next = $el.next();
+
+ if ($prev.hasClass("help-inline") || $prev.hasClass("help-block")) {
+ fieldMap[(this.id || $el.attr("name")).toLowerCase()] = $prev;
+ } else if ($next.hasClass("help-inline") || $next.hasClass("help-block")) {
+ fieldMap[(this.id || $el.attr("name")).toLowerCase()] = $next;
+ }
+ });
+ _.each(errors, function(error) {
+ var $field = fieldMap[(error.fieldName||"").toLowerCase()];
+ if (!$field) return;
+
+ $field.parent().addClass("error");
+ $field.html(filter(error.message, error.errorCode, "field"));
+ $field.show();
+ });
+ } else {
+ this.find(".error-summary").html(
+ filter(responseStatus.message || splitCase(responseStatus.errorCode), responseStatus.errorCode, "summary")
+ );
+ }
+ return this;
+ };
+
+ $.fn.clearErrors = function() {
+ this.removeClass("error");
+ this.find(".error>.help-inline, .error>.help-block").each(function () {
+ $(this).html("");
+ });
+ return this.find(".error").each(function() {
+ $(this).removeClass("error");
+ });
+ };
+
+})(window.jQuery);
View
24 src/ServiceStack.Authentication.OpenId/GoogleOpenIdOAuthProvider.cs
@@ -1,13 +1,13 @@
-using ServiceStack.Configuration;
-
-namespace ServiceStack.Authentication.OpenId
-{
- public class GoogleOpenIdOAuthProvider : OpenIdOAuthProvider
- {
- public const string Name = "GoogleOpenId";
- public static string Realm = "https://www.google.com/accounts/o8/id";
-
- public GoogleOpenIdOAuthProvider(IResourceManager appSettings)
- : base(appSettings, Name, Realm) { }
- }
+using ServiceStack.Configuration;
+
+namespace ServiceStack.Authentication.OpenId
+{
+ public class GoogleOpenIdOAuthProvider : OpenIdOAuthProvider
+ {
+ public const string Name = "GoogleOpenId";
+ public static string Realm = "https://www.google.com/accounts/o8/id";
+
+ public GoogleOpenIdOAuthProvider(IResourceManager appSettings)
+ : base(appSettings, Name, Realm) { }
+ }
}
View
24 src/ServiceStack.Authentication.OpenId/MyOpenIdOAuthProvider.cs
@@ -1,13 +1,13 @@
-using ServiceStack.Configuration;
-
-namespace ServiceStack.Authentication.OpenId
-{
- public class MyOpenIdOAuthProvider : OpenIdOAuthProvider
- {
- public const string Name = "MyOpenId";
- public static string Realm = "http://www.myopenid.com";
-
- public MyOpenIdOAuthProvider(IResourceManager appSettings)
- : base(appSettings, Name, Realm) { }
- }
+using ServiceStack.Configuration;
+
+namespace ServiceStack.Authentication.OpenId
+{
+ public class MyOpenIdOAuthProvider : OpenIdOAuthProvider
+ {
+ public const string Name = "MyOpenId";
+ public static string Realm = "http://www.myopenid.com";
+
+ public MyOpenIdOAuthProvider(IResourceManager appSettings)
+ : base(appSettings, Name, Realm) { }
+ }
}
View
592 src/ServiceStack.Authentication.OpenId/OpenIdOAuthProvider.cs
@@ -1,296 +1,296 @@
-using System;
-using System.Collections.Generic;
-using DotNetOpenAuth.Messaging;
-using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
-using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
-using DotNetOpenAuth.OpenId.RelyingParty;
-using ServiceStack.Common;
-using ServiceStack.Common.Web;
-using ServiceStack.Configuration;
-using ServiceStack.ServiceClient.Web;
-using ServiceStack.ServiceHost;
-using ServiceStack.ServiceInterface;
-using ServiceStack.ServiceInterface.Auth;
-using ServiceStack.Text;
-
-namespace ServiceStack.Authentication.OpenId
-{
- public class OpenIdOAuthProvider : OAuthProvider
- {
- public const string DefaultName = "OpenId";
-
- public OpenIdOAuthProvider(IResourceManager appSettings, string name = DefaultName, string realm = null)
- : base(appSettings, realm, name) { }
-
- public virtual ClaimsRequest CreateClaimsRequest(IHttpRequest httpReq)
- {
- return new ClaimsRequest {
- Country = DemandLevel.Request,
- Email = DemandLevel.Request,
- Gender = DemandLevel.Require,
- PostalCode = DemandLevel.Require,
- TimeZone = DemandLevel.Require,
- };
- }
-
- public override object Authenticate(IServiceBase authService, IAuthSession session, Auth request)
- {
- var tokens = Init(authService, ref session, request);
-
- var httpReq = authService.RequestContext.Get<IHttpRequest>();
- var httpMethod = httpReq.HttpMethod;
- if (httpMethod == HttpMethod.Post)
- {
- var openIdUrl = httpReq.GetParam("OpenIdUrl") ?? base.AuthRealm;
- if (openIdUrl.IsNullOrEmpty())
- throw new ArgumentException("'OpenIdUrl' is required a required field");
-
- try
- {
- using (var openid = new OpenIdRelyingParty())
- {
- var openIdRequest = openid.CreateRequest(openIdUrl);
-
- AddAttributeExchangeExtensions(openIdRequest);
-
- // This is where you would add any OpenID extensions you wanted
- // to include in the authentication request.
- openIdRequest.AddExtension(CreateClaimsRequest(httpReq));
-
- // Send your visitor to their Provider for authentication.
- var openIdResponse = openIdRequest.RedirectingResponse;
- var contentType = openIdResponse.Headers[HttpHeaders.ContentType];
- var httpResult = new HttpResult(openIdResponse.ResponseStream, contentType) {
- StatusCode = openIdResponse.Status,
- StatusDescription = "Moved Temporarily",
- };
- foreach (string header in openIdResponse.Headers)
- {
- httpResult.Headers[header] = openIdResponse.Headers[header];
- }
- return httpResult;
- }
- }
- catch (ProtocolException ex)
- {
- Log.Error("Failed to login to {0}".Fmt(openIdUrl), ex);
- return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "Unknown"));
- }
- }
-
- if (httpMethod == HttpMethod.Get)
- {
- using (var openid = new OpenIdRelyingParty())
- {
- var response = openid.GetResponse();
- if (response != null)
- {
- switch (response.Status)
- {
- case AuthenticationStatus.Authenticated:
-
- var authInfo = CreateAuthInfo(response);
-
- // Use FormsAuthentication to tell ASP.NET that the user is now logged in,
- // with the OpenID Claimed Identifier as their username.
- session.IsAuthenticated = true;
- authService.SaveSession(session, SessionExpiry);
- OnAuthenticated(authService, session, tokens, authInfo);
-
- //Haz access!
- return authService.Redirect(session.ReferrerUrl.AddHashParam("s", "1"));
-
- case AuthenticationStatus.Canceled:
- return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "ProviderCancelled"));
-
- case AuthenticationStatus.Failed:
- return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "Unknown"));
- }
- }
- }
- }
-
- //Shouldn't get here
- return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "Unknown"));
- }
-
- protected virtual Dictionary<string, string> CreateAuthInfo(IAuthenticationResponse response)
- {
- // This is where you would look for any OpenID extension responses included
- // in the authentication assertion.
- var claimsResponse = response.GetExtension<ClaimsResponse>();
- var authInfo = claimsResponse.ToDictionary();
-
- authInfo["user_id"] = response.ClaimedIdentifier; //a url
-
- // Store off the "friendly" username to display -- NOT for username lookup
- authInfo["openid_ref"] = response.FriendlyIdentifierForDisplay;
-
- var provided = GetAttributeEx(response);
- foreach (var entry in provided)
- {
- authInfo[entry.Key] = entry.Value;
- }
-
- return authInfo;
- }
-
- protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary<string, string> authInfo)
- {
- if (authInfo.ContainsKey("user_id"))
- tokens.UserId = authInfo.GetValueOrDefault("user_id");
-
- if (authInfo.ContainsKey("name"))
- tokens.DisplayName = authInfo.GetValueOrDefault("name");
-
- if (authInfo.ContainsKey("FullName"))
- {
- tokens.FullName = authInfo.GetValueOrDefault("FullName");
- if (tokens.DisplayName.IsNullOrEmpty())
- tokens.DisplayName = tokens.FullName;
- }
-
- if (authInfo.ContainsKey("Email"))
- tokens.Email = authInfo.GetValueOrDefault("Email");
-
- if (authInfo.ContainsKey("BirthDate"))
- tokens.BirthDate = authInfo.GetValueOrDefault("BirthDate").FromJsv<DateTime?>();
-
- if (authInfo.ContainsKey("BirthDateRaw"))
- tokens.BirthDateRaw = authInfo.GetValueOrDefault("BirthDateRaw");
-
- if (authInfo.ContainsKey("Country"))
- tokens.Country = authInfo.GetValueOrDefault("Country");
-
- if (authInfo.ContainsKey("Culture"))
- tokens.Culture = authInfo.GetValueOrDefault("Culture");
-
- if (authInfo.ContainsKey("Gender"))
- tokens.Gender = authInfo.GetValueOrDefault("Gender");
-
- if (authInfo.ContainsKey("MailAddress"))
- tokens.MailAddress = authInfo.GetValueOrDefault("MailAddress");
-
- if (authInfo.ContainsKey("Nickname"))
- tokens.Nickname = authInfo.GetValueOrDefault("Nickname");
-
- if (authInfo.ContainsKey("PostalCode"))
- tokens.PostalCode = authInfo.GetValueOrDefault("PostalCode");
-
- if (authInfo.ContainsKey("TimeZone"))
- tokens.TimeZone = authInfo.GetValueOrDefault("TimeZone");
-
- LoadUserOAuthProvider(userSession, tokens);
- }
-
- public override void LoadUserOAuthProvider(IAuthSession authSession, IOAuthTokens tokens)
- {
- var userSession = authSession as AuthUserSession;
- if (userSession == null) return;
- }
-
- private void AddAttributeExchangeExtensions(IAuthenticationRequest auth)
- {
- // Try to use OpenId 2.0's attribute exchange
- var fetch = new FetchRequest();
- //Technically, http://axschema.org/... are "standard", but we'll still find these in the wild
- fetch.Attributes.Add(new AttributeRequest("http://schema.openid.net/namePerson", false));
- fetch.Attributes.Add(new AttributeRequest("http://schema.openid.net/contact/email", false));
-
- fetch.Attributes.AddRequired("http://axschema.org/contact/country/home");
- fetch.Attributes.AddRequired("http://axschema.org/namePerson/first");
- fetch.Attributes.AddRequired("http://axschema.org/namePerson/last");
- fetch.Attributes.AddRequired("http://axschema.org/pref/language");
- fetch.Attributes.AddRequired("http://schemas.openid.net/ax/api/user_id");
-
- //Standard compliant AX schema
- fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.FullName, false));
-
- //For... no good reason, really, google OpenId requires you "require" an e-mail address to get it
- bool requireEmail = auth.Provider.Uri.AbsoluteUri.Contains(".google.com");
- fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email, requireEmail));
-
- auth.AddExtension(fetch);
- }
-
- /// <summary>
- /// Extracts an Attribute Exchange response, if one exists
- /// </summary>
- private Dictionary<string, string> GetAttributeEx(IAuthenticationResponse response)
- {
- var ret = new Dictionary<string, string>();
-
- var fetchResponse = response.GetExtension<FetchResponse>();
-
- if (fetchResponse == null) return ret;
-
- var names = new List<string>();
- var emails = new List<string>();
-
- if (fetchResponse.Attributes.Contains("http://schema.openid.net/namePerson"))
- names.AddRange(fetchResponse.Attributes["http://schema.openid.net/namePerson"].Values);
-
- if (fetchResponse.Attributes.Contains(WellKnownAttributes.Name.FullName))
- names.AddRange(fetchResponse.Attributes[WellKnownAttributes.Name.FullName].Values);
-
- if (fetchResponse.Attributes.Contains(WellKnownAttributes.Name.Alias))
- names.AddRange(fetchResponse.Attributes[WellKnownAttributes.Name.Alias].Values);
-
- if (fetchResponse.Attributes.Contains(WellKnownAttributes.Name.First))
- names.AddRange(fetchResponse.Attributes[WellKnownAttributes.Name.First].Values);
-
- if (fetchResponse.Attributes.Contains(WellKnownAttributes.Name.Last))
- names.AddRange(fetchResponse.Attributes[WellKnownAttributes.Name.Last].Values);
-
- if (fetchResponse.Attributes.Contains("http://schema.openid.net/contact/email"))
- emails.AddRange(fetchResponse.Attributes["http://schema.openid.net/contact/email"].Values);
-
- if (fetchResponse.Attributes.Contains(WellKnownAttributes.Contact.Email))
- emails.AddRange(fetchResponse.Attributes[WellKnownAttributes.Contact.Email].Values);
-
- if (names.Count > 0)
- ret["FullName"] = names[0];
-
- if (emails.Count > 0)
- ret["Email"] = emails[0];
-
- return ret;
- }
- }
-
- public static class OpenIdExtensions
- {
- public static Dictionary<string, string> ToDictionary(this ClaimsResponse response)
- {
- var map = new Dictionary<string, string>();
- if (response == null) return map;
-
- if (response.BirthDate.HasValue)
- map["BirthDate"] = response.BirthDate.Value.ToJsv();
- if (!response.BirthDateRaw.IsNullOrEmpty())
- map["BirthDateRaw"] = response.BirthDateRaw;
- if (!response.Country.IsNullOrEmpty())
- map["Country"] = response.Country;
- if (response.Culture != null)
- map["Culture"] = response.Culture.TwoLetterISOLanguageName;
- if (!response.Email.IsNullOrEmpty())
- map["Email"] = response.Email;
- if (!response.FullName.IsNullOrEmpty())
- map["FullName"] = response.FullName;
- if (response.Gender.HasValue)
- map["Gender"] = response.Gender.Value.ToString();
- if (!response.Language.IsNullOrEmpty())
- map["Language"] = response.Language;
- if (response.MailAddress != null)
- map["MailAddress"] = response.MailAddress.ToJsv();
- if (!response.Nickname.IsNullOrEmpty())
- map["Nickname"] = response.Nickname;
- if (!response.PostalCode.IsNullOrEmpty())
- map["PostalCode"] = response.PostalCode;
- if (!response.TimeZone.IsNullOrEmpty())
- map["TimeZone"] = response.TimeZone;
-
- return map;
- }
- }
-}
+using System;
+using System.Collections.Generic;
+using DotNetOpenAuth.Messaging;
+using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
+using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
+using DotNetOpenAuth.OpenId.RelyingParty;
+using ServiceStack.Common;
+using ServiceStack.Common.Web;
+using ServiceStack.Configuration;
+using ServiceStack.ServiceClient.Web;
+using ServiceStack.ServiceHost;
+using ServiceStack.ServiceInterface;
+using ServiceStack.ServiceInterface.Auth;
+using ServiceStack.Text;
+
+namespace ServiceStack.Authentication.OpenId
+{
+ public class OpenIdOAuthProvider : OAuthProvider
+ {
+ public const string DefaultName = "OpenId";
+
+ public OpenIdOAuthProvider(IResourceManager appSettings, string name = DefaultName, string realm = null)
+ : base(appSettings, realm, name) { }
+
+ public virtual ClaimsRequest CreateClaimsRequest(IHttpRequest httpReq)
+ {
+ return new ClaimsRequest {
+ Country = DemandLevel.Request,
+ Email = DemandLevel.Request,
+ Gender = DemandLevel.Require,
+ PostalCode = DemandLevel.Require,
+ TimeZone = DemandLevel.Require,
+ };
+ }
+
+ public override object Authenticate(IServiceBase authService, IAuthSession session, Auth request)
+ {
+ var tokens = Init(authService, ref session, request);
+
+ var httpReq = authService.RequestContext.Get<IHttpRequest>();
+ var httpMethod = httpReq.HttpMethod;
+ if (httpMethod == HttpMethod.Post)
+ {
+ var openIdUrl = httpReq.GetParam("OpenIdUrl") ?? base.AuthRealm;
+ if (openIdUrl.IsNullOrEmpty())
+ throw new ArgumentException("'OpenIdUrl' is required a required field");
+
+ try
+ {
+ using (var openid = new OpenIdRelyingParty())
+ {
+ var openIdRequest = openid.CreateRequest(openIdUrl);
+
+ AddAttributeExchangeExtensions(openIdRequest);
+
+ // This is where you would add any OpenID extensions you wanted
+ // to include in the authentication request.
+ openIdRequest.AddExtension(CreateClaimsRequest(httpReq));
+
+ // Send your visitor to their Provider for authentication.
+ var openIdResponse = openIdRequest.RedirectingResponse;
+ var contentType = openIdResponse.Headers[HttpHeaders.ContentType];
+ var httpResult = new HttpResult(openIdResponse.ResponseStream, contentType) {
+ StatusCode = openIdResponse.Status,
+ StatusDescription = "Moved Temporarily",
+ };
+ foreach (string header in openIdResponse.Headers)
+ {
+ httpResult.Headers[header] = openIdResponse.Headers[header];
+ }
+ return httpResult;
+ }
+ }
+ catch (ProtocolException ex)
+ {
+ Log.Error("Failed to login to {0}".Fmt(openIdUrl), ex);
+ return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "Unknown"));
+ }
+ }
+
+ if (httpMethod == HttpMethod.Get)
+ {
+ using (var openid = new OpenIdRelyingParty())
+ {
+ var response = openid.GetResponse();
+ if (response != null)
+ {
+ switch (response.Status)
+ {
+ case AuthenticationStatus.Authenticated:
+
+ var authInfo = CreateAuthInfo(response);
+
+ // Use FormsAuthentication to tell ASP.NET that the user is now logged in,
+ // with the OpenID Claimed Identifier as their username.
+ session.IsAuthenticated = true;
+ authService.SaveSession(session, SessionExpiry);
+ OnAuthenticated(authService, session, tokens, authInfo);
+
+ //Haz access!
+ return authService.Redirect(session.ReferrerUrl.AddHashParam("s", "1"));
+
+ case AuthenticationStatus.Canceled:
+ return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "ProviderCancelled"));
+
+ case AuthenticationStatus.Failed:
+ return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "Unknown"));
+ }
+ }
+ }
+ }
+
+ //Shouldn't get here
+ return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "Unknown"));
+ }
+
+ protected virtual Dictionary<string, string> CreateAuthInfo(IAuthenticationResponse response)
+ {
+ // This is where you would look for any OpenID extension responses included
+ // in the authentication assertion.
+ var claimsResponse = response.GetExtension<ClaimsResponse>();
+ var authInfo = claimsResponse.ToDictionary();
+
+ authInfo["user_id"] = response.ClaimedIdentifier; //a url
+
+ // Store off the "friendly" username to display -- NOT for username lookup
+ authInfo["openid_ref"] = response.FriendlyIdentifierForDisplay;
+
+ var provided = GetAttributeEx(response);
+ foreach (var entry in provided)
+ {
+ authInfo[entry.Key] = entry.Value;
+ }
+
+ return authInfo;
+ }
+
+ protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary<string, string> authInfo)
+ {
+ if (authInfo.ContainsKey("user_id"))
+ tokens.UserId = authInfo.GetValueOrDefault("user_id");
+
+ if (authInfo.ContainsKey("name"))
+ tokens.DisplayName = authInfo.GetValueOrDefault("name");
+
+ if (authInfo.ContainsKey("FullName"))
+ {
+ tokens.FullName = authInfo.GetValueOrDefault("FullName");
+ if (tokens.DisplayName.IsNullOrEmpty())
+ tokens.DisplayName = tokens.FullName;
+ }
+
+ if (authInfo.ContainsKey("Email"))
+ tokens.Email = authInfo.GetValueOrDefault("Email");
+
+ if (authInfo.ContainsKey("BirthDate"))
+ tokens.BirthDate = authInfo.GetValueOrDefault("BirthDate").FromJsv<DateTime?>();
+
+ if (authInfo.ContainsKey("BirthDateRaw"))
+ tokens.BirthDateRaw = authInfo.GetValueOrDefault("BirthDateRaw");
+
+ if (authInfo.ContainsKey("Country"))
+ tokens.Country = authInfo.GetValueOrDefault("Country");
+
+ if (authInfo.ContainsKey("Culture"))
+ tokens.Culture = authInfo.GetValueOrDefault("Culture");
+
+ if (authInfo.ContainsKey("Gender"))
+ tokens.Gender = authInfo.GetValueOrDefault("Gender");
+
+ if (authInfo.ContainsKey("MailAddress"))
+ tokens.MailAddress = authInfo.GetValueOrDefault("MailAddress");
+
+ if (authInfo.ContainsKey("Nickname"))
+ tokens.Nickname = authInfo.GetValueOrDefault("Nickname");
+
+ if (authInfo.ContainsKey("PostalCode"))
+ tokens.PostalCode = authInfo.GetValueOrDefault("PostalCode");
+
+ if (authInfo.ContainsKey("TimeZone"))
+ tokens.TimeZone = authInfo.GetValueOrDefault("TimeZone");
+
+ LoadUserOAuthProvider(userSession, tokens);
+ }
+
+ public override void LoadUserOAuthProvider(IAuthSession authSession, IOAuthTokens tokens)
+ {
+ var userSession = authSession as AuthUserSession;
+ if (userSession == null) return;
+ }
+
+ private void AddAttributeExchangeExtensions(IAuthenticationRequest auth)
+ {
+ // Try to use OpenId 2.0's attribute exchange
+ var fetch = new FetchRequest();
+ //Technically, http://axschema.org/... are "standard", but we'll still find these in the wild
+ fetch.Attributes.Add(new AttributeRequest("http://schema.openid.net/namePerson", false));
+ fetch.Attributes.Add(new AttributeRequest("http://schema.openid.net/contact/email", false));
+
+ fetch.Attributes.AddRequired("http://axschema.org/contact/country/home");
+ fetch.Attributes.AddRequired("http://axschema.org/namePerson/first");
+ fetch.Attributes.AddRequired("http://axschema.org/namePerson/last");
+ fetch.Attributes.AddRequired("http://axschema.org/pref/language");
+ fetch.Attributes.AddRequired("http://schemas.openid.net/ax/api/user_id");
+
+ //Standard compliant AX schema
+ fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.FullName, false));
+
+ //For... no good reason, really, google OpenId requires you "require" an e-mail address to get it
+ bool requireEmail = auth.Provider.Uri.AbsoluteUri.Contains(".google.com");
+ fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email, requireEmail));
+
+ auth.AddExtension(fetch);
+ }
+
+ /// <summary>
+ /// Extracts an Attribute Exchange response, if one exists
+ /// </summary>
+ private Dictionary<string, string> GetAttributeEx(IAuthenticationResponse response)
+ {
+ var ret = new Dictionary<string, string>();
+
+ var fetchResponse = response.GetExtension<FetchResponse>();
+
+ if (fetchResponse == null) return ret;
+
+ var names = new List<string>();
+ var emails = new List<string>();
+
+ if (fetchResponse.Attributes.Contains("http://schema.openid.net/namePerson"))
+ names.AddRange(fetchResponse.Attributes["http://schema.openid.net/namePerson"].Values);
+
+ if (fetchResponse.Attributes.Contains(WellKnownAttributes.Name.FullName))
+ names.AddRange(fetchResponse.Attributes[WellKnownAttributes.Name.FullName].Values);
+
+ if (fetchResponse.Attributes.Contains(WellKnownAttributes.Name.Alias))
+ names.AddRange(fetchResponse.Attributes[WellKnownAttributes.Name.Alias].Values);
+
+ if (fetchResponse.Attributes.Contains(WellKnownAttributes.Name.First))
+ names.AddRange(fetchResponse.Attributes[WellKnownAttributes.Name.First].Values);
+
+ if (fetchResponse.Attributes.Contains(WellKnownAttributes.Name.Last))
+ names.AddRange(fetchResponse.Attributes[WellKnownAttributes.Name.Last].Values);
+
+ if (fetchResponse.Attributes.Contains("http://schema.openid.net/contact/email"))
+ emails.AddRange(fetchResponse.Attributes["http://schema.openid.net/contact/email"].Values);
+
+ if (fetchResponse.Attributes.Contains(WellKnownAttributes.Contact.Email))
+ emails.AddRange(fetchResponse.Attributes[WellKnownAttributes.Contact.Email].Values);
+
+ if (names.Count > 0)
+ ret["FullName"] = names[0];
+
+ if (emails.Count > 0)
+ ret["Email"] = emails[0];
+
+ return ret;
+ }
+ }
+
+ public static class OpenIdExtensions
+ {
+ public static Dictionary<string, string> ToDictionary(this ClaimsResponse response)
+ {
+ var map = new Dictionary<string, string>();
+ if (response == null) return map;
+
+ if (response.BirthDate.HasValue)
+ map["BirthDate"] = response.BirthDate.Value.ToJsv();
+ if (!response.BirthDateRaw.IsNullOrEmpty())
+ map["BirthDateRaw"] = response.BirthDateRaw;
+ if (!response.Country.IsNullOrEmpty())
+ map["Country"] = response.Country;
+ if (response.Culture != null)
+ map["Culture"] = response.Culture.TwoLetterISOLanguageName;
+ if (!response.Email.IsNullOrEmpty())
+ map["Email"] = response.Email;
+ if (!response.FullName.IsNullOrEmpty())
+ map["FullName"] = response.FullName;
+ if (response.Gender.HasValue)
+ map["Gender"] = response.Gender.Value.ToString();
+ if (!response.Language.IsNullOrEmpty())
+ map["Language"] = response.Language;
+ if (response.MailAddress != null)
+ map["MailAddress"] = response.MailAddress.ToJsv();
+ if (!response.Nickname.IsNullOrEmpty())
+ map["Nickname"] = response.Nickname;
+ if (!response.PostalCode.IsNullOrEmpty())
+ map["PostalCode"] = response.PostalCode;
+ if (!response.TimeZone.IsNullOrEmpty())
+ map["TimeZone"] = response.TimeZone;
+
+ return map;
+ }
+ }
+}
View
72 src/ServiceStack.Authentication.OpenId/Properties/AssemblyInfo.cs
@@ -1,36 +1,36 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("ServiceStack.Authentication.OpenId")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("ServiceStack.Authentication.OpenId")]
-[assembly: AssemblyCopyright("Copyright © 2012")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("f6e833d0-068e-4276-abd0-1462055501d5")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ServiceStack.Authentication.OpenId")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ServiceStack.Authentication.OpenId")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("f6e833d0-068e-4276-abd0-1462055501d5")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
View
166 src/ServiceStack.Authentication.OpenId/ServiceStack.Authentication.OpenId.csproj
@@ -1,84 +1,84 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{6E240294-9D93-4C09-9BB0-38D82A22DEEE}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>ServiceStack.Authentication.OpenId</RootNamespace>
- <AssemblyName>ServiceStack.Authentication.OpenId</AssemblyName>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="DotNetOpenAuth, Version=4.1.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\DotNetOpenAuth.Ultimate.4.1.2.12274\lib\net35-full\DotNetOpenAuth.dll</HintPath>
- </Reference>
- <Reference Include="ServiceStack.Text">
- <HintPath>..\..\lib\ServiceStack.Text.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="GoogleOpenIdOAuthProvider.cs" />
- <Compile Include="MyOpenIdOAuthProvider.cs" />
- <Compile Include="OpenIdOAuthProvider.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="YahooOpenIdOAuthProvider.cs" />
- </ItemGroup>
- <ItemGroup>
- <None Include="packages.config" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\ServiceStack.Common\ServiceStack.Common.csproj">
- <Project>{982416DB-C143-4028-A0C3-CF41892D18D3}</Project>
- <Name>ServiceStack.Common</Name>
- </ProjectReference>
- <ProjectReference Include="..\ServiceStack.Interfaces\ServiceStack.Interfaces.csproj">
- <Project>{42E1C8C0-A163-44CC-92B1-8F416F2C0B01}</Project>
- <Name>ServiceStack.Interfaces</Name>
- </ProjectReference>
- <ProjectReference Include="..\ServiceStack.ServiceInterface\ServiceStack.ServiceInterface.csproj">
- <Project>{5A315F92-80D2-4C60-A5A4-22E027AC7E7E}</Project>
- <Name>ServiceStack.ServiceInterface</Name>
- </ProjectReference>
- <ProjectReference Include="..\ServiceStack\ServiceStack.csproj">
- <Project>{680A1709-25EB-4D52-A87F-EE03FFD94BAA}</Project>
- <Name>ServiceStack</Name>
- </ProjectReference>
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{6E240294-9D93-4C09-9BB0-38D82A22DEEE}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>ServiceStack.Authentication.OpenId</RootNamespace>
+ <AssemblyName>ServiceStack.Authentication.OpenId</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="DotNetOpenAuth, Version=4.1.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\DotNetOpenAuth.Ultimate.4.1.2.12274\lib\net35-full\DotNetOpenAuth.dll</HintPath>
+ </Reference>
+ <Reference Include="ServiceStack.Text">
+ <HintPath>..\..\lib\ServiceStack.Text.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="GoogleOpenIdOAuthProvider.cs" />
+ <Compile Include="MyOpenIdOAuthProvider.cs" />
+ <Compile Include="OpenIdOAuthProvider.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="YahooOpenIdOAuthProvider.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ServiceStack.Common\ServiceStack.Common.csproj">
+ <Project>{982416DB-C143-4028-A0C3-CF41892D18D3}</Project>
+ <Name>ServiceStack.Common</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\ServiceStack.Interfaces\ServiceStack.Interfaces.csproj">
+ <Project>{42E1C8C0-A163-44CC-92B1-8F416F2C0B01}</Project>
+ <Name>ServiceStack.Interfaces</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\ServiceStack.ServiceInterface\ServiceStack.ServiceInterface.csproj">
+ <Project>{5A315F92-80D2-4C60-A5A4-22E027AC7E7E}</Project>
+ <Name>ServiceStack.ServiceInterface</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\ServiceStack\ServiceStack.csproj">
+ <Project>{680A1709-25EB-4D52-A87F-EE03FFD94BAA}</Project>
+ <Name>ServiceStack</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
</Project>
View
24 src/ServiceStack.Authentication.OpenId/YahooOpenIdOAuthProvider.cs
@@ -1,13 +1,13 @@
-using ServiceStack.Configuration;
-
-namespace ServiceStack.Authentication.OpenId
-{
- public class YahooOpenIdOAuthProvider : OpenIdOAuthProvider
- {
- public const string Name = "YahooOpenId";
- public static string Realm = "https://me.yahoo.com";
-
- public YahooOpenIdOAuthProvider(IResourceManager appSettings)
- : base(appSettings, Name, Realm) { }
- }
+using ServiceStack.Configuration;
+
+namespace ServiceStack.Authentication.OpenId
+{
+ public class YahooOpenIdOAuthProvider : OpenIdOAuthProvider
+ {
+ public const string Name = "YahooOpenId";
+ public static string Realm = "https://me.yahoo.com";
+
+ public YahooOpenIdOAuthProvider(IResourceManager appSettings)
+ : base(appSettings, Name, Realm) { }
+ }
}
View
6 src/ServiceStack.Authentication.OpenId/packages.config
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
- <package id="DotNetOpenAuth.Ultimate" version="4.1.2.12274" />
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="DotNetOpenAuth.Ultimate" version="4.1.2.12274" />
</packages>
View
174 src/ServiceStack.Common/ActionExecExtensions.cs
@@ -1,88 +1,88 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using ServiceStack.Common.Support;
-
-namespace ServiceStack.Common
-{
- public static class ActionExecExtensions
- {
- public static void ExecAllAndWait(this ICollection<Action> actions, TimeSpan timeout)
- {
- var waitHandles = new WaitHandle[actions.Count];
- var i = 0;
- foreach (var action in actions)
- {
- waitHandles[i++] = action.BeginInvoke(null, null).AsyncWaitHandle;
- }
-
- WaitAll(waitHandles, timeout);
- }
-
- public static List<WaitHandle> ExecAsync(this IEnumerable<Action> actions)
- {
- var waitHandles = new List<WaitHandle>();
- foreach (var action in actions)
- {
- var waitHandle = new AutoResetEvent(false);
- waitHandles.Add(waitHandle);
- var commandExecsHandler = new ActionExecHandler(action, waitHandle);
- ThreadPool.QueueUserWorkItem(x => ((ActionExecHandler)x).Execute(), commandExecsHandler);
- }
- return waitHandles;
- }
-
- public static bool WaitAll(this List<WaitHandle> waitHandles, int timeoutMs)
- {
- return WaitAll(waitHandles.ToArray(), timeoutMs);
- }
-
- public static bool WaitAll(this ICollection<WaitHandle> waitHandles, int timeoutMs)
- {
- return WaitAll(waitHandles.ToArray(), timeoutMs);
- }
-
- public static bool WaitAll(this ICollection<WaitHandle> waitHandles, TimeSpan timeout)
- {
- return WaitAll(waitHandles.ToArray(), (int)timeout.TotalMilliseconds);
- }
-
-#if !SILVERLIGHT && !MONOTOUCH && !XBOX
- public static bool WaitAll(this List<IAsyncResult> asyncResults, TimeSpan timeout)
- {
- var waitHandles = asyncResults.ConvertAll(x => x.AsyncWaitHandle);
- return WaitAll(waitHandles.ToArray(), (int)timeout.TotalMilliseconds);
- }
-
- public static bool WaitAll(WaitHandle[] waitHandles, TimeSpan timeout)
- {
- return WaitAll(waitHandles, (int)timeout.TotalMilliseconds);
- }
-
- public static bool WaitAll(WaitHandle[] waitHandles, int timeOutMs)
- {
- // throws an exception if there are no wait handles
- if (waitHandles == null) throw new ArgumentNullException("waitHandles");
- if (waitHandles.Length == 0) return true;
-
- if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
- {
- // WaitAll for multiple handles on an STA thread is not supported.
- // CurrentThread is ApartmentState.STA when run under unit tests
- var successfullyComplete = true;
- foreach (var waitHandle in waitHandles)
- {
- successfullyComplete = successfullyComplete
- && waitHandle.WaitOne(timeOutMs, false);
- }
- return successfullyComplete;
- }
-
- return WaitHandle.WaitAll(waitHandles, timeOutMs, false);
- }
-#endif
-
- }
-
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using ServiceStack.Common.Support;
+
+namespace ServiceStack.Common
+{
+ public static class ActionExecExtensions
+ {
+ public static void ExecAllAndWait(this ICollection<Action> actions, TimeSpan timeout)
+ {
+ var waitHandles = new WaitHandle[actions.Count];
+ var i = 0;
+ foreach (var action in actions)
+ {
+ waitHandles[i++] = action.BeginInvoke(null, null).AsyncWaitHandle;
+ }
+
+ WaitAll(waitHandles, timeout);
+ }
+
+ public static List<WaitHandle> ExecAsync(this IEnumerable<Action> actions)
+ {
+ var waitHandles = new List<WaitHandle>();
+ foreach (var action in actions)
+ {
+ var waitHandle = new AutoResetEvent(false);
+ waitHandles.Add(waitHandle);
+ var commandExecsHandler = new ActionExecHandler(action, waitHandle);
+ ThreadPool.QueueUserWorkItem(x => ((ActionExecHandler)x).Execute(), commandExecsHandler);
+ }
+ return waitHandles;
+ }
+
+ public static bool WaitAll(this List<WaitHandle> waitHandles, int timeoutMs)
+ {
+ return WaitAll(waitHandles.ToArray(), timeoutMs);
+ }
+
+ public static bool WaitAll(this ICollection<WaitHandle> waitHandles, int timeoutMs)
+ {
+ return WaitAll(waitHandles.ToArray(), timeoutMs);
+ }
+
+ public static bool WaitAll(this ICollection<WaitHandle> waitHandles, TimeSpan timeout)
+ {
+ return WaitAll(waitHandles.ToArray(), (int)timeout.TotalMilliseconds);
+ }
+
+#if !SILVERLIGHT && !MONOTOUCH && !XBOX
+ public static bool WaitAll(this List<IAsyncResult> asyncResults, TimeSpan timeout)
+ {
+ var waitHandles = asyncResults.ConvertAll(x => x.AsyncWaitHandle);
+ return WaitAll(waitHandles.ToArray(), (int)timeout.TotalMilliseconds);
+ }
+
+ public static bool WaitAll(WaitHandle[] waitHandles, TimeSpan timeout)
+ {
+ return WaitAll(waitHandles, (int)timeout.TotalMilliseconds);
+ }
+
+ public static bool WaitAll(WaitHandle[] waitHandles, int timeOutMs)
+ {
+ // throws an exception if there are no wait handles
+ if (waitHandles == null) throw new ArgumentNullException("waitHandles");
+ if (waitHandles.Length == 0) return true;
+
+ if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
+ {
+ // WaitAll for multiple handles on an STA thread is not supported.
+ // CurrentThread is ApartmentState.STA when run under unit tests
+ var successfullyComplete = true;
+ foreach (var waitHandle in waitHandles)
+ {
+ successfullyComplete = successfullyComplete
+ && waitHandle.WaitOne(timeOutMs, false);
+ }
+ return successfullyComplete;
+ }
+
+ return WaitHandle.WaitAll(waitHandles, timeOutMs, false);
+ }
+#endif
+
+ }
+
}
View
144 src/ServiceStack.Common/AssertExtensions.cs
@@ -1,73 +1,73 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-
-namespace ServiceStack.Common
-{
- public static class AssertExtensions
- {
- public static void ThrowOnFirstNull(params object[] objs)
- {
- foreach (var obj in objs)
- {
- ThrowIfNull(obj);
- }
- }
-
- public static void ThrowIfNull(this object obj)
- {
- ThrowIfNull(obj, null);
- }
-
- public static void ThrowIfNull(this object obj, string varName)
- {
- if (obj == null)
- throw new ArgumentNullException(varName ?? "object");
- }
-
- public static void ThrowIfNullOrEmpty(this string strValue)
- {
- ThrowIfNullOrEmpty(strValue, null);
- }
-
- public static void ThrowIfNullOrEmpty(this string strValue, string varName)
- {
- if (string.IsNullOrEmpty(strValue))
- throw new ArgumentNullException(varName ?? "string");
- }
-
- public static void ThrowIfNullOrEmpty(this ICollection collection)
- {
- ThrowIfNullOrEmpty(collection, null);
- }
-
- public static void ThrowIfNullOrEmpty(this ICollection collection, string varName)
- {
- var fieldName = varName ?? "collection";
-
- if (collection == null)
- throw new ArgumentNullException(fieldName);
-
- if (collection.Count == 0)
- throw new ArgumentException(fieldName + " is empty");
- }
-
- public static void ThrowIfNullOrEmpty<T>(this ICollection<T> collection)
- {
- ThrowIfNullOrEmpty(collection, null);
- }
-
- public static void ThrowIfNullOrEmpty<T>(this ICollection<T> collection, string varName)
- {
- var fieldName = varName ?? "collection";
-
- if (collection == null)
- throw new ArgumentNullException(fieldName);
-
- if (collection.Count == 0)
- throw new ArgumentException(fieldName + " is empty");
- }
-
- }
-
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace ServiceStack.Common
+{
+ public static class AssertExtensions
+ {
+ public static void ThrowOnFirstNull(params object[] objs)
+ {
+ foreach (var obj in objs)
+ {
+ ThrowIfNull(obj);
+ }
+ }
+
+ public static void ThrowIfNull(this object obj)
+ {
+ ThrowIfNull(obj, null);
+ }
+
+ public static void ThrowIfNull(this object obj, string varName)
+ {
+ if (obj == null)
+ throw new ArgumentNullException(varName ?? "object");
+ }
+
+ public static void ThrowIfNullOrEmpty(this string strValue)
+ {
+ ThrowIfNullOrEmpty(strValue, null);
+ }
+
+ public static void ThrowIfNullOrEmpty(this string strValue, string varName)
+ {
+ if (string.IsNullOrEmpty(strValue))
+ throw new ArgumentNullException(varName ?? "string");
+ }
+
+ public static void ThrowIfNullOrEmpty(this ICollection collection)
+ {
+ ThrowIfNullOrEmpty(collection, null);
+ }
+
+ public static void ThrowIfNullOrEmpty(this ICollection collection, string varName)
+ {
+ var fieldName = varName ?? "collection";
+
+ if (collection == null)
+ throw new ArgumentNullException(fieldName);
+
+ if (collection.Count == 0)
+ throw new ArgumentException(fieldName + " is empty");
+ }
+
+ public static void ThrowIfNullOrEmpty<T>(this ICollection<T> collection)
+ {
+ ThrowIfNullOrEmpty(collection, null);
+ }
+
+ public static void ThrowIfNullOrEmpty<T>(this ICollection<T> collection, string varName)
+ {
+ var fieldName = varName ?? "collection";
+
+ if (collection == null)
+ throw new ArgumentNullException(fieldName);
+
+ if (collection.Count == 0)
+ throw new ArgumentException(fieldName + " is empty");
+ }
+
+ }
+
}
View
38 src/ServiceStack.Common/ByteArrayExtensions.cs
@@ -1,20 +1,20 @@
-namespace ServiceStack.Common
-{
- public static class ByteArrayExtensions
- {
- public static bool AreEqual(this byte[] b1, byte[] b2)
- {
- if (b1 == b2) return true;
- if (b1 == null || b2 == null) return false;
- if (b1.Length != b2.Length) return false;
-
- for (var i = 0; i < b1.Length; i++)
- {
- if (b1[i] != b2[i]) return false;
- }
-
- return true;
- }
-
- }
+namespace ServiceStack.Common
+{
+ public static class ByteArrayExtensions
+ {
+ public static bool AreEqual(this byte[] b1, byte[] b2)
+ {
+ if (b1 == b2) return true;
+ if (b1 == null || b2 == null) return false;
+ if (b1.Length != b2.Length) return false;
+
+ for (var i = 0; i < b1.Length; i++)
+ {
+ if (b1[i] != b2[i]) return false;
+ }
+
+ return true;
+ }
+
+ }
}
View
114 src/ServiceStack.Common/DictionaryExtensions.cs
@@ -1,58 +1,58 @@
-using System;
-using System.Collections.Generic;
-using ServiceStack.Common.Extensions;
-
-namespace ServiceStack.Common
-{
- public static class DictionaryExtensions
- {
- public static TValue GetValueOrDefault<TValue, TKey>(this Dictionary<TKey, TValue> dictionary, TKey key)
- {
- return dictionary.ContainsKey(key) ? dictionary[key] : default(TValue);
- }
-
- public static void ForEach<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, Action<TKey, TValue> onEachFn)
- {
- foreach (var entry in dictionary)
- {
- onEachFn(entry.Key, entry.Value);
- }
- }
-
- public static bool EquivalentTo<K, V>(this IDictionary<K, V> thisMap, IDictionary<K, V> otherMap)
- {
- if (thisMap == null || otherMap == null) return thisMap == otherMap;
- if (thisMap.Count != otherMap.Count) return false;
-
- foreach (var entry in thisMap)
- {
- V otherValue;
- if (!otherMap.TryGetValue(entry.Key, out otherValue)) return false;
- if (!Equals(entry.Value, otherValue)) return false;
- }
-
- return true;
- }
-
- public static List<T> ConvertAll<T, K, V>(IDictionary<K, V> map, Func<K, V, T> createFn)
- {
- var list = new List<T>();
- map.ForEach((kvp) => list.Add(createFn(kvp.Key, kvp.Value)));
- return list;
- }
-
- public static V GetOrAdd<K, V>(this Dictionary<K, V> map, K key, Func<K,V> createFn)
- {
- //simulate ConcurrentDictionary.GetOrAdd
- lock (map)
- {
- V val;
- if (!map.TryGetValue(key, out val))
- map[key] = val = createFn(key);
-
- return val;
- }
- }
-
- }
+using System;
+using System.Collections.Generic;
+using ServiceStack.Common.Extensions;
+
+namespace ServiceStack.Common
+{
+ public static class DictionaryExtensions
+ {
+ public static TValue GetValueOrDefault<TValue, TKey>(this Dictionary<TKey, TValue> dictionary, TKey key)
+ {
+ return dictionary.ContainsKey(key) ? dictionary[key] : default(TValue);
+ }
+
+ public static void ForEach<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, Action<TKey, TValue> onEachFn)
+ {
+ foreach (var entry in dictionary)
+ {
+ onEachFn(entry.Key, entry.Value);
+ }
+ }
+
+ public static bool EquivalentTo<K, V>(this IDictionary<K, V> thisMap, IDictionary<K, V> otherMap)
+ {
+ if (thisMap == null || otherMap == null) return thisMap == otherMap;
+ if (thisMap.Count != otherMap.Count) return false;
+
+ foreach (var entry in thisMap)
+ {
+ V otherValue;
+ if (!otherMap.TryGetValue(entry.Key, out otherValue)) return false;
+ if (!Equals(entry.Value, otherValue)) return false;
+ }
+
+ return true;
+ }
+
+ public static List<T> ConvertAll<T, K, V>(IDictionary<K, V> map, Func<K, V, T> createFn)
+ {
+ var list = new List<T>();
+ map.ForEach((kvp) => list.Add(createFn(kvp.Key, kvp.Value)));
+ return list;
+ }
+
+ public static V GetOrAdd<K, V>(this Dictionary<K, V> map, K key, Func<K,V> createFn)
+ {
+ //simulate ConcurrentDictionary.GetOrAdd
+ lock (map)
+ {
+ V val;
+ if (!map.TryGetValue(key, out val))
+ map[key] = val = createFn(key);
+
+ return val;
+ }
+ }
+
+ }
}
View
86 src/ServiceStack.Common/DirectoryInfoExtensions.cs
@@ -1,44 +1,44 @@
-#if !SILVERLIGHT
-using System.Collections.Generic;
-using System.IO;
-
-namespace ServiceStack.Common
-{
- public static class DirectoryInfoExtensions
- {
- public static IEnumerable<string> GetMatchingFiles(this DirectoryInfo rootDirPath, string fileSearchPattern)
- {
- return GetMatchingFiles(rootDirPath.FullName, fileSearchPattern);
- }
-
- public static IEnumerable<string> GetMatchingFiles(string rootDirPath, string fileSearchPattern)
- {
- var pending = new Queue<string>();
- pending.Enqueue(rootDirPath);
- string[] paths;
-
- while (pending.Count > 0)
- {
- rootDirPath = pending.Dequeue();
- paths = Directory.GetFiles(rootDirPath, fileSearchPattern);
- foreach (var filePath in paths) {
- yield return filePath;
- }
- paths = Directory.GetDirectories(rootDirPath);
- foreach (var dirPath in paths)
- {
- var dirAttrs = File.GetAttributes(dirPath);
- var isRecurseSymLink = (dirAttrs & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint;
-
- if (!isRecurseSymLink)
- {
- pending.Enqueue(dirPath);
- }
- }
- }
- }
-
- }
-
-}
+#if !SILVERLIGHT
+using System.Collections.Generic;
+using System.IO;
+
+namespace ServiceStack.Common
+{
+ public static class DirectoryInfoExtensions
+ {
+ public static IEnumerable<string> GetMatchingFiles(this DirectoryInfo rootDirPath, string fileSearchPattern)
+ {
+ return GetMatchingFiles(rootDirPath.FullName, fileSearchPattern);
+ }
+
+ public static IEnumerable<string> GetMatchingFiles(string rootDirPath, string fileSearchPattern)
+ {
+ var pending = new Queue<string>();
+ pending.Enqueue(rootDirPath);
+ string[] paths;
+
+ while (pending.Count > 0)
+ {
+ rootDirPath = pending.Dequeue();
+ paths = Directory.GetFiles(rootDirPath, fileSearchPattern);
+ foreach (var filePath in paths) {
+ yield return filePath;
+ }
+ paths = Directory.GetDirectories(rootDirPath);
+ foreach (var dirPath in paths)
+ {
+ var dirAttrs = File.GetAttributes(dirPath);
+ var isRecurseSymLink = (dirAttrs & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint;
+
+ if (!isRecurseSymLink)
+ {
+ pending.Enqueue(dirPath);
+ }
+ }
+ }
+ }
+
+ }
+
+}
#endif
View
90 src/ServiceStack.Common/DisposableExtensions.cs
@@ -1,46 +1,46 @@
-using System;
-using System.Collections.Generic;
-using ServiceStack.Logging;
-
-namespace ServiceStack.Common
-{
- public static class DisposableExtensions
- {
- public static void Dispose(this IEnumerable<IDisposable> resources, ILog log)
- {
- foreach (var disposable in resources)
- {
- try
- {
- disposable.Dispose();
- }
- catch (Exception ex)
- {
- if (log != null)
- {
- log.Error(string.Format("Error disposing of '{0}'", disposable.GetType().FullName), ex);
- }
- }
- }
- }
-
- public static void Dispose(this IEnumerable<IDisposable> resources)
- {
- Dispose(resources, null);
- }
-
- public static void Dispose(params IDisposable[] disposables)
- {
- Dispose(disposables, null);
- }
-
- public static void Run<T>(this T disposable, Action<T> runActionThenDispose)
- where T : IDisposable
- {
- using (disposable)
- {
- runActionThenDispose(disposable);
- }
- }
- }
+using System;
+using System.Collections.Generic;
+using ServiceStack.Logging;
+
+namespace ServiceStack.Common
+{
+ public static class DisposableExtensions
+ {
+ public static void Dispose(this IEnumerable<IDisposable> resources, ILog log)
+ {
+ foreach (var disposable in resources)
+ {
+ try
+ {
+ disposable.Dispose();
+ }
+ catch (Exception ex)
+ {
+ if (log != null)
+ {
+ log.Error(string.Format("Error disposing of '{0}'", disposable.GetType().FullName), ex);
+ }
+ }
+ }
+ }
+
+ public static void Dispose(this IEnumerable<IDisposable> resources)
+ {
+ Dispose(resources, null);
+ }
+
+ public static void Dispose(params IDisposable[] disposables)
+ {
+ Dispose(disposables, null);
+ }
+
+ public static void Run<T>(this T disposable, Action<T> runActionThenDispose)
+ where T : IDisposable
+ {
+ using (disposable)
+ {
+ runActionThenDispose(disposable);
+ }
+ }
+ }
}
View
218 src/ServiceStack.Common/EnumExtensions.cs
@@ -1,110 +1,110 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Reflection;
-
-namespace ServiceStack.Common
-{
- public static class EnumExtensions
- {
- /// <summary>
- /// Gets the textual description of the enum if it has one. e.g.
- ///
- /// <code>
- /// enum UserColors
- /// {
- /// [Description("Bright Red")]
- /// BrightRed
- /// }
- /// UserColors.BrightRed.ToDescription();
- /// </code>
- /// </summary>
- /// <param name="enum"></param>
- /// <returns></returns>
- public static string ToDescription(this Enum @enum)
- {
- var type = @enum.GetType();
- var memInfo = type.GetMember(@enum.ToString());
- if (memInfo != null && memInfo.Length > 0)
- {
- var attrs = memInfo[0].GetCustomAttributes(
- typeof(DescriptionAttribute),
- false);
-
- if (attrs != null && attrs.Length > 0)
- return ((DescriptionAttribute)attrs[0]).Description;
- }
-
- return @enum.ToString();
- }
-
- public static List<string> ToList(this Enum @enum)
- {
-#if !SILVERLIGHT4
- return new List<string>(Enum.GetNames(@enum.GetType()));
-#else
- return @enum.GetType().GetFields(BindingFlags.Static | BindingFlags.Public).Select(fi => fi.Name).ToList();
-#endif
- }
-
- public static bool Has<T>(this Enum type, T value)
- {
- try
- {
- return (((int)(object)type & (int)(object)value) == (int)(object)value);
- }
- catch
- {
- return false;
- }
- }
-
- public static bool Is<T>(this Enum type, T value)
- {
- try
- {
- return (int)(object)type == (int)(object)value;
- }
- catch
- {
- return false;
- }
- }
-
-
- public static T Add<T>(this Enum type, T value)
- {
- try
- {
- return (T)(object)(((int)(object)type | (int)(object)value));
- }
- catch (Exception ex)
- {
- throw new ArgumentException(
- string.Format(
- "Could not append value from enumerated type '{0}'.",
- typeof(T).Name
- ), ex);
- }
- }
-
- public static T Remove<T>(this Enum type, T value)
- {
- try
- {
- return (T)(object)(((int)(object)type & ~(int)(object)value));
- }
- catch (Exception ex)
- {
- throw new ArgumentException(
- string.Format(
- "Could not remove value from enumerated type '{0}'.",
- typeof(T).Name
- ), ex);
- }
- }
-
- }
-
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+
+namespace ServiceStack.Common
+{
+ public static class EnumExtensions
+ {
+ /// <summary>
+ /// Gets the textual description of the enum if it has one. e.g.
+ ///
+ /// <code>
+ /// enum UserColors
+ /// {
+ /// [Description("Bright Red")]
+ /// BrightRed
+ /// }
+ /// UserColors.BrightRed.ToDescription();
+ /// </code>
+ /// </summary>
+ /// <param name="enum"></param>
+ /// <returns></returns>
+ public static string ToDescription(this Enum @enum)
+ {
+ var type = @enum.GetType();
+ var memInfo = type.GetMember(@enum.ToString());
+ if (memInfo != null && memInfo.Length > 0)
+ {
+ var attrs = memInfo[0].GetCustomAttributes(
+ typeof(DescriptionAttribute),
+ false);
+
+ if (attrs != null && attrs.Length > 0)
+ return ((DescriptionAttribute)attrs[0]).Description;
+ }
+
+ return @enum.ToString();
+ }
+
+ public static List<string> ToList(this Enum @enum)
+ {
+#if !SILVERLIGHT4
+ return new List<string>(Enum.GetNames(@enum.GetType()));
+#else
+ return @enum.GetType().GetFields(BindingFlags.Static | BindingFlags.Public).Select(fi => fi.Name).ToList();
+#endif
+ }
+
+ public static bool Has<T>(this Enum type, T value)
+ {
+ try
+ {
+ return (((int)(object)type & (int)(object)value) == (int)(object)value);
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ public static bool Is<T>(this Enum type, T value)
+ {
+ try
+ {
+ return (int)(object)type == (int)(object)value;
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+
+ public static T Add<T>(this Enum type, T value)
+ {
+ try
+ {
+ return (T)(object)(((int)(object)type | (int)(object)value));
+ }
+ catch (Exception ex)
+ {
+ throw new ArgumentException(
+ string.Format(
+ "Could not append value from enumerated type '{0}'.",
+ typeof(T).Name
+ ), ex);
+ }
+ }
+
+ public static T Remove<T>(this Enum type, T value)
+ {
+ try
+ {
+ return (T)(object)(((int)(object)type & ~(int)(object)value));
+ }
+ catch (Exception ex)
+ {
+ throw new ArgumentException(
+ string.Format(
+ "Could not remove value from enumerated type '{0}'.",
+ typeof(T).Name
+ ), ex);
+ }
+ }
+
+ }
+
}
View
212 src/ServiceStack.Common/EnumerableExtensions.cs
@@ -1,107 +1,107 @@
-using System;
-using System.Collections.Generic;
-
-namespace ServiceStack.Common
-{
- public static class EnumerableExtensions
- {
- public static bool IsEmpty<T>(this ICollection<T> collection)
- {
- return collection == null || collection.Count == 0;
- }
-
- public static HashSet<T> ToHashSet<T>(this IEnumerable<T> items)
- {
- return new HashSet<T>(items);
- }
-
- public static List<To> SafeConvertAll<To, From>(this IEnumerable<From> items, Func<From, To> converter)
- {
- return items == null ? new List<To>() : Extensions.EnumerableExtensions.ConvertAll(items, converter);
- }
-
- public static List<object> ToObjects<T>(this IEnumerable<T> items)
- {
- var to = new List<object>();
- foreach (var item in items)
- {
- to.Add(item);
- }
- return to;
- }
-
- public static string FirstNonDefaultOrEmpty(this IEnumerable<string> values)
- {
- foreach (var value in values)
- {
- if (!string.IsNullOrEmpty(value)) return value;
- }
- return null;
- }
-
- public static T FirstNonDefault<T>(this IEnumerable<T> values)
- {
- foreach (var value in values)
- {
- if (!Equals(value, default(T))) return value;
- }
- return default(T);