/// <summary> /// Process this package /// </summary> public AppletAsset Process(string file, bool optimize) { try { if (optimize && !file.EndsWith(".min.css")) { var content = RemoveWhiteSpaceFromStylesheets(File.ReadAllText(file)); return(new AppletAsset() { MimeType = "text/css", Content = PakManTool.CompressContent(content) }); } else { return new AppletAsset() { MimeType = "text/css", Content = PakManTool.CompressContent(File.ReadAllText(file)) } }; } catch (Exception e) { Emit.Message("ERROR", "Error processing CSS file {0}: {1}", file, e.Message); throw; } }
/// <summary> /// Process the file /// </summary> public AppletAsset Process(string file, bool optimize) { try { String content = File.ReadAllText(file); return(new AppletAsset() { MimeType = "application/json", Content = PakManTool.CompressContent(content) }); } catch (Exception e) { Emit.Message("ERROR", "Cannot process JavaScript file {0} : {1}", file, e.Message); throw; } }
/// <summary> /// Process the XML file /// </summary> public virtual AppletAsset Process(string file, bool optimize) { // Verify that the file is XML try { var xe = new XmlDocument(); xe.Load(file); if (optimize) { using (var ms = new MemoryStream()) using (var xw = XmlWriter.Create(ms, new XmlWriterSettings() { Indent = false, OmitXmlDeclaration = true })) { xe.WriteContentTo(xw); xw.Flush(); return(new AppletAsset() { MimeType = "text/xml", Content = PakManTool.CompressContent(ms.ToArray()) }); } } else { return new AppletAsset() { MimeType = "text/xml", Content = PakManTool.CompressContent(File.ReadAllBytes(file)) } }; } catch (XmlException e) { Emit.Message("ERROR", " {0} is not well formed - {1} - @{2}:{3}", file, e.Message, e.LineNumber, e.LinePosition); throw; } }
/// <summary> /// Process the file /// </summary> public AppletAsset Process(string file, bool optimize) { try { var mime = System.Web.MimeMapping.GetMimeMapping(file); if (String.IsNullOrEmpty(mime)) { mime = "application/x-octet-stream"; } return(new AppletAsset() { MimeType = mime, Content = PakManTool.CompressContent(File.ReadAllBytes(file)) }); } catch (Exception e) { Emit.Message("ERROR", " Cannot process {0}: {1}", file, e.Message); throw; } }
/// <summary> /// Process the file /// </summary> public AppletAsset Process(string file, bool optimize) { try { String content = File.ReadAllText(file); if (optimize && !file.Contains("rules") && !file.Contains(".min.js")) { var minifier = new Ext.Net.Utilities.JSMin(); // HACK : JSMIN Hates /// Reference content = new Regex(@"\/\/\/\s?\<Reference.*", RegexOptions.IgnoreCase).Replace(content, ""); content = minifier.Minify(content); } return(new AppletAsset() { MimeType = "text/javascript", Content = PakManTool.CompressContent(content) }); } catch (Exception e) { Emit.Message("ERROR", "Cannot process JavaScript file {0} : {1}", file, e.Message); throw; } }