AnsweredAssumed Answered

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

Question asked by Pratik on Aug 14, 2015
Latest reply on Sep 28, 2015 by bshang

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];


            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"


                        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();




                          _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);