Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // This factory method is new in 2.8.
            PISystem ps = PISystem.CreatePISystem("PISRV01");

            using (new AFProbe("PrintAttributeCounts", ps))
            {
                AFDatabase db = ps.Databases["Feeder Voltage Monitoring"];

                // Build search object
                AFSearchToken searchToken = new AFSearchToken(
                    filter: AFSearchFilter.Root,
                    searchOperator: AFSearchOperator.Equal,
                    value: db.Elements["Assets"].GetPath());

                AFElementSearch elementSearch = new AFElementSearch(db, "Feeders and Transformers", new[] { searchToken });

                Console.WriteLine("Feeders and Transformers");
                // Use full load: true to fully load the elements
                foreach (AFElement element in elementSearch.FindElements(fullLoad: true))
                {
                    Console.WriteLine("Element: {0}, # Attributes: {1}", element.Name, element.Attributes.Count);
                }
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to quit");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            // This factory method is new in 2.8.
            PISystem ps = PISystem.CreatePISystem("PISRV01");

            using (new AFProbe("PrintAttributeCounts", ps))
            {
                AFDatabase db = ps.Databases["Feeder Voltage Monitoring"];

                // Build search object
                AFSearchToken searchToken = new AFSearchToken(
                    filter: AFSearchFilter.Root,
                    searchOperator: AFSearchOperator.Equal,
                    value: db.Elements["Assets"].GetPath());

                AFElementSearch elementSearch = new AFElementSearch(db, "Feeders and Transformers", new[] { searchToken });

                Console.WriteLine("Feeders and Transformers");
                // Use full load: true to fully load the elements
                foreach (AFElement element in elementSearch.FindElements(fullLoad: true))
                {
                    Console.WriteLine("Element: {0}, # Attributes: {1}", element.Name, element.Attributes.Count);
                }
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to quit");
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        internal static AFEventFrameSearch currentEventFrame(AFEventFrameSearch query)
        {
            List <AFSearchToken> tokens = query.Tokens.ToList();

            tokens.RemoveAll(t => t.Filter == AFSearchFilter.InProgress || t.Filter == AFSearchFilter.AllDescendants || t.Filter == AFSearchFilter.End || t.Filter == AFSearchFilter.Start || t.Filter == AFSearchFilter.Duration);
            AFSearchToken inprogress = new AFSearchToken(AFSearchFilter.InProgress, AFSearchOperator.Equal, "True");

            tokens.Add(inprogress);
            return(new AFEventFrameSearch(query.Database, "CurrentEventFrame", tokens));
        }
Ejemplo n.º 4
0
        public static List <AFElement> FindRepositoryById(AFElement orgElement, PluginParams pluginParams, string repositoryId)
        {
            AFSearchToken   templateToken = new AFSearchToken(AFSearchFilter.Template, AFSearchOperator.Equal, pluginParams.RepositoryTemplate.GetPath());
            AFSearchToken   valueToken    = new AFSearchToken(AFSearchFilter.Value, AFSearchOperator.Equal, repositoryId, pluginParams.RepositoryTemplate.AttributeTemplates[RepositoryIdAttributeName].GetPath());
            AFElementSearch elementSearch = new AFElementSearch(orgElement.Database, "FindRepositoryById", new[] { templateToken, valueToken });

            elementSearch.Refresh();
            var searchResult = elementSearch.FindElements(0, true, 1).ToList();

            return(searchResult);
        }
Ejemplo n.º 5
0
        static AFEventFrameCriteria queryToCriteria(OSIsoft.AF.Search.AFEventFrameSearch query)
        {
            AFEventFrameCriteria criteria = new AFEventFrameCriteria();

            criteria.Database = query.Database;
            IList <AFSearchToken> starts;

            query.TryFindSearchTokens(OSIsoft.AF.Search.AFSearchFilter.Start, out starts);
            IList <AFSearchToken> ends;

            query.TryFindSearchTokens(OSIsoft.AF.Search.AFSearchFilter.End, out ends);
            AFSearchToken templatename;

            query.TryFindSearchToken(OSIsoft.AF.Search.AFSearchFilter.Template, out templatename);
            IList <AFSearchToken> values;

            query.TryFindSearchTokens(OSIsoft.AF.Search.AFSearchFilter.Value, out values);

            if (values.Count != 0)
            {
                AFAttributeValueQuery[] queries = new AFAttributeValueQuery[values.Count];
                criteria.AttributeValueQueries = new AFAttributeValueQuery[values.Count];
                criteria.TemplateName          = templatename.Value;
                for (int i = 0; i < values.Count; i++)
                {
                    AFSearchToken       value             = values[i];
                    string              attributeName     = value.Path.TrimStart(new char[] { '|' });
                    AFElementTemplate   template          = query.Database.ElementTemplates[templatename.Value];
                    AFAttributeTemplate templateAttribute = template.AttributeTemplates[attributeName];
                    queries[i] = new AFAttributeValueQuery(templateAttribute, value.Operator, value.Value, templateAttribute.DefaultUOM);
                    criteria.AttributeValueQueries[i] = new AFAttributeValueQuery(templateAttribute, value.Operator, value.Value, templateAttribute.DefaultUOM);
                }

                //criteria.AttributeValueQueries = queries;
                //criteria.ValueQueryString = value.ToString();
                //criteria.
            }
            if (ends.Count == 2)
            {
                criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EndingBetween;
                criteria.StartTime  = ends[0].Value;
                criteria.EndTime    = ends[1].Value;
            }
            else if (starts.Count == 2)
            {
                criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.StartingBetween;
                criteria.StartTime  = starts[0].Value;
                criteria.EndTime    = starts[1].Value;
            }
            else if (starts.Count == 1 && ends.Count == 1)
            {
                AFSearchToken start = starts[0];
                AFSearchToken end   = ends[0];
                if (start.Operator == AFSearchOperator.LessThanOrEqual && end.Operator == AFSearchOperator.GreaterThanOrEqual)
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.ActiveBetween;
                    criteria.StartTime  = end.Value;
                    criteria.EndTime    = start.Value;
                }
                else if (start.Operator == AFSearchOperator.GreaterThanOrEqual && end.Operator == AFSearchOperator.LessThanOrEqual)
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EntirelyBetween;
                    criteria.StartTime  = start.Value;
                    criteria.EndTime    = end.Value;
                }
            }
            else if (starts.Count == 1)
            {
                AFSearchToken start = starts[0];
                if (start.Operator == AFSearchOperator.GreaterThanOrEqual)
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.StartingAfter;
                }
                else
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.StartingBefore;
                }
                criteria.AFStartTimeString = start.Value;
            }
            else if (ends.Count == 1)
            {
                AFSearchToken end = ends[0];
                if (end.Operator == AFSearchOperator.GreaterThanOrEqual)
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EndingAfter;
                }
                else
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EndingBefore;
                }
                criteria.AFStartTimeString = end.Value;
            }

            criteria.LastFullSearchString = stripTokens(query);
            return(criteria);
        }