/// <summary> /// Add CSS element /// </summary> /// <param name="html">HTML helper</param> /// <param name="location">A location of the script element</param> /// <param name="part">CSS part</param> /// <param name="pageHeadBuilder"></param> public static void AddCssFileParts(this HtmlHelper html, ResourceLocation location, string part, IPageHeadBuilder pageHeadBuilder = null) { if (pageHeadBuilder == null) pageHeadBuilder = EngineContext.Current.Resolve<IPageHeadBuilder>(); pageHeadBuilder.AddCssFileParts(location, part); }
public override void Convert(ResourceLocation source, ResourceLocation dest) { ContentBinaryReader br = new ContentBinaryReader(source); BinaryDataReader data = br.ReadBinaryData(); float xllcorner = data.GetDataSingle("xllcorner"); float yllcorner = data.GetDataSingle("yllcorner"); int width = data.GetDataInt32("width"); int height = data.GetDataInt32("height"); float[] demData = new float[height * width]; int bits = data.GetDataInt32("bits", 32); ContentBinaryReader br2 = data.GetData("data"); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { demData[i * width + j] = br2.ReadSingle(); } } br2.Close(); data.Close(); Half[] demData16 = Half.ConvertToHalf(demData); // ========================================================= BinaryDataWriter result = new BinaryDataWriter(); result.AddEntry("xllcorner", xllcorner); result.AddEntry("yllcorner", yllcorner); result.AddEntry("width", width); result.AddEntry("height", height); result.AddEntry("bits", 16); Stream dataStream = result.AddEntryStream("data"); ContentBinaryWriter bw = new ContentBinaryWriter(dataStream); for (int i = 0; i < demData.Length; i++) { bw.Write(demData16[i].InternalValue); } bw.Close(); bw = new ContentBinaryWriter(dest); bw.Write(result); bw.Close(); }
public override void Convert(ResourceLocation source, ResourceLocation dest) { TDMPIO srcData = new TDMPIO(); srcData.Load(source); srcData.Bits = 12; srcData.Save(dest.GetStream); }
// Internal constructor used by the engine to build // an instance of this class. internal ManifestResourceInfo(String fileName, Assembly assembly, ResourceLocation location) { this.fileName = fileName; this.assembly = assembly; this.location = location; }
public ManifestResourceInfo(Assembly containingAssembly, String containingFileName, ResourceLocation resourceLocation) { _containingAssembly = containingAssembly; _containingFileName = containingFileName; _resourceLocation = resourceLocation; }
public unsafe override void Convert(ResourceLocation source, ResourceLocation dest) { const int origWidth = 64; const int origHeight = 64; const int Id = 'S' << 24 | 'F' << 16 | 'N' << 8 | 'T'; Font font = new Font(currentFont, FontSize); ContentBinaryWriter bw = new ContentBinaryWriter(dest); bw.Write(Id); bw.Write((int)0); bw.Write((int)byte.MaxValue); bw.Write((int)origWidth); bw.Write((int)origHeight); bw.Write(FontSize); for (char c = '\0'; c < 256; c++) { Bitmap bmp = new Bitmap(origWidth, origHeight); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); g.Clear(Color.Black); Size size = TextRenderer.MeasureText(c.ToString(), font); TextRenderer.DrawText(g, c.ToString(), font, new Rectangle(0, 0, origWidth, origHeight) , Color.White, Color.Black, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter); g.Dispose(); BitmapData data = bmp.LockBits(new Rectangle(0, 0, origWidth, origHeight), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); byte* src = (byte*)data.Scan0; bw.Write((ushort)c); bw.Write(size.Width); bw.Write(size.Height); for (int i = 0; i < origHeight; i++) { for (int j = 0; j < origWidth; j++) { byte red = *src++; byte gr = *src++; byte bl = *src++; src++; float lum = (red * 0.3f + gr * 0.59f + bl * 0.11f); bw.Write((byte)lum); } } bmp.UnlockBits(data); //bmp.Save(@"E:\Desktop\out\" + ((ushort)c).ToString() + ".png", ImageFormat.Png); bmp.Dispose(); } bw.Close(); }
public override void Convert(ResourceLocation source, ResourceLocation dest) { XmlModelParser parser = new XmlModelParser(); ParsedXmlModel model = parser.Parse(source.GetStream); }
public void AddScriptParts(ResourceLocation location, params string[] parts) { if (!_scriptParts.ContainsKey(location)) _scriptParts.Add(location, new List<string>()); if (parts != null) foreach (string part in parts) if (!string.IsNullOrEmpty(part)) _scriptParts[location].Add(part); }
public virtual void AddCssFileParts(ResourceLocation location, string part) { if (!_cssParts.ContainsKey(location)) _cssParts.Add(location, new List<string>()); if (string.IsNullOrEmpty(part)) return; _cssParts[location].Add(part); }
/// <summary> /// Adds raw, pre-compressed resource data to a cache. /// </summary> /// <param name="resource">The resource reference to initialize.</param> /// <param name="location">The location where the resource should be stored.</param> /// <param name="data">The pre-compressed data to store.</param> public void AddRaw(ResourceReference resource, ResourceLocation location, byte[] data) { if (resource == null) throw new ArgumentNullException("resource"); resource.ChangeLocation(location); resource.DisableChecksum(); var cache = GetCache(resource); using (var stream = cache.File.Open(FileMode.Open, FileAccess.ReadWrite)) resource.Index = cache.Cache.AddRaw(stream, data); }
public PAKViewer(DesignerAbstractFactory fac, ResourceLocation res) { InitializeComponent(); LanguageParser.ParseLanguage(DevStringTable.Instance, this); LanguageParser.ParseLanguage(DevStringTable.Instance, listView1); Init(fac, res); Saved = true; }
private static string GetResourcePath(string path, ResourceType type, ResourceLocation loc) { if (path.StartsWith("/")) { path = path.Substring(1); } return string.Format("{0}{1}/{2}" , loc == ResourceLocation.Module ? ModuleFolder : ThemeFolder , type.ToString() , path ); }
public virtual void AddScriptParts(ResourceLocation location, string part, bool excludeFromBundle) { if (!_scriptParts.ContainsKey(location)) _scriptParts.Add(location, new List<ScriptReferenceMeta>()); if (string.IsNullOrEmpty(part)) return; _scriptParts[location].Add(new ScriptReferenceMeta() { ExcludeFromBundle = excludeFromBundle, Part = part }); }
public override void Convert(ResourceLocation source, ResourceLocation dest) { Bitmap bmp = new Bitmap(512 * 10, 512 * 5); BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); int ofsX = 0; int ofsY = 0; for (int i = 4; i >= 0; i--) { string[] files = Directory.GetFiles(Path.Combine(srcDir, "000" + i.ToString() + "\\"), "*.*"); for (int j = 0; j < 10; j++) { Bitmap b2 = new Bitmap(files[j]); BitmapData d2 = b2.LockBits(new Rectangle(0, 0, b2.Width, b2.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); int* src = (int*)d2.Scan0; int* dst = (int*)data.Scan0; for (int y = 0; y < b2.Height; y++) { for (int x = 0; x < b2.Width; x++) { dst[(y + ofsY) * bmp.Width + x + ofsX] = src[y * b2.Width + x]; } } ofsX += b2.Width; if (ofsX >= bmp.Width) { ofsX = 0; ofsY += b2.Height; } b2.UnlockBits(d2); b2.Dispose(); } } bmp.UnlockBits(data); Stream stm = dest.GetStream; bmp.Save(stm, ImageFormat.Png); stm.Close(); bmp.Dispose(); }
/// <summary> /// Loads a resource cache from a file. /// </summary> /// <param name="location">The resource cache type.</param> /// <param name="path">The path to the .dat file to read.</param> /// <exception cref="System.InvalidOperationException">Thrown if the cache is already loaded.</exception> public void LoadCache(ResourceLocation location, string path) { if (_loadedCaches.ContainsKey(location)) throw new InvalidOperationException("A resource cache for the " + location + " location has already been loaded."); var file = new FileInfo(path); using (var stream = file.OpenRead()) { _loadedCaches[location] = new LoadedCache { Cache = new ResourceCache(stream), File = file }; } }
public override void Initialize(string tagName, string markup, List<string> tokens) { base.Initialize(tagName, markup, tokens); var parameters = markup.ParseParameters(); if (!parameters.Any()) return; _resourceReferenceParameter = parameters.First(); if (parameters.Count() == 2 && parameters.Last().Equals("head", StringComparison.InvariantCultureIgnoreCase)) { _location = ResourceLocation.Head; } }
public override void Convert(ResourceLocation source, ResourceLocation dest) { TDMPIO src = new TDMPIO(); src.Load(source); float[] rsd = TDmpLodGen.Resize(src.Data, src.Width, src.Height, ResizeSize, ResizeSize); TDMPIO dst = new TDMPIO(); dst.Width = ResizeSize; dst.Height = ResizeSize; dst.Bits = src.Bits; dst.Xllcorner = src.Xllcorner; dst.Yllcorner = src.Yllcorner; dst.XSpan = src.XSpan; dst.YSpan = src.YSpan; dst.Data = rsd; dst.Save(dest.GetStream); }
public unsafe override void Convert(ResourceLocation source, ResourceLocation dest) { Stream stm = source.GetStream; Bitmap bmp = new Bitmap(stm); BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); uint* src = (uint*)data.Scan0; ulong totalR = 0; ulong totalG = 0; ulong totalB = 0; for (int i = 0; i < bmp.Height; i++) { for (int j = 0; j < bmp.Width; j++) { uint clr = src[i * bmp.Width + j]; totalR += ((clr & 0x00ff0000) >> 16); totalG += ((clr & 0x0000ff00) >> 8); totalB += clr & 0xff; } } totalR /= (ulong)(bmp.Width * bmp.Height); totalG /= (ulong)(bmp.Width * bmp.Height); totalB /= (ulong)(bmp.Width * bmp.Height); StringBuilder sb = new StringBuilder(50); sb.Append(totalR.ToString()); sb.Append(", "); sb.Append(totalG.ToString()); sb.Append(", "); sb.Append(totalB.ToString()); iniSect.Add(source.Name, sb.ToString()); stm.Close(); bmp.Dispose(); }
/// <summary> /// Adds a new resource to a cache. /// </summary> /// <param name="resource">The resource reference to initialize.</param> /// <param name="location">The location where the resource should be stored.</param> /// <param name="dataStream">The stream to read the resource data from.</param> /// <exception cref="System.ArgumentNullException">resource</exception> /// <exception cref="System.ArgumentException">The input stream is not open for reading;dataStream</exception> public void Add(ResourceReference resource, ResourceLocation location, Stream dataStream) { if (resource == null) throw new ArgumentNullException("resource"); if (!dataStream.CanRead) throw new ArgumentException("The input stream is not open for reading", "dataStream"); resource.ChangeLocation(location); var cache = GetCache(resource); using (var stream = cache.File.Open(FileMode.Open, FileAccess.ReadWrite)) { var dataSize = (int)(dataStream.Length - dataStream.Position); var data = new byte[dataSize]; dataStream.Read(data, 0, dataSize); uint compressedSize; resource.Index = cache.Cache.Add(stream, data, out compressedSize); resource.CompressedSize = compressedSize; resource.DecompressedSize = (uint)dataSize; resource.DisableChecksum(); } }
public GameConfiguration(ResourceLocation fl) : base(fl.Name, EqualityComparer<string>.Default) { XmlTextReader xml = new XmlTextReader(fl.GetStream); xml.WhitespaceHandling = WhitespaceHandling.None; int depth = xml.Depth; GameConfigurationSection currentSection = null; string currentAttrib = string.Empty; while (MoveToNextElement(xml)) { switch (xml.NodeType) { case XmlNodeType.Element: case XmlNodeType.Text: case XmlNodeType.CDATA: switch (xml.Depth) { case 1: currentSection = new GameConfigurationSection(xml.Name); Add(xml.Name, currentSection); break; case 2: currentAttrib = xml.Name; break; case 3: currentSection.Add(currentAttrib, xml.ReadString()); break; } break; } } xml.Close(); }
private void WriteResources(dynamic Display, TextWriter Output, string resourceType, ResourceLocation? includeLocation, ResourceLocation? excludeLocation) { bool debugMode; var site = _workContext.Value.CurrentSite; switch (site.ResourceDebugMode) { case ResourceDebugMode.Enabled: debugMode = true; break; case ResourceDebugMode.Disabled: debugMode = false; break; default: Debug.Assert(site.ResourceDebugMode == ResourceDebugMode.FromAppSetting, "Unknown ResourceDebugMode value."); debugMode = _httpContextAccessor.Value.Current().IsDebuggingEnabled; break; } var defaultSettings = new RequireSettings { DebugMode = debugMode, CdnMode = site.UseCdn, Culture = _workContext.Value.CurrentCulture, }; var requiredResources = _resourceManager.Value.BuildRequiredResources(resourceType); var appPath = _httpContextAccessor.Value.Current().Request.ApplicationPath; foreach (var context in requiredResources.Where(r => (includeLocation.HasValue ? r.Settings.Location == includeLocation.Value : true) && (excludeLocation.HasValue ? r.Settings.Location != excludeLocation.Value : true))) { var path = context.GetResourceUrl(defaultSettings, appPath); var condition = context.Settings.Condition; var attributes = context.Settings.HasAttributes ? context.Settings.Attributes : null; IHtmlString result; if (resourceType == "stylesheet") { result = Display.Style(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes); } else if (resourceType == "script") { result = Display.Script(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes); } else { result = Display.Resource(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes); } Output.Write(result); } }
public override DocumentBase CreateInstance(ResourceLocation res) { return(new PAKViewer(this, res)); }
public static void AddCssFileParts(this IPageAssetsBuilder builder, ResourceLocation location, bool excludeFromBundling, params string[] parts) { builder.AddCssFileParts(location, parts, excludeFromBundling, false); }
public ZipRemoteFile(ResourceLocation url) : this(url, ProtocolProviderFactory.GetProvider(url.URL)) { }
public bool Contains(ResourceLocation entity) { return(entity.IsDefaultNamespace() && Values.Contains(entity.Path)); }
/// <summary> /// Add script element /// </summary> /// <param name="html">HTML helper</param> /// <param name="location">A location of the script element</param> /// <param name="part">Script part</param> /// <param name="excludeFromBundle">A value indicating whether to exclude this script from bundling</param> public static void AddScriptParts(this IHtmlHelper html, ResourceLocation location, string part, bool excludeFromBundle = false, bool isAsync = false) { var pageHeadBuilder = EngineContextExperimental.Current.Resolve <IPageHeadBuilder>(); pageHeadBuilder.AddScriptParts(location, part, excludeFromBundle, isAsync); }
public static void AddCssFileParts(this HtmlHelper html, ResourceLocation location, params string[] parts) { var pageTitleBuilder = EngineContext.Current.Resolve<IPageTitleBuilder>(); pageTitleBuilder.AddCssFileParts(location, parts); }
/// <summary> /// Append CSS element /// </summary> /// <param name="html">HTML helper</param> /// <param name="location">A location of the script element</param> /// <param name="part">CSS part</param> public static void AppendCssFileParts(this HtmlHelper html, ResourceLocation location, string part) { var pageHeadBuilder = EngineContext.Current.Resolve <IPageHeadBuilder>(); pageHeadBuilder.AppendCssFileParts(location, part); }
public virtual string GenerateScripts(UrlHelper urlHelper, ResourceLocation location, bool? bundleFiles = null) { if (!_scriptParts.ContainsKey(location) || _scriptParts[location] == null) return ""; if (_scriptParts.Count == 0) return ""; if (!bundleFiles.HasValue) { //use setting if no value is specified bundleFiles = _seoSettings.EnableJsBundling && BundleTable.EnableOptimizations; } if (bundleFiles.Value) { var partsToBundle = _scriptParts[location] .Where(x => !x.ExcludeFromBundle) .Select(x => x.Part) .Distinct() .ToArray(); var partsToDontBundle = _scriptParts[location] .Where(x => x.ExcludeFromBundle) .Select(x => x.Part) .Distinct() .ToArray(); var result = new StringBuilder(); if (partsToBundle.Length > 0) { string bundleVirtualPath = GetBundleVirtualPath("~/bundles/scripts/", ".js", partsToBundle); //create bundle lock (s_lock) { var bundleFor = BundleTable.Bundles.GetBundleFor(bundleVirtualPath); if (bundleFor == null) { var bundle = new ScriptBundle(bundleVirtualPath); //bundle.Transforms.Clear(); //"As is" ordering bundle.Orderer = new AsIsBundleOrderer(); //disable file extension replacements. renders scripts which were specified by a developer bundle.EnableFileExtensionReplacements = false; bundle.Include(partsToBundle); BundleTable.Bundles.Add(bundle); } } //parts to bundle result.AppendLine(Scripts.Render(bundleVirtualPath).ToString()); } //parts to do not bundle foreach (var path in partsToDontBundle) { result.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>", urlHelper.Content(path)); result.Append(Environment.NewLine); } return result.ToString(); } else { //bundling is disabled var result = new StringBuilder(); foreach (var path in _scriptParts[location].Select(x => x.Part).Distinct()) { result.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>", urlHelper.Content(path)); result.Append(Environment.NewLine); } return result.ToString(); } }
public virtual string GenerateScripts(UrlHelper urlHelper, ResourceLocation location, bool?bundleFiles = null) { if (!_scriptParts.ContainsKey(location) || _scriptParts[location] == null) { return(""); } if (_scriptParts.Count == 0) { return(""); } if (!bundleFiles.HasValue) { //use setting if no value is specified bundleFiles = _seoSettings.EnableJsBundling && BundleTable.EnableOptimizations; } if (bundleFiles.Value) { var partsToBundle = _scriptParts[location] .Where(x => !x.ExcludeFromBundle) .Select(x => x.Part) .Distinct() .ToArray(); var partsToDontBundle = _scriptParts[location] .Where(x => x.ExcludeFromBundle) .Select(x => x.Part) .Distinct() .ToArray(); var result = new StringBuilder(); if (partsToBundle.Length > 0) { //IMPORTANT: Do not use bundling in web farms or Windows Azure string bundleVirtualPath = GetBundleVirtualPath("~/bundles/scripts/", ".js", partsToBundle); //create bundle lock (s_lock) { var bundleFor = BundleTable.Bundles.GetBundleFor(bundleVirtualPath); if (bundleFor == null) { var bundle = new ScriptBundle(bundleVirtualPath); //bundle.Transforms.Clear(); //"As is" ordering bundle.Orderer = new AsIsBundleOrderer(); //disable file extension replacements. renders scripts which were specified by a developer bundle.EnableFileExtensionReplacements = false; bundle.Include(partsToBundle); BundleTable.Bundles.Add(bundle); } } //parts to bundle result.AppendLine(Scripts.Render(bundleVirtualPath).ToString()); } //parts to do not bundle foreach (var path in partsToDontBundle) { result.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>", urlHelper.Content(path)); result.Append(Environment.NewLine); } return(result.ToString()); } else { //bundling is disabled var result = new StringBuilder(); foreach (var path in _scriptParts[location].Select(x => x.Part).Distinct()) { result.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>", urlHelper.Content(path)); result.Append(Environment.NewLine); } return(result.ToString()); } }
public async Task <PagedList <Cliente> > GetClientes(ClienteQueryFilter filters, ResourceLocation resourceLocation) { var clientes = await _unitOfWork.ClienteRepository.GetAll(); clientes = filters.Dni != null ? clientes = clientes.Where(x => x.Dni == filters.Dni) : clientes; clientes = filters.Nombre != null ? clientes = clientes.Where(x => x.Nombre.ToLower() == filters.Nombre.ToLower()) : clientes; clientes = filters.Apellidos != null ? clientes = clientes.Where(x => x.Apellidos.ToLower() == filters.Apellidos.ToLower()) : clientes; clientes = filters.Email != null ? clientes = clientes.Where(x => x.Email.ToLower().Contains(filters.Email.ToLower())) : clientes; clientes = filters.Telefono != null ? clientes = clientes.Where(x => x.Telefono == filters.Telefono) : clientes; clientes = filters.Direccion != null ? clientes = clientes.Where(x => x.Direccion.ToLower().Contains(filters.Direccion.ToLower())) : clientes; clientes = filters.Nacimiento != null ? clientes = clientes.Where(x => DateTime.Parse(x.Nacimiento).Year == filters.Nacimiento) : clientes; clientes = GetItemsOrdered(clientes, resourceLocation); return(_pagedGenerator.GeneratePagedList(clientes, filters)); }
public virtual string GenerateCssFiles(UrlHelper urlHelper, ResourceLocation location, bool?bundleFiles = null) { if (!_cssParts.ContainsKey(location) || _cssParts[location] == null) { return(""); } //use only distinct rows var distinctParts = _cssParts[location].Distinct().ToList(); if (distinctParts.Count == 0) { return(""); } if (!bundleFiles.HasValue) { //use setting if no value is specified bundleFiles = _seoSettings.EnableCssBundling && BundleTable.EnableOptimizations; } if (bundleFiles.Value) { //bundling is enabled var result = new StringBuilder(); var partsToBundle = distinctParts.ToArray(); if (partsToBundle.Length > 0) { //IMPORTANT: Do not use bundling in web farms or Windows Azure //IMPORTANT: Do not use CSS bundling in virtual categories string bundleVirtualPath = GetBundleVirtualPath("~/bundles/styles/", ".css", partsToBundle); //create bundle lock (s_lock) { var bundleFor = BundleTable.Bundles.GetBundleFor(bundleVirtualPath); if (bundleFor == null) { var bundle = new StyleBundle(bundleVirtualPath); //bundle.Transforms.Clear(); //"As is" ordering bundle.Orderer = new AsIsBundleOrderer(); //disable file extension replacements. renders scripts which were specified by a developer bundle.EnableFileExtensionReplacements = false; foreach (var ptb in partsToBundle) { bundle.Include(ptb, GetCssTranform()); } BundleTable.Bundles.Add(bundle); } } //parts to bundle result.AppendLine(Styles.Render(bundleVirtualPath).ToString()); } return(result.ToString()); } else { //bundling is disabled var result = new StringBuilder(); foreach (var path in distinctParts) { result.AppendFormat("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", urlHelper.Content(path)); result.Append(Environment.NewLine); } return(result.ToString()); } }
public static void AppendScriptParts(this IPageAssetsBuilder builder, ResourceLocation location, bool excludeFromBundling, params string[] parts) { builder.AddScriptParts(location, parts, excludeFromBundling, true); }
public void AppendCssFileParts(ResourceLocation location, params string[] parts) { if (!_cssParts.ContainsKey(location)) _cssParts.Add(location, new List<string>()); if (parts != null) foreach (string part in parts) if (!string.IsNullOrEmpty(part)) _cssParts[location].Insert(0, part); }
public override void Convert(ResourceLocation source, ResourceLocation dest) { throw new NotImplementedException(); }
private void WriteResources(TextWriter Output, string resourceType, ResourceLocation? includeLocation, ResourceLocation? excludeLocation) { bool debugMode = workContext.IsDebug; var defaultSettings = new RequireSettings { DebugMode = debugMode, Culture = CultureInfo.CurrentUICulture.Name, }; var appPath = httpContext.Request.ApplicationPath; if (debugMode == true) { #region debugMode var requiredResources = resourceManager.BuildRequiredResources(resourceType); foreach (var context in requiredResources.Where(r => (includeLocation.HasValue ? r.Settings.Location == includeLocation.Value : true) && (excludeLocation.HasValue ? r.Settings.Location != excludeLocation.Value : true))) { var path = context.GetResourceUrl(defaultSettings, appPath); var condition = context.Settings.Condition; var attributes = context.Settings.HasAttributes ? context.Settings.Attributes : null; //IHtmlString result; //if (resourceType == "stylesheet") //{ // result = Style(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes); //} //else //{ // result = Resource(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes); //} ResourceManager.WriteResource(Output, context.Resource, path, condition, attributes); // Output.Write(result); } #endregion } else { BundleCollection bundles = BundleTable.Bundles; var requiredGroupResources = resourceManager.BuildRequiredGroupResources(resourceType, includeLocation); foreach (var requiredGroupResource in requiredGroupResources) { var disableCompressResources = requiredGroupResource.Value.Where(o => o.Resource.EnableCompress == false).ToArray(); if (disableCompressResources != null) { foreach (var context in disableCompressResources) { var path = context.GetResourceUrl(defaultSettings, appPath); var condition = context.Settings.Condition; var attributes = context.Settings.HasAttributes ? context.Settings.Attributes : null; ResourceManager.WriteResource(Output, context.Resource, path, condition, attributes); } } string virtualPath = string.Format("~/{0}/{1}", resourceType, requiredGroupResource.Key); bool hasValue = BundleResolver.Current.IsBundleVirtualPath(virtualPath); if (!hasValue) { Bundle bundle = null; if (resourceType == "stylesheet") { bundle = new StyleBundle(virtualPath); } else { bundle = new ScriptBundle(virtualPath); } foreach (var context in requiredGroupResource.Value) { if (context.Resource.EnableCompress) { var bundlePath = "~" + context.GetResourceUrl(defaultSettings, appPath); bundle.Include(bundlePath); hasValue = true; } } if (hasValue) bundles.Add(bundle); } if (hasValue) { ResourceManager.WriteResource(Output, requiredGroupResource.Value[0].Resource, bundles.ResolveBundleUrl(virtualPath), null, null); } } } }
public virtual string GenerateCssFiles(UrlHelper urlHelper, ResourceLocation location, bool? bundleFiles = null) { if (!_cssParts.ContainsKey(location) || _cssParts[location] == null) return ""; //use only distinct rows var distinctParts = _cssParts[location].Distinct().ToList(); if (distinctParts.Count == 0) return ""; if (!bundleFiles.HasValue) { //use setting if no value is specified bundleFiles = _seoSettings.EnableCssBundling && BundleTable.EnableOptimizations; } if (bundleFiles.Value) { //bundling is enabled var result = new StringBuilder(); var partsToBundle = distinctParts.ToArray(); if (partsToBundle.Length > 0) { //IMPORTANT: Do not use CSS bundling in virtual categories string bundleVirtualPath = GetBundleVirtualPath("~/bundles/styles/", ".css", partsToBundle); //create bundle lock (s_lock) { var bundleFor = BundleTable.Bundles.GetBundleFor(bundleVirtualPath); if (bundleFor == null) { var bundle = new StyleBundle(bundleVirtualPath); //bundle.Transforms.Clear(); //"As is" ordering bundle.Orderer = new AsIsBundleOrderer(); //disable file extension replacements. renders scripts which were specified by a developer bundle.EnableFileExtensionReplacements = false; foreach (var ptb in partsToBundle) { bundle.Include(ptb, GetCssTranform()); } BundleTable.Bundles.Add(bundle); } } //parts to bundle result.AppendLine(Styles.Render(bundleVirtualPath).ToString()); } return result.ToString(); } else { //bundling is disabled var result = new StringBuilder(); foreach (var path in distinctParts) { result.AppendFormat("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", urlHelper.Content(path)); result.Append(Environment.NewLine); } return result.ToString(); } }
/// <summary> /// Append CSS element /// </summary> /// <param name="html">HTML helper</param> /// <param name="location">A location of the script element</param> /// <param name="part">CSS part</param> public static void AppendCssFileParts(this IHtmlHelper html, ResourceLocation location, string part, bool excludeFromBundle = false) { var pageHeadBuilder = EngineContextExperimental.Current.Resolve <IPageHeadBuilder>(); pageHeadBuilder.AppendCssFileParts(location, part, excludeFromBundle); }
public static void AddCssFileParts(this IPageAssetsBuilder builder, ResourceLocation location, params string[] parts) { builder.AddCssFileParts(location, parts, false, false); }
/// <summary> /// Generate all CSS parts /// </summary> /// <param name="urlHelper">URL Helper</param> /// <param name="location">A location of the script element</param> /// <param name="bundleFiles">A value indicating whether to bundle script elements</param> /// <returns>Generated string</returns> public virtual string GenerateCssFiles(IUrlHelper urlHelper, ResourceLocation location, bool bundleFiles) { if (!_cssParts.ContainsKey(location) || _cssParts[location] == null) { return(""); } if (!_cssParts.Any()) { return(""); } var debugModel = _hostingEnvironment.IsDevelopment(); //CSS bundling is not allowed in virtual directories if (urlHelper.ActionContext.HttpContext.Request.PathBase.HasValue) { bundleFiles = false; } if (bundleFiles) { var partsToBundle = _cssParts[location] .Where(x => !x.ExcludeFromBundle) .Distinct() .ToArray(); var partsToDontBundle = _cssParts[location] .Where(x => x.ExcludeFromBundle) .Distinct() .ToArray(); var result = new StringBuilder(); //parts to bundle if (partsToBundle.Any()) { //ensure \bundles directory exists _fileProvider.CreateDirectory(_fileProvider.GetAbsolutePath("bundles")); var bundle = new Bundle(); foreach (var item in partsToBundle) { var src = debugModel ? item.DebugSrc : item.Src; src = urlHelper.Content(src); //check whether this file exists var srcPath = _fileProvider.Combine(_hostingEnvironment.ContentRootPath, src.Remove(0, 1).Replace("/", "\\")); if (_fileProvider.FileExists(srcPath)) { //remove starting / src = src.Remove(0, 1); } else { //if not, it should be stored into /wwwroot directory src = "wwwroot/" + src; } bundle.InputFiles.Add(src); } //output file var outputFileName = GetBundleFileName(partsToBundle.Select(x => { return(debugModel ? x.DebugSrc : x.Src); }).ToArray()); bundle.OutputFileName = "wwwroot/bundles/" + outputFileName + ".css"; //save var configFilePath = _hostingEnvironment.ContentRootPath + "\\" + outputFileName + ".json"; bundle.FileName = configFilePath; lock (s_lock) { var cacheKey = $"minification.shouldrebuild.css-{outputFileName}"; var shouldRebuild = _staticCacheManager.Get(cacheKey, () => true, 120); if (shouldRebuild) { //process _processor.Process(configFilePath, new List <Bundle> { bundle }); _staticCacheManager.Set(cacheKey, false, 120); } } //render result.AppendFormat("<link href=\"{0}\" rel=\"stylesheet\" type=\"{1}\" />", urlHelper.Content("~/bundles/" + outputFileName + ".min.css"), "text/css"); result.Append(Environment.NewLine); } //parts not to bundle foreach (var item in partsToDontBundle) { var src = debugModel ? item.DebugSrc : item.Src; result.AppendFormat("<link href=\"{0}\" rel=\"stylesheet\" type=\"{1}\" />", urlHelper.Content(src), "text/css"); result.Append(Environment.NewLine); } return(result.ToString()); } else { //bundling is disabled var result = new StringBuilder(); foreach (var item in _cssParts[location].Distinct()) { var src = debugModel ? item.DebugSrc : item.Src; result.AppendFormat("<link href=\"{0}\" rel=\"stylesheet\" type=\"{1}\" />", urlHelper.Content(src), "text/css"); result.AppendLine(); } return(result.ToString()); } }
public static MvcHtmlString NopScripts(this HtmlHelper html, ResourceLocation location, params string[] parts) { var pageTitleBuilder = EngineContext.Current.Resolve<IPageTitleBuilder>(); html.AppendScriptParts(parts); return MvcHtmlString.Create(pageTitleBuilder.GenerateScripts(location)); }
/// <summary> /// Generate all script parts /// </summary> /// <param name="urlHelper">URL Helper</param> /// <param name="location">A location of the script element</param> /// <param name="bundleFiles">A value indicating whether to bundle script elements</param> /// <returns>Generated string</returns> public virtual string GenerateScripts(IUrlHelper urlHelper, ResourceLocation location, bool bundleFiles) { if (!_scriptParts.ContainsKey(location) || _scriptParts[location] == null) { return(""); } if (!_scriptParts.Any()) { return(""); } var debugModel = _hostingEnvironment.IsDevelopment(); if (bundleFiles) { var partsToBundle = _scriptParts[location] .Where(x => !x.ExcludeFromBundle) .Distinct() .ToArray(); var partsToDontBundle = _scriptParts[location] .Where(x => x.ExcludeFromBundle) .Distinct() .ToArray(); var result = new StringBuilder(); //parts to bundle if (partsToBundle.Any()) { //ensure \bundles directory exists _fileProvider.CreateDirectory(_fileProvider.GetAbsolutePath("bundles")); var bundle = new Bundle(); foreach (var item in partsToBundle) { new PathString(urlHelper.Content(debugModel ? item.DebugSrc : item.Src)) .StartsWithSegments(urlHelper.ActionContext.HttpContext.Request.PathBase, out PathString path); var src = path.Value.TrimStart('/'); //check whether this file exists, if not it should be stored into /wwwroot directory if (!_fileProvider.FileExists(_fileProvider.MapPath(path))) { src = $"wwwroot/{src}"; } bundle.InputFiles.Add(src); } //output file var outputFileName = GetBundleFileName(partsToBundle.Select(x => debugModel ? x.DebugSrc : x.Src).ToArray()); bundle.OutputFileName = "wwwroot/bundles/" + outputFileName + ".js"; //save var configFilePath = _hostingEnvironment.ContentRootPath + "\\" + outputFileName + ".json"; bundle.FileName = configFilePath; lock (s_lock) { var cacheKey = $"minification.shouldrebuild.js-{outputFileName}"; var shouldRebuild = _staticCacheManager.Get(cacheKey, () => true, 120); if (shouldRebuild) { //process _processor.Process(configFilePath, new List <Bundle> { bundle }); _staticCacheManager.Set(cacheKey, false, 120); } } //render result.AppendFormat("<script src=\"{0}\"></script>", urlHelper.Content("~/bundles/" + outputFileName + ".min.js")); result.Append(Environment.NewLine); } //parts to not bundle foreach (var item in partsToDontBundle) { var src = debugModel ? item.DebugSrc : item.Src; result.AppendFormat("<script {1}src=\"{0}\"></script>", urlHelper.Content(src), item.IsAsync ? "async " : ""); result.Append(Environment.NewLine); } return(result.ToString()); } else { //bundling is disabled var result = new StringBuilder(); foreach (var item in _scriptParts[location].Distinct()) { var src = debugModel ? item.DebugSrc : item.Src; result.AppendFormat("<script {1}src=\"{0}\"></script>", urlHelper.Content(src), item.IsAsync ? "async " : ""); result.Append(Environment.NewLine); } return(result.ToString()); } }
public string GenerateScripts(ResourceLocation location) { if (!_scriptParts.ContainsKey(location) || _scriptParts[location] == null) return ""; var result = new StringBuilder(); //use only distinct rows foreach (var scriptPath in _scriptParts[location].Distinct()) { result.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>", scriptPath); result.Append(Environment.NewLine); } return result.ToString(); }
public MobEffect(ResourceLocation effect) { Effect = effect; }
public string GenerateCssFiles(ResourceLocation location) { if (!_cssParts.ContainsKey(location) || _cssParts[location] == null) return ""; var result = new StringBuilder(); //use only distinct rows foreach (var cssPath in _cssParts[location].Distinct()) { result.AppendFormat("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", cssPath); result.Append(Environment.NewLine); } return result.ToString(); }
public static void AppendScriptParts(this IPageAssetsBuilder builder, ResourceLocation location, params string[] parts) { builder.AddScriptParts(location, parts, false, true); }