Skip to content

Commit

Permalink
#33 #39 #25 Added bus starting to HttpApplications.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdmdotnet committed Jul 18, 2017
1 parent b34630e commit 7c42ba4
Show file tree
Hide file tree
Showing 27 changed files with 153 additions and 76 deletions.
Expand Up @@ -48,8 +48,8 @@
<HintPath>..\..\..\packages\cdmdotnet.Performance.1.0.5.8\lib\net40\cdmdotnet.Performance.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="cdmdotnet.StateManagement, Version=3.0.9.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\cdmdotnet.StateManagement.3.0.9.7\lib\net40\cdmdotnet.StateManagement.dll</HintPath>
<Reference Include="cdmdotnet.StateManagement, Version=3.0.13.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\cdmdotnet.StateManagement.3.0.13.9\lib\net40\cdmdotnet.StateManagement.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AI.Agent.Intercept, Version=2.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down
Expand Up @@ -3,7 +3,7 @@
<package id="cdmdotnet.Logging" version="1.2.91.71" targetFramework="net46" />
<package id="cdmdotnet.Logging.Azure.ApplicationInsights" version="1.2.91.71" targetFramework="net46" />
<package id="cdmdotnet.Performance" version="1.0.5.8" targetFramework="net46" />
<package id="cdmdotnet.StateManagement" version="3.0.9.7" targetFramework="net46" />
<package id="cdmdotnet.StateManagement" version="3.0.13.9" targetFramework="net46" />
<package id="Microsoft.ApplicationInsights" version="2.2.0" targetFramework="net46" />
<package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.0.6" targetFramework="net46" />
<package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.2.0" targetFramework="net46" />
Expand Down
4 changes: 2 additions & 2 deletions Framework/Azure/Cqrs.Azure.WebJobs/Cqrs.Azure.WebJobs.csproj
Expand Up @@ -45,8 +45,8 @@
<HintPath>..\..\..\packages\cdmdotnet.Performance.1.0.5.8\lib\net40\cdmdotnet.Performance.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="cdmdotnet.StateManagement, Version=3.0.9.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\cdmdotnet.StateManagement.3.0.9.7\lib\net40\cdmdotnet.StateManagement.dll</HintPath>
<Reference Include="cdmdotnet.StateManagement, Version=3.0.13.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\cdmdotnet.StateManagement.3.0.13.9\lib\net40\cdmdotnet.StateManagement.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AI.Agent.Intercept, Version=2.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down
Expand Up @@ -5,15 +5,9 @@
</appSettings>

<appSettings>
<add key="Cqrs.Azure.WebJobs.PauseAndWaitMaximumCount" value="300" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.PauseAndWait" value="false" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.AppName" value="My CQRS WebJob" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.ApplicationInsightsInstrumentationKey" value="" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.EnabledApplicationInsightsDeveloperMode" value="false" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.DisableWebJobHostControl" value="true" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />

<add key="Cqrs.Azure.WebJobs.EnableEventReceiving" value="true" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.EnableCommandReceiving" value="true" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
</appSettings>

<connectionStrings xdt:Transform="InsertIfMissing">
Expand Down
Expand Up @@ -5,15 +5,9 @@
</appSettings>

<appSettings>
<add key="Cqrs.Azure.WebJobs.PauseAndWaitMaximumCount" value="300" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.PauseAndWait" value="false" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.AppName" value="My CQRS WebJob" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.ApplicationInsightsInstrumentationKey" value="" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.EnabledApplicationInsightsDeveloperMode" value="false" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.DisableWebJobHostControl" value="true" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />

<add key="Cqrs.Azure.WebJobs.EnableEventReceiving" value="true" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
<add key="Cqrs.Azure.WebJobs.EnableCommandReceiving" value="true" xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" />
</appSettings>

<connectionStrings xdt:Transform="InsertIfMissing">
Expand Down
2 changes: 1 addition & 1 deletion Framework/Azure/Cqrs.Azure.WebJobs/packages.config
Expand Up @@ -3,7 +3,7 @@
<package id="cdmdotnet.Logging" version="1.2.91.71" targetFramework="net45" />
<package id="cdmdotnet.Logging.Azure.ApplicationInsights" version="1.2.91.71" targetFramework="net46" />
<package id="cdmdotnet.Performance" version="1.0.5.8" targetFramework="net45" />
<package id="cdmdotnet.StateManagement" version="3.0.9.7" targetFramework="net45" />
<package id="cdmdotnet.StateManagement" version="3.0.13.9" targetFramework="net46" />
<package id="Microsoft.ApplicationInsights" version="2.2.0" targetFramework="net45" requireReinstallation="True" />
<package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.0.6" targetFramework="net45" />
<package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.2.0" targetFramework="net45" />
Expand Down
6 changes: 4 additions & 2 deletions Framework/Cqrs.WebApi/Controllers/ClientController.cs
Expand Up @@ -13,6 +13,7 @@
using System.Text;
using System.Web.Http;
using System.Web.Http.Description;
using Cqrs.Configuration;

namespace Cqrs.WebApi.Controllers
{
Expand All @@ -35,7 +36,7 @@ public virtual HttpResponseMessage Index()
metadata: {0},
useJson: true,
useXToken: true,
cookieTokenName: 'X-Token',
cookieTokenName: '{3}',
// This is because JQuery notes Global events are never fired for cross-domain script or JSONP requests, regardless of the value of global at https://api.jquery.com/category/ajax/global-ajax-event-handlers/
globalHandlers: {{
'before' : function(jqXHR, settings) {{}},
Expand Down Expand Up @@ -170,7 +171,8 @@ public virtual HttpResponseMessage Index()
}});",
System.Web.Helpers.Json.Encode(apiMethods),
host,
path);
path,
DependencyResolver.Current.Resolve<IConfigurationManager>().GetSetting("Cqrs.Web.AuthenticationTokenName") ?? "X-Token");

HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, responseBody);
response.Content = new StringContent(responseBody, Encoding.UTF8, "application/javascript");
Expand Down
27 changes: 16 additions & 11 deletions Framework/Cqrs.WebApi/CqrsApiController.cs
Expand Up @@ -17,43 +17,48 @@
using Cqrs.Authentication;
using Cqrs.Services;
using System.Net.Http.Formatting;
using System.Web.Http.Results;
using Cqrs.Configuration;

namespace Cqrs.WebApi
{
/// <summary>
/// A <see cref="ApiController"/> that expects the <see cref="ISingleSignOnToken.Token"/> to be sent as a <see cref="HttpHeaders"/> with a key of "X-Token", in accordance with OAuth specifications
/// A <see cref="ApiController"/> that expects the <see cref="ISingleSignOnToken.Token"/> to be sent as a <see cref="HttpHeaders"/> with a key whose name is defined by the <see cref="System.Configuration.ConfigurationManager.AppSettings"/> "Cqrs.Web.AuthenticationTokenName", in accordance with OAuth specifications
/// </summary>
/// <remarks>
/// See https://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/creating-api-help-pages for details on adding WebApi Help Pages.
/// </remarks>
public abstract class CqrsApiController
: ApiController
{
protected CqrsApiController(ILogger logger, ICorrelationIdHelper correlationIdHelper)
protected CqrsApiController(ILogger logger, ICorrelationIdHelper correlationIdHelper, IConfigurationManager configurationManager)
{
CorrelationIdHelper = correlationIdHelper;
ConfigurationManager = configurationManager;
Logger = logger;
}

protected ICorrelationIdHelper CorrelationIdHelper { get; private set; }

protected ILogger Logger { get; private set; }

protected IConfigurationManager ConfigurationManager { get; private set; }

protected virtual string GetToken()
{
string token = null;
string authenticationTokenName = ConfigurationManager.GetSetting("Cqrs.Web.AuthenticationTokenName") ?? "X-Token";

string xToken = null;
IEnumerable<string> tokenValue;
if (Request.Headers.TryGetValues("X-Token", out tokenValue))
token = tokenValue.First();
if (Request.Headers.TryGetValues(authenticationTokenName, out tokenValue))
xToken = tokenValue.First();
else
{
CookieHeaderValue cookie = Request.Headers.GetCookies("X-Token").FirstOrDefault();
CookieHeaderValue cookie = Request.Headers.GetCookies(authenticationTokenName).FirstOrDefault();
if (cookie != null)
token = cookie["X-Token"].Value;
xToken = cookie[authenticationTokenName].Value;
}

return token;
return xToken;
}

protected virtual IServiceRequest<TSingleSignOnToken> CreateRequest<TSingleSignOnToken>()
Expand Down Expand Up @@ -159,8 +164,8 @@ protected virtual HttpResponseMessage CompleteResponse<TServiceResponse>(TServic
public abstract class CqrsApiController<TAuthenticationToken>
: CqrsApiController
{
protected CqrsApiController(ILogger logger, ICorrelationIdHelper correlationIdHelper, IAuthenticationTokenHelper<TAuthenticationToken> authenticationTokenHelper)
: base(logger, correlationIdHelper)
protected CqrsApiController(ILogger logger, ICorrelationIdHelper correlationIdHelper, IConfigurationManager configurationManager, IAuthenticationTokenHelper<TAuthenticationToken> authenticationTokenHelper)
: base(logger, correlationIdHelper, configurationManager)
{
AuthenticationTokenHelper = authenticationTokenHelper;
}
Expand Down
5 changes: 3 additions & 2 deletions Framework/Cqrs.WebApi/CqrsEventApiController.cs
Expand Up @@ -10,6 +10,7 @@
using System.Collections.Generic;
using cdmdotnet.Logging;
using Cqrs.Authentication;
using Cqrs.Configuration;
using Cqrs.Events;
using Cqrs.Services;

Expand All @@ -23,8 +24,8 @@ public abstract class CqrsEventApiController<TSingleSignOnToken>
, IEventService<TSingleSignOnToken>
where TSingleSignOnToken : ISingleSignOnToken, new()
{
protected CqrsEventApiController(ILogger logger, ICorrelationIdHelper correlationIdHelper, IAuthenticationTokenHelper<TSingleSignOnToken> authenticationTokenHelper, IEventStore<TSingleSignOnToken> eventStore)
: base(logger, correlationIdHelper)
protected CqrsEventApiController(ILogger logger, ICorrelationIdHelper correlationIdHelper, IAuthenticationTokenHelper<TSingleSignOnToken> authenticationTokenHelper, IEventStore<TSingleSignOnToken> eventStore, IConfigurationManager configurationManager)
: base(logger, correlationIdHelper, configurationManager)
{
AuthenticationTokenHelper = authenticationTokenHelper;
EventStore = eventStore;
Expand Down
13 changes: 10 additions & 3 deletions Framework/Cqrs.WebApi/CqrsHttpApplicationWithSignalR.cs
Expand Up @@ -29,14 +29,17 @@ public abstract class CqrsHttpApplicationWithSignalR<TAuthenticationToken, TEven
{
protected override void Application_Start(object sender, EventArgs e)
{
ConfigureDefaultDependencyResolver();
SetBuses();

RegisterDefaultRoutes();

ConfigureMvcOrWebApi();

BusRegistrar registrar = RegisterCommandAndEventHandlers();
RegisterSignalR(registrar);

StartBuses();

LogApplicationStarted();
}

Expand Down Expand Up @@ -72,16 +75,20 @@ protected virtual void ConfigureMvcOrWebApi()
public abstract class CqrsHttpApplicationWithSignalR<TAuthenticationToken>
: CqrsHttpApplicationWithSignalR<TAuthenticationToken, GlobalEventToHubProxy<TAuthenticationToken>>
{
#region Overrides of CqrsHttpApplicationWithSignalR<TAuthenticationToken, TEventToHubProxy>

/// <summary>
/// Register SignalR and auto wire-up <see cref="GlobalEventToHubProxy{TAuthenticationToken}"/> to automatically proxy all <see cref="IEvent{TAuthenticationToken}">events</see> to SignalR.
/// </summary>
protected override void RegisterSignalR(BusRegistrar registrar)
{
base.RegisterSignalR(registrar);

var eventHandlerRegistrar = DependencyResolver.Resolve<IEventHandlerRegistrar>();
var proxy = DependencyResolver.Resolve<GlobalEventToHubProxy<TAuthenticationToken>>();
var eventHandlerRegistrar = DependencyResolver.Current.Resolve<IEventHandlerRegistrar>();
var proxy = DependencyResolver.Current.Resolve<GlobalEventToHubProxy<TAuthenticationToken>>();
eventHandlerRegistrar.RegisterGlobalEventHandler<IEvent<TAuthenticationToken>>(proxy.Handle, false);
}

#endregion
}
}
8 changes: 6 additions & 2 deletions Framework/Cqrs.WebApi/SignalR/Hubs/NotificationHub.cs
Expand Up @@ -12,6 +12,7 @@
using System.Threading;
using System.Threading.Tasks;
using cdmdotnet.Logging;
using Cqrs.Configuration;
using Cqrs.Events;
using Microsoft.AspNet.SignalR;

Expand Down Expand Up @@ -62,10 +63,13 @@ protected virtual string UserToken()
{
string userRsn;
Cookie cookie;
if (Context.RequestCookies.TryGetValue("X-Token", out cookie))

string authenticationTokenName = DependencyResolver.Current.Resolve<IConfigurationManager>().GetSetting("Cqrs.Web.AuthenticationTokenName") ?? "X-Token";

if (Context.RequestCookies.TryGetValue(authenticationTokenName, out cookie))
userRsn = cookie.Value;
else
userRsn = Context.QueryString["X-Token"];
userRsn = Context.QueryString[authenticationTokenName];

return userRsn.Replace(".", string.Empty);
}
Expand Down
2 changes: 0 additions & 2 deletions Framework/Cqrs/Hosts/CoreHost.cs
Expand Up @@ -68,7 +68,6 @@ protected CoreHost()
bool pauseAndWait;
long waitCounter = 0;
long maximumCount;
// I set this to true ... just because.
if (!long.TryParse(ConfigurationManager.GetSetting("Cqrs.Hosts.PauseAndWaitMaximumCount"), out maximumCount))
maximumCount = 300;
SpinWait.SpinUntil
Expand All @@ -83,7 +82,6 @@ protected CoreHost()
(short)1000
);

// I set this to true ... just because.
TelemetryName = ConfigurationManager.GetSetting("Cqrs.Hosts.AppName") ?? AppDomain.CurrentDomain.FriendlyName;
}
// ReSharper restore DoNotCallOverridableMethodsInConstructor
Expand Down

0 comments on commit 7c42ba4

Please sign in to comment.