public override object VisitScript([NotNull] HtmlParser.ScriptContext context) { foreach (var item in context.htmlAttribute()) { var name = item.htmlAttributeName().TAG_NAME().GetText(); if (name.ToUpper() != "SRC") { continue; } var manager = new HtmlAttributeManager(item); var path = manager.Value; Entities.File searchFile = valueProvider.GetFile(path); if (searchFile != null) { if (searchFile.IsExternal) { manager.Value = searchFile.FileName; } return(null); } try { HttpWebRequest req = WebRequest.CreateHttp(path); req.Method = "GET"; var result = req.GetResponse(); var fileName = Path.GetRandomFileName() + ".js"; Entities.File file = new ParseFile().ToParse(fileName, result.GetResponseStream(), Entities.FileType.Js); valueProvider.AddFile(file); file = new Entities.File { Type = file.Type, FileName = file.FileName, SearchName = path, IsExternal = true, }; valueProvider.AddFile(file); manager.Value = fileName; } catch { return(null); } } return(null); }
public void ToEdit(IValueProvider valueProvider) { var htmlFiles = valueProvider.GetFiles(Entities.FileType.Html); List <FileContext> files = new List <FileContext>(); var searcher = new HtmlJsFileSearcher(); foreach (var item in htmlFiles) { var list = searcher.Search(item.Tree); files.AddRange(list); } var uniqFiles = files.Distinct(); File commonFile = new File(); commonFile.FileName = IO.Path.GetRandomFileName(); commonFile.SearchName = commonFile.FileName; commonFile.Type = FileType.Js; ProgramContext program = new ProgramContext(null, 0); SourceElementsContext elems = new SourceElementsContext(program, 0); foreach (var item in uniqFiles) { var tree = item.File.Tree as ProgramContext; var treeElems = tree.sourceElements().sourceElement(); foreach (var elem in treeElems) { elems.AddChild(elem); } valueProvider.RemoveFile(item.File.FileName); } program.AddChild(elems); commonFile.Tree = program; valueProvider.AddFile(commonFile); HtmlAddScriptEditor htmlAdsScript = new HtmlAddScriptEditor(); foreach (var item in htmlFiles) { htmlAdsScript.Add(item.Tree, new File[] { commonFile }); } foreach (var item in files) { item.Context.Remove(); } }
public void ToEdit(IValueProvider valueProvider) { var htmlFiles = valueProvider.GetFiles(Entities.FileType.Html); List <FileContext> files = new List <FileContext>(); var searcher = new HtmlStyleFilesSearcher(); foreach (var item in htmlFiles) { var list = searcher.Search(item.Tree); files.AddRange(list); } var uniqFiles = files.Distinct(); File commonFile = new File(); commonFile.FileName = IO.Path.GetRandomFileName() + ".css"; commonFile.SearchName = commonFile.FileName; commonFile.Type = FileType.Css; StylesheetContext context = new StylesheetContext(null, 0); foreach (var item in uniqFiles) { var style = item.File.Tree as StylesheetContext; var nesteds = style.nestedStatement(); foreach (var nested in nesteds) { nested.parent = context; context.AddChild(nested); } valueProvider.RemoveFile(item.File.FileName); } commonFile.Tree = context; valueProvider.AddFile(commonFile); HtmlAddStyleEditor htmlAddStyle = new HtmlAddStyleEditor(); foreach (var item in htmlFiles) { htmlAddStyle.Add(item.Tree, new File[] { commonFile }); } foreach (var item in files) { item.Context.Remove(); } }
public void Init(IValueProvider valueProvider) { var curContent = styleContext.htmlContent(); var stream = curContent.GetStream(); File = new ParseFile().ToParse(IO.Path.GetRandomFileName(), stream, FileType.Css); File.IsInternal = true; ContentContext content = new ContentContext(styleContext, File); styleContext.Replace(curContent, content); valueProvider.AddFile(File); }
public void Init(IValueProvider valueProvider, IPathProvider pathProvider) { var curContent = scriptContext.htmlContent(); foreach (var attr in scriptContext.htmlAttribute()) { if (attr.htmlAttributeName().TAG_NAME().GetText().ToUpper() == "SRC") { HtmlAttributeManager manager = new HtmlAttributeManager(attr); string path = pathProvider.GetPathFile(manager.Value); File = valueProvider.GetFile(path); if (File == null) { return; } } } if (curContent == null) { return; } HtmlContentContext content = null; if (File == null) { var stream = curContent.GetStream(); File = new ParseFile().ToParse(IO.Path.GetRandomFileName(), stream, FileType.Js); File.IsInternal = true; valueProvider.AddFile(File); content = new ContentContext(scriptContext, File); } else { BufferValueContext <File> bufferValue = new BufferValueContext <File>(scriptContext, File); scriptContext.AddChild(bufferValue); content = new HtmlContentContext(scriptContext, 0); } scriptContext.Replace(curContent, content); }