public WebRequestOutput HandleRequest(WebRequestInput requestInput) { WebRequestOutput output = new WebRequestOutput(); Assembly assembly = Assembly.GetAssembly(this.GetType()); var resourceName = $"{assembly.GetName().Name}.Content{requestInput.RequestFileName.Replace('/', '.').Replace("..", ".")}"; var stream = assembly.GetManifestResourceStream(resourceName); if (stream != null) { using (stream) { using (StreamReader reader = new StreamReader(stream)) { string result = reader.ReadToEnd(); output.ContentType = "application/octet-stream"; output.Response = result; } } } else { output.Error = new ResourceNotFoundError(); } return output; }
public WebRequestOutput Create(string applicationPath, Uri uri, XmlDocument xmlDocument) { if (uri == null) throw new ArgumentNullException(nameof(uri)); if (xmlDocument == null) throw new ArgumentNullException(nameof(xmlDocument)); StringBuilder stringBuilder = new StringBuilder(); TextWriter textWriter = new StringWriter(stringBuilder); RenderContext renderContext = new RenderContext(new HtmlTextWriter(textWriter), referenceService, uri, applicationPath); WebRequestOutput output = new WebRequestOutput { ContentType = "text/html" }; IEnumerable<Type> availableTypes = this.GetType().Assembly.GetTypes().Where(t => typeof(IElement).IsAssignableFrom(t) && t.IsAbstract == false && t.IsInterface == false); var currentNode = xmlDocument.SelectSingleNode("/*[1]"); try { var element = CreateElement(renderContext, currentNode, availableTypes); var template = controlTemplateBinder.BindTemplate(element, renderContext); // TODO: Initialization to add scripts. template.Render(); output.Response = stringBuilder.ToString(); renderContext.HtmlTextWriter.Close(); } catch(ControlNotSupportedExecption cne) { output.Error = new ControlNotSupportedError(cne.NodeName); } return output; }