public void Initialize(IDictionary parentParameters, NTemplateEngine engine, TextWriter writer) { _engine = engine; _properties = new TemplateParameters(parentParameters); Writer = writer; }
internal static void Initialize() { if (initialized) return; initialized = true; Action<IConfiguration> configure = x => { }; if (HttpContext.Current != null) { var x = AppDomain.CurrentDomain.SetupInformation.CachePath; var dir = HttpContext.Current.Server.MapPath("~/bin"); Configuration = new AspNetAppConfiguration(); var dllFiles = (from f in Directory.GetFiles(dir, "*.dll", SearchOption.TopDirectoryOnly) select f) .ToDictionary(f => Path.GetFileName(f).ToUpper()); var target = Path.Combine(x, "manual"); if (Directory.Exists(target)) Directory.Delete(target, true); Directory.CreateDirectory(target); foreach (var assemblyFilename in Directory.GetFiles(x, "*.dll", SearchOption.AllDirectories)) { if (dllFiles.ContainsKey(Path.GetFileName(assemblyFilename).ToUpper())) { Configuration.AddRoutesAssembly(Assembly.LoadFile(assemblyFilename)); dllFiles.Remove(Path.GetFileName(assemblyFilename).ToUpper()); } } foreach (var missing in dllFiles.Values) { var targetDll = Path.Combine(target, Path.GetFileName(missing)); File.Copy(missing, targetDll); Configuration.AddRoutesAssembly(Assembly.LoadFile(targetDll)); } var currentApp = HttpContext.Current.ApplicationInstance as IWebOnDietApplication; if (currentApp != null) { configure = currentApp.Configure; Configuration.AddRoutesAssembly(currentApp.GetType().BaseType.Assembly); } } else { if (Embedded.Server.CurrentContext != null) { Configuration = new AspNetAppConfiguration(); configure = Embedded.Server.Current.Configure; } else throw new Exception("No hosting found"); } configure(Configuration); var routedMethods = (from assembly in Configuration.RouteAssemblies from type in assembly.GetExportedTypes() where type.IsInterface == false && type.IsAbstract == false from method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance) from attr in method.GetCustomAttributes(true) let routeAttribute = attr as IRouteAttribute where routeAttribute != null orderby routeAttribute.Precedence descending select new { RouteAttribute = routeAttribute, Method = method }).ToArray(); var routes = from r in routedMethods let route = r.RouteAttribute.Route.IndexOf(':') > 0 ? (IRoute)new PatternRoute(r.RouteAttribute.Route) { Target = new TargetMethod(r.Method) } : (IRoute)new ExactMatchRoute(r.RouteAttribute.Route) { Target = new TargetMethod(r.Method) } select route; Routes.AddRange(routes); var routeClasses = routedMethods.Select(m => m.Method.DeclaringType).Distinct().ToArray(); Container = new Kernel(); foreach (var routeClass in routeClasses) { Container.Register(routeClass, routeClass); } var templateEngine = new NTemplateEngine(AppDomain.CurrentDomain.SetupInformation.PrivateBinPath); templateEngine.Initialize(); wod.TemplateEngine = templateEngine; wod.Render = new Renderer(templateEngine); }
public AspViewCompiler(NTemplateEngine engine) { _engine = engine; }
public Renderer(NTemplateEngine templateEngine) { _templateEngine = templateEngine; }