14 Replies Latest reply on Aug 29, 2018 11:47 AM by Rick Davin

    How to create pi server collective?

    Noya

      I am writing a c# application that uses osisoft AFSDK dll (2016 version). My application should define pi server collective and send data to this collective. But what I'm trying to figure out is: using c# code, how to define a pi data archive servers as a collective? and how to configure one of them to be the primary server? I've been searching for code examples and couldn't find any code. Can anyone post an example or a reference to such an example?

        • Re: How to create pi server collective?
          Rick Davin

          Hello Noga,

           

          Thanks for posting your question here.  I am going to assume your company already has one or more PI Data Archive servers installed.  I recommend using the provided tool called PI Collective Manager to manage the collective.  I would think your application should have no concern about creating or configuring the PI Collective.  Instead your app should focus on the data end of things, such as creating PI points or reading and writing data.

           

          If you wish to create PI points or others items such as StateSets on the PI Collective, you would be doing this on the Primary.  It is then the responsibility of the Primary to propagate those server changes to its member servers.  Tag data changes from will be propagated if you have buffering in place.  To repeat: tag definitions are automatically propagated by the PI Collective, but tag data is propagated due to buffering.  If you don't use buffering, then you would have to a large bit of code to fan the data to the other member servers.

           

          The interesting thing, and perhaps reason why you haven't seen many examples, is that you will connect to the collective's primary by virtue of connecting to the PI Data Archive, almost as if it were a stand alone server.  Example:

           

          PIServer dataServer = new PIServers()["YourCollectiveName"];
          

           

          should connect you to the primary (unless it was available).  If you then need to work with the collective or individual members, you can start simple:

           

          PICollective collective = dataServer.Collective;
          bool isCollective = dataServer.Collective != null;
          

           

          If the collective were null, then you have a stand alone server.  If it's not null, then you may use any of the PICollective class members in code.  Help on the PICollectiveMember class is also available.

           

          However, unless you are writing a lot of custom code for your own data fanning, your may not need need to work too deeply with collective objects.

          1 of 1 people found this helpful
            • Re: How to create pi server collective?
              Noya

              Thank you Rick for your great replay.  So if I understand right,  using the PIServers Ctor will return an object of all pi servers known by the client.  But what if I want to include in my collection only specific servers and not all servers known to my local host? In this case "should I use the "Clear" and then the "Add PIServers class methods?   r

                • Re: How to create pi server collective?
                  Rick Davin

                  The PIServers returns all servers in your Known Servers Table (KST).  You do not want your app to clear your KST.  You instead want your app to filter the KST entries that will be shown to the user who is running your app.  What type of application are you writing?  Console, Winform, WPF, other?  How will you be presenting a filtered list of servers to the end-user?

                   

                  Just a brief example of filtering the KST to collectives only:

                   

                  PIServers kst = new PIServers();
                  List<PIServer> filtered = kst.Where(pida => pida.Collective != null).ToList();  // list could be empty
                  
                • Re: How to create pi server collective?
                  Noga

                  Hi Rick,

                  Returning to your answer above where you explained the following:

                   

                  "The interesting thing, and perhaps reason why you haven't seen many examples, is that you will connect to the collective's primary by virtue of connecting to the PI Data Archive, almost as if it were a stand alone server.  Example:

                   

                  1. PIServer dataServer = new PIServers()["YourCollectiveName"]; 

                  should connect you to the primary (unless it was available)."

                   

                  I am interested to know:

                  If I want to connect explicitly to a secondary member of my collective, would the following code do the work?

                  PIServer dataServer = new PIServers()["MySecondaryName"]; 

                  Where "MySecondaryName"- is the secondary member's i.p or machine-name.

                   

                   

                   

                   

                    • Re: How to create pi server collective?
                      Rick Davin

                      Hello Noga,

                       

                      What you have will not work as you intend.  First, I would suggest you take time to read and familiarize yourself with the objects you want to work with by clicking the links below:

                       

                      PICollective Class

                      PICollectiveMember Class

                       

                      With a collective, there are several PICollective.SwitchMember overloads.  Note none of them take a name (string).  You may use a name (string) to get a member using the PICollective.Members property.  The PICollectiveMember class has 2 other ways to connect: PICollectiveMember.Connect overloads and PICollectiveMember.ConnectDirect.  It is left for you to go to those help pages to understand what each of them does.

                       

                      Here is sample code showing the PICollective.SwitchMember.  Again, I encourage you to learn how to read the help files and see the other examples over at Live Library.

                       

                      string requestedServerName = "<Stand-alone or Collective Name>";
                      string requestedMemberName = "secondary member name";
                      
                      PIServer dataServer = new PIServers()[requestedServerName];
                      
                      if (dataServer.Collective != null)
                      {
                          Console.WriteLine($"{dataServer.Name} is a PI Collective.");
                          PICollectiveMember requestedMember = dataServer.Collective.Members[requestedMemberName];
                          dataServer.Collective.SwitchMember(requestedMember);
                          Console.WriteLine($"Connected member: {dataServer.Collective.CurrentMember.Name} ({dataServer.Collective.CurrentMember.ServerRole})");
                      }
                      else
                      {
                          Console.WriteLine($"{dataServer.Name} is a stand-alone PI Data Archive.");
                      }
                      
                      1 of 1 people found this helpful
                  • Re: How to create pi server collective?
                    Rick Davin

                    What does what the user configures in the XML have to do with filtering the PIServers?  Would the XML contain the name of one PIServer?  Or will there be a filter (e.g. collectives only, or name pattern to include, or name pattern to exclude)?  Or will there be a list in the XML of good or bad PIServer names?