protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var pinkoContainer = PinkoWebRoleContainerManager.Container; // Register pinko services // Setup Web Role _webRoleConnectManager = pinkoContainer .Resolve<IWebRoleConnectManager>() .InitializeWebRole(); // This service will be dealing with this message type pinkoContainer.Resolve<IIncominBusMessageHandlerManager>().AddBusTypeHandler<PinkoMsgCalculateExpression>(); // Register service controllers for this web service PinkoWebRoleContainerManager.Container.RegisterType<PinkoFormProcessorSubscriberController>(); PinkoWebRoleContainerManager.Container.RegisterType<PinkoFormProcessorController>(); PinkoWebRoleContainerManager.Container.RegisterType<PinkoDictionaryController>(); PinkoWebRoleContainerManager.Container.RegisterType<PinkoClientPingController>(); }
///// <summary> ///// Register all realtime message handlers to be routed via SiganlR to web clients ///// </summary> //public void RegisterRealTimeMessageHandlers() //{ // var pinkoSingalHubContext = GlobalHost.ConnectionManager.GetHubContext<PinkoSingalHub>(); // PinkoContainer = PinkoWebRoleContainerManager.Container; // var pinkoApplication = PinkoContainer.Resolve<IPinkoApplication>(); // Trace.TraceInformation("Registering message handlers: {0}", GetType()); // // route incoming heartbeat to all clients // pinkoApplication // .GetSubscriber<Tuple<IBusMessageInbound, PinkoRoleHeartbeat>>() // .Do(x => Trace.TraceInformation("WebRole Received: {0}: {1} - {2}", GetType(), x.Item1.Verbose(), x.Item2.ToString())) // .Subscribe(x => pinkoSingalHubContext.Clients.notifyClientPinkoRoleHeartbeat(x.Item1.PinkoProperties[PinkoMessagePropTag.MachineName], // x.Item1.PinkoProperties[PinkoMessagePropTag.DateTimeStamp])); //} /// <summary> /// Web Role Start /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Application_Start(object sender, EventArgs e) { Trace.TraceInformation("Starting Web Role: {0}", GetHashCode()); //// Streaming SignalR //RouteTable.Routes.MapConnection<PinkoSignalRConnection>("echo", "echo/{*operation}"); //// Setup Web Role //PinkoContainer = PinkoWebRoleContainerManager.Container; //var webRoleConnectManager = PinkoContainer.Resolve<IWebRoleConnectManager>(); //webRoleConnectManager.RegisterRealTimeMessageHandlers(); //webRoleConnectManager.StartmockHearbeat(); // Register pinko services // Setup Web Role _webRoleConnectManager = PinkoWebRoleContainerManager .Container .Resolve<IWebRoleConnectManager>() .InitializeWebRole(); //// TODO: Temporary //// timer //_webRoleHearBeat = Observable.Interval(TimeSpan.FromMilliseconds(1000), Scheduler.ThreadPool); //// Set listener for outbound messages //var pinkoApplication = PinkoContainer.Resolve<IPinkoApplication>(); //var incomingTopic = // pinkoApplication // .GetBus<IBusMessageOutbound>(); //_webRoleHearBeat // .Subscribe(x => incomingTopic.Publish(pinkoApplication.FactorWebEnvelop(string.Empty, _pinkoWebRoleManager.WebRoleId, new PinkoRoleHeartbeat()))); //_webRoleHearBeat // .Subscribe(x => // { // // // // https://github.com/SignalR/SignalR/tree/master/samples/SignalR.Hosting.AspNet.Samples // // // // // // https://github.com/SignalR/SignalR/wiki/SignalR-JS-Client-Hubs - Server to client // // // // // // http://stackoverflow.com/questions/7549179/signalr-posting-a-message-to-a-hub-via-an-action-method // // // ////var context = GlobalHost.ConnectionManager.GetHubContext<PinkoSingalHub>(); // var beat = new PinkoRoleHeartbeatHubDao // { // ResponderDateTime = DateTime.Now, // ResponderMachine = machineName // }; // //pinkoSingalHubContext.Clients.addMessage(beat); // //context.Clients.NotifyClientPinkoRoleHeartbeat("beat"); // //context.Connection.Broadcast(DateTime.Now.ToString()); // Debug.WriteLine(string.Format("Sending hearbeat to cleints: {0}", beat.Verbose())); // pinkoSingalHubContext.Clients.notifyClientPinkoRoleHeartbeat(beat.ResponderDateTime, beat.ResponderMachine); // }); //var IMessageHandlerManager ////Trace.Listeners.Add() //// timer //_webRoleHearBeat = Observable.Interval(TimeSpan.FromMilliseconds(1000), Scheduler.ThreadPool); ////var context = GlobalHost.ConnectionManager.GetHubContext<PinkoSingalHub>(); ////var context = GlobalHost.ConnectionManager.GetConnectionContext<Str>(); //var pinkoSingalHubContext = GlobalHost.ConnectionManager.GetHubContext<PinkoSingalHub>(); //_webRoleHearBeat // .Subscribe(x => // { // // // // https://github.com/SignalR/SignalR/tree/master/samples/SignalR.Hosting.AspNet.Samples // // // // // // https://github.com/SignalR/SignalR/wiki/SignalR-JS-Client-Hubs - Server to client // // // // // // http://stackoverflow.com/questions/7549179/signalr-posting-a-message-to-a-hub-via-an-action-method // // // ////var context = GlobalHost.ConnectionManager.GetHubContext<PinkoSingalHub>(); // var beat = new PinkoRoleHeartbeatHub // { // ResponderDateTime = DateTime.Now, // ResponderMachine = machineName // }; // //pinkoSingalHubContext.Clients.addMessage(beat); // //context.Clients.NotifyClientPinkoRoleHeartbeat("beat"); // //context.Connection.Broadcast(DateTime.Now.ToString()); // Debug.WriteLine(string.Format("Sending hearbeat to cleints: {0}", beat.Verbose())); // pinkoSingalHubContext.Clients.notifyClientPinkoRoleHeartbeat(beat.ResponderDateTime, beat.ResponderMachine); // //var clients = Hub.GetClients<NewsFeedHub>(); // //clients.MethodOnTheJavascript("Good news!"); //dynamic method called on the client // //context.Clients.addMessage(beat); // //context.Clients[group].methodInJavascript("hello world"); // ////var clients = Hub.GetClients<NewsFeedHub>(); // ////clients.MethodOnTheJavascript("Good news!"); //dynamic method called on the client // //// Important: .Resolve is an extension method inside SignalR.Infrastructure namespace. // //this. // //var connectionManager = AspNetHost.DependencyResolver.Resolve<IConnectionManager>(); // //var clients = connectionManager.GetClients<MyHub>(); // //// Broadcast to all clients. // //clients.MethodOnTheJavascript("Good news!"); // //// Broadcast only to clients in a group. // //clients["someGroupName"].MethodOnTheJavascript("Hello, some group!"); // //// Broadcast only to a particular client. // //clients["someConnectionId"].MethodOnTheJavascript("Hello, particular client!"); // // // // http://stackoverflow.com/questions/9942591/iis-background-thread-and-signalr // // // //var connectionManager = RouteTable.Routes[] // //var demoClients = connectionManager.GetClients<MyHubDerivedClass>(); // //demoClients.TellUsers(msg); // //var connectionManager = AspNetHost.DependencyResolver.Resolve<IConnectionManager>(); // //var demoClients = connectionManager.GetClients<MyHubDerivedClass>(); // //demoClients.TellUsers(msg); // //var hub = new PinkoSingalHub(); // //hub.NotifyClientPinkoRoleHeartbeat( // // new PinkoRoleHeartbeat // // { // // ResponderDateTime = DateTime.Now, // // ResponderMachine = "MachineName" // // }); // }); //protected void Application_Start(object sender, EventArgs e) //{ // ThreadPool.QueueUserWorkItem(_ => // { // var context = GlobalHost.ConnectionManager.GetConnectionContext<Streaming>(); // var hubContext = GlobalHost.ConnectionManager.GetHubContext<DemoHub>(); // while (true) // { // try // { // context.Connection.Broadcast(DateTime.Now.ToString()); // hubContext.Clients.fromArbitraryCode(DateTime.Now.ToString()); // } // catch (Exception ex) // { // Trace.TraceError("SignalR error thrown in Streaming broadcast: {0}", ex); // } // Thread.Sleep(2000); // } // }); // RouteTable.Routes.MapConnection<SendingConnection>("sending-connection", "sending-connection/{*operation}"); // RouteTable.Routes.MapConnection<TestConnection>("test-connection", "test-connection/{*operation}"); // RouteTable.Routes.MapConnection<Raw>("raw", "raw/{*operation}"); // RouteTable.Routes.MapConnection<Streaming>("streaming", "streaming/{*operation}"); }