3 Replies Latest reply on Apr 13, 2017 1:57 PM by David Hearn

    AFCase.FindCases Not Returning Results After Use of RemoveCase Method for Analysis

    bjsower

      I am trying to use the overload for AFCase.FindCases with a start and end date and max count arguments to find cases within a time range and then looping through each case and using the RemoveCase method for the AF analysis which they belong to.  Since I don't know how many cases there are I set the max count to a value like 25 and on the first call to find cases it returns 25 rows which I remove and then do a check-in.  I then loop around again and try to use the Find Cases method with all the same values for the arguments.  On the second attempt it does not find any cases, yet I know there are still are cases within that time frame.  If I stop and restart the application using the same values for the arguments it finds cases on the first call to AFCase.FindCases, but not on the 2nd pass after removing the cases and performing a check-in.  What am I doing wrong?

        • Re: AFCase.FindCases Not Returning Results After Use of RemoveCase Method for Analysis
          tramachandran

          The FindCases method returns a AFNamedCollectionList<AFCase> which has a Count property which will help you determine how many items were returned. You may loop through the list to perform operation on the members of the list.

           

          Would it be possible for you to share the code snippet and could you let me know of the AFSDK version you are using?

            • Re: AFCase.FindCases Not Returning Results After Use of RemoveCase Method for Analysis
              bjsower

              Dow Corning Confidential - INTERNAL

              Thank you for your response.  I am using AF 2.4.  I am using a similar technique for AFDB transfrers with no problem.

               

              public bool PurgeCases(DateTime SearchStart, DateTime SearchEnd)

                      {

                          string RtnName = "PurgeCases";

                          DateTime StartTime = DateTime.Now;

                          m_ErrMsg = "";

               

                          long i = 0;

                          long j = 0;

                          string LogPath = m_CasePath;

                          bool Continue;

               

                          try

                          {

                              bool DeleteFolder = false; //Probably better to handle file/folder maintenance elsewhere in case we want to keep the AF values longer the the files/folders **

                              bool UseSQL       = bool.Parse(m_RootElmt.Elements["Maintenance"].Attributes["AFCasePurge"].Attributes["UseSQL"].GetValue().Value.ToString());

                              bool DoAFExport   = bool.Parse(m_RootElmt.Elements["Maintenance"].Attributes["AFCasePurge"].Attributes["DoAFExport"].GetValue().Value.ToString());

                              long CheckInCount = long.Parse(m_RootElmt.Elements["Maintenance"].Attributes["AFCasePurge"].Attributes["CheckInCount"].GetValue().Value.ToString());

                              int LoopCount = 0;

                              bool AllProcessed = false;

                              long MaxQueryCount= 500;

               

                              DoAFExport = false; //Override Until Decide if we really need this.  Could also make it a parameter to pass in **

                              UseSQL     = false; //Override Until Decide if we really need this in AF 2.x **

               

               

                              //** Find Cases In Time Range **

                              //AFCases AnalCases = m_AFAnalysis.GetCases(AFSearchMode.StartInclusive, SearchStart, SearchEnd, 0);

                              do

                              {

                                  AFNamedCollectionList();

                                  AnalCases = AFCase.FindCases(m_AFAnalysis, AFSearchMode.StartInclusive, SearchStart, SearchEnd, null, null, null,

                                                               OSIsoft.AF.AFSortField.StartTime, OSIsoft.AF.AFSortOrder.Ascending, (int)MaxQueryCount);

               

                                  AllProcessed = (AnalCases.Count == 0);

                                  LoopCount++;

                                  i = 0;

                                  LogMsgInfo(2, string.Format("Purge Pass: {2} - Removing Cases From Analysis ...", AnalCases.Count, m_AFAnalysis.Name, LoopCount), RtnName);                     foreach (AFCase AnalCase in AnalCases)                     {                         i++;                         m_CaseID = 0;                         if (Continue)                         {                             if (Continue)                             {                                     j++;                                     LogMsgInfo(2, string.Format("Purge Pass: {2} - Removinging Case /...", i, AnalCases.Count, LoopCount), RtnName);                                     m_AFAnalysis.RemoveCase(AnalCase);                                     if (j % CheckInCount == 0)                                     {                                         LogMsgInfo(6, string.Format("Checking-In the Last {0} Case(s)...", CheckInCount), RtnName);                                         if (m_AFAnalysis.IsDirty) { m_AFDB.CheckIn();}  //** Check-In After Each N Cases are Removed **                                     }                             }                         }                         else                         {                             break;                         }                     }                     if (m_AFAnalysis.IsDirty) { m_AFDB.CheckIn(); }  //** Check-In Any Unchecked-In Changes **                 } while (!AllProcessed);             }             catch (Exception ex)             {                 m_ErrMsg = string.Format("Error Removing Cases From Analysis ", ex.ToString(),m_AFAnalysis.Name);                 LogMsgError(0, m_ErrMsg, RtnName);             }             LogMsgInfo(2, string.Format("Execution Time = ", GetTimeIntervalText(StartTime)), RtnName);

               

                          return (string.IsNullOrEmpty(m_ErrMsg));

                      }