MichaelvdV@Atos

A Quick introduction to LinqToPi

Discussion created by MichaelvdV@Atos on Apr 19, 2010

Description
A Language Integrated Query (Linq) provider for the PI system. This enabled you to access PI (meta) data with LINQ/lambda syntax. It uses the PI OLEDB provider for data access and enables programmers to quickly develop WPF applications and services using WCF, .NET RIA Services or ADO.NET Data Services.

LinqToPi was created using the IQToolkit tutorial by Matt Warren.

The initial prototype was presented at OSIsoft vCampus Live! 2009 in San Francisco, CA 

What is it?

 

A Language Integrated Query (Linq) provider for the PI system. This enabled you to access PI (meta) data with LINQ/lambda syntax. It uses the PI OLEDB provider for data access and enables programmers to quickly develop WPF applications and services using WCF, .NET RIA Services or ADO.NET Data Services.

 

For instance, you can access PI Values like this


   string tagname = "sinusoid";
   var startTime = DateTime.Now.AddHours(-1);
   var endTime = DateTime.Now;
   PiServerContext context = new PiServerContext("nlms028.nl.int.atosorigin.com", "piadmin", System.Console.Out);
            var ret = from
                          v
                      in
                          context.Archive.ArchiveData
                      where
                           v.Tag == tagname &&
                           v.Time.Between(startTime, endTime)
                      select v;

 

or, using lambda expressions


context.Archive.ArchiveData.Select(v => v.Tag == tagname && v.Time.Between(startTime, endTime));

 

 

What do I need?

 

First of all, you will need .NET 3.5 and the PI OLEDB Provider (version 3 minimal). If you want to explore the source, or help out with the project, you will need Visual Studio 2008 (Express).

 

Where can I get it?

 

Source Code

 

Binary

 

When can I use it?

 

The project is aimed at creating an IQueryable provider for PI. The simplest way to use it is in a WPF or Winforms application, to be able to quickly bind PI data to controls (a datagrid, listbox, etc). More advanced usage would be a WCF Service, WCF RIA Services (for use with Silverlight), or WCF Data Services (using the oData protocol, like in Steve's blog post)

 

Examples will be posted soon!

 

How do I use it?

 

To get started:

 

Download the binary

 

Create a new .NET project

 

Reference the LinqToPi.dll library

 

Add a 'using LinqToPi' statement

 

Instantiate a 'PiServerContext' object


 PiServerContext context = new PiServerContext("piserver", true, System.Console.Out);

This uses Integrated Security to access PI. There are several constructor overloads for you to explore.

 

Use Intellisense or the Object Browser to explore LinqToPi.

 

Are there any known issues?

 

Unfortunately, there are:

 

The LINQ provider at this point doesn't work well with single quotes in values. This is a problem when updating the ExDesc from Performance Equation tags.

 

Relative timestamps are not supported. You can use the PiRelativeTime object from the PiTimeServer SDK library to translate relative times to .NET DateTime objects.   

 

 I have a suggestion or code change / How do I get involved?

 

Please post it here, or PM me and together we can see how to update the project

 

 

Outcomes