private byte[] GetFile(string filePath) { if (this.theme == null || !this.theme.Exists) { string resourceName = "Gablarski.WebServer.Html." + filePath; Stream resourceStream; if (!ResourceNames.Contains(resourceName) || (resourceStream = WebAssembly.GetManifestResourceStream(resourceName)) == null) { return(null); } byte[] resourceBuffer = new byte[resourceStream.Length]; resourceStream.Read(resourceBuffer, 0, resourceBuffer.Length); return(resourceBuffer); } else { try { FileInfo file = new FileInfo(Path.Combine(theme.FullName, filePath)); if (!file.Exists) { return(null); } var fs = file.OpenRead(); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); return(buffer); } catch { return(null); } } }
/// <summary> /// Load a template into a <see cref="T:System.IO.TextReader"/> and return it. /// </summary> /// <param name="path">Relative path (and filename) to template.</param> /// <returns> /// a <see cref="T:System.IO.TextReader"/> if file was found; otherwise null. /// </returns> public TextReader LoadTemplate(string path) { var rs = WebAssembly.GetManifestResourceStream(ResourcePrefix + path); return(rs != null ? new StreamReader(rs) : null); }