Click or drag to resize
OSIsoft, LLC

AFSearchTFindObjectFieldsTObject Method (Int32, Int32)

This method will return the values for the fields defined by the user-defined type for each of the objects that match the search tokens.

Namespace:  OSIsoft.AF.Search
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 2.10.6.195
Syntax
public override IEnumerable<TObject> FindObjectFields<TObject>(
	int startIndex = 0,
	int pageSize = 0
)
where TObject : class

Parameters

startIndex (Optional)
Type: SystemInt32
The starting index (zero based) of the items to be returned.
pageSize (Optional)
Type: SystemInt32
The page size used for retrieving objects from the server. If this parameter is less than or equal to zero, then the page size will be set to the current value of the CollectionPageSize setting.

Type Parameters

TObject
The user-defined type of the object that is used for returning the field values. The type will define which fields are returned for each of the objects. By default, the field and/or property names in the user-defined type must match the desired object field names to be returned. If they do not match, then they will be skipped. The AFSearchObjectFieldAttribute can be used to specify the object field name to be used for the field or property instead of relying on the default mapping.

Return Value

Type: IEnumerableTObject
Returns an enumerable list of the used-defined objects for each object found using the search tokens for this search object.

Implements

IAFSearchTFindObjectFieldsTObject(Int32, Int32)
Exceptions
ExceptionCondition
FormatException This exception is thrown if the ThrowOnError property is and there is a format error in the search query.
NotSupportedException This exception is thrown if the ThrowOnError property is and one of the filters is not supported or the query is too complex to be evaluated by the server.
ArgumentNullException This exception is thrown if specified return type does not define any object fields to be returned.
InvalidCastException An invalid cast exception will the thrown when the type of the field value cannot be converted to the type of the associated field or property in the user-defined type.
Remarks

This method can be used to return only the values for the specified fields for each of the objects that match the search tokens instead of returning the full object. This can improve performance when the full object is not required and only some of the object's fields will be used.

The following chart shows which object fields are supported by each AFSearch class.

The following is a list of the supported object field names along with a description of each field. Unless otherwise indicted, the field values are returned as strings.

NameDescription
Analysis The name of the found object's Analysis.
AnalysisID The ID of the found object's Analysis returned as a Guid.
Categories The list of the found object's Categories.
ConfigString The found object's ConfigString.
Contact The name of the found object's Contact.
ContactID The ID of the found object's Contact returned as a Guid.
CreationDate The date when the found object was created returned as an AFTime.
Description The found object's Description.
Destination The found object's Destination.
DestinationID The ID of the found object's Destination returned as a Guid.
DisplayDigits The found object's DisplayDigits returned as a Int32.
Duration The found object's Duration. This is the AFTimeSpan between the object's StartTime and EndTime.
Element The name of the found object's Element.
ElementID The ID of the found object's Element returned as a Guid.
EndTime The found object's EndTime returned as an AFTime.
ID The found object's ID returned as a Guid.
IsAcknowledged The value of the found object's IsAcknowledged setting returned as a Boolean.
IsAnnotated The value of the found object's IsAnnotated setting returned as a Boolean.
IsInternal The value of the found object's IsInternal returned as a Boolean.
IsManualDataEntry The value of the found object's IsManualDataEntry returned as a Boolean.
ModifyDate The date when the found object was last modified returned as an AFTime.
Name The found object's Name.
Parent The name of the found object's Parent.
PlugIn The name of the found object's PlugIn. For AFAnalysisSearch and AFAnalysisTemplateSearch it will be the name of either the AnalysisRulePlugIn or TimeRulePlugIn. For AFNotificationContactTemplateSearch, it will be the name of the DeliveryChannelPlugIn.
PlugInID The ID of the found object's PlugIn returned as a Guid. For AFAnalysisSearch and AFAnalysisTemplateSearch it will be the ID of either the AnalysisRulePlugIn or TimeRulePlugIn. For AFNotificationContactTemplateSearch, it will be the ID of the DeliveryChannelPlugIn.
ParentID The ID of the found object's Parent returned as a Guid.
SecurityString The found object's SecurityString.
SecurityToken The value of the found object's SecurityToken returned as an AFSecurityRightsToken.
Severity The found object's Severity.
Source The name of the found object's Source.
SourceID The ID of the found object's Source returned as a Guid.
StartTime The found object's StartTime returned as an AFTime.
Status The found object's Status.
Target The name of the found object's Target.
TargetID The ID of the found object's Target returned as a Guid.
Template The name of the found object's Template.
TemplateID The ID of the found object's Template returned as a Guid.
Trait The found object's Trait.
Type The found object's Type.
UOM The name of the found object's UOM.
UOMAbbr The found object's UOM Abbreviation.
UOMID The ID of the found object's UOM.
Value The value of the found object's AFAttribute returned as an AFValue. The returned value will not have its Attribute property set. For AFAttributeSearch this field is specified as 'Value'. Otherwise, this field is specified as a path to the attribute relative to owning Element (e.g. '|Attr#1' or '|Attr#1|Attr#2|Attr#3').

Note Notes to Callers
This method, property, or class is only available in the .NET 4 version of the SDK.

Examples
//*************************************************************************
/// <summary>
/// This class defines the object fields returned from the 
/// FindObjectFields method.
/// </summary>
public class EventFrameFields
{
    // Field mapped using default name.
    public Guid ID;
    // Property mapped using default name.
    public string Name { get; set; }
    // Field mapped using 'ObjectField' attribute.
    [AFSearch.ObjectField("Duration")]
    public AFTimeSpan EFDuration;
    // Property mapped using 'ObjectField' attribute.
    [AFSearch.ObjectField("StartTime")]
    public AFTime EFStart { get; set; }
    // Attribute value mapped to property using 'ObjectField' attribute.
    [AFSearch.ObjectField("|Level")]
    public AFValue Level { get; set; }
}

//*************************************************************************
// Get the Database
PISystems myPISystems = new PISystems();
PISystem myPISystem = myPISystems.DefaultPISystem;
if (myPISystem == null)
    throw new InvalidOperationException("Default PISystem was not found.");
AFDatabase myDB = myPISystem.Databases[dbName];
if (myDB == null)
    throw new InvalidOperationException("Database was not found.");

// Create a search to find all the event frames created from the 'Event'
// template and its 'Level' attribute value is less than 90.
int count;
using (var search = new AFEventFrameSearch(myDB, "FindEventFields", @"Template:'Event' |Level:<90.0"))
{
    search.CacheTimeout = TimeSpan.FromMinutes(10);

    // Do the search
    // Return specified fields using dynamic type conversion.
    count = 0;
    var foundDynItems = search.FindObjectFields<EventFrameFields>();
    Console.WriteLine("Find Object Fields using Dynamic Type Conversion:");
    foreach (var row in foundDynItems)
    {
        count++;
        Console.WriteLine("ID={0}, N='{1}', ST={2}, D={3}, V={4}",
            row.ID, row.Name, row.EFStart, row.EFDuration, row.Level);
    }
    Console.WriteLine("Found {0} EventFrames.", count);
}
Version Information

AFSDK

Supported in: 2.10.5
See Also
Enabling Operational Intelligence