Cross Point


Collecting events

The following code snippet assumes you already have connected to a network and located a reader. This example collects all events, but it will display only the latest 10 events. Note that collecting all events is pretty slow, so be patient while this example executes...

The easiest method of executing this sample is to paste the code inside the sample code of Opening networks and locating readers example, just after the number of users is displayed, but before the Logoff method is called.

// Assume that oReader holds a valid logged-on reader object.

// Collect all events, this may take a while....
oReader.EventDatabase.CollectEvents();

// Copy all events to another object (only for readability)
var oEvents = oReader.EventDatabase.Events;
WScript.Echo("Number of collected events: " + oEvents.Count);
        
// Start with the newest item in the collection
var i = 0;
var oEvent = oEvents.LastItem;
while (oEvent && i < 10)
{
        // Display a messagebox with the text
        WScript.Echo("Date: " + oEvent.Date + ", Event: " + oEvent.Description);

        // Get the previous item in the collection
        oEvent = oEvents.PreviousItem;

        // Simple counter to stop this loop if we displayed the last 10 events
        i++;
}

© Copyright 2001 - 2006 Cross Point. Generated on Mon Mar 12 16:29:52 2007 Cross Point