Database Reference
In-Depth Information
Custom Data Provider Class (Listing 4-6):
Before beginning, it is important to understand some of the key concepts. First, prepare
to query data from those data sources that are not natively supported. Second, these
operations must be asynchronous in order to perform the tasks in a timely fashion. And,
most importantly, methods used must be thread-safe.
The
Microsoft.Office.Visio.Server
assembly provides these functionalities
with its abstract class
AddonDataHandler
and its abstract methods that deal with all the
necessary data module implementations.
Add a reference to
Microsoft.Office.Visio.Server
as the derived class will be
inheriting the
AddonDataHandler
abstract class. It needs to also inherit the
IAsyncResult
interface from the
System
namespace to get the result of the asynchronous operation.
Although there are many methods to override, the most important to understand are
BeginGetData
and
EndGetData
.
Visio Services calls the custom data provider's
BeginGetData()
method as soon
as the request begins. Under the
BeginData()
method, create a thread and delegate a
method to it. Create a callback method to be aware of when the thread completes its job:
ThreadPool.QueueUserWorkItem(new WaitCallback(GetData), callback);
In the
GetData()
method, create an instance to the WCF service object and call the
GetServerStatusDetails method to retrieve the
Server Status
details:
ServerStatusClient oServerStatus = new ServerStatusClient();
DataTable dt = oServerStatus.GetServerStatusDetails();
this.Data.Reset();
this.Data.Tables.Add(dt);
this.Data.AcceptChanges();
After the set operation completes its job by retrieving the data, Visio Services calls
the
EndGetData()
and returns the
Data
object as DataSet:
return this.Data;
VBA Code (Listing 4-8):
The VBA code is used to create and populate a data source that can be used by the Visio
diagrams. This is similar to creating a data source using macros.
The code is very simple. It begins by initializing the data objects such as recordset,
connection strings, command text, and so on:
Dim diagramServices As Integer
Dim vsoDataRecordset As Visio.dataRecordset
Dim dataRecordset As Visio.dataRecordset
Dim connectionString As String
Dim commandText As String