Visio Services in SharePoint 2010

What is Visio Services?

SharePoint 2010 has changed its way of behavior amongst services. It has opened new ways to interact with other products even outside the Microsoft suite. One of these services is called Visio Services. Visio Services enables your SharePoint 2010 environment to display and inter-act with Microsoft Visio documents.

How does it suites your business?

This means that you are able to visualize data in a completely different way. Normally if you want to show data at management level, lists and scorecards are used to display overall business data and drill-downs on different levels. Imagine that you enrich some or all of those levels with visual diagrams containing that data. That would greatly impact the way how management or departments are monitoring data. Visio Services will give you those tools to accomplish this.
 
As you know Microsoft Visio gives the ability to create all sorts of diagrams. Diagrams are based on shapes and can be enriched with data. Instead of placing the data inside the Visio diagram, we are now able to get data from different data sources and even from SharePoint 2010. By combining such a diagram and its data into SharePoint 2010 will give you a great and interactive view of data in a collaboration platform.
 
Let’s say we have an IT department monitoring worldwide the state and versions of hardware and software in their farms. Normally this would be implemented in documents stored in SharePoint or using lists in SharePoint. Now you are able to create a visual representation of your server farm(s) and present per server data next to it based on a data source. The data source can be stored in SharePoint, a known external data source as SQL Server or even in a non-Microsoft legacy system. As soon as data is updated in that data source, it is updated in the visual representation.
 
Another example is a visual representation of business processes. Be aware that this is not replacing a workflow. But it enhances the way of how management will see the data presented to them. A visual representation of its business processes, telling him how many orders are still open, in progress, closed or sent, containing links to scorecards giving more in-depth data, gives management a whole new experience. It becomes easier to view business data and share it with others because it is part of the collaboration platform.
Many more of these examples are available. But this will give you an idea of what is possible.

SharePoint 2010

Visio Graphics Service

The Visio Graphics Service is the service used for viewing of and inter-acting with Microsoft Visio diagrams. So how does it work? A quick explanation is helpful. As you all know with MOSS 2007 we had a Shared Service Provider. This provider delivered a set of services to your environment. With SharePoint 2010 the Shared Service Provider is replaced by Services. There are a lot of different Services available in SharePoint 2010. Each Service delivers some functionality and can be attached to a Web application by using a Service Application and a Service Application Proxy. In some cases a Service need some configuration data which is stored in a separate database connected to the Service Application. Multiple Service Applications are possible and some Services even support multi-tenancy. Each Service Application can be configured using its own Application Pool.

Service, Service Application and Proxy

To use the Visio Graphics Service we need to create a Service Application and Service Application Proxy. Before that we check if the Visio Graphics Service is actually running on the server. Go to Central Administration and click the link “Manage Service on server”. Scroll down to the Visio Graphics Service and click on the “Start” link.
 
Figure 1 Service Applications in Central Administration
 
After the activation go to the “Application Management” and click on the link “Manage service applications” as shown in figure 1. In the ribbon a button called “New” is shown. Click on that button and you will see all the available services on that server. By clicking on the “Visio Graphics Service” option an application page is opened to create the Service Application and the Service Application Proxy. Fill in the requested data and create both parts.
 
You will notice that a Visio Graphics Service Application and Visio Graphics Service Application Proxy are created. The first one allows you to click on and to go to the settings of the Service Application.

Service configurations

There are two configuration options, Global Settings and Trusted Data Providers as shown in figure 2. The Global Settings contains settings for performance and security. You are able to set the maximum web drawing size, caching, recalculation duration and handling of external data. When data is refreshed from an external data source, a so called Unattended Service Account is used. To secure this behavior an application ID needs to be registered in the Secure Store Service to reference such an account.
 
Figure 2 Manage the Visio Graphics Service
 
The Trusted Data Providers configuration will show you a list of those providers. SharePoint 2010 delivers out of the box providers for SQLOLEDB, SQL Server, Oracle, IBM, Excel Services and WSS. It also allows you to add your own data providers. Each Trusted Data Provider expects an identifier, type and description. This will be explained more in the last example.

Features

You will need the SharePoint 2010 Enterprise version to make use of Visio Services. To make use of Visio diagrams you need to activate the site collection and site feature called “SharePoint Server Enterprise”.

Visio Web Access Web Part

The features will activate a Web Part called “Visio Web Access”. Create a new page inside your site and select “Edit Page” from the ribbon. Click on the “Add a Web Part” link in one of the Web Part Zones. Choose the Visio Web Access Web Part from the “Business Data” category and add it to the Web Part Zone. The Web Part can be connected to a Visio Web Drawing and several settings can be set. Some of these settings are overriding the Web Drawings initial view with the ability to set the current page, pan and zoom. The automatic refresh interval can be set in minutes. Keep in mind that this will not override the cache settings in your Service Application configurations. It is also possible to expose certain shape data items to other Web Parts using Web Part connections. Furthermore you can define functionality like navigation, zoom, background and other things to appear or not. These options are divided into Toolbar and User Interface and Web Drawing interactivity.
 
By combining visual representation and data together as one creates great insights for business owners within any part of the organization

Visio Graphics Services

I will give you some impressions of the rich abilities of Visio Graphics Services. The following examples include out of the box functionality, using ECMA scripting and even C# development. The examples are:
 
·         SharePoint data and Visio Diagrams
·         Inter-act with a Visio diagram in SharePoint
·         Enrich your Visio diagram with data through a connector
For all these examples we will need a Microsoft Visio Diagram. The first step is creating a visual representation of the incident process for the company. The process is straight forward as can be seen in figure 3.
 
Figure 3 an example Visio Diagram.
 
It starts with an incident following the question if the incident is not valid anymore it is stored on a database server. If the incident is still valid the incident is changed into a service request and set to one of the service desk employees. Eventually this will result in some action.
 
For each of the examples we will need the Microsoft Visio Diagram stored as a Visio Drawing into a document library. You could save the Visio diagram as a Visio Drawing and then upload it into the document library. Or save the diagram directly from Microsoft Visio into the document library.
 
I have chosen the last option. Choose the “Save & Send” option under “File” in Microsoft Visio and choose at the right “Save to SharePoint”. Select Web Drawing as file type and click on the “Save as” button. Enter the URL to your document library and save the diagram as seen in figure 4. The Visio Diagram is now converted to a Visio Web Drawing and stored into the document library.
 
Figure 4 Save the Visio Drawing into a SharePoint List.
 
Go to your document library and you will see that the drawing is now saved over there. Open the Visio Drawing and you will notice that SharePoint uses the Visio Web Access component to enable you to view the Visio Diagram in the context of your browser.

SharePoint Data and Visio Diagrams

This example will talk about connecting SharePoint Data into a Microsoft Visio Diagram and display both on the same page in SharePoint. It will not contain any development steps and gives you a great example of using out-of-the-box functionality.
 
For this we need a custom SharePoint list named Incidents containing the columns Title, Open, Overdue and Closed. An example is shown in figure 5. These values will represent the number of incidents which are still open, not closed on time and are closed per part of the process.
 
Figure 5 The SharePoint list containing data for the Visio Shapes.
 
We will feed the Visio Diagram with the data from the Incidents list. In this case the list contains static data which needs to be filled by for example a manager. But you also could use an External List to get the data from an external data system or create some functionality which updates this list on a timely basis.
 
Open the Visio Diagram from your document library with Microsoft Visio. Select the shape called Incident and right mouse click to open the menu. Choose from the menu the option “Data à Shape Data”. A floating shape data property dialog opens. Right mouse click in this dialog and choose from the menu the option “Link Data to Shapes”.
 
Figure 6 Select the Microsoft SharePoint Foundation List as Data Selector.
 
Choose “Microsoft SharePoint Foundation list” as the source for your data and press the Next button which is shown in figure 6. Enter the URL of your SharePoint site containing the Incidents list and press the Next button again. Microsoft Visio will now connect to the site.
 
Figure 7 Select the SharePoint List.
 
In the following dialog step, shown in figure 7, select the Incidents list and choose the option “Link to a list”. It is also possible to link to a specific view of that list. Press the Finish button to finish the wizard. At the bottom of the screen all items from the Incidents list will appear as shown in figure 8.
 
Figure 8 Example of a SharePoint List connected to the Visio Diagram.
 
The next step is very easy. We need to connect each of the list items to one of the shapes. This is done by dragging them from the External Data pane on to a shape in the Visio Diagram. As soon as a list item is linked a link icon is shown in front of the row.
 
Figure 9 SharePoint List items are connected to the Visio Shapes.
 
You will notice that only the Title and Modified date columns are shown. Right click mouse on no particular shape and select the menu option “Data à Edit Data” Graphic. This will show the dialog seen in the figure 9. Remove the Modified Date column and add the Open, Overdue and Closed columns to the shape. When the Apply button is clicked you will see the selected columns at each of the linked shapes.
 
Figure 10 Change the refresh rate of the connection.
 
To make sure that the data is refreshed as soon as possible after a change you will need to set the refresh time. Right click mouse on any of the list items in the External Data pane and choose the menu option “Configure Refresh”. Change the “Automatic Refresh” into 1 minute as shown in figure 10. Keep in mind that normally this setting too low in combination with a slower data connection could cause delays in your web application. Press the OK button to save the settings. Save the Visio Diagram to the document library. If you opened it from the document library pressing the menu option save will be enough.
 
The next step is creating a SharePoint page containing the Visio Web Access Web Part and a view of the Incident list. Open the page in edit mode and click on the link “Add a Web Part” in one of the zones. Select the Visio Web Access Web Part from the Business Data category and the Incident list from the Lists and Libraries category.
 
Then we attach the Visio Drawing to the Visio Web Access Web Part by clicking on the “Click here to open the tool pane” and select the Web drawing URL by clicking on the symbol right from the field. Set the “Automatic Refresh Interval (in minutes)” to 1 minute. There are several other options to influence the behavior of the Web Part, but for now we just close the tool pane. When returning to the page you will notice that the Visio Drawing is loaded into the Web Part as shown in figure 11.
 
Figure 11 View the Visio Drawing and the data in SharePoint.
 
Notice the orange brown bar telling you that the refresh is disabled. You need to trust the contents before enabling it. Enabling is possible for the current session or all future sessions. If you do it for this session it will again ask if a new session is started in your browser.
 
Figure 12 Change the values of one of the items.
 
Let’s change the values for the Service Request list item as shown in figure 12. Press the Save button to leave the edit dialog.
 
Figure 13 Example of the updated data in the Visio Drawing.
 
Again notice the change being updated in the Visio Drawing as shown in figure 13. Keep in mind that it is possible that you will not see the change right away. This is caused by the caching of the data. We have now created a dashboard for managers where they can easily see the state of each step inside their process. You could expand this with for example using scorecards from Performance Point Services and place a link per shape to the different scorecards. This will allow people to click on the link inside the Visio Drawing and see a drilldown of the data next to the drawing or at another page.

Inter-act with a Visio Diagram in SharePoint

This example will show you how to interact with the Visio Diagram using ECMAScript Object Model. There is no need for any compiler while the script is referenced from a Content Editor Web Part. This object model is defined in the Vwa Namespace inside Visio Services and it gives you programmatic access to Visio Drawings.
 
You are able to access diagram page data and shape data using different set of classes named Page, ShapeCollection and Shape. These classes will allow you to use overlays, highlight certain shapes, change properties of the viewport and even respond to mouse events which take place in the Visio Drawing.
 
In our example we highlight the shapes by moving the mouse pointer over the shapes. We start by attaching a handler to the load event of Sys.Application class. In that handler we need to get the Visio Drawing by its ID. Look for the phrase class=”VisioWebAccess” in the source code of the SharePoint page. The ID of the Web Part will be in the format of “WebPartWPQ#” where the # sign represents a number. Be aware that this could be different on another page. In our case the ID is “WebPartWPQ2”.
 
The VwaControl object will allow you to use the method openDiagram to open the Visio Drawing. But due to the asynchronous operation you are not able the use that object anymore because it gets invalid. Instead we use the Vwa.diagramcomplete event. This event occurs when the Web Part has finished loading the Visio Drawing.
 
Sys.Application.add_load(onApplicationLoad)
var webPartElementID = "WebPartWPQ2"; 
var vwaControl;
var vwaShapes;

function onApplicationLoad()
{
    try
    {
         vwaControl=
            new Vwa.VwaControl(webPartElementID);
         vwaControl.addHandler(
            "diagramcomplete", onDiagramComplete);
    }
    catch(err)
    {
    }
}
 
function onDiagramComplete()
{
    try
    {
         var vwaPage = vwaControl.getActivePage();
         vwaPage.setZoom(-1);
         vwaShapes = vwaPage.getShapes();
         vwaControl.addHandler
                ("shapemouseleave", onShapeMouseLeave);
         vwaControl.addHandler
                ("shapemouseenter", onShapeMouseEnter);
    }
    catch(err)
    {
    }
}

In the onDiagramComplete method we get the active page and reset the zoom level. From the active page we retrieve the collection of shapes and store them in a variable. We also add two more handlers when the mouse pointer enters a shape and leaves a shape. They are called respectively shapemouseleave and shapemouseenter.

 
function onShapeMouseEnter(source, args)
{
    try
    {
            vwaShapes.getItemById(args).addHighlight
                           (5, "#FF0000");
    }
    catch(err)
    {
    }
}
 
function onShapeMouseLeave(source, args)
{
    try
    {
            vwaShapes.getItemById(args).removeHighlight();
    }
    catch(err)
    {
    }
}

To finalize we implement both methods called OnShapeMouseEnter and onShapeMouseLeave. These methods are called with the args parameter containing the ID of the shape. The only thing we do here is adding a highlight to the shape and removing it again from the shape.

Store this script into a JavaScript file (*.js) inside the elements <script type="text/javascript"> and </script>. Upload the JavaScript file to the same document library as where the Visio Drawing is stored.
 
Now we need a SharePoint page on which we use the Visio Web Access Web Part to view the Visio Drawing and a Content Editor Web Part to reference the ECMAScript file. Open the page in edit mode and click on the link “Add a Web Part” in one of the zones. Select the Visio Web Access Web Part from the Business Data category and the Content Editor Web Part from the Media and Content category.
 
Then we attach the Visio Drawing to the Visio Web Access Web Part by clicking on the “Click here to open the tool pane” and select the Web drawing URL by clicking on the symbol right from the field. When returning to the page you will notice that the Visio Drawing is loaded into the Web Part.
 
Finally we reference the JavaScript file with the “Content Link” in the tool pane of the Content Editor Web Part. This will not give you a fancy browse dialog so you need to get the specific URL to the JavaScript file.
 
Figure 14 Example of interaction with a Visio Drawing.
 
The SharePoint page is reloaded again and the Visio Drawing appears on the page as shown in figure 14. When you move the mouse pointer over the different shapes inside the Visio Drawing you will notice that the shapes are highlighted. Try changing the viewport, zoom and panning and see that the highlighting will still work. This is of course a simple example of interacting with the Visio Drawing. Have a closer look at the different classes within the Vwa Namespace. Some advanced things like overlay are really easy to implement allowing you to place text and images over shapes.

Custom Visio Service Data Provider

The last example will show you the steps to create your own custom Visio Service Data Provider to enrich a Visio Diagram with business data from for example a non-Microsoft legacy system. This example will not include a working version but will contain some guidelines to setup your own provider. The Microsoft SharePoint 2010 SDK Documentation gives a great in-depth example of accessing data in an XML file.
 
Visio Services offers functionality which allows Visio Drawings consume data from a variety of out-of-the-box Data Providers. The first example explained was using the Data Provider WSSList for connecting to data in SharePoint lists. What if these data providers are not suited to get data from an external system inside the company? For example a legacy system, non-Microsoft technology, highly complicated data structures or data / web services from a third-party? In those cases you can decide to create your own Custom Data Provider.

Writing your own Custom Data Provider

First of all you need to write code for your Custom Data Provider. This code will access the data source. Visio Services delivers an API containing two classes:
 
·         Microsoft.Office.Visio.Server.AddonDataHandler
·         Microsoft.Office.Visio.Server.AddonDataHandlerException.
 
The first class called AddonDataHandler is an abstract class. Custom Data Providers must implement this class. The second class called AddonDataHandlerException is used for communicating error messages to users.
 
First of all we create a C# Class Library Project in Visual Studio 2010. Your development machine needs to have SharePoint 2010 installed to allow you to access the Visio Services library assembly. You need to have a reference to the Microsoft.Office.Visio.Server.dll file. Because this assembly is only available through the GAC you need to access it via a specific path to reach it.
 
[drive]:\windows\assembly\GAC_MSIL\Microsoft.Office.Visio.Server\ 14.0.0.0__71e9bce111e9429c
 
Create a class called CustomDataProvider which is derived from AddonDataHandler and implements the IAsyncResult interface. Members of the IAsyncResult class are used to return the state of the asynchronous call. It also determines if the asynchronous call is completed.
 
private object asyncState = null;
private bool completed = false;
 
public class CustomDataProvider :
                 AddonDataHandler, IAsyncResult
{
    #region Implementation of IAsyncResult
    object IAsyncResult.AsyncState
    {
        get { return this.asyncState; }
    }
 
    bool IAsyncResult.IsCompleted
    {
        get { return this.completed; }
    }
 
    …
    #endregion
}
 
There are two other methods which are very important and need to be overridden. The first method is BeginGetData. This method is called by Visio Services to start the retrieval of data. It is very important to return from this method as soon as possible because providers need to be asynchronous. Therefor a separate thread with the actual data retrieval is started using ThreadPool.QueueUserWorkItem.
 
public override IAsyncResult BeginGetData(HttpContext context, AsyncCallback callback, object                            
                                                                              asyncState)
{
    ThreadPool.QueueUserWorkItem(
              new WaitCallback(ThreadTask, callback);
    return this;
}

The second method is called EndGetData. This method is called by the Visio Services when the custom provider has finished retrieving the data. It returns its own DataSet.

public override DataSet EndGetData(IAsyncResult result)
{
    return this.Data;
}

The actual data retrieval happens in the method called by the initiated thread from BeginGetData. This method is filling the DataSet in the provider from a particular data source. If in the event an error occurred we are able to return a message to the end user using the class AddonDataHandlerExpection.

try
    {
        this.Data.Reset();
        // set data in the DataSet of this class
    }
    catch(Exception ex)
    {
        this.Error = new AddonDataHandlerExpection(
                           “some error occured”);
    }
 
    this.completed = true;
    callback(this);
}

At the end of this method we set the completed variable to true indicating that the asynchronous process has finished. Finally we invoke the Visio Services callback method to return.

Use a separate project based on the “Visual Studio Installer” under the category “Setup and Deployment” to create a setup file to deploy your custom code.

Install a Custom Data Provider

You need to install the Custom Data Provider on a server which is running Visio Services. Make sure that you have your WSP package containing the Custom Data Provider placed on a known disk location. Go to the SharePoint Server 2010 computer and click on the Start button. Select the application called “SharePoint 2010 Management Shell”.
To install the Custom Data Provider use the following two commands:
 
Add-SPSolution <disk location>\CustomDataProvider.wsp
 
Install-SPSolution < disk location
              >\CustomDataProvider.wsp -GACDeployment
 
If you need to uninstall the Custom Data Provider, the following two commands need to be executed:
 
Get-SPSolution CustomDataProvider.wsp
                     | Uninstall-SPSolution
 
Remove-SPSolution CustomDataProvider.wsp

Make your Custom Data Provider trusted

The installed Custom Data Provider must be added to the list of trusted data providers for Visio Services. To enable refreshing a Visio Diagram with data stored in the Custom Data Provider, we need to add this provider to the trusted list.
 
Open Central Administration and select the option “Manage Service Applications” under the category “Application Management”. Click on the Visio Graphics Service Application link and choose the option “Trusted Data Providers”. Click on the link “Add a new Trusted Data Provider” and fill in the values.
 
The Trusted Data Provider ID is actually the namespace and declaration of the class and assembly containing the Custom Data Provider. It will be something like:
 
<Namespace.ClassName, AssemblyName, Version=version, Culture=culture, PublicKeyToken=token>.
 
Enter the value 6 for Visio Custom Data Providers in the Trusted Data Provider Type field and enter a description for the provider. Press the OK button to add the provider as trusted provider.

Consume from the Custom Data Provider

Last but not least is consuming from that Custom Data Provider from your Visio Drawing. This means doing some coding in Microsoft Visio using VBA code. Each Visio document has a collection named DataRecordsets of DataRecordset objects. The collection is initially empty. To connect a data source to your Visio Diagram you need to add a DataRecordset object to that collection.
 
The DataRecordsets collection gives you three different methods to add a new DataRecordset. They are called Add, AddFromConnectionFile and AddFromXML. The Add method allows you to retrieve data from an OLEDB or ODBC source, the AddFromConnectionFile allows you to retrieve data via an Office Data Connection (ODC) file from an OLEDB or ODBC source and AddFromXML retrieves data from an XML string.
 
Note: Keep in mind that Visio Diagrams can only read data from the data source but not write data back to the data source. Below an example connecting to an XML string.
 
Dim vsoDataRecordSet As Visio.DataRecordset
Dim strXML As String
 
Set strXML = “<some xml string>”
Set vsoDataRecordSet = ThisDocument.DataRecordsets.AddFromXML(
             strXML, 0, “XML Data Source”)
vsoDataRecordSet.CommandString =
             “DataModule=<namespace>.<classname>,
              <assemblyname>;File=<path>\some.xml” 

Whenever a refresh is executed the CommandString property is used to access the Custom Data Provider, and in the above case with the path to the XML file.

There is still a lot of work to create your own Custom Data Provider but it will give you a lot of possibilities to access your own data sources.

Conclusion

Visio Services allows you to create rich data driven dashboards containing visualized business processes with interaction. By combining visual representation and data together as one creates great insights for business owners within any part of the organization. It is a service on itself which can be easily combined with other functionality in SharePoint 2010 like lists, Excel Services and Performance Point Services. There are several ways of using and implementing Visio Services. Using out-of-the-box functionality lets non-developers with some knowledge of Microsoft Visio already accomplish a lot. Visio Services extend boundaries of data representation and makes it even possible to get data from external data sources such as old legacy systems in your organization. In that case you will need some experienced developers to make that happen.
 
The example solution used in this article can be downloaded from my blog http://www.bloggix.com or by contacting me at alexander@bloggix.com.

 

Geef feedback:

CAPTCHA image
Vul de bovenstaande code hieronder in
Verzend Commentaar