Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="cdmdotnet Limited">
4 : // // Copyright cdmdotnet Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System.Web.Http;
10 : using Cqrs.Configuration;
11 : using Microsoft.AspNet.SignalR;
12 : using Microsoft.Owin;
13 : using Microsoft.Owin.Cors;
14 : using Newtonsoft.Json;
15 : using Owin;
16 :
17 : [assembly: OwinStartup("Cqrs.WebApi.SignalR.Hubs.SignalRStartUp", typeof(Cqrs.WebApi.SignalR.Hubs.SignalRStartUp))]
18 : namespace Cqrs.WebApi.SignalR.Hubs
19 : {
20 : public class SignalRStartUp
21 0 : {
22 0 : public virtual void Configuration(IAppBuilder app)
23 : {
24 : string url;
25 : if (!new ConfigurationManager().TryGetSetting("Cqrs.WebApi.SignalR.EndpointPath", out url) || string.IsNullOrWhiteSpace(url))
26 : url = "/signalr";
27 : // Branch the pipeline here for requests that start with "/signalr"
28 : app.Map(url, map =>
29 : {
30 : // Setup the CORS middleware to run before SignalR.
31 : // By default this will allow all origins. You can
32 : // configure the set of origins and/or http verbs by
33 : // providing a cors options with a different policy.
34 : map.UseCors(CorsOptions.AllowAll);
35 : var hubConfiguration = new HubConfiguration
36 : {
37 : // You can enable JSONP by un-commenting line below.
38 : // JSONP requests are insecure but some older browsers (and some
39 : // versions of IE) require JSONP to work cross domain
40 : // EnableJSONP = true
41 : EnableDetailedErrors = true,
42 : // Resolver = new SignalRResolver()
43 : };
44 : // Run the SignalR pipeline. We're not using MapSignalR
45 : // since this branch already runs under the "/signalr"
46 : // path.
47 : map.RunSignalR(hubConfiguration);
48 : });
49 :
50 : JsonSerializer serializer = JsonSerializer.Create(GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings);
51 : GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), () => serializer);
52 : }
53 : }
54 : }
|