public void Run() { PISystems piSystems = new PISystems(); PISystem piSystem = piSystems["<AFSERVER>"]; AFDatabase afDatabase = piSystem.Databases["NuGreen"]; const int pageSize = 1000; int startIndex = 0; int totalCount; do { // Find a collection of elements instantiated from the Boiler tempplate. // Only the Elements' header information (Name, Description, Template, Type, etc.) // are loaded from the AF Server by this call. AFNamedCollection <AFElement> elements = AFElement.FindElements( database: afDatabase, searchRoot: null, query: "Boiler", field: AFSearchField.Template, searchFullHierarchy: true, sortField: AFSortField.Name, sortOrder: AFSortOrder.Ascending, startIndex: startIndex, maxCount: pageSize, totalCount: out totalCount); if (elements == null) { break; } // This call goes to the AF Server to fully load the found elements in one call, // so further AF Server calls can be avoided. AFElement.LoadElements(elements); // Now we can use the elements without having to make any additional server calls. // In the example below, accessing the Attributes collection would have // caused an additional call per element if we had not called LoadElements previously. Console.WriteLine("Found {0} Elements.", elements.Count); foreach (AFElement item in elements) { Console.WriteLine(" Element {0} has {1} Attributes", item.Name, item.Attributes.Count); } startIndex += pageSize; } while (startIndex < totalCount); }
public void Run() { PISystems piSystems = new PISystems(); PISystem piSystem = piSystems["<AFSERVER>"]; AFDatabase afDatabase = piSystem.Databases["NuGreen"]; const int pageSize = 1000; int startIndex = 0; int totalCount; do { // Find a collection of elements instantiated from the Boiler tempplate. // Only the Elements' header information (Name, Description, Template, Type, etc.) // are loaded from the AF Server by this call. AFNamedCollection <AFElement> elements = AFElement.FindElements( database: afDatabase, searchRoot: null, query: "Boiler", field: AFSearchField.Template, searchFullHierarchy: true, sortField: AFSortField.Name, sortOrder: AFSortOrder.Ascending, startIndex: startIndex, maxCount: pageSize, totalCount: out totalCount); if (elements == null) { break; } // Because we are just retrieving the element's name, no additional calls // to the AF Server are made. Console.WriteLine("Found {0} Elements.", elements.Count); foreach (AFElement item in elements) { Console.WriteLine(" Element name is {0}.", item.Name); } startIndex += pageSize; } while (startIndex < totalCount); }
public void Run() { PISystems piSystems = new PISystems(); PISystem piSystem = piSystems["<AFSERVER>"]; AFDatabase afDatabase = piSystem.Databases["NuGreen"]; AFElementTemplate boilerTemplate = afDatabase.ElementTemplates["Boiler"]; const int pageSize = 1000; int startIndex = 0; int totalCount; do { // Find a collection of elements instantiated from the Boiler tempplate. // Only the Elements' header information (Name, Description, Template, Type, etc.) // are loaded from the AF Server by this call. AFNamedCollection <AFElement> elements = AFElement.FindElements( database: afDatabase, searchRoot: null, query: "Boiler", field: AFSearchField.Template, searchFullHierarchy: true, sortField: AFSortField.Name, sortOrder: AFSortOrder.Ascending, startIndex: startIndex, maxCount: pageSize, totalCount: out totalCount); if (elements == null) { break; } // Partially load the element by retrieving information only for the Water Flow attribute. AFElement.LoadAttributes(elements, new[] { boilerTemplate.AttributeTemplates["Water Flow"] }); Console.WriteLine("Found {0} Elements.", elements.Count); AFAttributeList attrList = new AFAttributeList(); // Because we are retrieving the Water Flow attribute which was previously loaded, // no additional server calls are made. // If LoadAttributes had not been called previously, then a server call would have been made for each element // in the loop below. foreach (AFElement item in elements) { attrList.Add(item.Attributes["Water Flow"]); } AFValues values = attrList.GetValue(); Console.WriteLine(" Water Flow values"); foreach (AFValue val in values) { Console.WriteLine(" Element: {0}, Timestamp: {1}, Value: {2}", val.Attribute.Element, val.Timestamp, val.Value.ToString()); } startIndex += pageSize; } while (startIndex < totalCount); }
private static OSIsoft.AF.Search.AFEventFrameSearch searchToCriteria(OSIsoft.AF.UI.PropertyPage.EventFrameSearchPage page) { //page.EventFrameCriteria.SearchMode; AFDatabase db = page.Database; string start = page.EventFrameCriteria.StartTime; string end = page.EventFrameCriteria.EndTime; string AFstart = page.EventFrameCriteria.AFStartTimeString; bool inProgress = page.EventFrameCriteria.InProgress; string LastFullSeach = page.EventFrameCriteria.LastFullSearchString; LastFullSeach = LastFullSeach.Replace(@"\", "").Replace("\'", "'"); OSIsoft.AF.Search.AFEventFrameSearch timelessTerms = new OSIsoft.AF.Search.AFEventFrameSearch(db, "notime", LastFullSeach); List <AFSearchToken> tokens = timelessTerms.Tokens.ToList(); switch (page.EventFrameCriteria.SearchType) { case OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.ActiveBetween: tokens.Add(new AFSearchToken(AFSearchFilter.Start, AFSearchOperator.LessThanOrEqual, end)); tokens.Add(new AFSearchToken(AFSearchFilter.End, AFSearchOperator.GreaterThanOrEqual, start)); break; case OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EndingAfter: tokens.Add(new AFSearchToken(AFSearchFilter.End, AFSearchOperator.GreaterThanOrEqual, AFstart)); break; case OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EndingBefore: tokens.Add(new AFSearchToken(AFSearchFilter.End, AFSearchOperator.LessThanOrEqual, AFstart)); break; case OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EndingBetween: tokens.Add(new AFSearchToken(AFSearchFilter.End, AFSearchOperator.GreaterThanOrEqual, start)); tokens.Add(new AFSearchToken(AFSearchFilter.End, AFSearchOperator.LessThanOrEqual, end)); break; case OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EntirelyBetween: tokens.Add(new AFSearchToken(AFSearchFilter.Start, AFSearchOperator.GreaterThanOrEqual, start)); tokens.Add(new AFSearchToken(AFSearchFilter.End, AFSearchOperator.LessThanOrEqual, end)); break; case OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.StartingAfter: tokens.Add(new AFSearchToken(AFSearchFilter.Start, AFSearchOperator.GreaterThanOrEqual, AFstart)); if (inProgress) { tokens.Add(new AFSearchToken(AFSearchFilter.InProgress, AFSearchOperator.Equal, "true")); } break; case OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.StartingBefore: tokens.Add(new AFSearchToken(AFSearchFilter.Start, AFSearchOperator.LessThanOrEqual, AFstart)); if (inProgress) { tokens.Add(new AFSearchToken(AFSearchFilter.InProgress, AFSearchOperator.Equal, "true")); } break; case OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.StartingBetween: tokens.Add(new AFSearchToken(AFSearchFilter.Start, AFSearchOperator.GreaterThanOrEqual, start)); tokens.Add(new AFSearchToken(AFSearchFilter.Start, AFSearchOperator.LessThanOrEqual, end)); if (inProgress) { tokens.Add(new AFSearchToken(AFSearchFilter.InProgress, AFSearchOperator.Equal, "true")); } break; } OSIsoft.AF.Search.AFEventFrameSearch criteria = new OSIsoft.AF.Search.AFEventFrameSearch(db, "search", tokens); AFNamedCollection <AFEventFrame> UIFrames = page.EventFrames; IEnumerable <AFEventFrame> AFSDKframes = criteria.FindEventFrames(); try { int count = AFSDKframes.Count() > 1000 ? 1000 : AFSDKframes.Count(); if (UIFrames.Count != count) { MessageBox.Show("They UI and AFKSDK frames report different variables", "Count error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (System.FormatException e) { // Bad event frame search formatting for AFSDK UI. MessageBox.Show(e.Message); } return(criteria); }