Example #1
0
        private static MediaTypeFormatter CreateHtmlMicrodataFormatter(HttpConfiguration config)
        {
            var formatter = new HtmlMicrodataFormatter();

            // optional: use HtmlMicrodataFormatter for clients that request xml
            //formatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/xml"));
            //formatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml"));

            // optional: insert css and javascript
            const string bootstrapUrl            = "//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css";
            const string formTemplateRelativeUrl = "/Scripts/formtemplate.min.js";
            var          formTemplateUrl         = (config.VirtualPathRoot.Length == 1 ? "" : config.VirtualPathRoot) + formTemplateRelativeUrl;

            formatter.AddHeadContent(new XElement("title", "Actualizador"));
            formatter.AddHeadContent(
                new XElement("link",
                             new XAttribute("rel", "stylesheet"),
                             new XAttribute("href", bootstrapUrl)));
            formatter.AddHeadContent(
                new XElement("script",
                             new XAttribute("src", formTemplateUrl),
                             new XText("")));

            // optional: addd custom serializers to control how a specific Type is rendered as html:
            //formatter.RegisterSerializer(new ToStringSerializer(typeof (Version)));

            return(formatter);
        }
Example #2
0
 public void SetUp()
 {
     formatter     = new HtmlMicrodataFormatter();
     request       = new HttpRequestMessage(HttpMethod.Get, "http://localhost/");
     configuration = new HttpConfiguration(new HttpRouteCollection("/"));
     request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, configuration);
 }