/// <summary> /// Entry point for the program which launches the server /// </summary> /// <param name="args">Command Line Arguments</param> static void Main(string[] args) { try { RdfServerOptions options = new RdfServerOptions(args); switch (options.Mode) { case RdfServerConsoleMode.Run: using (HttpServer server = options.GetServerInstance()) { if (!options.QuietMode) { Console.WriteLine("rdfServer: Running"); } server.Start(); while (true) { Thread.Sleep(1000); } } break; case RdfServerConsoleMode.Quit: return; } if (!options.QuietMode) { Console.WriteLine("rdfServer: Finished - press any key to exit"); Console.ReadKey(); } } catch (Exception ex) { Console.Error.WriteLine("rdfServer: Error: An unexpected error occurred while trying to start up the Server. See subsequent error messages for details:"); Console.Error.WriteLine(ex.Message); Console.Error.WriteLine(ex.StackTrace); while (ex.InnerException != null) { Console.Error.WriteLine(); Console.Error.WriteLine("Inner Exception:"); Console.Error.WriteLine(ex.InnerException.Message); Console.Error.WriteLine(ex.InnerException.StackTrace); ex = ex.InnerException; } } }
/// <summary> /// Processes a request /// </summary> /// <param name="context">Server Context</param> public void ProcessRequest(HttpServerContext context) { //Get the server options RdfServerOptions options = context.Server.AppSettings[RdfServerOptions.ServerOptionsKey] as RdfServerOptions; if (options == null) { throw new DotNetRdfConfigurationException("rdfServer Options were not found"); } //Get the configuration graph IGraph g = context.Server.Context[RdfServerOptions.DotNetRdfConfigKey] as IGraph; if (g == null) { g = options.LoadConfigurationGraph(); if (g == null) { throw new DotNetRdfConfigurationException("The HTTP Server does not contain a Configuration Graph in its State Information"); } context.Server.Context[RdfServerOptions.DotNetRdfConfigKey] = g; } //Generate the expected Path and try and load the Configuration using the appropriate Node String expectedPath; WebConfigurationLoader.FindObject(g, context.Request.Url, out expectedPath); INode objNode = g.GetUriNode(new Uri("dotnetrdf:" + expectedPath)); if (objNode == null) { throw new DotNetRdfConfigurationException("The Configuration Graph does not contain a URI Node with the expected URI <dotnetrdf:" + expectedPath + ">"); } this._config = new SparqlServerConfiguration(g, objNode); //Dispath the request appropriately String path = context.Request.Url.AbsolutePath; path = path.Substring(path.LastIndexOf('/') + 1); switch (path) { case "query": this.ProcessQueryRequest(context); break; case "update": this.ProcessUpdateRequest(context); break; case "description": //TODO: Add Service Description support context.Response.StatusCode = (int)HttpStatusCode.NotImplemented; break; default: //TODO: Can we easily add Protocol Support or not? //this.ProcessProtocolRequest(context); context.Response.StatusCode = (int)HttpStatusCode.NotFound; break; } }