/// <summary> /// Sets the context. /// </summary> /// <param name="context">The context.</param> public override void SetContext(IEngineContext context) { base.SetContext(context); urlBuilder = (IUrlBuilder)context.GetService(typeof(IUrlBuilder)); currentUrl = context.UrlInfo; }
/// <summary> /// Sets the context. /// </summary> /// <param name="context">The context.</param> public override void SetContext(IEngineContext context) { base.SetContext(context); urlBuilder = (IUrlBuilder) context.GetService(typeof(IUrlBuilder)); currentUrl = context.UrlInfo; }
public void RenderComponent( string name, IDictionary parameters, Action body, IDictionary <string, Action> sections) { var service = (IViewComponentFactory)_context.GetService(typeof(IViewComponentFactory)); var component = service.Create(name); IViewComponentContext viewComponentContext = new ViewComponentContext(this, _viewEngine, parameters, body, sections); var oldContextVars = _contextVars; try { _contextVars = viewComponentContext.ContextVars; component.Init(_context, viewComponentContext); component.Render(); } finally { _contextVars = oldContextVars; } foreach (string key in viewComponentContext.ContextVars.Keys) { if (key.EndsWith(".@bubbleUp")) { string key2 = key.Substring(0, key.Length - ".@bubbleUp".Length); PropertyBag[key2] = viewComponentContext.ContextVars[key2]; } } }
/// <summary> /// Implementors should perform the action /// on the exception. Note that the exception /// is available in <see cref="IEngineContext.LastException"/> /// </summary> /// <param name="context"></param> public override void Process(IEngineContext context) { IEmailSender emailSender = (IEmailSender) context.GetService(typeof(IEmailSender)); String message = BuildStandardMessage(context); try { emailSender.Send(mailFrom, mailTo, "MonoRail Exception: " + context.LastException.GetType().Name, message); } catch(Exception) { // We ignore errors during send } InvokeNext(context); }
/// <summary> /// Implementors should perform the action /// on the exception. Note that the exception /// is available in <see cref="IEngineContext.LastException"/> /// </summary> /// <param name="context"></param> public override void Process(IEngineContext context) { var emailSender = (IEmailSender)context.GetService(typeof(IEmailSender)); var message = BuildStandardMessage(context); try { emailSender.Send(mailFrom, mailTo, "MonoRail Exception: " + context.LastException.GetType().Name, message); } catch (Exception) { // We ignore errors during send } InvokeNext(context); }
/// <summary> /// Implementors should perform the action /// on the exception. Note that the exception /// is available in <see cref="IEngineContext.LastException"/> /// </summary> /// <param name="context"></param> public override void Process(IEngineContext context) { ILoggerFactory factory = (ILoggerFactory) context.GetService(typeof(ILoggerFactory)); if (factory == null) { // No factory configured, but we can throw exception return; } if (context.CurrentController != null) { ILogger logger = factory.Create(context.CurrentController.GetType()); logger.Error(BuildStandardMessage(context)); } InvokeNext(context); }
/// <summary> /// Implementors should perform the action /// on the exception. Note that the exception /// is available in <see cref="IEngineContext.LastException"/> /// </summary> /// <param name="context"></param> public override void Process(IEngineContext context) { var factory = (ILoggerFactory)context.GetService(typeof(ILoggerFactory)); if (factory == null) { // No factory configured, but we can throw exception return; } if (context.CurrentController != null) { var logger = factory.Create(context.CurrentController.GetType()); logger.Error(BuildStandardMessage(context)); } InvokeNext(context); }
public void Init() { mocks = new MockRepository(); factory = new SparkViewFactory(); engineContext = mocks.CreateMock <IEngineContext>(); server = new MockServerUtility(); request = mocks.CreateMock <IRequest>(); response = mocks.CreateMock <IResponse>(); controller = mocks.CreateMock <IController>(); controllerContext = mocks.CreateMock <IControllerContext>(); routingEngine = mocks.CreateMock <IRoutingEngine>(); output = new StringWriter(); helpers = new HelperDictionary(); propertyBag = new Dictionary <string, object>(); flash = new Flash(); session = new Dictionary <string, object>(); requestParams = new NameValueCollection(); contextItems = new Dictionary <string, object>(); SetupResult.For(engineContext.Server).Return(server); SetupResult.For(engineContext.Request).Return(request); SetupResult.For(engineContext.Response).Return(response); SetupResult.For(engineContext.CurrentController).Return(controller); SetupResult.For(engineContext.CurrentControllerContext).Return(controllerContext); SetupResult.For(engineContext.Flash).Return(flash); SetupResult.For(engineContext.Session).Return(session); SetupResult.For(engineContext.Items).Return(contextItems); SetupResult.For(request.Params).Return(requestParams); SetupResult.For(controllerContext.LayoutNames).Return(new[] { "default" }); SetupResult.For(controllerContext.Helpers).Return(helpers); SetupResult.For(controllerContext.PropertyBag).Return(propertyBag); SetupResult.For(routingEngine.IsEmpty).Return(true); var urlBuilder = new DefaultUrlBuilder(server, routingEngine); var serviceProvider = mocks.CreateMock <IServiceProvider>(); var viewSourceLoader = new FileAssemblyViewSourceLoader("Views"); SetupResult.For(serviceProvider.GetService(typeof(IViewSourceLoader))).Return(viewSourceLoader); SetupResult.For(serviceProvider.GetService(typeof(ILoggerFactory))).Return(new NullLogFactory()); SetupResult.For(serviceProvider.GetService(typeof(ISparkViewEngine))).Return(null); SetupResult.For(serviceProvider.GetService(typeof(IUrlBuilder))).Return(urlBuilder); SetupResult.For(serviceProvider.GetService(typeof(IViewComponentFactory))).Return(null); mocks.Replay(serviceProvider); SetupResult.For(engineContext.GetService(null)).IgnoreArguments().Do( new Func <Type, object>(serviceProvider.GetService)); factory.Service(serviceProvider); manager = new DefaultViewEngineManager(); manager.RegisterEngineForExtesionLookup(factory); manager.RegisterEngineForView(factory); }
public void Init() { mocks = new MockRepository(); factory = new SparkViewFactory(); engineContext = mocks.CreateMock<IEngineContext>(); server = new MockServerUtility(); request = mocks.CreateMock<IRequest>(); response = mocks.CreateMock<IResponse>(); controller = mocks.CreateMock<IController>(); controllerContext = mocks.CreateMock<IControllerContext>(); routingEngine = mocks.CreateMock<IRoutingEngine>(); output = new StringWriter(); helpers = new HelperDictionary(); propertyBag = new Dictionary<string, object>(); flash = new Flash(); session = new Dictionary<string, object>(); requestParams = new NameValueCollection(); contextItems = new Dictionary<string, object>(); SetupResult.For(engineContext.Server).Return(server); SetupResult.For(engineContext.Request).Return(request); SetupResult.For(engineContext.Response).Return(response); SetupResult.For(engineContext.CurrentController).Return(controller); SetupResult.For(engineContext.CurrentControllerContext).Return(controllerContext); SetupResult.For(engineContext.Flash).Return(flash); SetupResult.For(engineContext.Session).Return(session); SetupResult.For(engineContext.Items).Return(contextItems); SetupResult.For(request.Params).Return(requestParams); SetupResult.For(controllerContext.LayoutNames).Return(new[] { "default" }); SetupResult.For(controllerContext.Helpers).Return(helpers); SetupResult.For(controllerContext.PropertyBag).Return(propertyBag); SetupResult.For(routingEngine.IsEmpty).Return(true); var urlBuilder = new DefaultUrlBuilder(server, routingEngine); var serviceProvider = mocks.CreateMock<IServiceProvider>(); var viewSourceLoader = new FileAssemblyViewSourceLoader("Views"); SetupResult.For(serviceProvider.GetService(typeof(IViewSourceLoader))).Return(viewSourceLoader); SetupResult.For(serviceProvider.GetService(typeof(ILoggerFactory))).Return(new NullLogFactory()); SetupResult.For(serviceProvider.GetService(typeof(ISparkViewEngine))).Return(null); SetupResult.For(serviceProvider.GetService(typeof(IUrlBuilder))).Return(urlBuilder); SetupResult.For(serviceProvider.GetService(typeof(IViewComponentFactory))).Return(null); mocks.Replay(serviceProvider); SetupResult.For(engineContext.GetService(null)).IgnoreArguments().Do( new Func<Type, object>(serviceProvider.GetService)); factory.Service(serviceProvider); manager = new DefaultViewEngineManager(); manager.RegisterEngineForExtesionLookup(factory); manager.RegisterEngineForView(factory); }
public static ILogger GetLogger(this IEngineContext context) { return(context.GetService(typeof(ILogger)) as ILogger ?? NullLogger.Instance); }