public Controller CreateController(UrlInfo urlInfo) { IWindsorContainer container = ContainerAccessorUtil.ObtainContainer(); ControllerTree tree = null; try { tree = (ControllerTree)container["rails.controllertree"]; } catch (ComponentNotFoundException) { throw new RailsException("ControllerTree not found. Check whether RailsFacility is properly configured/registered"); } String key = (String)tree.GetController(urlInfo.Area, urlInfo.Controller); if (key == null || key.Length == 0) { throw new ControllerNotFoundException(urlInfo); } if (container.Kernel.HasComponent(key)) { return((Controller)container[key]); } return(null); }
/// <summary> /// Unsubscribes the specified <paramref name="handler"/> from the controller with the specified <paramref name="controllerId"/>. /// The handler won't get executed on a change of the controller. /// </summary> /// <param name="controllerId">The id of the controller to not anymore observe.</param> /// <param name="handler">The handler to unsubscribe.</param> public void UnsubsribeFromControllerChanges(int controllerId, Action <IController> handler) { IController controller = ControllerTree.GetController(controllerId); foreach (Tag controllerTag in controller.GetAllAssociatedTags()) { controllerTag.ValueChanged -= NotifySubscribers; SlowTagListener.RemoveTag(controllerTag); } lock (_lockSubscribers) { _subscribers.RemoveAll(t => Equals(t.Item2, handler)); } }
/// <summary> /// Subscribes the specified <paramref name="handler"/> on the controller with the specified <paramref name="controllerId"/>. /// The handler gets executed whenever the controller changed a value. /// </summary> /// <param name="controllerId">The id of the controller to observe.</param> /// <param name="handler">The handler to get executed on a controller change.</param> public void SubscribeForControllerChanges(int controllerId, Action <IController> handler) { IController controller = ControllerTree.GetController(controllerId); lock (_lockSubscribers) { _subscribers.Add(new Tuple <int, Action <IController> >(controllerId, handler)); } foreach (Tag controllerTag in controller.GetAllAssociatedTags()) { SlowTagListener.AddTag(controllerTag); controllerTag.ValueChanged += NotifySubscribers; } SlowTagListener.RefreshAll(); }