/// <summary> /// Processes the request by loading the Configuration in order to obtain the Graph to be served and then serving it to the client /// </summary> /// <param name="context">HTTP Context</param> public void ProcessRequest(HttpContext context) { this._config = this.LoadConfig(context); //Add our Standard Headers HandlerHelper.AddStandardHeaders(context, this._config); //Check whether we need to use authentication //If there are no user groups then no authentication is in use so we default to authenticated with no per-action authentication needed bool isAuth = true; if (this._config.UserGroups.Any()) { //If we have user isAuth = HandlerHelper.IsAuthenticated(context, this._config.UserGroups); } if (!isAuth) { return; } //Check whether we can just send a 304 Not Modified if (HandlerHelper.CheckCachingHeaders(context, this._config.ETag, null)) { context.Response.StatusCode = (int)HttpStatusCode.NotModified; HandlerHelper.AddCachingHeaders(context, this._config.ETag, null); return; } try { String[] acceptTypes = HandlerHelper.GetAcceptTypes(context); //Retrieve an appropriate MIME Type Definition which can be used to get a Writer MimeTypeDefinition definition = MimeTypesHelper.GetDefinitions(acceptTypes).FirstOrDefault(d => d.CanWriteRdf); if (definition == null) { throw new RdfWriterSelectionException("No MIME Type Definitions have a registered RDF Writer for the MIME Types specified in the HTTP Accept Header"); } IRdfWriter writer = this.SelectWriter(definition); HandlerHelper.ApplyWriterOptions(writer, this._config); IGraph g = this.ProcessGraph(this._config.Graph); if (this._config.ETag == null) { this._config.ETag = this.ComputeETag(g); } //Serve the Graph to the User context.Response.ContentType = definition.CanonicalMimeType; HandlerHelper.AddCachingHeaders(context, this._config.ETag, null); if (writer is IHtmlWriter) { if (!this._config.Stylesheet.Equals(String.Empty)) { ((IHtmlWriter)writer).Stylesheet = this._config.Stylesheet; } } context.Response.ContentEncoding = definition.Encoding; HandlerHelper.ApplyWriterOptions(writer, this._config); writer.Save(g, new StreamWriter(context.Response.OutputStream, definition.Encoding)); this.UpdateConfig(context); } catch (RdfWriterSelectionException) { context.Response.StatusCode = (int)HttpStatusCode.NotAcceptable; } catch { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; } }