public void ProcessRequest(HttpContext context) { //Turn on Response Buffering context.Response.Buffer = true; //Prepare the Cache Directories if (!Path.IsPathRooted(this._cacheDir)) { this._cacheDir = context.Server.MapPath(this._cacheDir); } if (this._loader == null) { this._loader = new ExpansionLoader(this._cacheDir); } //Add our Custom Headers try { context.Response.Headers.Add("X-dotNetRDF-Version", Assembly.GetAssembly(typeof(VDS.RDF.IGraph)).GetName().Version.ToString()); } catch (PlatformNotSupportedException) { context.Response.AddHeader("X-dotNetRDF-Version", Assembly.GetAssembly(typeof(VDS.RDF.IGraph)).GetName().Version.ToString()); } try { //Retrieve the desired URI and Profile URI from Querystring parameters String uri = context.Request.QueryString["uri"]; String profile = context.Request.QueryString["profile"]; if (uri == null) { if (context.Request.Url.Query.Equals(String.Empty)) { throw new ArgumentNullException("uri", "Required uri parameter used to designate the URI you wish to expand was not found. Your request must use a URI of the form " + context.Request.Url.ToString() + "?uri=" + Uri.EscapeDataString("http://example.org")); } else { throw new ArgumentNullException("uri", "Required uri parameter used to designate the URI you wish to expand was not found. Your request must use a URI of the form " + context.Request.Url.ToString().Replace(context.Request.Url.Query, String.Empty) + "?uri=" + Uri.EscapeDataString("http://example.org")); } } //Note that the ExpansionLoader class automatically handles all the Caching for us IInMemoryQueryableStore store; String uriHash = new Uri(uri).GetSha256Hash(); if (profile == null) { //Use Default Profile store = this._loader.Load(new Uri(uri)); } else { //Use Custom Profile store = this._loader.Load(new Uri(uri), new Uri(profile)); } String ctype; IStoreWriter writer = MimeTypesHelper.GetStoreWriter(context.Request.AcceptTypes, out ctype); context.Response.ContentType = ctype; writer.Save(store, new StreamParams(context.Response.OutputStream)); } catch (ArgumentNullException argNull) { HandleErrors(context, "Missing Argument", argNull); } catch (RdfParseException parseEx) { HandleErrors(context, "RDF Parser Error", parseEx); } catch (RdfException rdfEx) { HandleErrors(context, "RDF Error", rdfEx); } catch (Exception ex) { HandleErrors(context, "Error", ex); } }
public void ProcessRequest(HttpContext context) { //Turn on Response Buffering context.Response.Buffer = true; //Prepare the Cache Directories if (!Path.IsPathRooted(this._cacheDir)) { this._cacheDir = context.Server.MapPath(this._cacheDir); } if (this._loader == null) this._loader = new ExpansionLoader(this._cacheDir); //Add our Custom Headers try { context.Response.Headers.Add("X-dotNetRDF-Version", Assembly.GetAssembly(typeof(VDS.RDF.IGraph)).GetName().Version.ToString()); } catch (PlatformNotSupportedException) { context.Response.AddHeader("X-dotNetRDF-Version", Assembly.GetAssembly(typeof(VDS.RDF.IGraph)).GetName().Version.ToString()); } try { //Retrieve the desired URI and Profile URI from Querystring parameters String uri = context.Request.QueryString["uri"]; String profile = context.Request.QueryString["profile"]; if (uri == null) { if (context.Request.Url.Query.Equals(String.Empty)) { throw new ArgumentNullException("uri", "Required uri parameter used to designate the URI you wish to expand was not found. Your request must use a URI of the form " + context.Request.Url.ToString() + "?uri=" + Uri.EscapeDataString("http://example.org")); } else { throw new ArgumentNullException("uri", "Required uri parameter used to designate the URI you wish to expand was not found. Your request must use a URI of the form " + context.Request.Url.ToString().Replace(context.Request.Url.Query, String.Empty) + "?uri=" + Uri.EscapeDataString("http://example.org")); } } //Note that the ExpansionLoader class automatically handles all the Caching for us IInMemoryQueryableStore store; String uriHash = new Uri(uri).GetSha256Hash(); if (profile == null) { //Use Default Profile store = this._loader.Load(new Uri(uri)); } else { //Use Custom Profile store = this._loader.Load(new Uri(uri), new Uri(profile)); } String ctype; IStoreWriter writer = MimeTypesHelper.GetStoreWriter(context.Request.AcceptTypes, out ctype); context.Response.ContentType = ctype; writer.Save(store, new StreamParams(context.Response.OutputStream)); } catch (ArgumentNullException argNull) { HandleErrors(context, "Missing Argument", argNull); } catch (RdfParseException parseEx) { HandleErrors(context, "RDF Parser Error", parseEx); } catch (RdfException rdfEx) { HandleErrors(context, "RDF Error", rdfEx); } catch (Exception ex) { HandleErrors(context, "Error", ex); } }