Click or drag to resize
OSIsoft, LLC

AFSearchTFindObjectFieldsTObject Method (String, FuncIListObject, TObject, Int32, Int32)

This method will return the values as an object for the specified fields for each of the objects that match the search tokens using the supplied factory delegate.

Namespace:  OSIsoft.AF.Search
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 2.10.6.195
Syntax
public override IEnumerable<TObject> FindObjectFields<TObject>(
	string fields,
	Func<IList<Object>, TObject> factory,
	int startIndex = 0,
	int pageSize = 0
)

Parameters

fields
Type: SystemString
The string that defines the list of fields to be returned from the search for each object. The valid field names are listed below and are separated by whitespace. The order of the returned list of values for each object used in the factory delegate is defined by this parameter.
factory
Type: SystemFuncIListObject, TObject
The delegate that is used to convert the returned list of values for each object into the user-defined return type. The order of the list of values is defined by the order of the fields parameter.
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 the returned fields are mapped into using the specified factory delegate.

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(String, FuncIListObject, TObject, 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 the fields parameter is a or empty string.
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').

Examples
// 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 as an anonymous type.
    count = 0;
    var foundItems2 = search.FindObjectFields("ID Name StartTime EndTime |Level",
        i => new { ID = i[0], Name = i[1], Start = i[2], End = i[3], Value = i[4] });
    Console.WriteLine("Find Object Fields using Anonymous Type:");
    foreach (var row in foundItems2)
    {
        count++;
        Console.WriteLine("ID={0}, N='{1}', ST={2}, ET={3}, V={4}",
            row.ID, row.Name, row.Start, row.End, row.Value);
    }
    Console.WriteLine("Found {0} EventFrames.", count);

    // Return event frame name as list of strings.
    count = 0;
    var foundItems3 = search.FindObjectFields("Name", i => i[0].ToString());
    Console.WriteLine("Find Object Names as list of strings:");
    foreach (var row in foundItems3)
    {
        count++;
        Console.WriteLine(row);
    }
    Console.WriteLine("Found {0} EventFrames.", count);
    // 
    // Return event frame security tokens as list and check security for current user.
    count = 0;
    var foundItems4 = search.FindObjectFields("SecurityToken", i => (AFSecurityRightsToken)i[0]);
    Console.WriteLine("Find Object SecurityTokens and Check Security:");
    foreach (var tokenList in foundItems4.ChunkedBy(500))
    {
        // Check Security using Windows Identity.
        var rights = AFSecurity.CheckSecurity(myPISystem, WindowsIdentity.GetCurrent(), tokenList);
        foreach (var rightsItem in rights)
        {
            Console.WriteLine($"  Security Rights for '{myPISystem.CurrentUserName}': {rightsItem.Key} = {rightsItem.Value}");
        }

        // Check Security using Identities.
        rights = AFSecurity.CheckSecurity(myPISystem, myPISystem.CurrentUserIdentities, tokenList, myPISystem.CurrentUserName);
        foreach (var rightsItem in rights)
        {
            Console.WriteLine($"  Security Rights for '{myPISystem.CurrentUserIdentityString}': {rightsItem.Key} = {rightsItem.Value}");
        }
        count += tokenList.Count;
    }
    Console.WriteLine("Found {0} EventFrames.", count);
}
Version Information

AFSDK

Supported in: 2.10.5
See Also
Enabling Operational Intelligence