. . . . . . . . . . . "2017-06-13T05:45:25Z" . "VirtSPASQLWinFormApp" . . . . . . . . . "VirtSPASQLWinFormApp" . . . . "%META:TOPICPARENT{name=\"VirtAdoNet35Provider\"}%\n\n---+ Creating a Windows Forms Application To Access RDF Data Using The Virtuoso ADO.Net Provider\n\n%TOC%\n\n---++ Introduction\n\nThis document will guide you through creating a simple application that allows you to access RDF \ndata in a Virtuoso database as an Entity DataSet and explore that RDF data in \nan intuitive way by clicking on dereferenceable \n[[http://docs.openlinksw.com/virtuoso/rdfdatarepresentation.html#rdfiriidtype][IRIs]].\n\n---++ Prerequisites\n\n 1 Microsoft Visual Studio 2008\n 1 The Virtuoso ADO.Net provider for .Net 3.5 and the Entity Framework\n 1 The example assumes that you have a local Virtuoso server with the Northwind demo \ndatabase installed. If the demo database is not already installed then download the \n[[http://s3.amazonaws.com/opldownload/uda/vad-packages/6.1/virtuoso/demo_dav.vad][demo database VAD package]] \n(demo_dav.vad) and install it. The VAD package will create a new database in \nVirtuoso called demo containing the familiar Northwind tables. It will also creates \n[[http://docs.openlinksw.com/virtuoso/rdfsparqlintegrationmiddleware.html#rdfviews][Linked Data Views]] \nof the Northwind tables. In the example we assume the database is accessible on a hostname of \n\"demo.openlinksw.com\" on the default port 80, where an actually live \ninstance of the Virtuoso Demo database is hosted. Users would use the appropriate hostname and \nport number of their Virtuoso installation to create the sample application, and would be \nlocalhost:8890 for a default installation or whatever the \n[[http://docs.openlinksw.com/virtuoso/databaseadmsrv.html#ini_URIQA][URIQA DefaultHost]]\nVirtuoso configuration parameter is set to when the demo database VAD package is installed.\n\n---++ Creating the Application\n\n---+++ Step 1 - Create a view of the RDF data\n\nWe want to be able to access the RDF data in Visual Studio and the easiest way to do this is \nto create a view of the data that we are interested in and bind that view to a \nDataSet. This can be considered as using server side \n[[http://docs.openlinksw.com/virtuoso/rdfsparql.html][SPARQL]]. Virtuoso supports an \nextension to standard SQL that allows execution of\n[[http://docs.openlinksw.com/virtuoso/rdfsparql.html#rdfsparqlinline][SPARQL within a SQL statement]]. \nIf a SQL query begins with the keyword SPARQL then the rest of the query is interpreted by \nas SPARQL. If a SPARQL query is used as the definition of a view then that view can be \nmanipulated using SQL like any other view. In this way the result set from a SPARQL query \ncan be easily accessed from Visual Studio using ADO.Net and the Entity Framework.\n\n 1. To create a view of the customers in the Northwind, first open the Virtuoso Conductor and log \nin as dba.\n * Note:\n * If the view is added to the Visual Studio project as user \"demo\" (or any other than \"dba'), \nthen it must be ensured that the \"SPARQL_SELECT\" and \"SPARQL_SPONGE\" roles are assigned to this \nuser, which can be done via the Virtuoso Conductor in the \"System Admin\" -> \"User Accounts\" tab.\n * Execute permissions will also need to be granted to the following procedure:\n\nGRANT EXECUTE \n ON DB.DBA.RDF_MAKE_LONG_OF_SQLVAL \n TO \"demo\"\n\n 1. Then open iSQL from the menu on the left and execute the following \nstatement --\n\nCREATE VIEW Demo.demo.sparqlview AS\n SPARQL\n PREFIX nwind: \n SELECT DISTINCT ?s \n FROM \n WHERE { ?s a nwind:Customer }\n\n%BR%%BR%%BR%%BR%\n\n---+++ Step 2 - Create a simple grid form in Visual Studio\n\n 1 Open *Visual Studio* and create a new *Windows Forms Application* called \nRDFDemo.\n 1 In the *Form Designer* drag a DataGridView on to the form. \n 1 Click the *Choose Data Source* drop down and select *Add Project Data Source*. \n%BR%%BR%%BR%%BR%\n 1 In the *Data* *Source* *Configuration Wizard* choose *Database* and then set up \na connection to the demo database on your local Virtuoso server. \n 1 On the *Choose Your Data Objects* page expand the *Views* and select sparqlview.\n%BR%%BR%%BR%%BR% \n 1 Click *Finish*.\n 1 In the *Form* *Designer* select dataGridView1 and change the \nAutoSizeColumnsMode to AllCellsExceptHeader. \n 1 Select the DefaultCellStyle and click on the ellipsis. This will \nopen the CellStyleBuilder. Change the ForeColor \nto Blue.\n%BR%%BR%%BR%%BR%\n 1 Expand *Font* and change *Underline* to True. Click *OK*.\n\n---+++ Step 3 - Change the mapping of the DataSet\n\n 1 In the *Solution Explorer* you will now have a DataSet called \nDemoDataSet.xsd. \n 1 If you double click on this it opens the DataSet Designer. \n 1 Select the column called s in the sparqlview table, and in the *Properties* pane,\nchange the DataType from System.String to System.Object. \n * The data returned by a SPARQL query can either be an \n[[http://docs.openlinksw.com/virtuoso/rdfdatarepresentation.html#rdfiriidtype][IRI]] \nor a literal value. In order to distinguish between the two the Virtuoso ADO.Net \nprovider defines an additional data type, SQLExtendedString. By setting \nthe column type to System.Object we can cast the fetched data back to \nSQLExtendedString and find out if an individual value is an \nIRI or a literal and handle it appropriately. \n\n---+++ Step 4 - Create the on_click event handler for the cells in the DataGridView\n\n 1 Return to the *Form* *Designer* and double click on the cell of the \nDataGridView. This creates the \ndataGridView1_CellContentClick method in Form1.cs. \nThis is the method that handles clicking on \nIRI objects in the grid.\n 1 Paste the following block of code into the body of the \ndataGridView1_CellContentClick method.\n\nint column = e.ColumnIndex;\n object o = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;\n Type t = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ValueType;\n\n if (o is SqlExtendedString)\n { \n SqlExtendedString se = (SqlExtendedString) o; \n ExtendedStringHandler seHandler = new ExtendedStringHandler(se, this.sparqlviewTableAdapter.Connection);\n seHandler.displayData();\n }\n else if (o is SqlRdfBox)\n { \n //doesn't do anything at the moment\n }\n\n 1 As we are using the SQLExtendedString extension from the Virtuoso ADO.Net \nprovider you will also need to add\n \nusing OpenLink.Data.Virtuoso;\n\nat the top of the file.\n\n---+++ Step 5 - Create a class to handle exploring the RDF data\n\n 1 Add a new C# class to the project called ExtendedStringHandler, by \nright-clicking on RDFDemo in the *Solution* *Explorer* and *Add* a Class.\n 1 Add the following using statements to the top of the file\n\nusing OpenLink.Data.Virtuoso;\nusing System.Data;\nusing System.Windows.Forms;\nusing System.Drawing;\nusing System.Data.Mapping;\nusing System.Data.Common;\n\n 1 Paste the following block of code into the class definition.\n\nStringBuilder DescribeCommand;\nVirtuosoConnection ParentConnection;\nList\n 1 The ExtendedStringHandler class creates a new SPARQL query based on the IRI \nthat was clicked. This query is executed against Virtuoso using the ADO.Net connection in \nthe same way that any SQL statement would be executed across an ADO.Net connection. This \ncan be considered as Client Side SPARQL. The result set from the query describes the selected \nobject and is returned as an ADO.Net DataAdapter. The \nDataAdapter is used to fill a DataTable which is displayed \non a new form. We now need to add the new DataSet to the project and define \nthe DataTable that will hold the query results.\n\n---+++ Step 6 - Add a new Data Set to hold the query results\n\n 1 Right click RDFDemo in the *Solution* *Explorer* and add a new \nDataSet. Call the new DataSet \nDescribeDataSet.\n%BR%%BR%%BR%%BR%\n 1 Double click on DescribeDataSet in the *Solution Explorer* to open \nthe DataSet Designer and drag a DataTable \nfrom the Toolbox into it. \n 1 Add two columns, p and o, to the DataTable and set the \nDataType of each column to System.Object.\n%BR%%BR%%BR%%BR%\n\n---+++ Step 7 - Build and run the application\n\n 1 You should see a form displaying all the Northwind customers, like this.\n%BR%%BR%%BR%%BR% \n 1 When any customer is clicked it opens a new form showing customer details.\n%BR%%BR%%BR%%BR% \n 1 Clicking on the links in the new form allows you to drill down further to get order, \nproduct, location details etc.\n%BR%%BR%%BR%%BR% \n%BR%%BR%%BR%%BR% \n\n---++ Next Steps\n\nYou will notice if you keep clicking on the links that this application will only display \ndata that is held in the Northwind graph. Clicking on an external link, for example the \nlink to Berlin in dbpedia, http://dbpedia.org/resource/Berlin, results \nin a empty window and an error message. The next step is to \n[[VirtSPASQLRDFDemoExternalDereferencing][extend this application so that it can handle dereferencing external IRIs]]. \n\n" . . . . "2017-06-13T05:45:25.371523"^^ . "2017-06-13T05:45:25.371523"^^ . "2017-06-13T05:45:25Z" . . "1393a4d6a6238463fd455091d43068d0" . . . . . "VirtSPASQLWinFormApp" .