2 Replies Latest reply on Mar 11, 2015 8:56 AM by jenilshah

    Hi, I want to delete PI historical data using AF SDK in C# code. Is it possible?

    jenilshah

      Hi, I want to delete PI historical data using AF SDK in C# code. Is it possible?

        • Re: Hi, I want to delete PI historical data using AF SDK in C# code. Is it possible?
          Sam Pride

          Yes, you can easily delete events using the AF SDK.

           

          To delete events, you will need to call the UpdateValues method of either the AFData (when using a PIPoint DR) or PIPoint class using the AFUpdateMethod of "Remove". You will first need to build a list of events to delete.

           

          Here's a quick example of deleting values using the AF SDK:

           

           

          string piPointName = "sinusoid";
          
          
          PISystems myPISystems = new PISystems();
          PISystem myPISystem = myPISystems.DefaultPISystem;
          PIServer myPIServer = new PIServers().DefaultPIServer;
          PIPoint myPIPoint = PIPoint.FindPIPoint(myPIServer, piPointName);
          
          
          AFTimeRange myTimeRange = new AFTimeRange();
          myTimeRange.StartTime = DateTime.Now.AddHours(-1);
          myTimeRange.EndTime = DateTime.Now;
          
          
          try
          {
               //Find our events to delete
              AFValues dataToDelete = myPIPoint.RecordedValues(myTimeRange, OSIsoft.AF.Data.AFBoundaryType.Inside, "", true, 0);
               //delete them by using the remove option for the UpdateEvents. If possible, event deletes will be buffered and replicated to other collective members.
              myPIPoint.UpdateValues(dataToDelete, OSIsoft.AF.Data.AFUpdateOption.Remove, OSIsoft.AF.Data.AFBufferOption.BufferIfPossible);
          }
          catch (Exception ex)
          {
              Console.WriteLine("Something went wrong reading or deleting events:" + ex.ToString());
          }
          
          1 of 1 people found this helpful