3 Replies Latest reply on Mar 6, 2018 9:10 PM by Rick Davin

    AFEventFrameSearch by Element ID


      Struggling with the AFEventFrame search class to implement a search by category for Event Frames starting in a given time period for a specific AF Element. The code below doesn't return any records for Elements that have Event Frames.


      AFElement unit ....

      string query = @"CategoryName:='" + category + "' Element:=" + unit.ID.ToString() + "";              

      AFEventFrameSearch efs = new AFEventFrameSearch(afd, "EFSearch",AFEventFrameSearchMode.ForwardFromStartTime, new AFTime("*-90d"), query);

      List<AFEventFrame> efList = efs.FindEventFrames().ToList();


      The Search Overview documentation was not completely clear to me on querying by Element GUID.


        • Re: AFEventFrameSearch by Element ID
          Rick Davin

          Hi Brendan,


          What version of AF Client and Server are you using?


          With AF SDK 2.9.0, the AFSearch classes became disposable, so we urge to you wrap your code within a using statement.


          We also strongly recommend you opt-in to server-side caching by specifying a CacheTimeout > 0.


          Unless you absolutely, positively know the returned result count will be reasonably small, you should use ToList() with caution.  You don't want to choke the client PC trying to download half a million event frames into a list.


          AF SDK 2.7.5 allows the name to be an ID if formatted correctly.  AF SDK 2.10 will actually have an ID filter, making it all the easier.  Anyway, the correct way to use the ID as a name or path would be:




          It does not contain any blanks so you don't have to wrap it in quotes.  You may do so if you like.  If the above still doesn't work for you, I would suggest the following instead:




          But you should definitely wrap that in quotes.  On the topic of quotes, your query string could become an Interpolated String as in:


          string query = $"CategoryName:='{category}' Element:='{unit.ID.ToString("B")}' ";


          The blank between the last single and double quotes is added for emphasis.  Putting it altogether, it could look like:


          string query = $"CategoryName:='{category}' Element:='{unit.ID.ToString("B")}' ";
          using (AFEventFrameSearch efs = new AFEventFrameSearch(afd, "EFSearch",AFEventFrameSearchMode.ForwardFromStartTime, new AFTime("*-90d"), query))
              efs.CacheTimeout = TimeSpan.FromMinutes(10);
             IEnumerable <AFEventFrame> eventFrames = efs.FindEventFrames();
              foreach (AFEventFrame eventFrame in eventFrames)
                  // do something


          Finally one very last critical thing to know.  The CategoryName to be filtered is the Event Frame's category.  It's not the Element's or any attribute(s)'s categories.