6 Replies Latest reply on Sep 26, 2016 4:20 PM by Rick Davin

    Hello All, i am trying to find changes for PI Points from source PI Server using changes = (List<PIPointChangeInfo>)PiserverSource.FindChangedPIPoints(int.MaxValue, afTime, out lastCookieCalled); and send the configurations to other PI Server in order to

    josephhmoussa

      Hello All, i am trying to find changes for PI Points from source PI Server using        changes = (List<PIPointChangeInfo>)PiserverSource.FindChangedPIPoints(int.MaxValue, afTime, out lastCookieCalled); and send the configurations to other PI Server in order to have same tags, same configuration. this code is working properly for create, update and delete tags. my question is there a feature or a way while renaming a tag from source PI Server to capture the event and send the same to the destination server even if we have archives for the renamed tag and how to do this? Thanks

        • Re: Hello All, i am trying to find changes for PI Points from source PI Server using changes = (List<PIPointChangeInfo>)PiserverSource.FindChangedPIPoints(int.MaxValue, afTime, out lastCookieCalled); and send the configurations to other PI Server in order
          pmartin

          Hi Joseph,

           

          Name changes are tracked by FindChangedPIPoints so it should be fairly simple.  After you get the changes you can use:

          PIPoint.FindPIPoint(pi, changes[i].ID).Name
          

          to get the new name.

            • Re: Hello All, i am trying to find changes for PI Points from source PI Server using changes = (List<PIPointChangeInfo>)PiserverSource.FindChangedPIPoints(int.MaxValue, afTime, out lastCookieCalled); and send the configurations to other PI Server in order
              qarnism

              Thanks Paul,

              All what i need is once i get the changes[i].ID i will know that it is an update event. my question is when i send the configuration to the destination PI Server i need to have the same archives for the renamed tag. my code is at below:

               

              Send the Configuration from Source PI Server:

              private void SendConfigList(IList<PIPointChangeInfo> changes)
                      {
                          List<int> pointIds = new List<int>();
                          PIPointList pointList = new PIPointList();
                          List<ConfigurationEvent> ConfigurationData = null;
                          DataLayer.PIDataArchive.ConfigurationEvent ConfDataEvent;
                          foreach (PIPointChangeInfo change in changes)
                          {
                              pointIds.Add(change.ID);
                              PIPoint piPoint = PIPoint.FindPIPoint(PiserverSource, change.ID);
                              ConfDataEvent = new DataLayer.PIDataArchive.ConfigurationEvent();
                              ConfigurationData = new List<ConfigurationEvent>();
                              if (change.Action != (AFChangeInfoAction.Removed))
                              {
                                  IDictionary<string, object> Idictionary = piPoint.GetAttributes();
                                  ConfDataEvent.Idictionary = Idictionary;
                                  ConfDataEvent.TagName = piPoint.Name;
                                  ConfDataEvent.ConfigEventType = (Enums.ConfigEventType)change.Action;
                              }
                              else
                              {
                                  foreach (KeyValuePair<string, PIPoint> entry in DicTags)
                                  {
                                      if (entry.Value.ID.ToString() == change.ID.ToString())
                                      {
                                          ConfDataEvent.TagName = entry.Value.Name;
                                          break;
                                      }
                                      // do something with entry.Value or entry.Key
                                  }
                                  ConfDataEvent.ConfigEventType = Enums.ConfigEventType.Removed;
                              }
                              ConfigurationData.Add(ConfDataEvent);
                          }
                          if (ConfigurationData != null)
                          {
                              ProxyMessage ProxyMessage = new ProxyMessage(null, ConfigurationData);
                              DataLayer.PIDataArchive.AsynchronousClient ASC = new DataLayer.PIDataArchive.AsynchronousClient();
                              AsynchronousClient.StartClient(ProxyMessage);
                          }
                      }
              

               

              Receive the Configuration in Destination PI Server:

              if (Data.ConfigEvents[i].ConfigEventType == Enums.ConfigEventType.Added)
                                  {
                                      Data.ConfigEvents[i].Idictionary.Remove("creationdate");
                                      Data.ConfigEvents[i].Idictionary.Remove("creator");
                                      Data.ConfigEvents[i].Idictionary.Remove("changedate");
                                      Data.ConfigEvents[i].Idictionary.Remove("changer");
                                      Data.ConfigEvents[i].Idictionary.Remove("recno");
                                      Data.ConfigEvents[i].Idictionary.Remove("ptclassrev");
                                      Data.ConfigEvents[i].Idictionary.Remove("pointid");
                                      pointDict.Add(Data.ConfigEvents[i].TagName, Data.ConfigEvents[i].Idictionary);
                                      AFListResults<string, PIPoint> results = piserver.CreatePIPoints(pointDict);
                                  }
                                  else if (Data.ConfigEvents[i].ConfigEventType == Enums.ConfigEventType.Updated)
                                  {
                                      PIPoint piPoint = PIPoint.FindPIPoint(piserver, Data.ConfigEvents[i].TagName);
                                      Data.ConfigEvents[i].Idictionary.Remove("creationdate");
                                      Data.ConfigEvents[i].Idictionary.Remove("creator");
                                      Data.ConfigEvents[i].Idictionary.Remove("changedate");
                                      Data.ConfigEvents[i].Idictionary.Remove("changer");
                                      Data.ConfigEvents[i].Idictionary.Remove("recno");
                                      Data.ConfigEvents[i].Idictionary.Remove("ptclassrev");
                                      Data.ConfigEvents[i].Idictionary.Remove("pointid");
                                      AFErrors<string> errors = piPoint.SaveAttributes(Data.ConfigEvents[i].Idictionary);
                                  }
                                  else if (Data.ConfigEvents[i].ConfigEventType == Enums.ConfigEventType.Removed)
                                  {
                                      piserver.DeletePIPoint(Data.ConfigEvents[i].TagName);
                                  }
              
              • Re: Hello All, i am trying to find changes for PI Points from source PI Server using changes = (List<PIPointChangeInfo>)PiserverSource.FindChangedPIPoints(int.MaxValue, afTime, out lastCookieCalled); and send the configurations to other PI Server in order
                Rick Davin

                Hi Joseph,

                 

                If you are expecting many name changes to existing PIPoints, see this reply on making one call:

                https://pisquare.osisoft.com/message/29639#29674

                 

                What's returned in the PIPointChangeInfo structure is the ID of the PIPoint, not the PIPoint object itself.  Sounds like you have 2 Data Archives to monitor, a source server and a target server.  A PIPoint with the same name of both servers does not have to have the same ID. In fact, its best to assume the ID's will differ.  And since the name may change on the source, you can't automatically link to the target by name.  Thus you will need to have a mapping in-between that correlates the ID of a source PIPoint to a target PIPoint.  But that requires you knowing that a given collection of source points may possibly change while your app is running.