Click or drag to resize
OSIsoft, LLC

PIServerFindChangedPIPoints Method

Find all the PI Points that have changed in the PIServer.

Namespace:  OSIsoft.AF.PI
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 2.10.6.195
Syntax
public IList<PIPointChangeInfo> FindChangedPIPoints(
	int maxCount,
	Object cookie,
	out PIPointChangesCookie nextCookie,
	IEnumerable<PIPoint> filterPoints = null
)

Parameters

maxCount
Type: SystemInt32
The maximum number of changes to be returned.
cookie
Type: SystemObject
Use the return from a previous call to this method to find all changes since the last call. Pass begin monitoring for changes to PI Points on the PIServer. Pass an AFTime to find all changes, since a particular time.
nextCookie
Type: OSIsoft.AF.PIPIPointChangesCookie
An object to pass into the next call to this method to find all changes since the previous call.
filterPoints (Optional)
Type: System.Collections.GenericIEnumerablePIPoint
A list of PIPoint objects for which the resulting changes should be filtered.

Return Value

Type: IListPIPointChangeInfo
A list of PIPointChangeInfo structures which represent the PI Points that have changed in the PIServer.
Exceptions
ExceptionCondition
ArgumentExceptionWhen the cookie is not of a valid type.
ArgumentOutOfRangeExceptionWhen the maxCount is less than or equal to zero.
PIConnectionExceptionA connection to the PI Data Archive server cannot be made.
Remarks
This method uses a pipe to track changes to PIPoint objects on a PIServer. If an AFTime is passed as the cookie, then a query is used to find changes since the given time. After the query completes, a new pipe is established to more efficiently track changes to subsequent calls via the nextCookie. The pipe is faster and more efficient than the query. Since the pipe is faster and more efficient users should only pass in an AFTime for the cookie on the first call. If the pipe loses connection, then a query is used to find changes that have occurred while the pipe was down. Queries will not reveal points that have been deleted; therefore, FindChangedPIPoints cannot report deleted points while the pipe is down unless filterPoints have been passed. If filterPoints have been provided, then their IDs will be validated after a query is used to backfill changes that occurred while the pipe was down. Any IDs that are not valid, will be reported as removed PI Points.
Examples
// Get the PIServers collection for the current user and default PIServer.
PIServer myPIServer = new PIServers().DefaultPIServer;

// File used to persist the cookie while the process is not running.
FileStream cookieFile = null;

// Used to serialize / deserialize the cookie
IFormatter formatter = new BinaryFormatter();

// Cookie used to get changes since the last call
PIPointChangesCookie cookie = null;

try
{
    // Try to open the file containing the persisted cookie
    using (cookieFile = new FileStream("cookie.dat", FileMode.Open))
    {
        // Try to read the cookie from the file
        cookie = (PIPointChangesCookie)formatter.Deserialize(cookieFile);

        cookieFile.Close();
    }
}
catch (FileNotFoundException) { /* Cookie has never been persisted */ }
catch (SerializationException) { /* Cookie could not be read */ }
catch (SecurityException) { /* No permission to read this file */ }
catch (IOException) { /* Some other I/O Exception */ }

// If the cookie is null, initialize it to start monitoring changes
if (ReferenceEquals(cookie, null))
    myPIServer.FindChangedPIPoints(int.MaxValue, null, out cookie);

// Perform the operation 100 times...
for (int loopIndex = 0; loopIndex < 100; loopIndex++)
{
    // Create a new point which should cause a change
    PIPoint testPoint = myPIServer.CreatePIPoint("testPoint");

    // Edit the point's name to cause a change
    testPoint.Name = "testPoint_Renamed";

    // Delete the point which should cause a change
    myPIServer.DeletePIPoint(testPoint.Name);

    // Log changes that have occurred since the last call
    IList<PIPointChangeInfo> changes = myPIServer.FindChangedPIPoints(
        int.MaxValue, cookie, out cookie);

    if (!ReferenceEquals(changes, null))
    {
        foreach (PIPointChangeInfo change in changes)
        {
            Console.WriteLine("ID: {0} Action: {1}", change.ID, change.Action);
        }
    }

    // Sleep for three seconds, don't peg the CPU
    System.Threading.Thread.Sleep(3000);
}

try
{
    // Persist cookie so that the process can pick up changes where it left off
    using (cookieFile = new FileStream("cookie.dat", FileMode.Create))
    {
        // Write the cookie to the file
        formatter.Serialize(cookieFile, cookie);

        cookieFile.Close();
    }
}
catch (SerializationException) { /* Cookie could not be written */ }
catch (SecurityException) { /* No permission to write this file */ }
catch (IOException) { /* Some other I/O Exception */ }
Version Information

AFSDK

Supported in: 2.10.5, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7, 2.6
See Also
Enabling Operational Intelligence