Visio Services in SharePoint 2010 – Part 2

(Updated 18/01/2011: Apologies Some Content seemed to have got lost!) Quite a while ago I published a blog entry on Visio Services , and recently I’ve picked up quite a few comments asking when Part 2 is going to happen.  Well about 2.5 years after Part 1, comes Part 2

Since Part 1 was pretty much just a showcase of what you can do in Visio Services, I thought Part 2 should be more of a “How To”, and following on from a session I did at the SharePoint Best Practices Conference 2011 in London, in this blog entry I’m going to show you how to create a Simple Server Visio Diagram linked to a SQL Server Database using no code. I’ll provide also the downloads needed to get the example working.

To do this demo yourself, you need a few things:

  • The ServerPinger.exe application
  • A SQL Server Database
  • Visio Professional 2010
  • SharePoint 2010 Enterprise CAL

The first you can download from here.  The second I’ve supplied a script for here,  and you can download SQL Server Express from here, the third and fourth?  Sorry, you’ll have to supply yourselves, though you can get evaluation copies of Visio 2010 Premium here and of SharePoint 2010 Enterprise here.

The ServerPinger.exe is a little executable I’ve written to simulate pinging servers on a network.  It actually pings a number of public DNS addresses and also your localhost.  It stores the results of those pings in a database, and you may need to change the database string which is present in the config file which comes with the exe, so that you can store the results of the pings.  We’re going to hook up our Visio Services Diagram to the database and create a data-driven Visio Services Diagram.

So architecturally, our system looks like Figure 1.

Server Pinger Architecture

Figure 1 : Server Pinger Architecture

Here’s the Steps to do this and what is involved.

Step 1: Create the Server Database by running the Server.sql SQL Script

Step 2: Copy the unzip the ServerPinger.zip file and copy the ServerPinger.exe and ServerPinger.exe.config files to a folder location.  Open up the ServerPinger.exe.config file and change the database connection string to point to your database server.

Step 3: Open up Visio 2010 and create a Server Diagram as follows:

        File -> New -> Detailed Network Diagram(Metric) -> Create

Shapes Panel -> Rack Mounted Servers (Metric)

Drag on a Database Server, a Server and a Web Server shape.

Select all the shapes, and on the Ribbon click Insert -> Container

Pick a style of Container. This simply adds a frame around our servers.

You should now have a diagram that looks something like Figure 2.

Visio 2010 Diagram

Figure 2 : Visio 2010 Diagram

Step 4: Link the Data to the Shapes by simple drag and drop.  So in the Ribbon select the Data Tab, click “Link Data to Shapes”, in the dialog box, select “Microsoft SQL Server database”, click Next then enter your server name, use “Windows Authentication” or put in a Username and Password, dependent upon how you access you SQL Server, then click Next.  From the drop down, select the “Network” database and click “Connect to a Specific Table” and select “vServers”.  So your dialog box should look like Figure 3.

Figure 3 : Database Connection Dialog

Figure 3 : Database Connection Dialog

When you click “Next” you get to fill out the various details of the Office Data Connection which will be used to connect the Visio Services diagram to the data source.  Make sure you check the box which says “Always attempt to use this file to refresh data” as in Figure 4

Figure 4 : Data Connection File Names

Figure 4 : Data Connection File Names

Click on “Finish” and now you get an option to save your data connection to your SharePoint site.  Make sure you have a Data Connections library in your target SharePoint site and it is in the same site as the Visio Diagrams you upload too.  Once you’ve saved your ODC data connection, click “Finish”.  You’ll be prompted to update any Metadata for the Data Connection, and then you’ll be asked what data connection you want to use. This seems a little excessive seeing as you’ve just created and uploaded to SharePoint the exact data connection you want, but hey, it’s not a big thing really …
Click “Next” and you’re asked to pick the columns and rows that you want to include in your data. For the moment, just take the default of “All” for both and click “Next”, you can click “Next” again, as this screen just allows you to pick a unique identifier, which we already have in the “Id” column. Click “Finish” and you’re done.
You now see the External Data window and a helpful little callout saying drag rows onto the page to link data.  I suggest you do just that.
Figure 5 : Drag and Drop

Figure 5 : Drag and Drop

Carry on dragging and dropping until you have linked all the data items you want.
Step 5 : Edit Your Data Graphics.  By default, you get two rather boring Text Data Graphics set against your shapes.  HostName and PingTime.  Let’s change these to give more a more exciting experience. So select all your servers and then from the Ribbon click the Data Tab and then click the down arrow on the “Data Graphics” button and then select “Edit Data Graphic …”  You will now see the Edit Data Graphic Dialog.
Firstly highlight both existing Data Graphics one at a time and click the Delete button, as we won’t be needing these.  Click “New Item …”, in the Data Field select PingTime and in the “Displayed As” drop down select “Icon Set”.  Select the style you want, I’m selecting the traffic lights style and then select the rules for each Icon.  I’ve selected my rules as shown in Figure 6.
Figure 6 : Configure Data Graphic One

Figure 6 : Configure Data Graphic One

 Click “OK” and “Apply”.  We’re nearly there, but we want to add in a new data graphic which allows the shapes to change colour when the data changes. So in the Edit Data Graphic dialog, click “New Item …”, in the Data Field select “SecondsSinceLastPing” and in “DisplayedAs” select “”Color By Value” (should be spelt Colour By Value – typical Americans … just joking!).  Select ” Each color represents a range of values”  and configure your rules as in Figure 7.
Figure 7 : Configure Data Graphic Two

Figure 7 : Configure Data Graphic Two

Click “OK” and “Apply”.  Now we are  done designing, we just need to publish.

Step 6.  To publish to our SharePoint site we simply do File -> Save & Send -> Save to SharePoint -> Web Drawing -> Save As, and then select the SharePoint Library you wish to publish to.  Visio 2010 itself looks after  the conversion of the file into a VDW format, but in order to view a Visio Services diagram in the browser, you must have a SharePoint Farm with Enterprise CAL and a Visio Services Service Application enabled and your Web Application must be associated with that Service Application.

One other thing.  Don’t necessarily do this in production, but go to your Visio Services Service Application in Central Administration, go to Global Settings and in the “Minimum Cache Age” textbox  type “0”.  This will disable caching of the rendered silverlight controls, otherwise you will not immediately see changes in the diagram when the data changes.

Once the Visio diagram is converted and published, Visio should open a browser window and you should see our diagram in all it’s glory.  You need to click the yellow “Enable” button to allow Data Refresh. I’ve not found a way of disabling that yet unfortunately …

To test our diagram, start up the ServerPinger.exe application and click “Start” to start the pings going.  Your diagram should then look something like Figure 8:

Figure 8 : Completed Visio Services Diagram

Figure 8 : Completed Visio Services Diagram

Now click “Fail” and wait a few seconds and you should see your diagram change to something like Figure 9.

Figure 9 : Dynamic Visio Services Image

Figure 9 : Dynamic Visio Services Image

Pretty cool huh? Simple, easy, but so , so effective and communicating data.

In Part 3, which hopefully you  won’t have to wait quite so long for, I’ll cover writing a Custom Data Connector to communicate with any ad-hoc data source.

Cheers

Dave Mc

Advertisements

About davemcmahon81
Software Developer & Architect, User Group Leader, Speaker, Writer, Blogger, Occasional Guitarist, Man-made Global Warming Sceptic, Climate Change Believer, General Optimist but most of all proud Husband and Dad ...

2 Responses to Visio Services in SharePoint 2010 – Part 2

  1. Pingback: Sharepoint Updates December-16-2011 | SDavara's Sharepoint Knowledge Center

  2. Christos K says:

    Nice!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: