This article targets: TIBCO Spotfire S+® Server 8.1 and forward.
This article is intended to help you write Web applications or pure C# applications that send S-PLUS expressions to, or call S-PLUS functions on, a TIBCO Spotfire S+ Server.
The Expression and Function client APIs both contain an Eval method, which returns results as an SplusDataResult object. To display or use the result of a call to the Spotfire S+ Server in a C# application, in most cases, you would need to convert the SPXML comprising the returned object to a native ADO object. That is, if your Spotfire S+ call returns data that you want to display or further process in C#, use the utility method SPXmlFileToDataSet to convert an SplusDataResult to an ADO object.
SPXmlFileToDataSet is the only public method in the Spoftire S+ Server helper class DataSetTransformer in the SplusDataSetSupport namespace of the Spotfire S+ Server C# API.
Creating the SPXML to ADO Project
- Using Microsoft Visual Studio® 8 (any version, including the freely-available Express version), create a blank Visual C# ASP.NET Web Site project.
- For the project's resources, add the server DLLs. (For example, in Visual Studio 2008 Professional Edition, in the Solution Explorer, right-click the project name, and then Add Reference. In the Add Reference dialog, click the Browse tab, and then select the DLLs to add.)
- In the Solution Explorer, expand the folder Default.aspx and note that the project includes a default C# file named Default.aspx.cs.
- In Default.aspx.cs, add the following declarations (note that the last, the Function client DLL, is added for completeness only; this example does not use the Function client).
using System.Data;
using Tibco.SplusServer.Api;
using Tibco.SplusServer.Api.Administration;
using Tibco.SplusServer.Api.DataSetSupport;
using Tibco.SplusServer.Api.Domain;
using Tibco.SplusServer.Api.Expression;
using Tibco.SplusServer.Api.Function;
- In the Solution Explorer, right-click Default.aspx and in the menu, select View Designer.
- From the toolbox, insert a Button and a GridView (
"GridView1").
- Generate a default handler stub for the button by double-clicking it.
- In the Button's stub code, create an Expression Client object, passing in only your Spotfire S+ Server URL:
IExpressionClient api = ClientFactory.GetExpressionClient("http://servername:8080/SplusServer");
- Also, in the stub, add the following to send a synchronous evaluation request that just gets the Spotfire S+ data set
fuel.frame (it is returned as an SplusDataResult object):
SplusDataResult execResult = api.Eval("fuel.frame", false);
NOTE: For simplicity's sake, this example sends a synchronous request. Typically, in a production environment, we recommend sending an asynchronous request and adding a notification listener to listen for the results. (Synchronous requests tie up threads on the server, which can have deleterious effects in a clustered environment.)
- Again, in the Button stub, add the following to create a
DataSet object, calling the utility method SPXmlFileToDataSet, and passing in the SplusValue object of the SplusDataResult:
DataSet ds = DataSetTransformer.SPXmlFileToDataSet(execResult.ReturnValue.SplusValue);
The SplusValue object is converted through the utility SPXmlFileToDataSet.
This utility traverses the SplusValue object and returns an ADO DataSet object containing one or more DataTable objects, accessed through the DataSet's Tables property. Each DataTable is a rectangular data object created from a corresponding Spotfire S+ object.
In this example, it recognizes the data frame as a contiguous rectangular object and returns a DataSet (ds) with one DataTable element. This element is accessed with ds.Tables[0]. (Note that the data appears only at runtime. If you are familiar with the Visual Studio debugger, you might find it useful for sorting through the structure.)
- Finally, in the Button stub, connect the
fuel.frame data to the grid view:
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
- Save the project files and build the project.
- Run the project. Your Web browser displays the button. When you click the button, the grid view is populated as follows:
