Hi again. Last time we found how to choose AF database or PI Data Archive. I will be working just with AF Databases from now. If you want, I can make some chapters about PI Data Archives too, but I would like to focus on AF for now.

 

So what we did to choose the database:

1. We added information that we would like to use these classes:

using OSIsoft.AF;  
using OSIsoft.AF.Asset;  

 

2. We choosed the server and the database:

PISystems myPIsystems = new PISystems();
PISystem myPISystem = myPIsystems["W-SRV1"];
AFDatabases myDatabases = myPISystem.Databases;
AFDatabase myDatabase = myDatabases["test"];

 

'W-SRV1' is my server name and 'test' is name of the database.

 

Printing information

Today I would like to show how to print some information about selected server and database to the command line.

 

For this we will need to know how to use Consolas.Write() and Consolas.WriteLine() methods. WriteLine print sthe content to the new line so it is useful.You can put what you want into braces, string or variable. If you want to put some variable into a string, you can use this:

Consolas.WriteLine("Parameters are: param1 {0}, param2 {1}...", variabile1, variabile2);

 

{x} will be replaced with variables after comas.

Now I would like to show how to make little report about selected database an.If you write you PISystem variable name and 'dot' you get the list of methods and parameters .

Parameters contains some information, configuration or child objects and this is what we want.

Console.WriteLine(myPISystem.Name);
Console.WriteLine("Version: {0}", myPISystem.ServerVersion);
Console.WriteLine("Connected user {0}, ", myPISystem.CurrentUserName);
Console.WriteLine("Server time is: {0}", myPISystem.ServerTime);
Console.WriteLine("Server timezone: {0}", myPISystem.ServerTimeZone);
Console.WriteLine("-------------------------------------------------------------------------------");
Console.WriteLine("Selected database: {0}           Last modification: {1}", myDatabase.Name, myDatabase.ModifyDate);

 

If you run debug now you will not be able to see command line, because the application is ended immediately. It is why I have never ending loop at the end:

while(true);

 

Result

End

Ok so this is all for now. You should be able to use parameter and print your own reports. Next chapter will be about how to get data from attributes.