public virtual void Init() { mocks = new MockRepository(); var services = new StubMonoRailServices(); services.ViewSourceLoader = new FileAssemblyViewSourceLoader("MonoRail.Tests.Views"); services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader); viewComponentFactory = new DefaultViewComponentFactory(); viewComponentFactory.Initialize(); services.AddService(typeof(IViewComponentFactory), viewComponentFactory); services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry); var settings = new SparkSettings(); engine = new SparkViewEngine(settings); services.AddService(typeof(ISparkViewEngine), engine); factory = new SparkViewFactory(); factory.Service(services); controller = MockRepository.GenerateMock<IController>(); controllerContext = new ControllerContext(); var request = new StubRequest(); request.FilePath = ""; var response = new StubResponse(); engineContext = new StubEngineContext(request, response, new UrlInfo("", "Home", "Index", "/", "castle")); engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory); engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry); }
public void PdfResultShouldWriteToOutputStream() { var settings = new SparkSettings(); var viewFolder = new InMemoryViewFolder { { "foo/bar.spark", HelloWorldXml } }; var factory = new SparkViewFactory(settings) { ViewFolder = viewFolder }; var stream = new MemoryStream(); var controllerContext = GetControllerContext(stream); var result = new PdfViewResult { ViewEngineCollection = new ViewEngineCollection(new[] { factory }) }; result.ExecuteResult(controllerContext); Assert.That(stream.Length, Is.Not.EqualTo(0)); }
public void Init() { mocks = new MockRepository(); MockServices services = new MockServices(); services.ViewSourceLoader = new FileAssemblyViewSourceLoader("Views"); services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader); viewComponentFactory = new DefaultViewComponentFactory(); viewComponentFactory.Initialize(); services.AddService(typeof(IViewComponentFactory), viewComponentFactory); services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry); controller = mocks.DynamicMock<IController>(); engineContext = new MockEngineContext(new UrlInfo("", "Home", "Index", "/", "castle")); controllerContext = new ControllerContext(); factory = new SparkViewFactory(); factory.Service(services); engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory); engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry); manager = new DefaultViewEngineManager(); manager.RegisterEngineForExtesionLookup(factory); manager.RegisterEngineForView(factory); }
public virtual void Init() { mocks = new MockRepository(); var services = new StubMonoRailServices(); services.ViewSourceLoader = new FileAssemblyViewSourceLoader("MonoRail.Tests.Views"); services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader); viewComponentFactory = new DefaultViewComponentFactory(); viewComponentFactory.Initialize(); services.AddService(typeof(IViewComponentFactory), viewComponentFactory); services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry); var settings = new SparkSettings(); engine = new SparkViewEngine(settings); services.AddService(typeof(ISparkViewEngine), engine); factory = new SparkViewFactory(); factory.Service(services); controller = MockRepository.GenerateMock <IController>(); controllerContext = new ControllerContext(); var request = new StubRequest(); request.FilePath = ""; var response = new StubResponse(); engineContext = new StubEngineContext(request, response, new UrlInfo("", "Home", "Index", "/", "castle")); engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory); engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry); }
protected void AddViewFolder(string virtualFolderRoot) { _sparkViewFactory = ObjectFactory.Container.GetInstance<SparkViewFactory>(); ((SparkSettings)_sparkViewFactory.Settings) .AddViewFolder(ViewFolderType.VirtualPathProvider, new Dictionary<string, string> { { "virtualBaseDir", virtualFolderRoot } }); }
private static void PrecompileViews(SparkViewFactory viewFactory) { var batch = new SparkBatchDescriptor(); batch.For <HomeController>().For <ManageController>(); viewFactory.Precompile(batch); }
public void Init() { mocks = new MockRepository(); MockServices services = new MockServices(); services.ViewSourceLoader = new FileAssemblyViewSourceLoader("Views"); services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader); viewComponentFactory = new DefaultViewComponentFactory(); viewComponentFactory.Initialize(); services.AddService(typeof(IViewComponentFactory), viewComponentFactory); services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry); controller = mocks.DynamicMock <IController>(); engineContext = new MockEngineContext(new UrlInfo("", "Home", "Index", "/", "castle")); controllerContext = new ControllerContext(); factory = new SparkViewFactory(); factory.Service(services); engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory); engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry); 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 SparkViewFacility(SparkViewFactory viewFactory, Func<Type, bool> sparkActionEndPointConventionFilter, Func<string, string> getActionNameFromCallConvention) { _viewFactory = viewFactory; _sparkActionEndPointConventionFilter = sparkActionEndPointConventionFilter; _getActionNameFromCallConvention = getActionNameFromCallConvention; }
public SparkViewFacility(SparkViewFactory viewFactory, Func<Type, bool> actionEndPointFilter, Func<Type, string> getViewLocatorNameFromActionType) { _viewFactory = viewFactory; _actionEndPointFilter = actionEndPointFilter; _getViewLocatorNameFromActionType = getViewLocatorNameFromActionType; }
public override void Install(IDictionary stateSaver) { // figure out all paths based on this assembly in the bin dir var assemblyPath = Parent.GetType().Assembly.Location; var targetPath = Path.ChangeExtension(assemblyPath, ".Views.dll"); var webSitePath = Path.GetDirectoryName(Path.GetDirectoryName(assemblyPath)); var webBinPath = Path.Combine(webSitePath, "bin"); var webFileHack = Path.Combine(webSitePath, "web"); var viewsLocation = Path.Combine(webSitePath, "Views"); if (!string.IsNullOrEmpty(TargetAssemblyFile)) { targetPath = Path.Combine(webBinPath, TargetAssemblyFile); } ISparkSettings settings; if (SettingsInstantiator != null) { settings = SettingsInstantiator(); } else { // this hack enables you to open the web.config as if it was an .exe.config File.Create(webFileHack).Close(); var config = ConfigurationManager.OpenExeConfiguration(webFileHack); File.Delete(webFileHack); // GetSection will try to resolve the "Spark" assembly, which the installutil appdomain needs help finding AppDomain.CurrentDomain.AssemblyResolve += ((sender, e) => Assembly.LoadFile(Path.Combine(webBinPath, e.Name + ".dll"))); settings = (ISparkSettings)config.GetSection("spark"); } // Finally create an engine with the <spark> settings from the web.config var factory = new SparkViewFactory(settings) { ViewFolder = new FileSystemViewFolder(viewsLocation) }; // And generate all of the known view/master templates into the target assembly var batch = new SparkBatchDescriptor(targetPath); // create entries for controller attributes in the parent installer's assembly batch.FromAssembly(Parent.GetType().Assembly); // and give the containing installer a change to add entries if (DescribeBatch != null) { DescribeBatch(this, new DescribeBatchEventArgs { Batch = batch }); } factory.Precompile(batch); base.Install(stateSaver); }
void IMonoRailContainerEvents.Initialized(IMonoRailContainer container) { Assembly precompiled = Assembly.Load("PrecompiledViews.Views"); var factory = new SparkViewFactory(); factory.Service(container); factory.Engine.LoadBatchCompilation(precompiled); }
public void Init() { var settings = new SparkSettings(); _factory = new SparkViewFactory(settings) { ViewFolder = new FileSystemViewFolder("AspNetMvc.Tests.Views") }; }
/// <summary> /// Gets the view engine from a precompiled view file with the same name as the assembly of the tenant type is "Views" appended /// </summary> /// <returns>View engine for the application tenant</returns> protected virtual IViewEngine DetermineViewEngine() { var factory = new SparkViewFactory(); var file = GetType().Assembly.CodeBase.Without("file:///").Replace(".dll", ".Views.dll").Replace('/', '\\'); var assembly = Assembly.LoadFile(file); factory.Engine.LoadBatchCompilation(assembly); return(factory); }
public void SetUp() { var settings = new SparkSettings(); _factory = new SparkViewFactory(settings) { ViewFolder = new FileSystemViewFolder("FubuMVC.Tests.Views") }; }
public void Init() { _factory = new SparkViewFactory(null); _viewFolder = new InMemoryViewFolder(); _factory.ViewFolder = _viewFolder; var controller = new StubController(); _actionContext = new ActionContext(controller.GetType().Namespace, "Bar"); }
public static void RegisterViewEngine(ICollection <IViewEngine> engines) { var engine = new SparkViewFactory(); engine.AddSharedPath("~/ExtraCommon"); engine.AddLayoutsPath("~/Masters"); engine.AddEmbeddedResources(Assembly.Load("AdditionalViewResources"), "AdditionalViewResources.MoreViews"); engines.Add(engine); }
public MigrationSampleRegistry(bool debuggingEnabled, string controllerAssembly, SparkViewFactory viewFactory) : base(debuggingEnabled, controllerAssembly) { _viewFactory = viewFactory; //HomeIs<HomeController>(c => c.List(new ListInputModel() { Page = 1 })); Output.To(call => new JavaScriptOutputNode(GetJavaScriptViewToken(call), call)) .WhenTheOutputModelIs <JavaScriptResponse>(); }
public SparkDefaultStructureMapRegistry(bool debuggingEnabled, string controllerAssembly) { _sparkViewFactory = ObjectFactory.Container.GetInstance<SparkViewFactory>(); IncludeDiagnostics(debuggingEnabled); Applies.ToAssembly(controllerAssembly); Routes.IgnoreControllerNamespaceEntirely(); }
public void Init() { // reset routes RouteTable.Routes.Clear(); RouteTable.Routes.Add(new Route("{controller}/{action}/{id}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { action = "Index", id = "" }) }); httpContext = MockHttpContextBase.Generate("/", new StringWriter()); //_requestBase = MockRepository.GenerateStub<HttpRequestBase>(); //_responseBase = MockRepository.GenerateStub<HttpResponseBase>(); //_sessionStateBase = MockRepository.GenerateStub<HttpSessionStateBase>(); //_serverUtilityBase = MockRepository.GenerateStub<HttpServerUtilityBase>(); //httpContext.Stub(x => x.Request).Return(_requestBase); //httpContext.Stub(x => x.Response).Return(_responseBase); //httpContext.Stub(x => x.Session).Return(_sessionStateBase); //httpContext.Stub(x => x.Server).Return(_serverUtilityBase); //_responseBase.Stub(x => x.OutputStream).Return(new MemoryStream()); //_responseBase.Stub(x => x.Output).Return(new StringWriter()); //_requestBase.Stub(x => x.ApplicationPath).Return("/"); //_requestBase.Stub(x => x.Path).Return("/"); //_responseBase.Stub(x => x.ApplyAppPathModifier(null)) // .IgnoreArguments() // .Do(new Func<string, string>(path => path)); response = httpContext.Response; output = response.Output; controller = MockRepository.GenerateStub <ControllerBase>(); routeData = new RouteData(); routeData.Values.Add("controller", "Home"); routeData.Values.Add("action", "Index"); controllerContext = new ControllerContext(httpContext, routeData, controller); var settings = new SparkSettings().AddNamespace("System.Web.Mvc.Html").SetAutomaticEncoding(true); factory = new SparkViewFactory(settings) { ViewFolder = new FileSystemViewFolder("AspNetMvc.Tests.Views") }; ControllerBuilder.Current.SetControllerFactory(new DefaultControllerFactory()); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(factory); }
public virtual string CompileView(string view) { var viewFactory = new SparkViewFactory(); var descriptor = new SparkViewDescriptor {Language = LanguageType.Javascript}; descriptor.AddTemplate(string.Format("{0}{1}{2}", ControllerContext.ViewFolder, Path.DirectorySeparatorChar, view)); ((IViewSourceLoaderContainer)viewFactory).ViewSourceLoader = Context.Services.ViewSourceLoader; var entry = viewFactory.Engine.CreateEntry(descriptor); return entry.SourceCode; }
public void Init() { var settings = new SparkSettings(); var services = new StubMonoRailServices(); services.AddService(typeof(IViewSourceLoader), new FileAssemblyViewSourceLoader("MonoRail.Tests.Views")); services.AddService(typeof(ISparkViewEngine), new SparkViewEngine(settings)); services.AddService(typeof(IControllerDescriptorProvider), services.ControllerDescriptorProvider); _factory = new SparkViewFactory(); _factory.Service(services); }
public static void Install(ViewEngineCollection engines) { if (engines == null) { throw new ApplicationException("ViewEngines.Engines Found"); } var sparkSettings = GetSparkSettings(Assembly.GetCallingAssembly()); var sparkViewFactory = new SparkViewFactory(sparkSettings); engines.Clear(); engines.Add(sparkViewFactory); }
public void Init() { _factory = new SparkViewFactory(); _viewFolder = new InMemoryViewFolder(); _factory.ViewFolder = _viewFolder; var httpContext = MockRepository.GenerateStub <HttpContextBase>(); _routeData = new RouteData(); var controller = MockRepository.GenerateStub <ControllerBase>(); _controllerContext = new ControllerContext(httpContext, _routeData, controller); }
public SparkDefaultStructureMapRegistry(bool debuggingEnabled, string controllerAssembly, SparkViewFactory viewFactory) { IncludeDiagnostics(debuggingEnabled); Applies.ToAssembly(controllerAssembly); Actions.IncludeTypesNamed(x => x.EndsWith("Controller")); Routes.IgnoreControllerNamespaceEntirely(); Views.Facility(new SparkViewFacility(viewFactory, actionType => actionType.Name.EndsWith("Controller"))) .TryToAttach(x => x.BySparkViewDescriptors(action => action.RemoveSuffix("Controller"))); }
protected override void Configure() { factory = new SparkViewFactory(); factory.Service(serviceProvider); manager = new DefaultViewEngineManager(); manager.Service(serviceProvider); serviceProvider.ViewEngineManager = manager; serviceProvider.AddService(typeof(IViewEngineManager), manager); manager.RegisterEngineForExtesionLookup(factory); manager.RegisterEngineForView(factory); }
public virtual string CompileView(string view) { var viewFactory = new SparkViewFactory(); var descriptor = new SparkViewDescriptor { Language = LanguageType.Javascript }; descriptor.AddTemplate(string.Format("{0}{1}{2}", ControllerContext.ViewFolder, Path.DirectorySeparatorChar, view)); ((IViewSourceLoaderContainer)viewFactory).ViewSourceLoader = Context.Services.ViewSourceLoader; var entry = viewFactory.Engine.CreateEntry(descriptor); return(entry.SourceCode); }
public void Configure() { SparkSettings settings = new SparkSettings(); SparkViewFactory viewFactory = new SparkViewFactory(settings) { ViewFolder = new MyViewFolder() }; var container = new SparkServiceContainer(settings); ConfigureContainer(container); return(container); }
public void Precompile() { var settings = new SparkSettings(); var factory = new SparkViewFactory(settings) { ViewFolder = new FileSystemViewFolder("AspNetMvc.Tests.Views") }; var batch = new SparkBatchDescriptor(); batch.For <FailureController>(); factory.Precompile(batch); }
public void SetUp() { var settings = new SparkSettings(); _factory = new SparkViewFactory(settings) { ViewFolder = new FileSystemViewFolder("FubuMVC.Tests.Views") }; _httpContext = MockHttpContextBase.Generate("/", new StringWriter()); _response = _httpContext.Response; _output = _response.Output; _routeData = new RouteData(); _routeData.Values.Add("action", "Index"); _actionContext = new ActionContext(new StubController().GetType().Namespace, "Stub"); }
public static void RegisterViewEngine(ICollection <IViewEngine> engines) { SparkSettings settings = new SparkSettings() .SetDebug(true) .SetAutomaticEncoding(true) .AddNamespace("System.Collections.Generic") .AddNamespace("Microsoft.Web.Mvc") .AddNamespace("ModularForum.Controllers") .AddNamespace("ModularForum.Models"); var engine = new SparkViewFactory(settings) { ViewFolder = new EmbeddedViewFolder(Assembly.Load("ModularForum"), "ModularForum.Views") }; engines.Add(engine); }
protected override void Configure() { var settings = new SparkSettings(); settings.SetNullBehaviour(NullBehaviour.Strict); var sparkViewEngine = new SparkViewEngine(settings); serviceProvider.AddService(typeof(ISparkViewEngine), sparkViewEngine); factory = new SparkViewFactory(); factory.Service(serviceProvider); manager = new DefaultViewEngineManager(); manager.Service(serviceProvider); serviceProvider.ViewEngineManager = manager; serviceProvider.AddService(typeof(IViewEngineManager), manager); manager.RegisterEngineForExtesionLookup(factory); manager.RegisterEngineForView(factory); factory.Service(serviceProvider); }
public static string RenderViewImpl(string controllerName, string viewName, ViewDataDictionary viewData, TempDataDictionary tempData, Func <IViewEngine, ControllerContext, ViewEngineResult> findView) { var settings = new SparkSettings(); var viewEngine = new SparkViewFactory(settings); viewEngine.ViewFolder = new FileSystemViewFolder(AppDomain.CurrentDomain.BaseDirectory + @"\..\..\..\IntegrationTestingViews\Views"); var routeData = new RouteData(); routeData.Values["controller"] = controllerName; var controllerContext = new ControllerContext( new HttpContextStub(), routeData, new ControllerStub()); var view = (SparkView)findView(viewEngine, controllerContext).View; try { var writer = new StringWriter(); var viewContext = new ViewContext( controllerContext, view, viewData ?? new ViewDataDictionary(), tempData ?? new TempDataDictionary(), writer); view.Render(viewContext, writer); return(writer.ToString()); } finally { viewEngine.Engine.ReleaseInstance(view); } }
protected override void OnApplicationStarted() { Error += OnError; EndRequest += OnEndRequest; var settings = new SparkSettings() .AddNamespace("System") .AddNamespace("System.Collections.Generic") .AddNamespace("System.Web.Mvc") .AddNamespace("System.Web.Mvc.Html") .AddNamespace("MvcContrib.FluentHtml") .AddNamespace("CodeBetter.Canvas") .AddNamespace("CodeBetter.Canvas.Web") .SetPageBaseType("ApplicationViewPage") .SetAutomaticEncoding(true); #if DEBUG settings.SetDebug(true); #endif var viewFactory = new SparkViewFactory(settings); ViewEngines.Engines.Add(viewFactory); #if !DEBUG PrecompileViews(viewFactory); #endif RegisterAllControllersIn("CodeBetter.Canvas.Web"); log4net.Config.XmlConfigurator.Configure(); RegisterRoutes(RouteTable.Routes); Factory.Load(new Components.WebDependencies()); ModelBinders.Binders.DefaultBinder = new Binders.GenericBinderResolver(Factory.TryGet <IModelBinder>); ValidatorConfiguration.Initialize("CodeBetter.Canvas"); HtmlValidationExtensions.Initialize(ValidatorConfiguration.Rules); }
public void Init() { CompiledViewHolder.Current = null; _viewFolder = new InMemoryViewFolder(); _factory = new SparkViewFactory(new SparkSettingsFactory()) { ViewFolder = _viewFolder }; var httpContext = MockRepository.GenerateStub<HttpContextBase>(); _routeData = new RouteData(); var controller = new StubController(); _actionContext = new ActionContext(httpContext, _routeData, controller.GetType().Namespace); }
public override void Install(IDictionary stateSaver) { // figure out all paths based on this assembly in the bin dir var assemblyPath = Parent.GetType().Assembly.CodeBase.Replace("file:///", ""); var targetPath = Path.ChangeExtension(assemblyPath, ".Views.dll"); var appBinPath = Path.GetDirectoryName(assemblyPath); var appBasePath = Path.GetDirectoryName(appBinPath); var viewPath = ViewPath; if (string.IsNullOrEmpty(viewPath)) { viewPath = "Views"; } if (!Directory.Exists(Path.Combine(appBasePath, viewPath)) && Directory.Exists(Path.Combine(appBinPath, viewPath))) { appBasePath = appBinPath; } var webFileHack = Path.Combine(appBasePath, "web"); var viewsLocation = Path.Combine(appBasePath, viewPath); if (!string.IsNullOrEmpty(TargetAssemblyFile)) { targetPath = Path.Combine(appBinPath, TargetAssemblyFile); } // this hack enables you to open the web.config as if it was an .exe.config File.Create(webFileHack).Close(); var config = ConfigurationManager.OpenExeConfiguration(webFileHack); File.Delete(webFileHack); // GetSection will try to resolve the "Spark" assembly, which the installutil appdomain needs help finding AppDomain.CurrentDomain.AssemblyResolve += ((sender, e) => Assembly.LoadFile(Path.Combine(appBinPath, e.Name + ".dll"))); var settings = (ISparkSettings)config.GetSection("spark"); var services = new StubMonoRailServices(); services.AddService(typeof(IViewSourceLoader), new FileAssemblyViewSourceLoader(viewsLocation)); services.AddService(typeof(ISparkViewEngine), new SparkViewEngine(settings)); services.AddService(typeof(IControllerDescriptorProvider), services.ControllerDescriptorProvider); var factory = new SparkViewFactory(); factory.Service(services); // And generate all of the known view/master templates into the target assembly var batch = new SparkBatchDescriptor(targetPath); // create entries for controller attributes in the parent installer's assembly batch.FromAssembly(Parent.GetType().Assembly); // and give the containing installer a change to add entries if (DescribeBatch != null) { DescribeBatch(this, new DescribeBatchEventArgs { Batch = batch }); } factory.Precompile(batch); base.Install(stateSaver); }
public static void AddFilter(this SparkViewFactory target, IDescriptorFilter filter) { target.DescriptorBuilder.AddFilter(filter); }
public void SetUp() { var settings = new SparkSettings(); var serviceLocator = MockRepository.GenerateStub<IServiceLocator>(); _factory = new SparkViewFactory(settings, serviceLocator) { ViewFolder = new FileSystemViewFolder("FubuMVC.Tests.Views") }; _getActionName = action => action.RemoveSuffix("Controller"); }
public override void Install(IDictionary stateSaver) { // figure out all paths based on this assembly in the bin dir var assemblyPath = Parent.GetType().Assembly.CodeBase.Replace("file:///", ""); var targetPath = Path.ChangeExtension(assemblyPath, ".Views.dll"); var appBinPath = Path.GetDirectoryName(assemblyPath); var appBasePath = Path.GetDirectoryName(appBinPath); var viewPath = ViewPath; if (string.IsNullOrEmpty(viewPath)) viewPath = "Views"; if (!Directory.Exists(Path.Combine(appBasePath, viewPath)) && Directory.Exists(Path.Combine(appBinPath, viewPath))) { appBasePath = appBinPath; } var webFileHack = Path.Combine(appBasePath, "web"); var viewsLocation = Path.Combine(appBasePath, viewPath); if (!string.IsNullOrEmpty(TargetAssemblyFile)) targetPath = Path.Combine(appBinPath, TargetAssemblyFile); // this hack enables you to open the web.config as if it was an .exe.config File.Create(webFileHack).Close(); var config = ConfigurationManager.OpenExeConfiguration(webFileHack); File.Delete(webFileHack); // GetSection will try to resolve the "Spark" assembly, which the installutil appdomain needs help finding AppDomain.CurrentDomain.AssemblyResolve += ((sender, e) => Assembly.LoadFile(Path.Combine(appBinPath, e.Name + ".dll"))); var settings = (ISparkSettings)config.GetSection("spark"); var services = new StubMonoRailServices(); services.AddService(typeof(IViewSourceLoader), new FileAssemblyViewSourceLoader(viewsLocation)); services.AddService(typeof(ISparkViewEngine), new SparkViewEngine(settings)); services.AddService(typeof(IControllerDescriptorProvider), services.ControllerDescriptorProvider); var factory = new SparkViewFactory(); factory.Service(services); // And generate all of the known view/master templates into the target assembly var batch = new SparkBatchDescriptor(targetPath); // create entries for controller attributes in the parent installer's assembly batch.FromAssembly(Parent.GetType().Assembly); // and give the containing installer a change to add entries if (DescribeBatch != null) DescribeBatch(this, new DescribeBatchEventArgs { Batch = batch }); factory.Precompile(batch); base.Install(stateSaver); }
public static void LoadPrecompiledViews(ViewEngineCollection engines) { SparkViewFactory factory = engines.OfType <SparkViewFactory>().First(); factory.Engine.LoadBatchCompilation(Assembly.Load("Precompiled")); }
public static void Main(string[] args) { var location = typeof(AscendApplication).Assembly.Location; string target = Path.ChangeExtension(location, ".Views.dll"); string root = Path.GetDirectoryName(Path.GetDirectoryName(location)); //string webBinPath = Path.Combine (directoryName, "bin"); Console.WriteLine("Precompiling to target: {0}", target); Console.WriteLine("Root folder: {0}", root); try { var factory = new SparkViewFactory(AscendApplication.CreateSparkSettings()); factory.ViewFolder = new VirtualPathCompatableViewFolder(root); factory.Engine.ViewFolder = factory.ViewFolder; var builder = new DefaultDescriptorBuilder(factory.Engine); builder.Filters.Add(new Ascend.Web.AreaDescriptorFilter()); factory.DescriptorBuilder = builder; var batch = new SparkBatchDescriptor(target); batch.FromAssembly(typeof(AscendApplication).Assembly); var descriptors = new List <SparkViewDescriptor>(); foreach (var entry in batch.Entries) { var t = entry.ControllerType; var name = t.Name.Substring(0, t.Name.Length - ("Controller".Length)); var parts = t.Namespace.Split('.'); var area = parts[1 + Array.LastIndexOf(parts, "Areas")]; foreach (var view in factory.ViewFolder.ListViews(Path.Combine(root, "Areas", area, "Views", name))) { var locations = new List <string>(); var descriptor = factory.DescriptorBuilder.BuildDescriptor( new BuildDescriptorParams( t.Namespace, name, Path.GetFileNameWithoutExtension(view), null, true, new Dictionary <string, object> { { "area", area } }), locations); descriptors.Add(descriptor); } } var result = factory.Engine.BatchCompilation(target, descriptors); // var descriptors = factory.CreateDescriptors(batch); // factory.Precompile(batch); } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw ex; } }
public void Init() { // clears cache CompiledViewHolder.Current = null; // reset routes RouteTable.Routes.Clear(); RouteTable.Routes.Add(new Route("{controller}/{action}/{id}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { action = "Index", id = "" }) }); httpContext = MockHttpContextBase.Generate("/", new StringWriter()); //_requestBase = MockRepository.GenerateStub<HttpRequestBase>(); //_responseBase = MockRepository.GenerateStub<HttpResponseBase>(); //_sessionStateBase = MockRepository.GenerateStub<HttpSessionStateBase>(); //_serverUtilityBase = MockRepository.GenerateStub<HttpServerUtilityBase>(); //httpContext.Stub(x => x.Request).Return(_requestBase); //httpContext.Stub(x => x.Response).Return(_responseBase); //httpContext.Stub(x => x.Session).Return(_sessionStateBase); //httpContext.Stub(x => x.Server).Return(_serverUtilityBase); //_responseBase.Stub(x => x.OutputStream).Return(new MemoryStream()); //_responseBase.Stub(x => x.Output).Return(new StringWriter()); //_requestBase.Stub(x => x.ApplicationPath).Return("/"); //_requestBase.Stub(x => x.Path).Return("/"); //_responseBase.Stub(x => x.ApplyAppPathModifier(null)) // .IgnoreArguments() // .Do(new Func<string, string>(path => path)); response = httpContext.Response; output = response.Output; controller = MockRepository.GenerateStub<ControllerBase>(); routeData = new RouteData(); routeData.Values.Add("controller", "Home"); routeData.Values.Add("action", "Index"); controllerContext = new ControllerContext(httpContext, routeData, controller); var settings = new SparkSettings().AddNamespace("System.Web.Mvc.Html"); factory = new SparkViewFactory(settings) { ViewFolder = new FileSystemViewFolder("AspNetMvc.Tests.Views") }; ControllerBuilder.Current.SetControllerFactory(new DefaultControllerFactory()); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(factory); }
public void Init() { //CompiledViewHolder.Current = null; var serviceLocator = MockRepository.GenerateStub<IServiceLocator>(); _factory = new SparkViewFactory(null); _viewFolder = new InMemoryViewFolder(); _factory.ViewFolder = _viewFolder; var httpContext = MockRepository.GenerateStub<HttpContextBase>(); _routeData = new RouteData(); var controller = new StubController(); _actionContext = new ActionContext(httpContext, _routeData, controller.GetType().Namespace, "Bar"); }
public void SetUp() { _factory = new SparkViewFactory(new TestSparkSettingsFactory()) { ViewFolder = new FileSystemViewFolder("FubuMvc.Tests.Views") }; ; }
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() { _factory = new SparkViewFactory(); _viewFolder = new InMemoryViewFolder(); _factory.ViewFolder = _viewFolder; var httpContext = MockRepository.GenerateStub<HttpContextBase>(); _routeData = new RouteData(); var controller = MockRepository.GenerateStub<ControllerBase>(); _controllerContext = new ControllerContext(httpContext, _routeData, controller); }
public void SetUp() { var settings = new SparkSettings(); var serviceLocator = MockRepository.GenerateStub<IServiceLocator>(); _factory = new SparkViewFactory(settings, serviceLocator) { ViewFolder = new FileSystemViewFolder("FubuMVC.Tests.Views") }; }
public override void Install(IDictionary stateSaver) { // figure out all paths based on this assembly in the bin dir var assemblyPath = Parent.GetType().Assembly.Location; var targetPath = Path.ChangeExtension(assemblyPath, ".Views.dll"); var webSitePath = Path.GetDirectoryName(Path.GetDirectoryName(assemblyPath)); var webBinPath = Path.Combine(webSitePath, "bin"); var webFileHack = Path.Combine(webSitePath, "web"); var viewsLocation = Path.Combine(webSitePath, "Views"); if (!string.IsNullOrEmpty(TargetAssemblyFile)) targetPath = Path.Combine(webBinPath, TargetAssemblyFile); // this hack enables you to open the web.config as if it was an .exe.config File.Create(webFileHack).Close(); var config = ConfigurationManager.OpenExeConfiguration(webFileHack); File.Delete(webFileHack); // GetSection will try to resolve the "Spark" assembly, which the installutil appdomain needs help finding AppDomain.CurrentDomain.AssemblyResolve += ((sender, e) => Assembly.LoadFile(Path.Combine(webBinPath, e.Name + ".dll"))); var settings = (ISparkSettings) config.GetSection("spark"); // Finally create an engine with the <spark> settings from the web.config var factory = new SparkViewFactory(settings) { ViewFolder = new FileSystemViewFolder(viewsLocation) }; // And generate all of the known view/master templates into the target assembly var batch = new SparkBatchDescriptor(targetPath); // create entries for controller attributes in the parent installer's assembly batch.FromAssembly(Parent.GetType().Assembly); // and give the containing installer a change to add entries if (DescribeBatch != null) DescribeBatch(this, new DescribeBatchEventArgs {Batch = batch}); factory.Precompile(batch); base.Install(stateSaver); }