Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public class when_resolving_a_string_without_any_match

Because of = () => result = mapper.Resolve(input);

It should_return_empty = () => result.ShouldEqual(string.Empty);
It should_return_null = () => result.ShouldBeNull();
}
}
9 changes: 3 additions & 6 deletions Source/Bifrost.Web/Applications/ApplicationRouteHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Bifrost.Web.Applications
{
public class ApplicationRouteHandler : IRouteHandler
{
string _url;
Assembly _assembly;
readonly string _url;
readonly Assembly _assembly;
IHttpHandler _httpHandler;

public ApplicationRouteHandler(string url, Assembly assembly)
Expand All @@ -22,10 +22,7 @@ public ApplicationRouteHandler(string url, Assembly assembly)

public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
if (_httpHandler == null)
_httpHandler = new ApplicationRouteHttpHandler(_url, _assembly);

return _httpHandler;
return _httpHandler ?? (_httpHandler = new ApplicationRouteHttpHandler(_url, _assembly));
}
}
}
5 changes: 2 additions & 3 deletions Source/Bifrost.Web/Assets/AssetManagerRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
* Copyright (c) 2008-2017 Dolittle. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System.Reflection;
using System.Web.Routing;

namespace Bifrost.Web.Assets
{
public class AssetManagerRoute : Route
{
public AssetManagerRoute(string url)
: base(url, new AssetManagerRouteHandler(url))
public AssetManagerRoute(string url)
: base(url, new AssetManagerRouteHandler())
{
}

Expand Down
12 changes: 1 addition & 11 deletions Source/Bifrost.Web/Assets/AssetManagerRouteHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,18 @@
* Copyright (c) 2008-2017 Dolittle. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System.Reflection;
using System.Web;
using System.Web.Routing;

namespace Bifrost.Web.Assets
{
public class AssetManagerRouteHandler : IRouteHandler
{
string _url;
IHttpHandler _httpHandler;

public AssetManagerRouteHandler(string url)
{
_url = url;
}

public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
if (_httpHandler == null)
_httpHandler = new AssetManagerRouteHttpHandler(_url);

return _httpHandler;
return _httpHandler ?? (_httpHandler = new AssetManagerRouteHttpHandler());
}
}
}
20 changes: 6 additions & 14 deletions Source/Bifrost.Web/Assets/AssetManagerRouteHttpHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,30 @@
* Copyright (c) 2008-2017 Dolittle. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System.Linq;
using System.Reflection;
using System.Web;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using System.Text;
using System.Web;
using Bifrost.Configuration;
using Newtonsoft.Json;

namespace Bifrost.Web.Assets
{
public class AssetManagerRouteHttpHandler : IHttpHandler
{
string _url;

public AssetManagerRouteHttpHandler(string url)
{
_url = url;
}

public bool IsReusable { get { return true; } }
public bool IsReusable => true;

public void ProcessRequest(HttpContext context)
{
var assetsManager = Configure.Instance.Container.Get<IAssetsManager>();
IEnumerable<string> assets = new string[0];
var extension = context.Request.Params["extension"];
if( extension != null )
if (extension != null)
{
assets = assetsManager.GetFilesForExtension(extension);
if (context.Request.Params["structure"] != null)
{
assets = assetsManager.GetStructureForExtension(extension);
}
}
var serialized = JsonConvert.SerializeObject(assets);
context.Response.Write(serialized);
Expand Down
52 changes: 28 additions & 24 deletions Source/Bifrost.Web/Commands/CommandProxies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,52 @@ namespace Bifrost.Web.Commands
{
public class CommandProxies : IProxyGenerator
{
internal static List<string> _namespacesToExclude = new List<string>();
internal static List<string> NamespacesToExclude = new List<string>();

ITypeDiscoverer _typeDiscoverer;
ITypeImporter _typeImporter;
ICodeGenerator _codeGenerator;
WebConfiguration _configuration;
readonly ITypeDiscoverer _typeDiscoverer;
readonly ITypeImporter _typeImporter;
readonly ICodeGenerator _codeGenerator;
readonly WebConfiguration _configuration;

public static void ExcludeCommandsStartingWithNamespace(string @namespace)
{
_namespacesToExclude.Add(@namespace);
NamespacesToExclude.Add(@namespace);
}

public CommandProxies(ITypeDiscoverer typeDiscoverer, ITypeImporter typeImporter, ICodeGenerator codeGenerator, WebConfiguration configuration)
public CommandProxies(
ITypeDiscoverer typeDiscoverer,
ITypeImporter typeImporter,
ICodeGenerator codeGenerator,
WebConfiguration configuration)
{
_typeDiscoverer = typeDiscoverer;
_typeImporter = typeImporter;
_codeGenerator = codeGenerator;

_configuration = configuration;
}

string ClientNamespace(string @namespace)
{
return _configuration.NamespaceMapper.GetClientNamespaceFrom(@namespace) ?? Namespaces.COMMANDS;
}

public string Generate()
{
var typesByNamespace = _typeDiscoverer.FindMultiple<ICommand>().Where(t => !_namespacesToExclude.Any(n => t.Namespace.StartsWith(n))).GroupBy(t=>t.Namespace);
var typesByNamespace = _typeDiscoverer
.FindMultiple<ICommand>()
.Where(t => !t.IsGenericType)
.Where(t => !NamespacesToExclude.Any(n => t.Namespace.StartsWith(n)))
.OrderBy(t => t.FullName)
.GroupBy(t => ClientNamespace(t.Namespace))
.OrderBy(n => n.Key);
var commandPropertyExtenders = _typeImporter.ImportMany<ICanExtendCommandProperty>();

var result = new StringBuilder();

Namespace currentNamespace;
Namespace globalCommands = _codeGenerator.Namespace(Namespaces.COMMANDS);

foreach (var @namespace in typesByNamespace)
{
if (_configuration.NamespaceMapper.CanResolveToClient(@namespace.Key))
currentNamespace = _codeGenerator.Namespace(_configuration.NamespaceMapper.GetClientNamespaceFrom(@namespace.Key));
else
currentNamespace = globalCommands;

var currentNamespace = _codeGenerator.Namespace(@namespace.Key);
foreach (var type in @namespace)
{
if (type.IsGenericType) continue;

var name = type.Name.ToCamelCase();
currentNamespace.Content.Assign(name)
.WithType(t =>
Expand All @@ -72,15 +76,15 @@ public string Generate()
.WithObservablePropertiesFrom(type, excludePropertiesFrom: typeof(ICommand), observableVisitor: (propertyName, observable) =>
{
foreach (var commandPropertyExtender in commandPropertyExtenders)
{
commandPropertyExtender.Extend(type, propertyName, observable);
}
}));
}

if (currentNamespace != globalCommands)
result.Append(_codeGenerator.GenerateFrom(currentNamespace));
result.Append(_codeGenerator.GenerateFrom(currentNamespace));
}
result.Append(_codeGenerator.GenerateFrom(globalCommands));


return result.ToString();
}
}
Expand Down
36 changes: 12 additions & 24 deletions Source/Bifrost.Web/Commands/CommandSecurityProxies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,27 @@ public CommandSecurityProxies(
_commandSecurityManager = commandSecurityManager;
}

string ClientNamespace(string @namespace)
{
return _configuration.NamespaceMapper.GetClientNamespaceFrom(@namespace) ?? Namespaces.COMMANDS;
}

public string Generate()
{
var typesByNamespace = _typeDiscoverer
.FindMultiple<ICommand>()
.Where(t => !CommandProxies._namespacesToExclude.Any(n => t.Namespace.StartsWith(n)))
.GroupBy(t => t.Namespace);

.Where(t => !t.IsGenericType)
.Where(t => !CommandProxies.NamespacesToExclude.Any(t.Namespace.StartsWith))
.OrderBy(t => t.FullName)
.GroupBy(t => ClientNamespace(t.Namespace))
.OrderBy(n => n.Key);
var result = new StringBuilder();
var globalCommands = _codeGenerator.Namespace(Namespaces.COMMANDS);

foreach (var @namespace in typesByNamespace)
{
Namespace currentNamespace;
if (_configuration.NamespaceMapper.CanResolveToClient(@namespace.Key))
{
currentNamespace = _codeGenerator.Namespace(_configuration.NamespaceMapper.GetClientNamespaceFrom(@namespace.Key));
}
else
{
currentNamespace = globalCommands;
}

var currentNamespace = _codeGenerator.Namespace(@namespace.Key);
foreach (var type in @namespace)
{
if (type.IsGenericType)
{
continue;
}

var command = Activator.CreateInstance(type) as ICommand;
var authorizationResult = _commandSecurityManager.Authorize(command);
var name = $"{type.Name.ToCamelCase()}SecurityContext";
Expand All @@ -81,13 +73,9 @@ public string Generate()
);
}

if (currentNamespace != globalCommands)
{
result.Append(_codeGenerator.GenerateFrom(currentNamespace));
}
result.Append(_codeGenerator.GenerateFrom(currentNamespace));
}

result.Append(_codeGenerator.GenerateFrom(globalCommands));
return result.ToString();
}
}
Expand Down
7 changes: 2 additions & 5 deletions Source/Bifrost.Web/Configuration/ConfigurationRouteHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Copyright (c) 2008-2017 Dolittle. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System.Web.Routing;
using System.Web;
using System.Web.Routing;

namespace Bifrost.Web.Configuration
{
Expand All @@ -13,10 +13,7 @@ public class ConfigurationRouteHandler : IRouteHandler

public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
if (_httpHandler == null)
_httpHandler = new ConfigurationRouteHttpHandler();

return _httpHandler;
return _httpHandler ?? (_httpHandler = new ConfigurationRouteHttpHandler());
}
}
}
31 changes: 14 additions & 17 deletions Source/Bifrost.Web/Hubs/HubProxies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace Bifrost.Web.Hubs
{
public class HubProxies : IProxyGenerator
{
ITypeDiscoverer _typeDiscoverer;
ICodeGenerator _codeGenerator;
WebConfiguration _configuration;
readonly ITypeDiscoverer _typeDiscoverer;
readonly ICodeGenerator _codeGenerator;
readonly WebConfiguration _configuration;

public HubProxies(ITypeDiscoverer typeDiscoverer, ICodeGenerator codeGenerator, WebConfiguration configuration)
{
Expand All @@ -27,22 +27,23 @@ public HubProxies(ITypeDiscoverer typeDiscoverer, ICodeGenerator codeGenerator,
_configuration = configuration;
}

string ClientNamespace(string @namespace)
{
return _configuration.NamespaceMapper.GetClientNamespaceFrom(@namespace) ?? Namespaces.HUBS;
}

public string Generate()
{
var typesByNamespace = _typeDiscoverer.FindMultiple<Hub>().GroupBy(t=>t.Namespace);
var typesByNamespace = _typeDiscoverer
.FindMultiple<Hub>()
.OrderBy(t => t.FullName)
.GroupBy(t => ClientNamespace(t.Namespace))
.OrderBy(n => n.Key);
var result = new StringBuilder();

Namespace currentNamespace;
Namespace globalHubs = _codeGenerator.Namespace(Namespaces.HUBS);

foreach (var @namespace in typesByNamespace)
{
if (_configuration.NamespaceMapper.CanResolveToClient(@namespace.Key))
currentNamespace = _codeGenerator.Namespace(_configuration.NamespaceMapper.GetClientNamespaceFrom(@namespace.Key));
else
currentNamespace = globalHubs;

var currentNamespace = _codeGenerator.Namespace(@namespace.Key);
foreach (var type in @namespace)
{
if (type.IsGenericType) continue;
Expand All @@ -60,12 +61,8 @@ public string Generate()
);
}

if (currentNamespace != globalHubs)
result.Append(_codeGenerator.GenerateFrom(currentNamespace));


result.Append(_codeGenerator.GenerateFrom(currentNamespace));
}
result.Append(_codeGenerator.GenerateFrom(globalHubs));

return result.ToString();
}
Expand Down
6 changes: 2 additions & 4 deletions Source/Bifrost.Web/Proxies/GeneratedProxies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ namespace Bifrost.Web.Proxies
[Singleton]
public class GeneratedProxies
{
public string All { get; }

public GeneratedProxies(
CommandProxies commandProxies,
CommandSecurityProxies commandSecurityProxies,
QueryProxies queryProxies,
ReadModelProxies readModelProxies,
ServiceProxies serviceProxies,
Expand All @@ -29,7 +30,6 @@ public GeneratedProxies(
{
var builder = new StringBuilder();
builder.Append(commandProxies.Generate());
builder.Append(commandSecurityProxies.Generate());
builder.Append(readModelProxies.Generate());
builder.Append(queryProxies.Generate());
builder.Append(serviceProxies.Generate());
Expand All @@ -45,7 +45,5 @@ public GeneratedProxies(

All = builder.ToString();
}

public string All { get; private set; }
}
}
Loading