mhalhead

LightSwitch with PI

Blog Post created by mhalhead Champion on Jul 4, 2013

Microsoft LightSwitch is a Visual Studio add in for rapid application development. If you want to know more google it, but here's a good starting point. IMNHO LS is a really good tool for build quick CRUD style applications (forms over data), you probably could build a nice functional dashboard in LS but this doesn't mean that it is a good idea. The hard core developers reading this are shuddering, but there are times when you need a method of developing a solution without months of plumbing. I've also found that LS solutions are more maintainable as all the plumbing code isn't there. For me the biggest difference between LS and other RAD platforms is that LS is pure .NET. There is no weird and Wonderful runtime engine (other than the CLR) all there is, is a .NET framework that incorporate the best patterns and practises. Because it is pure .NET you can do pretty much anything in LS that you could do in a normal .NET app, yes you might fight the framework but you can do it; again this doesn't mean it is a good idea.

 

Microsoft's marketing department really hasn't done LS any favours; I think that its confused them. You can use LS for the following:

  • Create a quick well formed CRUD application
  • Create a OData service - you can publish a service only layer with LS providing an OData service that has minor things like really authentication and permissions
  • SharePoint 2013 development - LS is being pushed (badly) as a preferred method of writing SharePoint 2013 applications. We're still on 2010 so I have tried this
  • Mobile clients - the default UI is built in Silverlight but you can also create a companion UI in HTML5. Not you can't create a Win8 RT app directly. You could use the data service layer to create the server side and use the normal VS templates to create the client app.

So where does PI fit in? Well there are numerous examples floating around vCampus of data entry into PI. The example I'm going to use is Event Frames. Yes PI can generate EFs no problem (Abacus will make this work a lot better - Sorry Steve couldn't resist), but there is no easy way out of the box to let users enter additional information into the EFs. I don't know about everyone else but I'm certainly not going to give my users PSE with sufficient rights to edit events.

 

There are a number of mechanism for connecting to data in LS:

  • Database - Effectively the entity frame providers. I must confess I never tried anything other the SQL Server
  • SharePoint
  • OData
  • WCF RIA Service

Seeing that I'm trying to talk to AF my options are limited. Currently OSIsoft doesn't have OData support and even if they did LS doesn't support OData operation (please add some votes to the feature request on Microsoft's connect site). So WCF RIA Services is it.

 

The first thing to bear in mind is that LS uses an entity model for data. This means that you will need to project your EFTemplate as an entity; you do this with a plain old C# Object (POCO); don't worry I will show an example.

 

The first step is to create a new LS project and then add a Class Library Project to the solution; hint user a plain old class library not a WCF Service Library.

Outcomes