3 Replies Latest reply on Jun 1, 2011 1:24 PM by hanyong

    How to check that a running PI Notification service is targeting a PI AF Database

    Rafik.Rezine
      I want to check in my code (using AF SDK or AN SDK) if there is any PI Notification Scheduler service running on a specif PI AF Server/ Database. Is that possible?
        • Re: How to check that a running PI Notification service is targeting a PI AF Database
          hanyong

          Hi Rafik, 

           

          I think one of the place you can look at the ANServiceInformation class, in the OSIsoft.AN.Service namespace part of AN SDK. It provides some static method that can allow you to get the PI Notification services information by providing the information of the PISystem (AF Server) or AFDatabase object

           

          A simple code snippet to get the host of the PI Notifications Service linked to an AF server

          using OSIsoft.AF;
          using OSIsoft.AN.Service;

          ...

               PISystems _AFSDK = new PISystems();
               PISystem _AFServer = _AFSDK["<your AF server name>"];

               string Notification_Host = ANServiceInformation.GetHost(_AFServer.ID); 

            • Re: How to check that a running PI Notification service is targeting a PI AF Database
              Rafik.Rezine

              Nice :)

               

              When the Notifications service is stopped, the previous code throws an exception "No PI Notification Service is running".

               

              When the Notifications service is running, the GetHost call succeeds without exception.

               

              So it does the job :)

               

               

               

              Using ANServiceInformation.TryGetLocation seems better, as it doesn't throws an exception, just returns a booelan:

               

               

               

               

               
              using OSIsoft.AF;
              using OSIsoft.AN.Service;
              
              
              ....
              
              
                              PISystems _AFSDK = new PISystems();
                              PISystem _AFServer = _AFSDK["PIPIAF2010"];
              
                              AFDatabase _AFDatabase = null;
                              _AFDatabase = _AFServer.Databases["Configuration"];
              
                              String strMachine = String.Empty;
                              Boolean bLoc = ANServiceInformation.TryGetLocation(_AFServer.ID, _AFDatabase.ID, out strMachine);
              
                              if (bLoc)
                              {
                                  MessageBox.Show("PI Notifications service is running");
                              }
                              else
                              {
                                  MessageBox.Show("PI Notifications service is NOT running");
                              }