Skip navigation
All Places > PI Developers Club > Blog > 2011 > July

Here is the article talking about the current structure of the giant companies along with this interesting cartoon:



If you are developing using Microsoft Products, you have probably heard of Channel9. Channel9 provides tutorial-, interview- and behind the scenes videos about topics that involve Microsoft development and integration. Microsoft and OSIsoft are partners, OSIsoft was even awarded the 'Sustainability Partner of the Year' award!


I personally love Channel9 because it has good resources, I visit the site regularly to find new video's. I really like the no-nonsense and pure technical approach of the video's. I few years ago I already bumped into a three part video on OSIsoft, and 'forgot' about it. Today I bumped into it again, and thought it would be great to share it with vCampus! If you have a coffeebreak comming up, it is really worth watching.


It's from 2007 (which is ages in IT-years), but the content is still very valid. It stars some interesting people (including Dr. Kennedy himself).


Here are the links: part I, part II, part III (demo)









Everyone who has worked with Microsoft Office in the past knows the paperclip office assistant 'Clippy'. I think most of us had a love-hate relationship with this, sometimes annoying, feature. The Office assistant was first introduced in the 1997 release of Microsoft Office, and it was removed as a feature in Microsoft Office 2007. Altough most users experienced the feature as annoying and intrusive, there is actually some really nice science involved!


The origin of the feature was started in 1993 with codename Lumiere. The goal was to study and improve human computer interaction using Bayesian Probabilities. They wanted to create a way to infer or predict user goals. As software in general (and in this case, Microsoft Office in particular) became more and more complex, the idea of having an 'assistant' that helps you achieve your goals makes sense to me.




The internet of things

Posted by MichaelvdV@Atos Jul 19, 2011

Cisco released a nice infographic called 'The Internet of Things'.


The interesting part is that there are more 'things' connected to the internet then there are people in the world. And we are not just talking about pc's, laptops, smartphones and tablets. There are a whole range of new developments and products that are connected to the internet. I think that this infographic nicely visualizes that the internet is not just a 'people' internet anymore. Not every device has a user behind it requesting information from the internet. It has become much more than that. In the comming years we will see much more of these new developments, now that wireless access (WiFi, 3G) are getting much wider acceptance due to lower costs and more covering.


For us, as users/developers/architects working with PI this opens up a whole new range of possibilities. Many of these devices need to interconnect, store and share information. In a lot of cases, this will be timeseries or asset data. It really makes me think what new possibilities and markets are out there for the PI system. With a lot of functionality and applications moving to the cloud, and now that the sharing of information becomes more and more important, I envision a whole new future of unexplored possibilities for us!





edit: I think Cisco might have exaggerated the statement that 'At the end of 2011 20 households will generate more traffic than the entire internet in 2008'. The facts really state otherwise, even if you compare the world wide internet traffic of 2011 to 1998 this statement still does not seem true. Wikipedia has some nice information about the history of Internet traffic here. Besides this, the infographic shows some nice insights.

If you have developed with Silverlight, you will probably have noticed that there are a lot of, sometimes subtle, features that can make your live as a programmer a lot easier. Some of these features are sometimes a little bit hidden. It's always nice to see some small tutorials on how you can do certain things, so you know it exists. When you are in a situation where it could be applicable, you will certainly think about it!


Here are some 'must read' tutorials for Silverlight developers, have fun reading!


StringFormat for DateTime conversion


Explains how to use the stringformat property of a textbox when binding to a DateTime value


Treeview Drag & Drop


Explains how to use drag and drop targets in Silverlight 4 to easily enable drag & drop for the Treeview.


Silverlight Chart Example


There is a very big chance that you will want to visualize PI data using a chart in Silverlight. This article should get you started with using the Charts.


Data Validation in Silverlight


Validating user input data and responding with clear messages is very important. Silverlight has very nice built-in data validation mechanisms


Assembly caching in Silverlight 4


You can drastically speed up download and load time of your Silverlight application by using 'assembly caching'. This article explains how to enable assembly caching.


Printing support in Silverlight 4


Want to be able to print out that nice report with PI data from your Silverlight application? This is a good place to start!


Using Duplex WCF communication with Silverlight


Want to push events to the client using your WCF service? This is a good place to start learning about the PollingDuplexHttpBinding

Ahmad Fattahi

Project Euler

Posted by Ahmad Fattahi Employee Jul 12, 2011

I just heard about this super cool website and problems collection called Project Euler (Thanks to Luis Moux-Domínguez). This is a collection of interesting geeky computer science-type/math problems that you can solve with some analytical as well as programming/scripting effort. I personally found them very mind-stimulating as well as educational.


Another cool thing about it is that until you post the right solution it doesn't show you the answer; really daring





This already is the third part in a blogpost series where we explore lesser known C# language features. You can find part I here, and part II here. We already discussed several keywords and operators. We didn't receive a lot of feedback on this series. We would really appreciate any feedback! With this third post, we will continue on our quest to explore the lesser known features of C#


Extension methods


Extension methods were introduced in .NET 3.5 (and C# 3.0). They are an exceptional type of method. They are static methods, but are called if they where instance methods. You can use extension methods to 'extent' methods to an existing class. This means you can add methods to an already existing type, that you don't even have the sourcecode or internals for.


The big advantages of using Extension methods:

  • Reusability. Declare the method once, and it will be available troughout the application.
  • Extension methods extend methods: you can add methods to existing classes. This allows you to use the Object Oriented paradigm better
  • Portability. You can create your own library with extension methods you can use troughout different applications.

LINQ heavily relies on extension methods. You can recognize extension methods in Visual Studio by the downward arrow if you use Intellisense. You will also notice the '(extension)' prefix before the documentation.




You can create your own extension methods by creating a static class. Inside this static class you declare static methods. The first parameter of these static methods should be of the type that you want to extent. This parameter should be preceded by the 'this' modifier.


In this example, we are extending the 'PIPoint' class with an extension method called 'GetAttribute', which takes an attribute name, and returns the attribute value.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PISDK;

namespace PIExtensions
    public static class PIExtensions
        public static string GetAttribute(this PIPoint point, string name)
            return point.PointAttributes[name].Value.ToString();



We can use this extension method by bringing the 'PIExtensions' namespace into scope, and calling 'GetAttribute' on an object of type 'PIPoint'.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PIExtensions;

namespace ExtensionMethods
    class Program
        static void Main(string[] args)
            var server = new PISDK.PISDK().Servers["hans-ottosrv"];
            var point = server.PIPoints["sinusoid"];

            var span = point.GetAttribute("span");




This way, no mather where  you are in your application: if you have a 'using PIExtensions;' directive, you can use the PIExtensions extension methods.


A more 'real live' example would be an extension method to copy a pipoint:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PISDK;

namespace PIExtensions
    public static class PIExtensions
        static string[] ReadOnlyAttributes = new string[] 

        public static PISDK.PIPoint CopyPoint(this PISDK.PIPoint sourcePoint, string newName)
            return CopyPoint(sourcePoint, newName, sourcePoint.Server);

        public static PISDK.PIPoint CopyPoint(this PISDK.PIPoint sourcePoint, string newName, PISDK.Server destServer) 
             var sourceAttribs = sourcePoint.PointAttributes.GetAttributes();   
             var newAttribs = new PISDKCommon.NamedValues();            
             var ptClass = sourcePoint.PointClass.Name;             
             var ptType = sourcePoint.PointType;             
             foreach (PISDKCommon.NamedValue nv in sourceAttribs)   
                 if (!ReadOnlyAttributes.Contains(nv.Name.ToLower()))   
                 newAttribs.Add(nv.Name, nv.Value);        
             return destServer.PIPoints.Add(newName, ptClass, ptType, newAttribs);  

 This is also an example of overloading your extension methods. In this case we have an CopyPoint method that accepts only a new tagname, and we have a CopyPoint method that accepts a new tagname and a new server. You can use these extension methods like so:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PIExtensions;

namespace ExtensionMethods
    class Program
        static void Main(string[] args)
            var sdk = new PISDK.PISDK();
            var server = sdk.Servers["hans-ottosrv"];
            var otherServer = sdk.Servers.DefaultServer;
            var point = server.PIPoints["sinusoid"];

            //copy point to same server

            //copy point to different server
            point.CopyPoint("sinusoid-new-otherserver", otherServer);




 A few tips and tricks when dealing with Extension methods:

  • You cannot 'replace' or 'override' existing methods. If your extension method has the same name as an already existing method, your extension method will never get called
  • You can overload new extension methods
  • Extension methods are brought into scope on the namespace level. If you have multiple 'extension classes' defined in the same namespace, they will all be in scope.
  • If you have certain actions that you find cumbersome, or that you need in multiple applications: extension methods are a great way to have in a seperate 'helper' library, that you can reference into your new applications. This saves you a lot of time and effort.

 And, to conclude this article, some small tips and tricks about strings!


String checking and comparison


Since .NET 4.0, the String class has a 'NullOrWhiteSpace' method. There always was an 'NullOrEmpty' method, but that didn't account for extra whitespace. In order to be secure, you had to use the 'Trim()' method. This will fail if the string is indeed null, and throw an exception


Old way (bad):

            var checkString = " ";
            if (string.IsNullOrEmpty(checkString.Trim()))
                //do something



Using 'NullOrWhiteSpace' (good):

      var checkString = " ";
            if (string.IsNullOrWhiteSpace(checkString))
                //do something



When dealing with string comparison, do you do it like this?

       var string1 = "HeLLo WoRlD";

            var string2 = "hellO wOrlD";

            if (string1.ToUpper() == string2.ToUpper())
                //they are the same!
                //they are not the same!



A far better way is using string.Equals(). This can account for cultural and case comparison.

  var string1 = "HeLLo WoRlD";
            var string2 = "hellO wOrlD";
            if (string1.Equals(string2, StringComparison.CurrentCultureIgnoreCase)
                //they are the same!
                //they are not the same!



This will account for the culturesettings of the string, and is best practice when dealing with string comparison!


Further reads


 Extension Methods (MSDN)


Database of extension methods (


How to implement and call a custom Extension Method (MSDN)


String.IsNullOrWhiteSpace (MSDN)


String.Equals (MSDN)


Previous articles in this series


Exploring lesser known C# Language Features Part I


Exploring lesser known C# Language Features Part II





MITRE released the 2011 'Top 25 most dangerous software errors'. You can find it on the CWE website.


While it is a very long document, and it looks a bit intimidating, it is actually a very good read (well, maybe not all of it, but it is very interesting to browse trough). They offer a lot of in-depth information with code samples. I think this is a must read for people who develop software in critical environments (that's us...). The list offers information about the severity, attack frequency, consequences, etc.


Here's a summary of the top 25 most dangerous software errors, with links to sections in the article:




Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')




Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')




Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')




Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')




Missing Authentication for Critical Function




Missing Authorization




Use of Hard-coded Credentials




Missing Encryption of Sensitive Data




Unrestricted Upload of File with Dangerous Type




Reliance on Untrusted Inputs in a Security Decision




Execution with Unnecessary Privileges




Cross-Site Request Forgery (CSRF)




Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')




Download of Code Without Integrity Check




Incorrect Authorization




Inclusion of Functionality from Untrusted Control Sphere




Incorrect Permission Assignment for Critical Resource




Use of Potentially Dangerous Function




Use of a Broken or Risky Cryptographic Algorithm




Incorrect Calculation of Buffer Size




Improper Restriction of Excessive Authentication Attempts




URL Redirection to Untrusted Site ('Open Redirect')




Uncontrolled Format String




Integer Overflow or Wraparound




Use of a One-Way Hash without a Salt

In the first part of this series we discussed the 'yield' keyword, and we learned about 'lazy' and 'eager' evaluation. In this part we continue with some of the lesser known C# language features. Like mentioned in the first post, its sometimes difficult to determine what featurers are really 'lesser known', as this is different for every developer. In this post we are looking at several language features, so I'm sure there's something for everyone!


Inline if statement (:? operator)


The inline if operator is a ternary operator (it uses 3 'arguments', and creates one result). The inline if operator is a conditional operator that can be used as a single expression.


Let's take a look at the 'regular' if statement:

string state = "NOT DEFINED";

if (GetValue() > 10)
  state = "High";
  state = "Low";

To give an example, you can use the inline if operator to get the same result with less code:

string state = GetValue() > 10 ? "Hight : "Low"

 If we compare the grammer of the two:

//'Normal' if statement
if (boolean expression)
  true expression
  false expression

//Inline if statement
boolean expression ? true expression : false expression
Using normal if statements, we can nest several statements:
if (condition1)
else if (condition2)
  else if (condition3)

We can do the same with the inline if operator:
var value = condition1 ? action1
                 : condition2 ? action2
                 : condition3 ? action3
                 : action4

 It get's really interesting if you think of the inline if operator as just another expression, much like '10 + 10' or '"Hello" + "World"'. Here are some examples how you can use the inline if operator, to shorten your code, and make it much easier to read:

var useFirstServer = true;
            var server = new PISDK.PISDK().Servers[useFirstServer ? "firstServer" : "secondServer"];

            var number = 10;
            var elem = new AFElement(number < 10 ? "LowNumberElement" : "HighNumberElement");

            var day = "yesterday";
            var value = new AFValue(100, day == "today" ? DateTime.Today : DateTime.Today.AddDays(-1));





The ?? operator (null-coalescing)


One of the things we as programmers have to do all to often, is check for null values. You can never trust user input, or know if a calculation produced a null result. A simple example would be this:

  public void SchrodingersCat()
            //Create a new random generator
            var random = new Random();
            //Create an array with objects and nulls
            var stateArray = new object[] { "Hello world!" , null, "Hello Again!", null };
            //Get a state using a random generated index
            var state = stateArray[random.Next(stateArray.Length -1)];

            //We don't know what 'state' will be, it can be an object or a null

            string stateText = string.Empty;
            if (state != null)
                stateText = state.ToString();
                stateText = "NOTHING";




We cannot know what 'state' will be until we check it. It can be either null or a string. In this case, we use an if statement to check wheter state is null. We can also do it shorter with the inline if statement we discussed earlier in this article.

 public void SchrodingersCat()
            //Create a new random generator
            var random = new Random();
            //Create an array with objects and nulls
            var stateArray = new object[] { "Hello world!" , null, "Hello Again!", null };
            //Get a state using a random generated index
            var state = stateArray[random.Next(stateArray.Length -1)];

            //We don't know what 'state' will be, it can be an object or a null

            Console.WriteLine(state != null ? state.ToString() : "NOTHING");





Here we use the inline if statement to check for a null value. As you can see we don't need any intermediary variables. This is already really short. But, C# provides us with an ever shorter way: the null-coalescing operator (or ??).


The grammer of the ?? operator is:


possiblyNullValue ?? valueIfNull


So, if we want to use it in this case:



  public void SchrodingersCat()
            //Create a new random generator
            var random = new Random();
            //Create an array with objects and nulls
            var stateArray = new object[] { "Hello world!" , null, "Hello Again!", null };
            //Get a state using a random generated index
            var state = stateArray[random.Next(stateArray.Length -1)];

            //We don't know what 'state' will be, it can be an object or a null

            Console.WriteLine(state ?? "NOTHING");





That's even shorter! And it produces again less code. In this case it also improves readability, once you are used to using the ?? operator.


The 'using' statement


The term 'using' has two distinct functions within C#. We all use the 'using' directive everytime we create a new application.


The using directive let's us 'import' a namespace, so that we can use the types of that namespace without having to use the full typename. For example:

using System.Xml.Linq;
using OSIsoft.AF.Asset;



This is something we use everyday. The 'using statement' has a totally different function.


We can use the using statement to define a scope. Outside of this scope, the objects will be disposed. Objects that implement the IDisposable interface deal with unmanaged code. This means, they have unmanaged pointers or handlers that cannot be controlled (or freed) by the Garbage Collector of .NET. The IDisposable interface has only one method, the 'Dispose' method. This happens when you are for instance dealing with the filesystem, or certain network related objects.


For example, let's say we want to make use of a MemoryStream, and ensure that all the (unmanaged) handlers are freed successfully after use. We can use the following code:

  var text = "Hello world!";
            var buffer = Encoding.ASCII.GetBytes(text);
            var stream = new MemoryStream(buffer);

            //Do something with the stream


            //Stream is still accessable here, but it is already disposed. We will get Exceptions when we try
            //to access it after the Dispose method is called



We call the 'Dispose' method after we are done dealing with the MemoryStream. The issue here is that the 'stream' variable will still be in scope (accessable) after we have called the 'Dispose' method. Once you have called the 'Dispose' method, the underlying resources are freed. You will get an Exception if you would try to use stream.Peek().


There is a better, nicer and safer way to ensure proper disposal. This is done with the 'using' statement.

var text = "Hello world!";
var buffer = Encoding.ASCII.GetBytes(text);
using (var stream = new MemoryStream(buffer))
      //Do something with the stream
//stream will be out of scope here



In this case, we are creating a new memorystream from a byte[] array. We can use the stream inside the using block. The variable will be out of scope after the using block, and it will automatically call the 'Dispose' method of the MemoryStream. This is a much safer way than manually having to call 'dispose'. Offcourse, you can 'nest' using statements, which creates really clean code:

var text = "Hello world!";
            var buffer = Encoding.ASCII.GetBytes(text);
            using (var stream = new MemoryStream(buffer))
            using (var streamReader = new StreamReader(stream))
            using (var streamWriter = new StreamWriter(stream))
                //Do something with the stream, streamReader and streamWriter
            //stream, streamReader, streamWriter are out of scope now





In this article we described the usage of the 'inline if' operator, or ?: operator. It can help you produce cleaner and lesser code. We also learned about the null-coalescing operator, or the ?? operator. It is a very short way of doing null checks in a single statement.


The 'using statement', not to be confused with the 'using directive' allows us to create safe and clean code when dealing with unmanaged resources.


Further reads


The :? operator (MSDN)


The ?? operator (MSDN)


The using statement (MSDN)


The using directive (MSDN)


The IDisposable interface (MSDN)


IDisposable: What your mother never told you about resource deallocation (CodeProject)




Previous articles in this series


Exploring lesser known C# Language features Part I (the 'yield' statement)





Hello fellow vCampus members!


The vCampus All-Star awards are granted to vCampus members that actively share their technical expertise with the community. They are considered the most active and most valuable members in the community. Last year there where 3 All-Stars awarded. These where Rhys Kirk from RJK Solutions, Asle Frantzen from Amitec and myself (when I was still working for our partner Atos Origin).


This year we will again reward those who are considered the most valuable members in the community. Next to getting recognized by the community, being a vCampus All-Star will profile yourself (and your company) as being PI development experts. We are planning on announcing the vCampus All-Stars for this year in October. You can get awarded multiple years in a row for your continued involvement with vCampus.


Being a vCampus All-Star will also get you:

  • Personal vCampus blog (if desired)
  • Moderate vCampus forums (if desired)
  • Voluntary participation to team meetings
  • Free admissions for the year to come
    • OSIsoft vCampus & OSIsoft vCampus Live
    • Users Conference
  • A few more surprises…

OSIsoft and the vCampus team will determine who are considered the most valuable members, and who are eligable for this award. We do need input from the community for this. We really want to hear from you! Who do you consider the most valuable members? Is there someone who always has bright answers and questions, who takes part in discussions, and who you consider being among the best and brightest on vCampus?


Let us know by emailing to











Filter Blog

By date: By tag: