 | AFSearchTFindObjectIds Method |
This method will return a list of the
ID for each object that matches the
search tokens.
Namespace:
OSIsoft.AF.Search
Assembly:
OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 2.10.8.440
Syntaxpublic override IEnumerable<Guid> FindObjectIds(
int startIndex = 0,
int pageSize = 0
)
Public Overrides Function FindObjectIds (
Optional startIndex As Integer = 0,
Optional pageSize As Integer = 0
) As IEnumerable(Of Guid)
Dim instance As AFSearch
Dim startIndex As Integer
Dim pageSize As Integer
Dim returnValue As IEnumerable(Of Guid)
returnValue = instance.FindObjectIds(startIndex,
pageSize)
public:
virtual IEnumerable<Guid>^ FindObjectIds(
int startIndex = 0,
int pageSize = 0
) override
abstract FindObjectIds :
?startIndex : int *
?pageSize : int
(* Defaults:
let _startIndex = defaultArg startIndex 0
let _pageSize = defaultArg pageSize 0
*)
-> IEnumerable<Guid>
override FindObjectIds :
?startIndex : int *
?pageSize : int
(* Defaults:
let _startIndex = defaultArg startIndex 0
let _pageSize = defaultArg pageSize 0
*)
-> IEnumerable<Guid>
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 theCollectionPageSize
setting.
Return Value
Type:
IEnumerableGuid
Returns a list of the
ID for each object that matches the
search tokens for this search object.
Implements
IAFSearchTFindObjectIds(Int32, Int32)
ExceptionsException | Condition |
---|
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.
|
Remarks
The
QuerySearchAnalysis feature can be checked to
determine if this search method is supported by the server. If it is not supported by
the server, then it will be implemented in the SDK.
Examples
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.");
int totalCount = 0;
using (var search = new AFElementSearch(myDB, "FindTanks", @"Template:'TankAdvanced' |Status:<>'OS'"))
{
search.CacheTimeout = TimeSpan.FromMinutes(10);
AFElementTemplate tankTemplate = myDB.ElementTemplates["Tank"];
AFNamedCollectionList<AFAttributeTemplate> myAttributes =
new AFNamedCollectionList<AFAttributeTemplate>();
myAttributes.Add(tankTemplate.AttributeTemplates["Volume"]);
myAttributes.Add(tankTemplate.AttributeTemplates["Level"]);
myAttributes.Add(tankTemplate.AttributeTemplates["Level|HighLimit"]);
myAttributes.Add(tankTemplate.AttributeTemplates["Level|LowLimit"]);
AFTime today = new AFTime("T", CultureInfo.CurrentCulture);
UOM bbl = myDB.PISystem.UOMDatabase.UOMs["bbl"];
UOM meter = myDB.PISystem.UOMDatabase.UOMs["m"];
const int pageSize = 1000;
int startIndex = 0;
IList<Guid> myElementIds = new List<Guid>(pageSize);
do
{
var results = search.FindObjectIds(startIndex, pageSize: pageSize);
myElementIds.Clear();
int c = 0;
foreach (Guid id in results)
{
totalCount++;
myElementIds.Add(id);
c++;
if (c >= pageSize)
break;
}
if (myElementIds.Count == 0) break;
AFNamedCollectionList<AFElement> elements =
AFElement.LoadAttributes(myPISystem, myElementIds, myAttributes);
foreach (AFElement element in elements)
{
try
{
AFAttributeList attributes = new AFAttributeList();
attributes.Add(element.Attributes["Volume"]);
attributes.Add(element.Attributes["Level"]);
attributes.Add(element.Attributes["Level|HighLimit"]);
attributes.Add(element.Attributes["Level|LowLimit"]);
AFValues values = attributes.GetValue(today);
if (values[0].IsGood && values[1].IsGood &&
values[2].IsGood && values[3].IsGood)
{
double volume = (double)values[0].Convert(bbl).Value;
double level = (double)values[1].Convert(meter).Value;
double high = (double)values[2].Convert(meter).Value;
double low = (double)values[3].Convert(meter).Value;
Console.WriteLine("Tank Inventory for '{0}' is {1} bbl. %Full={2}",
element.Name, volume, 100 * (high - low) / level);
}
else
{
Console.WriteLine("Bad data in Tank '{0}'", element.Name);
}
}
catch (FormatException)
{
Console.WriteLine("Error in Tank '{0}'", element.Name);
}
}
startIndex += myElementIds.Count;
} while (myElementIds.Count > 0 && myElementIds.Count >= pageSize);
}
Console.WriteLine("Processed {0} Elements.", totalCount);
Dim myPISystems As New PISystems()
Dim myPISystem As PISystem = myPISystems.DefaultPISystem
If myPISystem Is Nothing Then
Throw New InvalidOperationException("Default PISystem was not found.")
End If
Dim myDB As AFDatabase = myPISystem.Databases(dbName)
If myDB Is Nothing Then
Throw New InvalidOperationException("Database was not found.")
End If
Dim totalCount As Integer = 0
Using search As New AFElementSearch(myDB, "FindTanks", )
search.CacheTimeout = TimeSpan.FromMinutes(10)
Dim tankTemplate As AFElementTemplate = myDB.ElementTemplates("Tank")
Dim myAttributes As New AFNamedCollectionList(Of AFAttributeTemplate)()
myAttributes.Add(tankTemplate.AttributeTemplates("Volume"))
myAttributes.Add(tankTemplate.AttributeTemplates("Level"))
myAttributes.Add(tankTemplate.AttributeTemplates("Level|HighLimit"))
myAttributes.Add(tankTemplate.AttributeTemplates("Level|LowLimit"))
Dim today As New AFTime("T", CultureInfo.CurrentCulture)
Dim bbl As UOM = myDB.PISystem.UOMDatabase.UOMs("bbl")
Dim meter As UOM = myDB.PISystem.UOMDatabase.UOMs("m")
Const pageSize As Integer = 1000
Dim startIndex As Integer = 0
Dim myElementIds As IList(Of Guid) = New List(Of Guid)(pageSize)
Do
Dim results As IEnumerable(Of Guid) = search.FindObjectIds(startIndex, pageSize:=pageSize)
myElementIds.Clear()
Dim c As Integer = 0
For Each id As Guid In results
totalCount += 1
myElementIds.Add(id)
c += 1
If c >= pageSize Then
Exit For
End If
Next
If myElementIds.Count = 0 Then
Exit Do
End If
Dim elements As AFNamedCollectionList(Of AFElement) =
AFElement.LoadAttributes(myPISystem, myElementIds, myAttributes)
For Each element As AFElement In elements
Try
Dim attributes As New AFAttributeList()
attributes.Add(element.Attributes("Volume"))
attributes.Add(element.Attributes("Level"))
attributes.Add(element.Attributes("Level|HighLimit"))
attributes.Add(element.Attributes("Level|LowLimit"))
Dim values As AFValues = attributes.GetValue(today)
If values(0).IsGood AndAlso values(1).IsGood AndAlso values(2).IsGood AndAlso values(3).IsGood Then
Dim volume As Double = CDbl(values(0).Convert(bbl).Value)
Dim level As Double = CDbl(values(1).Convert(meter).Value)
Dim high As Double = CDbl(values(2).Convert(meter).Value)
Dim low As Double = CDbl(values(3).Convert(meter).Value)
Console.WriteLine(, element.Name, volume, 100 * (high - low) / level)
Else
Console.WriteLine(, element.Name)
End If
Catch generatedExceptionName As FormatException
Console.WriteLine(, element.Name)
End Try
Next
startIndex += myElementIds.Count
Loop While myElementIds.Count > 0 AndAlso myElementIds.Count >= pageSize
End Using
Console.WriteLine("Processed {0} Elements.", totalCount)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
Version InformationAFSDK
Supported in: 2.10.5
See Also