private static string ParseDependency(string line) { string path = null; if (line == null) { return(null); } if (line.StartsWith("/// <depends")) { // old way: /// <depends path="$skin/scripts/jquery/jquery.js" /> var startidx = line.IndexOf('"'); var endidx = line.LastIndexOf('"'); path = line.Substring(startidx + 1, endidx - startidx - 1); } else if (line.StartsWith("//")) { // new way: var linePart = line.Substring(2).Trim(); if (linePart.StartsWith(_usingStr)) { // // using $skin/scripts/jquery/jquery.js path = linePart.Substring(_usingStr.Length).Trim(); } else if (linePart.StartsWith(_resourceStr)) { // // resource UserBrowse var className = linePart.Substring(_resourceStr.Length).Trim(); path = ResourceScripter.GetResourceUrl(className); } } return(path); }
// Events ////////////////////////////////////////////////////// protected override void OnInit(EventArgs e) { UITools.AddPickerCss(); UITools.AddScript(UITools.ClientScriptConfigurations.MSAjaxPath); UITools.AddScript(UITools.ClientScriptConfigurations.jQueryPath); UITools.AddScript(UITools.ClientScriptConfigurations.SNWebdavPath); UITools.AddScript(UITools.ClientScriptConfigurations.SNPickerPath); UITools.AddScript(UITools.ClientScriptConfigurations.SNWallPath); UITools.AddScript(ResourceScripter.GetResourceUrl("ActionMenu")); base.OnInit(e); }
private static string ParseDependency(string line) { string path = null; if (line == null) { return(null); } if (line.StartsWith("/// <depends")) { // old way: /// <depends path="$skin/scripts/jquery/jquery.js" /> var startidx = line.IndexOf('"'); var endidx = line.LastIndexOf('"'); path = line.Substring(startidx + 1, endidx - startidx - 1); } else if (line.StartsWith("//")) { // new way: var linePart = line.Substring(2).Trim(); if (linePart.StartsWith(_usingStr)) { // // using $skin/scripts/jquery/jquery.js path = linePart.Substring(_usingStr.Length).Trim(); } else if (linePart.StartsWith(_resourceStr)) { // // resource UserBrowse var className = linePart.Substring(_resourceStr.Length).Trim(); path = ResourceScripter.GetResourceUrl(className); } else { string tempCategory; // template script will be resolved later on-the-fly, when the context is available if (HtmlTemplate.TryParseTemplateCategory(linePart, out tempCategory)) { path = linePart; } } } return(path); }
/// <summary> /// Gets the text content from a given path and processes it. Override this method if you want to implement custom logic when each file is loaded. /// </summary> /// <param name="path">The path from which to the content should be retrieved.</param> /// <returns>The processed text content of the given path, or null if it was not found.</returns> protected virtual string GetTextFromPath(string path) { if (path[0] == '/') { // This is a repository URL var fsPath = HostingEnvironment.MapPath(path); var fileNodeHead = NodeHead.Get(path); var fileNode = fileNodeHead != null && SecurityHandler.HasPermission(fileNodeHead, PermissionType.Open) ? Node.Load <File>(path) : null; System.IO.Stream stream = null; if ((RepositoryPathProvider.DiskFSSupportMode == DiskFSSupportMode.Prefer || fileNode == null) && System.IO.File.Exists(fsPath)) { // If DiskFsSupportMode is Prefer and the file exists, or it's fallback but the node doesn't exist in the repo get it from the file system stream = new System.IO.FileStream(fsPath, System.IO.FileMode.Open, System.IO.FileAccess.Read); } else if (path[0] == '/' && fileNode != null) { // If the node exists, get it from the repo stream = fileNode.Binary.GetStream(); } else if (path.StartsWith("/" + ResourceHandler.UrlPart + "/")) { // Special case, this is a resource URL, we will just render the resource script here var parsed = ResourceHandler.ParseUrl(path); if (parsed == null) { return(null); } var className = parsed.Item2; var culture = CultureInfo.GetCultureInfo(parsed.Item1); try { return(ResourceScripter.RenderResourceScript(className, culture)); } catch (Exception exc) { Logger.WriteException(exc); return(null); } } try { return(stream != null?Tools.GetStreamString(stream) : null); } finally { if (stream != null) { stream.Dispose(); } } } if (path.StartsWith("http://") || path.StartsWith("https://")) { // This is a web URL try { HttpWebRequest req; if (PortalContext.IsKnownUrl(path)) { string url; var ub = new UriBuilder(path); var origHost = ub.Host; ub.Host = "127.0.0.1"; url = ub.Uri.ToString(); req = (HttpWebRequest)HttpWebRequest.Create(url); req.Host = origHost; } else { req = (HttpWebRequest)HttpWebRequest.Create(path); } req.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; var res = req.GetResponse(); using (var st = res.GetResponseStream()) using (var stream = new System.IO.MemoryStream()) { st.CopyTo(stream); var arr = stream.ToArray(); var result = Encoding.UTF8.GetString(arr); return(result); } } catch (Exception exc) { Logger.WriteError(EventId.Bundling.ContentLoadError, "Error during bundle request: " + exc, properties: new Dictionary <string, object> { { "Path", path } }); return(null); } } return(null); }