public void Process(BundleContext context, BundleResponse response) { var pathsAllowed = new[] { context.HttpContext.Server.MapPath("~/Content/css/"), context.HttpContext.Server.MapPath(BundleConfig.AdminThemeDirectory) }; var builder = new StringBuilder(); foreach (var bundleFile in response.Files) { string normalizeFile = context.HttpContext.Server.MapPath(bundleFile.IncludedVirtualPath); if (pathsAllowed.Any(normalizeFile.StartsWith) == false) throw new Exception("Path not allowed"); if (File.Exists(normalizeFile) == false) continue; var content = File.ReadAllText(normalizeFile); string path; if (FilesToNormalize.TryGetValue(bundleFile.VirtualFile.Name, out path)) content = NormalizeImports(content, context.HttpContext.Server.MapPath(path)); builder.AppendLine(content); } response.Content = Less.Parse(builder.ToString(), new DotlessConfiguration { DisableUrlRewriting = true }); response.ContentType = "text/css"; }
/// <summary> /// Handles any defined global parameter that has any input /// </summary> private void HandleDefinedGlobals(Dictionary<string, string> args, object obj) { var globals = GetDefinedGlobals(); foreach (var method in globals) { var att = method.GetAttribute<GlobalAttribute>(); var name = att.Name ?? method.Name; var allNames = new[] { name }.Union(att.Aliases.CommaSplit()); var key = args.Keys.FirstOrDefault( k => allNames.Any( n => n.Equals(k, StringComparison.InvariantCultureIgnoreCase))); if (key != null) { var parameters = method.GetParameters(); if (parameters.Length == 0) { MethodInvoker.Invoke(method, obj, null); } else if (parameters.Length == 1) { string stringValue; if (args.TryGetValue(key, out stringValue)) { var p = parameters.First(); var value = ValuesFactory.GetValueForParameter(p, p.ParameterType, key, stringValue); // validation // if (value != null && p.HasAttribute<ValidationAttribute>()) { var parameterValidators = p.GetAttributes<ValidationAttribute>().Select(a => a.GetValidator()); // all validators must pass // foreach (var validator in parameterValidators) { validator.Validate(new ValueInfo(p.Name, p.ParameterType, value)); } } var validators = method.GetInterfaceAttributes<ICollectionValidation>(). Select(a => a.GetValidator()); foreach (var validator in validators) { validator.Validate(new[] { new ValueInfo(p.Name, p.ParameterType, value), }); } MethodInvoker.Invoke(method, obj, new[] { value }); } } else { throw new NotSupportedException( "Method {0} has more than one parameter and cannot be handled as a global handler".FormatWith(method.Name)); } // remove it so later we'll see which ones were not handled // args.Remove(key); } } }