public static string GetStringAsset(string path, IMapPathResolver mapPathResolver, string webRoot, string pagePath) { if (DetectBundle(path)) { using (var webClient = new WebClient()) { try { var style = webClient.DownloadString(webRoot + path); return(style); } catch (WebException wex) { // TODO: log web exception return(string.Empty); } } } var localpath = mapPathResolver.MapPath(pagePath, path); if (File.Exists(localpath)) { var style = File.ReadAllText(localpath); return(style); } else { return(string.Empty); } }
public static async Task <byte[]> GetBinaryAsset(string path, IMapPathResolver mapPathResolver, string webRoot, string pagePath) { byte[] content = null; try { var localpath = mapPathResolver.MapPath(pagePath, path); if (File.Exists(localpath)) { content = File.ReadAllBytes(localpath); } } catch (Exception ex) { // TODO: trace somewhere } if (content == null) { using (var webClient = new HttpClient()) { try { if (path.StartsWith("http") || path.StartsWith("//")) { content = await webClient.GetByteArrayAsync(path); } else { content = await webClient.GetByteArrayAsync(webRoot + path); } } catch (Exception ex) { // TODO: trace somewhere } } } return(content); }
public static async Task <string> GetStringAsset(string path, IMapPathResolver mapPathResolver, string webRoot, string pagePath) { var stringContent = string.Empty; try { var localpath = mapPathResolver.MapPath(pagePath, path); if (File.Exists(localpath)) { stringContent = File.ReadAllText(localpath); } } catch (Exception ex) { /* TODO: Trace something */ } if (stringContent == string.Empty) { using (var webClient = new HttpClient()) { try { if (path.StartsWith("http") || path.StartsWith("//")) { stringContent = await webClient.GetStringAsync(path); } else { stringContent = await webClient.GetStringAsync(webRoot + path); } } catch (WebException wex) { // TODO: log web exception } } } return(stringContent); }
public static byte[] GetBinaryAsset(string path, IMapPathResolver mapPathResolver, string webRoot, string pagePath) { if (DetectBundle(path)) { using (var webClient = new WebClient()) { var asset = webClient.DownloadData(webRoot + path); return(asset); } } var localpath = mapPathResolver.MapPath(pagePath, path); if (File.Exists(localpath)) { var asset = File.ReadAllBytes(localpath); return(asset); } else { return(new byte[] { }); } }
public static async Task <byte[]> GetBinaryAsset(string path, IMapPathResolver mapPathResolver, string webRoot, string pagePath) { if (DetectBundle(path)) { using (var webClient = new HttpClient()) { var asset = await webClient.GetByteArrayAsync(webRoot + path); return(asset); } } var localpath = mapPathResolver.MapPath(pagePath, path); if (File.Exists(localpath)) { var asset = File.ReadAllBytes(localpath); return(asset); } else { return(new byte[] { }); } }