7 Replies Latest reply on Jan 26, 2014 8:21 AM by bperry

    Get root elements in a AF database via PI Web Services

    botne

      Hi!

       

       

       

      I would like to fetch the AF tree via webservices.

       

      Using this code I get all the elements of the tree, and when adding

       

      searchmanner.ChildElementDepth = 10; i get all the elements with all the children embedded.

       

       

       
                  PISoapServiceClient afClient = AFClient;
                  ElementSearchConstraints constraints = new ElementSearchConstraints();
                  ElementSearchManner searchManner = new ElementSearchManner();
                  //searchManner.ChildElementDepth = 10;
                  searchManner.IncludeTemplateName = true;
                  constraints.RootPath = selectedSystem.AFRoot;
                  Task<Element[]> getTreeTask = afClient.FindElementsAsync(constraints, searchManner);
      

       

       

      Is there a way I can get only the first Level of elements after database root, but with all the children embedded?

       

      I've looked into GetElementsByPaths but this needs a spesific element to work.

        • Re: Get root elements in a AF database via PI Web Services
          Bhess

          I believe the parameter you're looking for is called "SearchFullHierarchy" in ElementSearchConstraints.  Setting that to false should ensure that your top level results are children (and not all descendants) of the search root.

            • Re: Get root elements in a AF database via PI Web Services
              Bhess

              Oops, I should have looked more closely before posting.  You're correct, this isn't implemented for Element search.  It's there for Event Frame search only.

                • Re: Get root elements in a AF database via PI Web Services
                  botne

                  Yes, that's what I've found as well.

                   

                  Workarounds?

                    • Re: Get root elements in a AF database via PI Web Services
                      Bhess

                      Unless there is some information that is unique to root elements, like name mask, template, category, or attributes, then I'm afraid there's not a way to do this in one call.

                       

                      You can do this in two calls.  First, make the same call you're making now (without specifying child element depth), except add FlatHierarchy=true to the manner.  Iterate over the results list in your client code to pull out the paths of elements having a depth of 0, and submit those paths to GetElementsByPaths, with your child depth specified in the manner in that call.  Not ideal, but that's about the best you'll be able to do at this time.

                        • Re: Get root elements in a AF database via PI Web Services
                          botne

                          For this I've ended up doing a query return all elements, and then using the paths to match up With their parents.

                           

                          Not Nice, but working - and one Query with minimal output over the wire (no children information in xml)

                           

                           

                           
                                      ElementSearchConstraints constraints = new ElementSearchConstraints();
                                      ElementSearchManner searchManner = new ElementSearchManner();
                                      searchManner.IncludeTemplateName = true;
                                      constraints.RootPath = selectedSystem.AFRootPath;
                          
                                      Task<Element[]> getTreeTask = afClient.FindElementsAsync(constraints, searchManner);
                          
                          
                          //In the iteration of the elements i do
                          // Has parents?
                          Element[] parents = elements.Where(n=>n.Path == element.Path.Substring(0, element.Path.Length - element.Name.Length -1)).ToArray();
                          

                           

                            • Re: Get root elements in a AF database via PI Web Services
                              Bhess

                              If you're developing something that'll be reused across multiple AF databases, and you won't necessarily know the data profile, I'd take care to ensure that your approach behaves as expected when working with referenced elements.  By my cursory glance, it looks like it should.

                               

                              Best,

                               

                              Brad

                                • Re: Get root elements in a AF database via PI Web Services
                                  bperry

                                  A note for any folks who come across this thread,

                                   

                                  Pushing the entire hierarchy over the wire gets exponentially ugly when AF databases get big. Unfortunately, workarounds for the PISoapService hierarchy-search limitation are not straightforward, and require you to have some level of control over the target AF database.

                                   

                                  This might be the perfect time to - if REST is an option - check out the newer RESTful PI WebAPI.

                                   

                                  If REST isn't an option, and your client may target large AF databases, performance concerns might lead you to augment PISoapService with a SOAP service of your own.