refactor: apply default vs transform to xproj

refactor(spa-services): clean code

refactor(node-services): clean code, extract classes nto separate files

refactor(angular-services): prime cache cleanup
This commit is contained in:
Andrei Tserakhau
2016-05-23 11:28:42 +03:00
parent 2c35945562
commit 95cba7f5dd
32 changed files with 621 additions and 448 deletions

View File

@@ -4,18 +4,34 @@ using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.SpaServices;
// Putting in this namespace so it's always available whenever MapRoute is
namespace Microsoft.AspNetCore.Builder
{
public static class SpaRouteExtensions
{
private const string ClientRouteTokenName = "clientRoute";
public static void MapSpaFallbackRoute(this IRouteBuilder routeBuilder, string name, object defaults, object constraints = null, object dataTokens = null)
{
MapSpaFallbackRoute(routeBuilder, name, /* templatePrefix */ (string)null, defaults, constraints, dataTokens);
}
public static void MapSpaFallbackRoute(
this IRouteBuilder routeBuilder,
string name,
object defaults,
object constraints = null,
object dataTokens = null)
=> MapSpaFallbackRoute(
routeBuilder,
name,
/* templatePrefix */ null,
defaults,
constraints,
dataTokens);
public static void MapSpaFallbackRoute(this IRouteBuilder routeBuilder, string name, string templatePrefix, object defaults, object constraints = null, object dataTokens = null)
public static void MapSpaFallbackRoute(
this IRouteBuilder routeBuilder,
string name,
string templatePrefix,
object defaults,
object constraints = null,
object dataTokens = null)
{
var template = CreateRouteTemplate(templatePrefix);
@@ -29,25 +45,27 @@ namespace Microsoft.AspNetCore.Builder
{
templatePrefix = templatePrefix ?? string.Empty;
if (templatePrefix.Contains("?")) {
if (templatePrefix.Contains("?"))
{
// TODO: Consider supporting this. The {*clientRoute} part should be added immediately before the '?'
throw new ArgumentException("SPA fallback route templates don't support querystrings");
}
if (templatePrefix.Contains("#")) {
throw new ArgumentException("SPA fallback route templates should not include # characters. The hash part of a URI does not get sent to the server.");
if (templatePrefix.Contains("#"))
{
throw new ArgumentException(
"SPA fallback route templates should not include # characters. The hash part of a URI does not get sent to the server.");
}
if (templatePrefix != string.Empty && !templatePrefix.EndsWith("/")) {
if (templatePrefix != string.Empty && !templatePrefix.EndsWith("/"))
{
templatePrefix += "/";
}
return templatePrefix + $"{{*{ ClientRouteTokenName }}}";
return templatePrefix + $"{{*{ClientRouteTokenName}}}";
}
private static IDictionary<string, object> ObjectToDictionary(object value)
{
return value as IDictionary<string, object> ?? new RouteValueDictionary(value);
}
=> value as IDictionary<string, object> ?? new RouteValueDictionary(value);
}
}
}