Exemplo n.º 1
0
 private static void PrecompileViews(SparkViewFactory viewFactory)
 {
     var batch = new SparkBatchDescriptor();
     batch
         .For<HomeController>();
     viewFactory.Precompile(batch);
 }
Exemplo n.º 2
0
 public SparkCompiler(SparkViewFactory sparkViewFactory, string indexFileName)
 {
     _sparkViewFactory = sparkViewFactory;
     _indexFileName = indexFileName;
     _dllCachePath = FilePaths.StorageFolder;
     _themePath = FilePaths.ThemesFolder;
 }
Exemplo n.º 3
0
        private void RegisterViewFolders(Assembly assembly, SparkViewFactory sparkViewFactory)
        {
            var viewFolder = new EmbeddedViewFolder(assembly, assembly.GetName().Name + ".Mvc.Views");

            sparkViewFactory.ViewFolder = sparkViewFactory.ViewFolder
                .Append(new SubViewFolder(viewFolder, AreaName))
                .Append(new SubViewFolder(viewFolder, "Shared\\" + AreaName));
        }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
        public void Configure()
        {
            SparkSettings settings = new SparkSettings();
            
            SparkViewFactory viewFactory = new SparkViewFactory(settings) {ViewFolder = new MyViewFolder()};

            var container = new SparkServiceContainer(settings);
            ConfigureContainer(container);
            return container;            
        }
Exemplo n.º 6
0
        public void Application_Start()
        {
            IViewEngine engine = new SparkViewFactory();
            ViewEngines.Engines.Add(engine);
            RouteCollection routes = RouteTable.Routes;

            routes.MapRoute("default",
                            "{controller}/{action}",
                            new {controller = "Home", action = "Index"});
        }
        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);
        }
Exemplo n.º 8
0
        private static IList<SparkViewDescriptor> AllKnownDescriptors(SparkViewFactory viewFactory)
        {
            //build the batch
            var batch = new SparkBatchDescriptor();
            batch
                .For<HomeController>().Layout("Application")
                .For<FirstController>().Layout("Application")
                .For<SecondController>().Layout("Application")
                .For<ThirdController>().Layout("Application")
                .For<FourthController>().Layout("Application")
                .For<FifthController>().Layout("Application")
                .For<SixthController>().Layout("Application")
                .For<SeventhController>().Layout("Application")
                .For<EigthController>().Layout("Application")
                .For<NinthController>().Layout("Application")
                .For<TenthController>().Layout("Application");

            //find all the custom themes
            var themeMasters = new List<string>();

            var themePath = ThemeDirectory + "\\";
            var themedMasterFiles = Directory.GetFiles(themePath, "index.html", SearchOption.AllDirectories);
            foreach (var master in themedMasterFiles)
            {
                var themeMasterName = master.Remove(0, themePath.Length);
                themeMasters.Add(themeMasterName);
            }

            //adjust the batch to precompile for each custom theme
            var generatedDescriptors = viewFactory.CreateDescriptors(batch);
            var allDescriptors = new List<SparkViewDescriptor>();

            foreach (var descriptor in generatedDescriptors)
            {
                allDescriptors.Add(descriptor);

                var isAppMaster = descriptor.Templates.Any(x => x.Contains("Application"));
                if (!isAppMaster) continue;

                foreach (var themeMaster in themeMasters)
                {
                    var themeDescriptor = new SparkViewDescriptor()
                        .SetLanguage(descriptor.Language)
                        .SetTargetNamespace(descriptor.TargetNamespace)
                        .AddTemplate(descriptor.Templates[0]);

                    themeDescriptor.AddTemplate(themeMaster);

                    allDescriptors.Add(themeDescriptor);
                }
            }

            return allDescriptors;
        }
Exemplo n.º 9
0
        protected override void RegisterArea(AreaRegistrationContext context, Assembly assembly, SparkViewFactory sparkViewFactory)
        {
            context.Routes.Add(new Route("assets/default/{*resource}",
                new RouteValueDictionary(),
                new RouteValueDictionary(),
                new EmbeddedContentRouteHandler(assembly, assembly.GetName().Name + ".Mvc.DefaultTemplate.Assets")));

            context.Routes.Add(new Route("services/templates/bbcode", new BBCodeRouteHandler()));

            var viewFolder = new EmbeddedViewFolder(assembly, assembly.GetName().Name + ".Mvc.DefaultTemplate.Views");

            sparkViewFactory.ViewFolder = sparkViewFactory.ViewFolder
                .Append(viewFolder);
        }
Exemplo n.º 10
0
        public static void Configure(ViewEngineCollection viewEngines)
        {
            var settings = new SparkSettings()
                .AddNamespace("System")
                .AddNamespace("System.Collections.Generic")
                .AddNamespace("System.Web.Mvc")
                .AddNamespace("System.Web.Mvc.Html")
                .AddNamespace("Sox.UI")
                .AddNamespace("Sox.UI.Infrastructure")
                .SetPageBaseType("ApplicationViewPage")
                .SetAutomaticEncoding(true);

            settings.SetDebug(true);
            var viewFactory = new SparkViewFactory(settings);
            viewEngines.Add(viewFactory);
        }
Exemplo n.º 11
0
        public void Configure()
        {
            _engines.Clear();
            var settings = new SparkSettings
                               {
                                   AutomaticEncoding = true,
                                   Debug = true,
                               };

            settings
                .AddAssembly(typeof(IConfigurator).Assembly)
                .AddAssembly(typeof(Controller).Assembly)
                .SetPageBaseType("ApplicationView");
            var viewFactory = new SparkViewFactory(settings);
            //PrecompileViews(viewFactory);
            _engines.Add(viewFactory);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        public static void Configure(ViewEngineCollection engines)
        {
            //engines.Clear();
            var settings = new SparkSettings
                               {
                                   AutomaticEncoding = true,
                                   Debug = true,
                               };

            settings
                .AddAssembly(typeof(LearningTrackerMvcApplication).Assembly.GetName().Name)
                .AddAssembly(typeof(Controller).Assembly.GetName().Name)
                .SetPageBaseType("ApplicationViewPage");
            var viewFactory = new SparkViewFactory(settings);
            PrecompileViews(viewFactory);
            engines.Add(viewFactory);
        }
Exemplo n.º 14
0
 protected void Application_Start()
 {
     RegisterRoutes(RouteTable.Routes);
     try
     {
         var engine = new SparkViewFactory();
         container = new WindsorContainer("Configuration/castle.xml");
         ViewEngines.Engines.Add(engine);
     }
     catch (Exception)
     {
     }
     container.Kernel.Resolver.AddSubResolver(new ListResolver(container.Kernel));
     container.Install(new DefaultComponentInstallers());
     ControllerBuilder.Current.SetControllerFactory(container.Resolve<IExtendedControllerFactory>());
     BlogContextProvider.Current = container.Resolve<BlogContextProvider>();
 }
Exemplo n.º 15
0
        protected void Application_Start()
        {
            Validator.InitializeFromAssembly(System.Reflection.Assembly.GetExecutingAssembly());
            ModelValidatorProviders.Providers.Clear();
            ModelValidatorProviders.Providers.Add(new ValidatorProvider());
            
            var viewFactory = new SparkViewFactory(new SparkSettings()
                .AddNamespace("System")
                .AddNamespace("System.Collections.Generic")
                .AddNamespace("System.Web.Mvc.Html")
                .AddNamespace("Metsys.Validate.Mvc")
                .AddNamespace("Metsys.Validate.MvcSample")
                .SetAutomaticEncoding(true)
                .SetDebug(_debug));

        
            ViewEngines.Engines.Add(viewFactory);           
            RegisterRoutes(RouteTable.Routes);
        }
Exemplo n.º 16
0
        private static IEnumerable<SparkViewDescriptor> RootThemableDescriptors(SparkViewFactory viewFactory)
        {
            var batch = new SparkBatchDescriptor();
            batch
                //Guest Interface
                .For<SparkDynamicTheme.Controllers.HomeController>().Layout(ApplicationLayout)
                .For<SparkDynamicTheme.Controllers.FirstController>().Layout(ApplicationLayout)
                .For<SparkDynamicTheme.Controllers.SecondController>().Layout(ApplicationLayout)
                .For<SparkDynamicTheme.Controllers.ThirdController>().Layout(ApplicationLayout)
                .For<SparkDynamicTheme.Controllers.FourthController>().Layout(ApplicationLayout)
                .For<SparkDynamicTheme.Controllers.FifthController>().Layout(ApplicationLayout)
                .For<SparkDynamicTheme.Controllers.SixthController>().Layout(ApplicationLayout)
                .For<SparkDynamicTheme.Controllers.SeventhController>().Layout(ApplicationLayout)
                .For<SparkDynamicTheme.Controllers.EigthController>().Layout(ApplicationLayout)
                .For<SparkDynamicTheme.Controllers.NinthController>().Layout(ApplicationLayout)
                .For<SparkDynamicTheme.Controllers.TenthController>().Layout(ApplicationLayout);

            return viewFactory.CreateDescriptors(batch);
        }
Exemplo n.º 17
0
		public void Compile(Assembly sourceAsm)
		{
			var sparkViewFactory = new SparkViewFactory(GetSparkSettings())
			                       	{
			                       		ViewFolder = new FileSystemViewFolder(EnsureDirectoryExists(_arguments.Views))
			                       	};
			var batch = new SparkBatchDescriptor(GetOutputDllFullPath());
			batch.FromAssembly(sourceAsm);
			
			DescribeSparkViews(batch, sourceAsm);
			DescribeCustomSparkViews(batch, sourceAsm);

			sparkViewFactory.DescriptorBuilder = new AutoMasterDescriptorBuilder(sparkViewFactory.Engine);

			try
			{
				sparkViewFactory.Precompile(batch);
			}
			catch (CompilerException e)
			{
				File.WriteAllText("arq.CompilerException.txt", e.Message);
				throw new CompilerException(e.Message.FirstLine() + "\nSee arq.CompilerException.txt for full description");
			}
		}
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        public static void Start()
        {
            LoggingConfig.Configure();

            ViewEngines.Engines.Clear();

            var settings = new SparkSettings()
                .AddViewFolder(ViewFolderType.FileSystem, new Dictionary<string, string>
                                                              {
                                                                  {"basePath", ThemeDirectory}
                                                              })
                .SetAutomaticEncoding(true);

            if (Debugger.IsAttached)
                settings.SetDebug(true);

            var viewFactory = new SparkViewFactory(settings);

            var sparkServiceContainer = new SparkServiceContainer(settings);
            sparkServiceContainer.SetServiceBuilder<IViewEngine>(c => viewFactory);
            sparkServiceContainer.SetServiceBuilder<IDescriptorBuilder>(c => new DefaultDescriptorBuilder());
            sparkServiceContainer.SetServiceBuilder<ICacheServiceProvider>(c => new DefaultCacheServiceProvider());
            sparkServiceContainer.AddFilter(new AreaDescriptorFilter());
            sparkServiceContainer.AddFilter(CustomThemeFilter.For(GetCustomerId));

            ViewEngines.Engines.Add(sparkServiceContainer.GetService<IViewEngine>());

            var sparkEngine = sparkServiceContainer.GetService<ISparkViewEngine>();

            var timer = new Stopwatch();
            timer.Start();
            sparkEngine.BatchCompilation(AllKnownDescriptors(viewFactory));
            timer.Stop();

            "SparkWebMvc".Log().Info("Pre-compile time: {0} seconds", timer.Elapsed.TotalSeconds);
        }
Exemplo n.º 20
0
        protected void Application_Start()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModule<DomainModule>();
            builder.RegisterModule<MessagingModule>();
            builder.RegisterModule<ServicesModule>();
            builder.RegisterModule<SourceControlModule>();

            _containerProvider = new ContainerProvider(builder.Build());

            ControllerBuilder.Current.SetControllerFactory(new AutofacControllerFactory(_containerProvider));

            var batch = new SparkBatchDescriptor();
            batch.For<AccountController>()
                .For<DashboardController>()
                .For<ProjectController>();

            var viewFactory = new SparkViewFactory();
            viewFactory.Precompile(batch);

            ViewEngines.Engines.Add(viewFactory);

            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
            //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
        }
Exemplo n.º 21
0
        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 viewContext = new ViewContext(
                    controllerContext,
                    view,
                    viewData ?? new ViewDataDictionary(),
                    tempData ?? new TempDataDictionary());

                var writer = new StringWriter();
                view.Render(viewContext, writer);
                return writer.ToString();
            }
            finally
            {
                viewEngine.Engine.ReleaseInstance(view);
            }
        }
Exemplo n.º 22
0
        private IList<SparkViewDescriptor> ThemableDescriptors(SparkViewFactory viewFactory)
        {
            var generatedDescriptors = RootThemableDescriptors(viewFactory);
            var allDescriptors = new List<SparkViewDescriptor>();

            foreach (var descriptor in generatedDescriptors)
            {
                var isAppMaster = descriptor.Templates.Any(x => x.Contains(ApplicationLayout));
                if (!isAppMaster) continue;

                var themeDescriptor = new SparkViewDescriptor()
                    .SetLanguage(descriptor.Language)
                    .SetTargetNamespace(descriptor.TargetNamespace)
                    .AddTemplate(descriptor.Templates[0]);

                themeDescriptor.AddTemplate(MasterPage);

                allDescriptors.Add(themeDescriptor);
            }

            return allDescriptors;
        }
Exemplo n.º 23
0
 public static void Install(SparkViewFactory factory, Func<ControllerContext, string> selector)
 {
     factory.AddFilter(new Filter(selector));
     factory.ViewFolder = new Folder(factory.ViewFolder);
 }
 public void Execute()
 {
     var sparkViewFactory = new SparkViewFactory();
     _container.Kernel.AddComponentInstance<IViewFolderContainer>(sparkViewFactory);
     ViewEngines.Engines.Add(sparkViewFactory);
 }
 /// <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;
 }
Exemplo n.º 26
0
 public static void Install(SparkViewFactory factory, Func <ControllerContext, string> selector)
 {
     factory.AddFilter(new Filter(selector));
     factory.ViewFolder = new Folder(factory.ViewFolder);
 }
Exemplo n.º 27
0
 protected virtual void RegisterArea(AreaRegistrationContext context, Assembly assembly,
     SparkViewFactory sparkViewFactory)
 {
 }