private void ProcessTestDirectory(String dir)
        {
            Console.WriteLine("## Processing Directory '" + dir + "'");

            //First need to find the manifest file
            if (File.Exists(dir + "manifest.ttl"))
            {
                Graph manifest = new Graph();
                manifest.BaseUri = new Uri("file:///" + Path.GetFullPath(dir));
                try
                {
                    FileLoader.Load(manifest, dir + "manifest.ttl");
                    Console.WriteLine("Loaded Tests Manifest OK");
                    Console.WriteLine();
                }
                catch (RdfParseException parseEx)
                {
                    this.ReportError("Manifest Parser Error for Directory '" + dir + "'", parseEx);
                }

                //Ensure qt and ut namespaces
                manifest.NamespaceMap.AddNamespace("qt", new Uri("http://www.w3.org/2001/sw/DataAccess/tests/test-query#"));
                manifest.NamespaceMap.AddNamespace("ut", new Uri("http://www.w3.org/2009/sparql/tests/test-update#"));

                //Create necessary Uri Nodes
                IUriNode rdfType = manifest.CreateUriNode("rdf:type");
                IUriNode rdfsComment = manifest.CreateUriNode("rdfs:comment");
                IUriNode positiveSyntaxTest = manifest.CreateUriNode("mf:PositiveSyntaxTest");
                IUriNode positiveSyntaxTest11 = manifest.CreateUriNode("mf:PositiveSyntaxTest11");
                IUriNode positiveUpdateSyntaxTest = manifest.CreateUriNode("mf:PositiveUpdateSyntaxTest11");
                IUriNode negativeSyntaxTest = manifest.CreateUriNode("mf:NegativeSyntaxTest");
                IUriNode negativeSyntaxTest11 = manifest.CreateUriNode("mf:NegativeSyntaxTest11");
                IUriNode negativeUpdateSyntaxTest = manifest.CreateUriNode("mf:NegativeUpdateSyntaxTest11");
                IUriNode evaluationTest = manifest.CreateUriNode("mf:QueryEvaluationTest");
                IUriNode updateEvaluationTest = manifest.CreateUriNode("ut:UpdateEvaluationTest");
                IUriNode action = manifest.CreateUriNode("mf:action");
                IUriNode result = manifest.CreateUriNode("mf:result");
                IUriNode approval = manifest.CreateUriNode("dawgt:approval");
                IUriNode approvedTest = manifest.CreateUriNode("dawgt:Approved");
                IUriNode unclassifiedTest = manifest.CreateUriNode("dawgt:NotClassified");
                IUriNode query = manifest.CreateUriNode("qt:query");
                IUriNode data = manifest.CreateUriNode("qt:data");
                IUriNode graphData = manifest.CreateUriNode("qt:graphData");

                //Create SPARQL Query Parser
                SparqlQueryParser queryParser = new SparqlQueryParser();
                SparqlUpdateParser updateParser = new SparqlUpdateParser();
                queryParser.DefaultBaseUri = (manifest.BaseUri != null ? manifest.BaseUri : manifest.NamespaceMap.GetNamespaceUri(String.Empty));
                updateParser.DefaultBaseUri = manifest.NamespaceMap.GetNamespaceUri(String.Empty);

                //Find all the Positive Syntax Tests
                foreach (Triple t in manifest.GetTriplesWithPredicateObject(rdfType, positiveSyntaxTest).Concat(manifest.GetTriplesWithPredicateObject(rdfType, positiveSyntaxTest11)).Concat(manifest.GetTriplesWithPredicateObject(rdfType, positiveUpdateSyntaxTest)))
                {
                    //Test ID
                    INode testID = t.Subject;

                    //See whether the Test is approved
                    if (manifest.Triples.Contains(new Triple(testID, approval, approvedTest)) || manifest.Triples.Contains(new Triple(testID, approval, unclassifiedTest)))
                    {
                        tests++;
                        testsSyntax++;

                        //Find the Test Query
                        Triple queryDef = manifest.Triples.WithSubjectPredicate(testID, action).FirstOrDefault();
                        if (queryDef != null)
                        {
                            this.ProcessSyntaxTest(queryParser, updateParser, queryDef.Object.ToString(), true);
                        }
                        else
                        {
                            Console.WriteLine("Unable to find the Test Query/Update for Syntax Test ID '" + testID.ToString() + "' in '" + dir + "'");
                            testsIndeterminate++;
                            testsSyntaxIndeterminate++;
                        }

                        Debug.WriteLine(tests + " Tests Completed");
                    }
                    
                }

                //Find all the Negative Syntax Tests
                foreach (Triple t in manifest.GetTriplesWithPredicateObject(rdfType, negativeSyntaxTest).Concat(manifest.GetTriplesWithPredicateObject(rdfType, negativeSyntaxTest11)).Concat(manifest.GetTriplesWithPredicateObject(rdfType, negativeUpdateSyntaxTest)))
                {
                    //Test ID
                    INode testID = t.Subject;

                    //See whether the Test is approved
                    if (manifest.Triples.Contains(new Triple(testID, approval, approvedTest)) || manifest.Triples.Contains(new Triple(testID, approval, unclassifiedTest)))
                    {
                        tests++;
                        testsSyntax++;

                        //Find the Test Query
                        Triple queryDef = manifest.Triples.WithSubjectPredicate(testID, action).FirstOrDefault();
                        if (queryDef != null)
                        {
                            this.ProcessSyntaxTest(queryParser, updateParser, queryDef.Object.ToString(), false);
                        }
                        else
                        {
                            Console.WriteLine("Unable to find the Test Query/Update for Syntax Test ID '" + testID.ToString() + "' in '" + dir + "'");
                            testsIndeterminate++;
                            testsSyntaxIndeterminate++;
                        }

                        Debug.WriteLine(tests + " Tests Completed");
                    }
                }

                //Find all the Query Evaluation Tests
                foreach (Triple t in manifest.Triples.WithPredicateObject(rdfType, evaluationTest))
                {
                    //Test ID
                    INode testID = t.Subject;

                    //See whether the Test is approved
                    if (manifest.Triples.Contains(new Triple(testID, approval, approvedTest)) || manifest.Triples.Contains(new Triple(testID, approval, unclassifiedTest)))
                    {
                        tests++;
                        testsEvaluation++;
                        
                        //Find the Action ID
                        Triple actionDef = manifest.Triples.WithSubjectPredicate(testID, action).FirstOrDefault();
                        if (actionDef != null)
                        {
                            INode actionID = actionDef.Object;

                            //Get the Query
                            Triple queryDef = manifest.Triples.WithSubjectPredicate(actionID, query).FirstOrDefault();
                            if (queryDef != null)
                            {
                                //Get the Default Graph
                                Triple defaultGraphDef = manifest.Triples.WithSubjectPredicate(actionID, data).FirstOrDefault();
                                String defGraph = (defaultGraphDef == null) ? null : defaultGraphDef.Object.ToString();

                                //Get the Named Graphs if any
                                List<String> namedGraphs = manifest.Triples.WithSubjectPredicate(actionID, graphData).Select(gdef => gdef.Object.ToString()).ToList();

                                //Get the expected Result
                                Triple resultDef = manifest.Triples.WithSubjectPredicate(testID, result).FirstOrDefault();
                                if (resultDef != null)
                                {
                                    //Try to get the comments on the Test
                                    Triple commentDef = manifest.Triples.WithSubjectPredicate(testID, rdfsComment).FirstOrDefault();

                                    //Run the Evaluation Test
                                    int eval = this.ProcessEvaluationTest(queryParser, commentDef, queryDef.Object.ToString(), defGraph, namedGraphs, resultDef.Object.ToString());
                                }
                                else
                                {
                                    Console.WriteLine("Unable to find the Expected Result file for Test ID '" + testID.ToString() + "' in '" + dir + "'");
                                    testsIndeterminate++;
                                    testsEvaluationIndeterminate++;
                                }
                            }
                            else
                            {
                                Console.WriteLine("Unable to find the Test Query for Test ID '" + testID.ToString() + "' in '" + dir + "'");
                                testsIndeterminate++;
                                testsEvaluationIndeterminate++;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Unable to find the Action for Test ID '" + testID.ToString() + "' + in + '" + dir + "'");
                            testsIndeterminate++;
                            testsEvaluationIndeterminate++;
                        }

                        Console.WriteLine();
                        Console.WriteLine(new String('-', 150));
                    }

                    Debug.WriteLine(tests + " Tests Completed");
                }

                //Find all the Update Evaluation Tests
                foreach (Triple t in manifest.GetTriplesWithPredicateObject(rdfType, updateEvaluationTest))
                {
                    if (manifest.Triples.Contains(new Triple(t.Subject, approval, approvedTest)) || manifest.Triples.Contains(new Triple(t.Subject, approval, unclassifiedTest)))
                    {
                        tests++;
                        testsEvaluation++;
                        int eval = this.ProcessUpdateEvaluationTest(manifest, t.Subject);

                        Console.WriteLine();
                        Console.WriteLine(new String('-', 150));

                        Debug.WriteLine(tests + " Tests Completed");
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine("## Finished processing directory '" + dir + "'");
            Console.WriteLine(new String('=', 150));
            Console.WriteLine();

            //if (dir.EndsWith("il8n\\"))
            //{
            //    Options.UriNormalization = true;
            //}
        }
Exemple #2
0
        public void RunDeploy(String[] args)
        {
            if (args.Length < 3)
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: 3 Arguments are required in order to use the -deploy mode, type rdfWebDeploy -help to see usage summary");
                return;
            }
            if (args.Length > 3)
            {
                if (!this.SetOptions(args.Skip(3).ToArray()))
                {
                    Console.Error.WriteLine("rdfWebDeploy: Deployment aborted since one/more options were not valid");
                    return;
                }
            }

            if (this._noLocalIIS)
            {
                Console.WriteLine("rdfWebDeploy: No Local IIS Server available so switching to -xmldeploy mode");
                XmlDeploy xdeploy = new XmlDeploy();
                xdeploy.RunXmlDeploy(args);
                return;
            }

            //Define the Server Manager object
            Admin.ServerManager manager = null;

            try
            {
                //Connect to the Server Manager
                if (!this._noIntegratedRegistration) manager = new Admin.ServerManager();

                //Open the Configuration File
                System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(args[1], this._site);
                Console.Out.WriteLine("rdfWebDeploy: Opened the Web.config file for the specified Web Application");

                //Detect Folders
                String appFolder = Path.GetDirectoryName(config.FilePath);
                String binFolder = Path.Combine(appFolder, "bin\\");
                String appDataFolder = Path.Combine(appFolder, "App_Data\\");
                if (!Directory.Exists(binFolder))
                {
                    Directory.CreateDirectory(binFolder);
                    Console.WriteLine("rdfWebDeploy: Created a bin\\ directory for the web application");
                }
                if (!Directory.Exists(appDataFolder))
                {
                    Directory.CreateDirectory(appDataFolder);
                    Console.WriteLine("rdfWebDeploy: Created an App_Data\\ directory for the web application");
                }

                //Deploy dotNetRDF and required DLLs to the bin directory of the application
                String sourceFolder = RdfWebDeployHelper.ExecutablePath;
                foreach (String dll in RdfWebDeployHelper.RequiredDLLs)
                {
                    if (File.Exists(Path.Combine(sourceFolder, dll)))
                    {
                        File.Copy(Path.Combine(sourceFolder, dll), Path.Combine(binFolder, dll), true);
                        Console.WriteLine("rdfWebDeploy: Deployed " + dll + " to the web applications bin directory");
                    }
                    else
                    {
                        Console.Error.WriteLine("rdfWebDeploy: Error: Required DLL " + dll + " which needs deploying to the web applications bin directory could not be found");
                        return;
                    }
                }

                //Deploy the configuration file to the App_Data directory
                if (File.Exists(args[2]))
                {
                    File.Copy(args[2], Path.Combine(appDataFolder, args[2]), true);
                    Console.WriteLine("rdfWebDeploy: Deployed the configuration file to the web applications App_Data directory");
                }
                else if (!File.Exists(Path.Combine(appDataFolder, args[2])))
                {
                    Console.Error.WriteLine("rdfWebDeploy: Error: Unable to continue deployment as the configuration file " + args[2] + " could not be found either locally for deployment to the App_Data folder or already present in the App_Data folder");
                    return;
                }

                //Set the AppSetting for the configuration file
                config.AppSettings.Settings.Remove("dotNetRDFConfig");
                config.AppSettings.Settings.Add("dotNetRDFConfig", "~/App_Data/" + Path.GetFileName(args[2]));
                Console.WriteLine("rdfWebDeploy: Set the \"dotNetRDFConfig\" appSetting to \"~/App_Data/" + Path.GetFileName(args[2]) + "\"");

                //Now load the Configuration Graph from the App_Data folder
                Graph g = new Graph();
                FileLoader.Load(g, Path.Combine(appDataFolder, args[2]));

                Console.WriteLine("rdfWebDeploy: Successfully deployed required DLLs and appSettings");
                Console.WriteLine();

                //Get the sections of the Configuration File we want to edit
                HttpHandlersSection handlersSection = config.GetSection("system.web/httpHandlers") as HttpHandlersSection;
                if (handlersSection == null)
                {
                    Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Handlers section of the web applications Web.Config file");
                    return;
                }

                //Detect Handlers from the Configution Graph and deploy
                IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
                IUriNode dnrType = g.CreateUriNode(new Uri(ConfigurationLoader.ConfigurationNamespace + "type"));
                IUriNode httpHandler = g.CreateUriNode(new Uri(ConfigurationLoader.ConfigurationNamespace + "HttpHandler"));

                //Deploy for IIS Classic Mode
                if (!this._noClassicRegistration)
                {
                    Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Classic Mode");
                    foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandler).Select(t => t.Subject))
                    {
                        if (n.NodeType == NodeType.Uri)
                        {
                            String handlerPath = ((IUriNode)n).Uri.AbsolutePath;
                            INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault();
                            if (type == null)
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified");
                                continue;
                            }
                            if (type.NodeType == NodeType.Literal)
                            {
                                String handlerType = ((ILiteralNode)type).Value;

                                //First remove any existing registration
                                handlersSection.Handlers.Remove("*", handlerPath);

                                //Then add the new registration
                                handlersSection.Handlers.Add(new HttpHandlerAction(handlerPath, handlerType, "*"));

                                Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file");
                            }
                            else
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal");
                                continue;
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node");
                        }
                    }

                    //Deploy Negotiate by File Extension if appropriate
                    if (this._negotiate)
                    {
                        HttpModulesSection modulesSection = config.GetSection("system.web/httpModules") as HttpModulesSection;
                        if (modulesSection == null)
                        {
                            Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Modules section of the web applications Web.Config file");
                            return;
                        }
                        modulesSection.Modules.Remove("NegotiateByExtension");
                        modulesSection.Modules.Add(new HttpModuleAction("NegotiateByExtension", "VDS.RDF.Web.NegotiateByFileExtension"));
                        Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module");
                    }

                    Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Classic Mode");
                }

                //Save the completed Configuration File
                config.Save(ConfigurationSaveMode.Minimal);
                Console.WriteLine();

                //Deploy for IIS Integrated Mode
                if (!this._noIntegratedRegistration)
                {
                    Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Integrated Mode");
                    Admin.Configuration adminConfig = manager.GetWebConfiguration(this._site, args[1]);
                    Admin.ConfigurationSection newHandlersSection = adminConfig.GetSection("system.webServer/handlers");
                    Admin.ConfigurationElementCollection newHandlers = newHandlersSection.GetCollection();

                    foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandler).Select(t => t.Subject))
                    {
                        if (n.NodeType == NodeType.Uri)
                        {
                            String handlerPath = ((IUriNode)n).Uri.AbsolutePath;
                            INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault();
                            if (type == null)
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified");
                                continue;
                            }
                            if (type.NodeType == NodeType.Literal)
                            {
                                String handlerType = ((ILiteralNode)type).Value;

                                //First remove any existing registration
                                foreach (Admin.ConfigurationElement oldReg in newHandlers.Where(el => el.GetAttributeValue("name").Equals(handlerPath)).ToList())
                                {
                                    newHandlers.Remove(oldReg);
                                }

                                //Then add the new registration
                                Admin.ConfigurationElement reg = newHandlers.CreateElement("add");
                                reg["name"] = handlerPath;
                                reg["path"] = handlerPath;
                                reg["verb"] = "*";
                                reg["type"] = handlerType;
                                newHandlers.AddAt(0, reg);

                                Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file");
                            }
                            else
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal");
                                continue;
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node");
                        }

                        //Deploy Negotiate by File Extension if appropriate
                        if (this._negotiate)
                        {
                            Admin.ConfigurationSection newModulesSection = adminConfig.GetSection("system.webServer/modules");
                            if (newModulesSection == null)
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Modules section of the web applications Web.Config file");
                                return;
                            }

                            //First remove the Old Module
                            Admin.ConfigurationElementCollection newModules = newModulesSection.GetCollection();
                            foreach (Admin.ConfigurationElement oldReg in newModules.Where(el => el.GetAttribute("name").Equals("NegotiateByExtension")).ToList())
                            {
                                newModules.Remove(oldReg);
                            }

                            //Then add the new Module
                            Admin.ConfigurationElement reg = newHandlers.CreateElement("add");
                            reg["name"] = "NegotiateByFileExtension";
                            reg["type"] = "VDS.RDF.Web.NegotiateByFileExtension";
                            newModules.AddAt(0, reg);

                            Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module");
                        }
                    }

                    manager.CommitChanges();
                    Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Integrated Mode");
                }

            }
            catch (ConfigurationException configEx)
            {
                Console.Error.Write("rdfWebDeploy: Configuration Error: " + configEx.Message);
            }
            catch (Exception ex)
            {
                Console.Error.Write("rdfWebDeploy: Error: " + ex.Message);
            }
            finally
            {
                if (manager != null) manager.Dispose();
            }
        }
Exemple #3
0
        public void RunXmlDeploy(String[] args)
        {
            if (args.Length < 3)
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: 3 Arguments are required in order to use the -xmldeploy mode, type rdfWebDeploy -help to see usage summary");
                return;
            }
            if (args.Length > 3)
            {
                if (!this.SetOptions(args.Skip(3).ToArray()))
                {
                    Console.Error.WriteLine("rdfWebDeploy: Deployment aborted since one/more options were not valid");
                    return;
                }
            }

            try
            {
                //Determine the path to the Web.config file if possible
                if (args[1].Equals("."))
                {
                    args[1] = Path.Combine(".", "Web.config");
                }
                else if (Path.GetFileName(args[1]).Equals(String.Empty))
                {
                    //If we were given a Folder Path then add Web.config to the end
                    args[1] = Path.Combine(args[1], "Web.config");
                } 
                else  if (!Path.GetFileName(args[1]).Equals("Web.config", StringComparison.OrdinalIgnoreCase))
                {
                    //If out path was to a file and it wasn't a Web.config file we error
                    Console.Error.WriteLine("rdfWebDeploy: Error: You must specify a Web.config file for the web application you wish to deploy to");
                    return;
                }

                //Open the Configuration File
                XmlDocument config = new XmlDocument();
                if (File.Exists(args[1]))
                {
                    //If the File exists open it
                    config.Load(args[1]);

                    //Verify this does appear to be a Web.config file
                    if (!config.DocumentElement.Name.Equals("configuration"))
                    {
                        Console.Error.WriteLine("rdfWebDeploy: Error: The Web.Config file for the Web Application does not appear to be a valid Web.Config file");
                        return;
                    }
                }
                else
                {
                    //If the Web.Config file doesn't exist then create one
                    XmlDeclaration decl = config.CreateXmlDeclaration("1.0", "utf-8", null);
                    config.AppendChild(decl);
                    XmlElement docEl = config.CreateElement("configuration");
                    config.AppendChild(docEl);
                    config.Save(args[1]);
                }
                Console.Out.WriteLine("rdfWebDeploy: Opened the Web.Config file for the specified Web Application");
                
                XmlNode reg = null;

                //Detect Folders
                String appFolder = Path.GetDirectoryName(args[1]);
                String binFolder = Path.Combine(appFolder, "bin\\");
                String appDataFolder = Path.Combine(appFolder, "App_Data\\");
                if (!Directory.Exists(binFolder))
                {
                    Directory.CreateDirectory(binFolder);
                    Console.WriteLine("rdfWebDeploy: Created a bin\\ directory for the web application");
                }
                if (!Directory.Exists(appDataFolder))
                {
                    Directory.CreateDirectory(appDataFolder);
                    Console.WriteLine("rdfWebDeploy: Created an App_Data\\ directory for the web application");
                }

                //Deploy dotNetRDF and required DLLs to the bin directory of the application
                String sourceFolder = RdfWebDeployHelper.ExecutablePath;
                IEnumerable<String> dlls = RdfWebDeployHelper.RequiredDLLs;
                if (this._sql) dlls = dlls.Concat(RdfWebDeployHelper.RequiredSqlDLLs);
                if (this._virtuoso) dlls = dlls.Concat(RdfWebDeployHelper.RequiredVirtuosoDLLs);
                if (this._fulltext) dlls = dlls.Concat(RdfWebDeployHelper.RequiredFullTextDLLs);
                foreach (String dll in dlls)
                {
                    if (File.Exists(Path.Combine(sourceFolder, dll)))
                    {
                        File.Copy(Path.Combine(sourceFolder, dll), Path.Combine(binFolder, dll), true);
                        Console.WriteLine("rdfWebDeploy: Deployed " + dll + " to the web applications bin directory");
                    }
                    else
                    {
                        Console.Error.WriteLine("rdfWebDeploy: Error: Required DLL " + dll + " which needs deploying to the web applications bin directory could not be found");
                        return;
                    }
                }

                //Deploy the configuration file to the App_Data directory
                if (File.Exists(args[2]))
                {
                    File.Copy(args[2], Path.Combine(appDataFolder, args[2]), true);
                    Console.WriteLine("rdfWebDeploy: Deployed the configuration file to the web applications App_Data directory");
                }
                else if (!File.Exists(Path.Combine(appDataFolder, args[2])))
                {
                    Console.Error.WriteLine("rdfWebDeploy: Error: Unable to continue deployment as the configuration file " + args[2] + " could not be found either locally for deployment to the App_Data folder or already present in the App_Data folder");
                    return;
                }

                //Set the AppSetting for the configuration file
                XmlNodeList appSettingsNodes = config.DocumentElement.GetElementsByTagName("appSettings");
                XmlNode appSettings;
                if (appSettingsNodes.Count == 0)
                {
                    appSettings = config.CreateElement("appSettings");
                    config.DocumentElement.AppendChild(appSettings);
                }
                else if (appSettingsNodes.Count > 1)
                {
                    Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <appSettings> node exists");
                    return;
                }
                else
                {
                    appSettings = appSettingsNodes[0];
                }
                XmlNode configFileSetting = null;
                foreach (XmlNode setting in appSettings.ChildNodes)
                {
                    if (setting.Attributes.GetNamedItem("key") != null)
                    {
                        if (setting.Attributes["key"].Value.Equals("dotNetRDFConfig"))
                        {
                            configFileSetting = setting;
                            break;
                        }
                    }
                }
                if (configFileSetting == null)
                {
                    configFileSetting = config.CreateElement("add");
                    XmlAttribute attr = config.CreateAttribute("key");
                    attr.Value = "dotNetRDFConfig";
                    configFileSetting.Attributes.Append(attr);
                    attr = config.CreateAttribute("value");
                    attr.Value = "~/App_Data/" + Path.GetFileName(args[2]);
                    configFileSetting.Attributes.Append(attr);
                    appSettings.AppendChild(configFileSetting);
                }
                else
                {
                    configFileSetting.Attributes["value"].Value = "~/App_Data/" + Path.GetFileName(args[2]);
                }
                Console.WriteLine("rdfWebDeploy: Set the \"dotNetRDFConfig\" appSetting to \"~/App_Data/" + Path.GetFileName(args[2]) + "\"");

                //Now load the Configuration Graph from the App_Data folder
                Graph g = new Graph();
                FileLoader.Load(g, Path.Combine(appDataFolder, args[2]));

                Console.WriteLine("rdfWebDeploy: Successfully deployed required DLLs and appSettings");
                config.Save(args[1]);
                Console.WriteLine();

                //Detect Handlers from the Configution Graph and deploy
                IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
                IUriNode dnrType = g.CreateUriNode(new Uri(ConfigurationLoader.ConfigurationNamespace + "type"));
                IUriNode httpHandlerType = g.CreateUriNode(new Uri(ConfigurationLoader.ConfigurationNamespace + "HttpHandler"));

                //Deploy for IIS Classic Mode
                if (!this._noClassicRegistration)
                {
                    Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Classic Mode");

                    //Get the appropriate section of the Config File
                    XmlNodeList systemWebNodes = config.DocumentElement.GetElementsByTagName("system.web");
                    XmlElement systemWeb;
                    if (systemWebNodes.Count == 0)
                    {
                        systemWeb = config.CreateElement("system.web");
                        config.DocumentElement.AppendChild(systemWeb);
                    }
                    else if (systemWebNodes.Count > 1)
                    {
                        Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <system.web> node exists");
                        return;
                    }
                    else
                    {
                        systemWeb = (XmlElement)systemWebNodes[0];
                    }

                    XmlNodeList httpHandlersNodes = systemWeb.GetElementsByTagName("httpHandlers");
                    XmlElement httpHandlers;
                    if (httpHandlersNodes.Count == 0)
                    {
                        httpHandlers = config.CreateElement("httpHandlers");
                        systemWeb.AppendChild(httpHandlers);
                    }
                    else if (httpHandlersNodes.Count > 1)
                    {
                        Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <httpHandlers> node exists");
                        return;
                    }
                    else
                    {
                        httpHandlers = (XmlElement)httpHandlersNodes[0];
                    }

                    foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandlerType).Select(t => t.Subject))
                    {
                        if (n.NodeType == NodeType.Uri)
                        {
                            String handlerPath = ((IUriNode)n).Uri.AbsolutePath;
                            INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault();
                            if (type == null)
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified");
                                continue;
                            }
                            if (type.NodeType == NodeType.Literal)
                            {
                                String handlerType = ((ILiteralNode)type).Value;

                                //Add XML to register the Handler
                                reg = null;
                                foreach (XmlNode existingReg in httpHandlers.ChildNodes)
                                {
                                    if (existingReg.Attributes.GetNamedItem("path") != null)
                                    {
                                        if (existingReg.Attributes["path"].Value.Equals(handlerPath))
                                        {
                                            reg = existingReg;
                                            break;
                                        }
                                    }
                                }
                                if (reg == null)
                                {
                                    reg = config.CreateElement("add");
                                    XmlAttribute attr = config.CreateAttribute("path");
                                    attr.Value = handlerPath;
                                    reg.Attributes.Append(attr);
                                    attr = config.CreateAttribute("verb");
                                    attr.Value = "*";
                                    reg.Attributes.Append(attr);
                                    attr = config.CreateAttribute("type");
                                    attr.Value = handlerType;
                                    reg.Attributes.Append(attr);
                                    httpHandlers.AppendChild(reg);
                                }
                                else
                                {
                                    reg.Attributes["type"].Value = handlerType;
                                }

                                Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file");
                            }
                            else
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal");
                                continue;
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node");
                        }
                    }

                    //Deploy Negotiate by File Extension
                    if (this._negotiate)
                    {
                        XmlNodeList httpModulesNodes = systemWeb.GetElementsByTagName("httpModules");
                        XmlElement httpModules;
                        if (httpModulesNodes.Count == 0)
                        {
                            httpModules = config.CreateElement("httpModules");
                            systemWeb.AppendChild(httpModules);
                        }
                        else if (httpModulesNodes.Count > 1)
                        {
                            Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <httpModules> node exists");
                            return;
                        }
                        else
                        {
                            httpModules = (XmlElement)httpModulesNodes[0];
                        }
                        reg = null;
                        foreach (XmlNode existingReg in httpModules.ChildNodes)
                        {
                            if (existingReg.Attributes.GetNamedItem("name") != null)
                            {
                                if (existingReg.Attributes["name"].Value.Equals("NegotiateByExtension"))
                                {
                                    reg = existingReg;
                                    break;
                                }
                            }
                        }
                        if (reg == null)
                        {
                            reg = config.CreateElement("add");
                            XmlAttribute name = config.CreateAttribute("name");
                            name.Value = "NegotiateByExtension";
                            reg.Attributes.Append(name);
                            XmlAttribute type = config.CreateAttribute("type");
                            type.Value = "VDS.RDF.Web.NegotiateByFileExtension";
                            reg.Attributes.Append(type);
                            httpModules.AppendChild(reg);
                        }
                        Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module");
                    }

                    config.Save(args[1]);
                    Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Classic Mode");
                }

                Console.WriteLine();

                //Deploy for IIS Integrated Mode
                if (!this._noIntegratedRegistration)
                {
                    Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Integrated Mode");

                    //Get the appropriate section of the Config File
                    XmlNodeList systemWebServerNodes = config.DocumentElement.GetElementsByTagName("system.webServer");
                    XmlElement systemWebServer;
                    if (systemWebServerNodes.Count == 0)
                    {
                        systemWebServer = config.CreateElement("system.webServer");
                        config.DocumentElement.AppendChild(systemWebServer);
                    }
                    else if (systemWebServerNodes.Count > 1)
                    {
                        Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <system.webServer> node exists");
                        return;
                    }
                    else
                    {
                        systemWebServer = (XmlElement)systemWebServerNodes[0];
                    }

                    //Set the <validation validateIntegratedModeConfiguration="false" /> element
                    XmlNodeList validateNodes = systemWebServer.GetElementsByTagName("validation");
                    if (validateNodes.Count > 0)
                    {
                        foreach (XmlNode validate in validateNodes)
                        {
                            if (validate.Attributes.GetNamedItem("validateIntegratedModeConfiguration") != null)
                            {
                                validate.Attributes["validateIntegratedModeConfiguration"].Value = "false";
                            }
                            else
                            {
                                XmlAttribute valAttr = config.CreateAttribute("validateIntegratedModeConfiguration");
                                valAttr.Value = "false";
                                validate.Attributes.Append(valAttr);
                            }
                        }
                    }
                    else
                    {
                        XmlElement valEl = config.CreateElement("validation");
                        XmlAttribute valAttr = config.CreateAttribute("validateIntegratedModeConfiguration");
                        valAttr.Value = "false";
                        valEl.Attributes.Append(valAttr);
                        systemWebServer.AppendChild(valEl);
                    }

                    //Find <handlers> element
                    XmlNodeList httpHandlersNodes = systemWebServer.GetElementsByTagName("handlers");
                    XmlElement httpHandlers;
                    if (httpHandlersNodes.Count == 0)
                    {
                        httpHandlers = config.CreateElement("handlers");
                        systemWebServer.AppendChild(httpHandlers);
                    }
                    else if (httpHandlersNodes.Count > 1)
                    {
                        Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <handlers> node exists");
                        return;
                    }
                    else
                    {
                        httpHandlers = (XmlElement)httpHandlersNodes[0];
                    }

                    foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandlerType).Select(t => t.Subject))
                    {
                        if (n.NodeType == NodeType.Uri)
                        {
                            String handlerPath = ((IUriNode)n).Uri.AbsolutePath;
                            INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault();
                            if (type == null)
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified");
                                continue;
                            }
                            if (type.NodeType == NodeType.Literal)
                            {
                                String handlerType = ((ILiteralNode)type).Value;

                                //Add XML to register the Handler
                                reg = null;
                                foreach (XmlNode existingReg in httpHandlers.ChildNodes)
                                {
                                    if (existingReg.Attributes.GetNamedItem("path") != null)
                                    {
                                        if (existingReg.Attributes["path"].Value.Equals(handlerPath))
                                        {
                                            reg = existingReg;
                                            break;
                                        }
                                    }
                                }
                                if (reg == null)
                                {
                                    reg = config.CreateElement("add");
                                    XmlAttribute attr = config.CreateAttribute("name");
                                    attr.Value = handlerPath;
                                    reg.Attributes.Append(attr);                                        
                                    attr = config.CreateAttribute("path");
                                    attr.Value = handlerPath;
                                    reg.Attributes.Append(attr);
                                    attr = config.CreateAttribute("verb");
                                    attr.Value = "*";
                                    reg.Attributes.Append(attr);
                                    attr = config.CreateAttribute("type");
                                    attr.Value = handlerType;
                                    reg.Attributes.Append(attr);
                                    httpHandlers.AppendChild(reg);
                                }
                                else
                                {
                                    reg.Attributes["type"].Value = handlerType;
                                }

                                Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file");
                            }
                            else
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal");
                                continue;
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node");
                        }
                    }

                    //Deploy Negotiate by File Extension
                    if (this._negotiate)
                    {
                        XmlNodeList httpModulesNodes = systemWebServer.GetElementsByTagName("modules");
                        XmlElement httpModules;
                        if (httpModulesNodes.Count == 0)
                        {
                            httpModules = config.CreateElement("modules");
                            systemWebServer.AppendChild(httpModules);
                        }
                        else if (httpModulesNodes.Count > 1)
                        {
                            Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <modules> node exists");
                            return;
                        }
                        else
                        {
                            httpModules = (XmlElement)httpModulesNodes[0];
                        }
                        reg = null;
                        foreach (XmlNode existingReg in httpModules.ChildNodes)
                        {
                            if (existingReg.Attributes.GetNamedItem("name") != null)
                            {
                                if (existingReg.Attributes["name"].Value.Equals("NegotiateByExtension"))
                                {
                                    reg = existingReg;
                                    break;
                                }
                            }
                        }
                        if (reg == null)
                        {
                            reg = config.CreateElement("add");
                            XmlAttribute name = config.CreateAttribute("name");
                            name.Value = "NegotiateByExtension";
                            reg.Attributes.Append(name);
                            XmlAttribute type = config.CreateAttribute("type");
                            type.Value = "VDS.RDF.Web.NegotiateByFileExtension";
                            reg.Attributes.Append(type);
                            httpModules.AppendChild(reg);
                        }
                        Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module");
                    }

                    config.Save(args[1]);
                    Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Integrated Mode");
                }

            }
            catch (ConfigurationException configEx)
            {
                Console.Error.Write("rdfWebDeploy: Configuration Error: " + configEx.Message);
            }
            catch (Exception ex)
            {
                Console.Error.Write("rdfWebDeploy: Error: " + ex.Message);
            }
        }