private void InitializeSettings(XElement xe) { Name = xe.Attr <string>(SchemaConstants.Set.Name); var duration = ModelUtils.GetString(xe, SchemaConstants.Set.Duration, Settings.DefaultDuration == null ? null : Settings.DefaultDuration.ToString()); DurationInDays = TimeSpan.FromDays(int.Parse(duration, CultureInfo.InvariantCulture)); Type = xe.Attr <ResourceType>(SchemaConstants.Set.Type); var debugEnabled = xe.Attr <string>(SchemaConstants.Set.DebugEnabled); DebugEnabled = string.IsNullOrEmpty(debugEnabled) ? Settings.DefaultDebugEnabled // use parent if not specified : debugEnabled.Equals(SchemaConstants.Set.Auto, StringComparison.OrdinalIgnoreCase) ? HttpContext.Current.IsDebuggingEnabled // use web.config if autor : bool.Parse(debugEnabled); var fileErrorsEnabled = xe.Attr <string>(SchemaConstants.Set.FileErrorsEnabled); FileErrorsEnabled = string.IsNullOrEmpty(fileErrorsEnabled) ? Settings.ShownotFoundFilesError // use parent if not specified : fileErrorsEnabled.Equals(SchemaConstants.Set.Auto, StringComparison.OrdinalIgnoreCase) ? HttpContext.Current.IsDebuggingEnabled // use web.config if autor : bool.Parse(fileErrorsEnabled); IgnorePipelineWhenDebug = (bool)xe.Attr <string>(SchemaConstants.Set.IgnorePipelineWhenDebug) .ConvertToType(typeof(bool), Settings.DefaultIgnorePipelineWhenDebug); CompressionEnabled = (bool)xe.Attr <string>(SchemaConstants.Set.CompressionEnabled) .ConvertToType(typeof(bool), Settings.DefaultCompressionEnabled); }
private static Type GetBinderType(XElement child) { var binderTypeName = child.Attr <string>(SchemaConstants.Binder.Type); return(binderTypeName == null ? Default.Binder.Type : ModelUtils.LoadType("Binder", binderTypeName, SchemaConstants.Binder.ValidTypes)); }
private void LoadResourceSets(XContainer xe) { var rsXe = xe.Element(XName.Get(SchemaConstants.Setting.ResourceSets, SchemaConstants.Namespace)); Url = rsXe.Attr <string>(SchemaConstants.Setting.Url); Host = rsXe.Attr <string>(SchemaConstants.Setting.Host); SslHost = rsXe.Attr <string>(SchemaConstants.Setting.SslHost); DefaultDuration = rsXe.Attr <int?>(SchemaConstants.Setting.DefaultDuration); DefaultVersion = rsXe.Attr <string>(SchemaConstants.Setting.DefaultVersion); var generatorType = rsXe.Attr <string>(SchemaConstants.Setting.DefaultVersionGenerator); DefaultVersionGeneratorType = string.IsNullOrEmpty(generatorType) ? Default.ResourceSet.VersionGeneratorType : ModelUtils.LoadType("Generator", generatorType, SchemaConstants.VersionGenerator.ValidTypes); LocalChangeMonitorInterval = rsXe.Attr <int?>(SchemaConstants.Setting.LocalChangeMonitorInterval); RemoteChangeMonitorInterval = rsXe.Attr <int?>(SchemaConstants.Setting.RemoteChangeMonitorInterval); var debugEnabled = rsXe.Attr <string>(SchemaConstants.Setting.DefaultDebugEnabled); DefaultDebugEnabled = string.IsNullOrEmpty(debugEnabled) ? Default.ResourceSet.DebugEnabled : debugEnabled.Equals(SchemaConstants.Set.Auto, StringComparison.OrdinalIgnoreCase) ? HttpContext.Current.IsDebuggingEnabled : bool.Parse(debugEnabled); var fileErrorsEnabled = rsXe.Attr <string>(SchemaConstants.Setting.ShownotFoundFilesError); ShownotFoundFilesError = string.IsNullOrEmpty(fileErrorsEnabled) ? Default.ResourceSet.FileErrorsEnabled : fileErrorsEnabled.Equals(SchemaConstants.Set.Auto, StringComparison.OrdinalIgnoreCase) ? HttpContext.Current.IsDebuggingEnabled : bool.Parse(fileErrorsEnabled); DefaultIgnorePipelineWhenDebug = (bool)rsXe.Attr <string>(SchemaConstants.Setting.DefaultIgnorePipelineWhenDebug) .ConvertToType(typeof(bool), Default.ResourceSet.IgnorePipelineWhenDebug); DefaultCompressionEnabled = (bool)rsXe.Attr <string>(SchemaConstants.Setting.DefaultCompressionEnabled) .ConvertToType(typeof(bool), Default.ResourceSet.CompressionEnabled); DefaultJSMinifierRef = GetMinifier(rsXe, SchemaConstants.Setting.DefaultJSMinifierRef, JSMinifierMap); DefaultCssMinifierRef = GetMinifier(rsXe, SchemaConstants.Setting.DefaultCssMinifierRef, CssMinifierMap); ResourceSets = new List <ResourceSet>(); foreach (var node in rsXe.Elements()) { var rs = new ResourceSet(this, node); if (ResourceSets.Contains(rs)) { throw new XmlSchemaException("Duplicated resource set"); } ResourceSets.Add(rs); } ResourceSets = ResourceSets.ToList().AsReadOnly(); }
internal Resource(ResourceSet parent, XElement xe) { ParentSet = parent; Path = xe.Attr <string>(SchemaConstants.Resource.Path); Mode = xe.Attr(SchemaConstants.Resource.Mode, Default.Resource.Mode); ForwardCookie = xe.Attr(SchemaConstants.Resource.ForwardCookie, Default.Resource.ForwardCookie); Minifier = ParentSet.Type == ResourceType.JS ? ModelUtils.LoadMinifier(xe, SchemaConstants.Resource.MinifierRef, ParentSet.Minifier.Name, ParentSet.Settings.JSMinifierMap) : ModelUtils.LoadMinifier(xe, SchemaConstants.Resource.MinifierRef, ParentSet.Minifier.Name, ParentSet.Settings.CssMinifierMap); if (Mode == ResourceMode.Static && ForwardCookie) { throw new XmlSchemaException("ForwardCookie must not be True when Mode is Static"); } }
private void InitializeVersion(XElement xe, Settings parent) { Version = ModelUtils.GetString(xe, SchemaConstants.Set.Version, parent.DefaultVersion); var generatorType = xe.Attr <string>(SchemaConstants.Set.VersionGenerator); if (string.IsNullOrEmpty(generatorType)) { VersionGeneratorType = parent.DefaultVersionGeneratorType; } else { VersionGeneratorType = ModelUtils.LoadType("Generator", generatorType, SchemaConstants.VersionGenerator.ValidTypes); } if (IsAutoVersion) { Hash = ComputeHash(); } }
private static void LoadMinifiers(XElement xe, string elementName, IDictionary <string, MinifierInfo> map) { foreach (var childXe in xe.ChildrenOfChild(elementName, SchemaConstants.Namespace)) { var name = childXe.Attr <string>(SchemaConstants.Minifier.Name); if (map.ContainsKey(name)) { throw new XmlSchemaException(string.Format(CultureInfo.InvariantCulture, "Minifier {0} already exists", name)); } var typeName = childXe.Attr <string>(SchemaConstants.Minifier.Type); var type = ModelUtils.LoadType("Minifier", typeName, SchemaConstants.Minifier.ValidTypes); var minifier = new MinifierInfo { Name = name, Type = type, Parameters = childXe.Elements(XName.Get(SchemaConstants.Param.Root, SchemaConstants.Namespace)).ToList(), BinderType = GetBinderType(childXe), }; map.Add(name, minifier); } }
private void LoadCacheVaryProvider(XElement xe) { var providerInfoList = new List <CacheVaryProviderInfo>(); foreach (var child in xe.ChildrenOfChild(SchemaConstants.Setting.CacheVaryProviders, SchemaConstants.Namespace)) { var typeName = child.Attr <string>(SchemaConstants.CacheVaryProvider.Type); var type = ModelUtils.LoadType("CacheVaryProvider", typeName, SchemaConstants.CacheVaryProvider.ValidTypes); var acceptedResourceSets = child.Attr <string>(SchemaConstants.CacheVaryProvider.AcceptedResourceSets); var setNameList = acceptedResourceSets == null ? null : acceptedResourceSets.Trim(';', ' ').Split(';').ToList(); var provider = new CacheVaryProviderInfo { Type = type, Parameters = child.Elements(XName.Get(SchemaConstants.Param.Root, SchemaConstants.Namespace)).ToList(), BinderType = GetBinderType(child), ResourceSetNames = setNameList }; providerInfoList.Add(provider); } CacheVaryProviderInfoList = providerInfoList.AsReadOnly(); }
internal Resource(ResourceSet parent, XElement xe) { ParentSet = parent; Path = xe.Attr <string>(SchemaConstants.Resource.Path); if (Path.Contains("${")) { Path.Split('$').ToList().ForEach(p => { if (p.Contains('{')) { string resourceSetting = p.Split(new char[] { '{', '}' })[1]; String resourceContent = ConfigurationManager.AppSettings[resourceSetting]; if (String.IsNullOrEmpty(resourceContent)) { resourceContent = "empty"; } Path = Path.Replace("${" + resourceSetting + "}", resourceContent); } }); } Mode = xe.Attr(SchemaConstants.Resource.Mode, Default.Resource.Mode); if (Mode == ResourceMode.Auto) { Mode = Path.StartsWith("http") ? ResourceMode.Dynamic : ResourceMode.Static; } ForwardCookie = xe.Attr(SchemaConstants.Resource.ForwardCookie, Default.Resource.ForwardCookie); Minifier = ParentSet.Type == ResourceType.JS ? ModelUtils.LoadMinifier(xe, SchemaConstants.Resource.MinifierRef, ParentSet.Minifier.Name, ParentSet.Settings.JSMinifierMap) : ModelUtils.LoadMinifier(xe, SchemaConstants.Resource.MinifierRef, ParentSet.Minifier.Name, ParentSet.Settings.CssMinifierMap); if (Mode == ResourceMode.Static && ForwardCookie) { throw new XmlSchemaException("ForwardCookie must not be True when Mode is Static"); } }
private void InitializeMinifier(XElement xe) { Minifier = Type == ResourceType.JS ? ModelUtils.LoadMinifier(xe, SchemaConstants.Set.MinifierRef, Settings.DefaultJSMinifierRef, Settings.JSMinifierMap) : ModelUtils.LoadMinifier(xe, SchemaConstants.Set.MinifierRef, Settings.DefaultCssMinifierRef, Settings.CssMinifierMap); }