6 Replies Latest reply on Sep 28, 2015 11:38 PM by bshang

    Not able to Sign up the AFElement Attribute list for Data update with Data pipe in Windows Service

    Pratik

      I am trying to write a windows service. The Service will build an AF data pipe and sign up some AF element and corresponding attributes for data update. So Far I am able to connect with PISever and required database. I am also able to obtain the AFElement and it's attribute from the server. But my service is unable to sign up the attribute list to data pipe update/ monitor. Below is the code I am using. [Please note : I am writing a Windows service, The console application with the same code works absolutely fine]

       

                 // connect to AF Server

                  PISystems afServers = new PISystems();

                  afServer = afServers[AFserverName];

                  afServer.Connect();

                  var database = afServer.Databases[AFdatabaseName];

                  if (afServer != null && database != null)

                  {

                      logger("Connections with AFServer " + afServer.Name + " and Database " + database.Name + " have been established");

                          /******************************************************************************

                          AF DATA PIPE

                          ******************************************************************************/

                          // We select the elements we want to monitor, from the given path list

                          AFKeyedResults<string, AFElement> results = AFElement.FindElementsByPath(pathLists, null); // pathLists is predefined with the the path information of AFElements

                          logger("retrieved AFElement lsits: " + results.Count);

                          foreach (AFElement result in results)

                          {

                              //Signed up only those attrributes for data updates

                              foreach (var attribute in result.Attributes)

                              {

                                  if (attributeList.Contains(attribute.Name)) // attributeList is defined

                                  {

                                      logger("I matched " + result.GetPath() + "  " + attribute);

                                      attributesForSignUp.Add(attribute);  // attributesForSignUp is being generated based on attributeList

                                  }

                              }

                              logger("total attributesForSignUp " + attributesForSignUp.Count);

                              // Sign up for updates, Specified attribute of the element will be "monitored"

                              AFDataPipe.AddSignups(attributesForSignUp);

                              attributesForSignUp = null;

                          }

       

                          //Varify the list of assets signed up for the updates

                          IList<AFAttribute> signedupElements = AFDataPipe.GetSignups();

                          logger("Total signed up elments are " + signedupElements.Count);

                          foreach (var attribute in signedupElements)

                          {

                              logger("Signed up " + attribute.GetPath() + " : " + attribute.Name);

                          }

       

                          logger("Starting Monitoring Events in data pipe.");

       

                          // we create threads that will monitor our data pipes.

                          // Note: for a real application UI may be blocked when checking data if there is a lot of data to process

                          // so this is an example of how you could check the data in another thread.

                          Task.Factory.StartNew(() => MonitorAfDataPipe(AFDataPipe));

       

                          // for this command line application, I use an infinite loop were we are just waiting

                          // until the user presses X.  Data Pipe checks are performed in other threads (tasks).

                          /*      Console.WriteLine("Press X key to stop monitor the Data Pipes.");

                                var keyinfo = Console.ReadKey();

                                while (keyinfo.Key != ConsoleKey.X)

                                {

                                    keyinfo = Console.ReadKey();

                                    Thread.Sleep(125);

                                }

       

                                _canContinue = false;

                        */

                          // we wait to make sure all threads stops after we set the _canContinue to false.

                          Console.WriteLine("Terminating, waiting for processing threads to terminate");

                          Thread.Sleep(DataReadInterval + 100);

        • Re: Not able to Sign up the AFElement Attribute list for Data update with Data pipe in Windows Service
          Marcos Vainer Loeff

          Hi Pratik, how are you?

           

          This seems to be a security issue. Which user domain account is your service running as?

           

          Your service seems to be able to connect to the PI AF Server but to the PI Data Archive. Could you test if this service can get the snapshot/end of the stream from the PI Point sinusoid? Do you receive any exception message?

          • Re: Not able to Sign up the AFElement Attribute list for Data update with Data pipe in Windows Service
            Mike Zboray

            AddSignups should return errors for the sign ups that failed. You should inspect those to get more information on the problem.

             

            That said it sounds like the the local system does not have permission to access the Data Archive. There are two solutions. Either add a trust for all connections from the service machine in the PI Data Archive, or change the logon user for the windows service to a user that has permission to access the PI Data Archive. For testing, you might try changing it to run as you.

            • Re: Not able to Sign up the AFElement Attribute list for Data update with Data pipe in Windows Service
              Pratik

              Updating Thread; (Windows service)

               

              What kind of access is needed here? I am able to connect with AF Server and underlying database. I am also able to get AF element (with AFElement result = database.Elements[path]). But I am not able to signup AF Attribute for the update on data pipe. (AFDataPipe.AddSignups(attributesForSignUp) is not working)

               

              I am getting below errors;

              OSIsoft.AF.PI.PIAuthenticationException: Cannot connect to the PI Server. Windows authentication trial failed because insufficient privilege to access the PI Server. ---> System.AggregateException: One or more errors occurred.

              ---> OSIsoft.AF.PI.PIAuthenticationException: Cannot connect to the PI Server. Windows authentication trial failed because insufficient privilege to access the PI Server.

               

               

              Error stack Trace:

              2015-09-28 11:24:46,770 [6] DEBUG PIAFConnectorAdaptor.AFDataPipeConnectorNew AF Errors value OSIsoft.AF.PI.PIAuthenticationException: Cannot connect to the PI Server. Windows authentication trial failed because insufficient privilege to access the PI Server.  ---> System.AggregateException: One or more errors occurred. ---> OSIsoft.AF.PI.PIAuthenticationException: Cannot connect to the PI Server. Windows authentication trial failed because insufficient privilege to access the PI Server.

              --- End of inner exception stack trace ---

              --- End of inner exception stack trace ---

                 at OSIsoft.AF.PI.PIException.ConvertAndThrowException(PIServer piServer, Exception ex, String message)

                 at OSIsoft.AF.PI.PIServer.RemoteConnect(AFConnectionPreference preference, NetworkCredential credential, PIAuthenticationMode authenticationMode)

                 at OSIsoft.AF.PI.PIServer.InternalConnect(Int32 numRetries, IWin32Window owner, AFConnectionPreference preference, NetworkCredential credential, PIAuthenticationMode authenticationMode)

                 at OSIsoft.AF.PI.PIServer.AutoConnect(Boolean allowDirectConnect, Boolean force)

                 at OSIsoft.AF.PI.PIPoint.FindPIPoint(PIServer piServer, Int32 pointID)

                 at OSIsoft.AF.Asset.DataReference.PIPointDR.TryResolveTagInternal()

                 at OSIsoft.AF.Asset.DataReference.PIPointDR.TryGetAFPointWithoutTagLookup(PIPoint& piPoint, Boolean& configErrorOccurred, Exception& returnException)

              2015-09-28 11:24:46,770 [6] DEBUG PIAFConnectorAdaptor.AFDataPipeConnectorNew AF Errors key Mvars

              2015-09-28 11:24:46,770 [6] DEBUG PIAFConnectorAdaptor.AFDataPipeConnectorNew AF Errors value OSIsoft.AF.PI.PIAuthenticationException: Cannot connect to the PI Server. Windows authentication trial failed because insufficient privilege to access the PI Server.

                 at OSIsoft.AF.PI.PIServer.CheckFailedServer(PIServerError& serverError)

                 at OSIsoft.AF.PI.PIServer.AutoConnect(Boolean allowDirectConnect, Boolean force)

                 at OSIsoft.AF.PI.PIPoint.FindPIPoint(PIServer piServer, Int32 pointID)

                 at OSIsoft.AF.Asset.DataReference.PIPointDR.TryResolveTagInternal()

                 at OSIsoft.AF.Asset.DataReference.PIPointDR.TryGetAFPointWithoutTagLookup(PIPoint& piPoint, Boolean& configErrorOccurred, Exception& returnException)

              2015-09-28 11:24:46,770 [6] DEBUG PIAFConnectorAdaptor.AFDataPipeConnectorNew AF Errors key MVA

              2015-09-28 11:24:46,770 [6] DEBUG PIAFConnectorAdaptor.AFDataPipeConnectorNew AF Errors value OSIsoft.AF.PI.PIAuthenticationException: Cannot connect to the PI Server. Windows authentication trial failed because insufficient privilege to access the PI Server.

                 at OSIsoft.AF.PI.PIServer.CheckFailedServer(PIServerError& serverError)

                 at OSIsoft.AF.PI.PIServer.AutoConnect(Boolean allowDirectConnect, Boolean force)

                 at OSIsoft.AF.PI.PIPoint.FindPIPoint(PIServer piServer, Int32 pointID)

                 at OSIsoft.AF.Asset.DataReference.PIPointDR.TryResolveTagInternal()

                 at OSIsoft.AF.Asset.DataReference.PIPointDR.TryGetAFPointWithoutTagLookup(PIPoint& piPoint, Boolean& configErrorOccurred, Exception& returnException)