AFCollective Class
- Last UpdatedNov 18, 2025
- 9 minute read
- PI System
- AF SDK 2024 R2
- Developer

Inheritance Hierarchy
Namespace: OSIsoft.AF.Collective
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
[SerializableAttribute] public sealed class AFCollective : AFObject, IAFChangedEvent, IEquatable<AFCollective>
<SerializableAttribute> Public NotInheritable Class AFCollective Inherits AFObject Implements IAFChangedEvent, IEquatable(Of AFCollective) Dim instance As AFCollective
[SerializableAttribute] public ref class AFCollective sealed : public AFObject, IAFChangedEvent, IEquatable<AFCollective^>
[<SealedAttribute>] [<SerializableAttribute>] type AFCollective = class inherit AFObject interface IAFChangedEvent interface IEquatable<AFCollective> end
The AFCollective type exposes the following members.
Properties
| Name | Description | |
|---|---|---|
| ConnectedMemberType |
Indicates the role of the currently connected collective member.
| |
| CurrentMember |
The current active collective member.
| |
| ID |
Read-only property that provides a unique identifier for the object to be used for
quick access that is not dependent upon the index.
(Inherited from AFObject.) | |
| Identity |
This read-only property contains identity of the object.
(Inherited from AFObject.) | |
| IsDeleted |
This read-only property indicates whether the object has been deleted.
(Inherited from AFObject.) | |
| IsDirty |
This read-only property indicates whether the collective has been modified since the
last save to the PI AF Server.
| |
| Members |
The collection of AFCollectiveMember objects that are configured
for the AFCollective.
| |
| ModifyDate |
This read-only property returns the time when the object's configuration was last modified.
| |
| PISystem |
This read-only property allows access to the PISystem associated with this
object.
(Inherited from AFObject.) | |
| UniqueID |
Read-only property that provides the object's ID as a String.
(Inherited from AFObject.) |
Methods
| Name | Description | |
|---|---|---|
| ApplyChanges |
Save collective changes to the PI AF Server without specifying an event handler.
| |
| ApplyChanges(EventHandlerAFProgressEventArgs) |
Save collective changes to the PI AF Server and notify client of progress
using specified event handler.
| |
| CompareTo(Object) |
Compares this instance with a specified Object.
(Inherited from AFObject.) | |
| CompareTo(AFObject) |
Compares this instance with a specified AFObject.
(Inherited from AFObject.) | |
| Delete |
Delete the collective by removing all members from the collective.
| |
| Equals(Object) |
Determines whether the specified Object is equal to the current object.
(Inherited from AFObject.) | |
| Equals(AFCollective) |
Indicates whether the current object is equal to another object of the same type.
| |
| Equals(AFObject) |
Indicates whether the current object is equal to another object of the same type.
(Inherited from AFObject.) | |
| FindPrimary |
Finds the primary member of the collective.
| |
| GetHashCode |
Gets the hash code for this instance of the object which is suitable for use in hashing
algorithms and data structures like a hash table.
(Inherited from AFObject.) | |
| GetPath |
Returns the full path to the object, using just the names.
(Inherited from AFObject.) | |
| GetPath(AFObject) |
Returns the path to the object relative from another object.
(Inherited from AFObject.) | |
| GetPath(AFEncodeType, AFObject) |
Returns the path to the object relative from another object,
using the name and/or id as specified
by encodeType.
(Inherited from AFObject.) | |
| GetStatusDetails |
Gets the detailed collective status information for the collective members from the server.
| |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| Persist |
This method returns the persistence string for the object.
(Inherited from AFObject.) | |
| Refresh |
Refreshes the client with any changes that have been made to the collective since loaded.
| |
| SwitchMember(AFConnectionPreference) |
The SwitchMember method is used to change the currently connected
member of the collective using default credentials.
| |
| SwitchMember(NetworkCredential, AFConnectionPreference) |
The SwitchMember method is used to change the currently connected
member of the collective using the specified credentials.
| |
| SwitchMember(Boolean, IWin32Window, AFConnectionPreference) |
The SwitchMember method is used to change the currently connected
member of the collective with a credential prompt if necessary.
| |
| ToString |
Returns a String that represents the current object.
(Overrides AFObjectToString.) |
Events
| Name | Description | |
|---|---|---|
| Changed |
Event is raised when the object or one of its sub-objects is changed.
|
Remarks
A PISystem collective is a group of physical PI AF Servers (member servers) that maintain consistent configuration. A collective is accessed by a PISystem object that represents the entire collective. When a program is connected to a collective and its connection to a particular member is lost, the AF SDK will failover to another member in the collective. This behavior supports high availability of data stored in AF.
PI AF Server access functions are intended to work seamlessly between server collectives and single servers. However, the PI AF Server collective members have some behaviors that may vary between the members. The choice of member server during a connection may be influenced through the AFConnectionInfo.Preference property and properties of the AFCollectiveMember. A connection to a specific server can be created using one of the AFCollectiveMember.Connect Overload methods. The AF SDK also switches connections dynamically to support calls that are only supported on certain members of the collective.
Use the PISystem.Supports method to check if the PISystem supports the HighAvailability feature. A collective is created by calling the PISystem.CreateCollective method. Members are added to the collective using the Add(PISystem) method of the Members collection. The StartReplication method must be called on the Primary member first and then on each Secondary member when the Primary is ready (when the SyncStatus is not SnapshotNotReady).
Examples
// This example demonstrates how to create and remove a collective. // Add the PISystem to be used as the primary PISystems myPISystems = new PISystems(); PISystem primary = myPISystems.Add(primaryName); primary.Connect(); // Check if primary is already a collective if (primary.Collective != null) throw new InvalidOperationException(string.Format("Primary '{0}' is already a collective.", primary.Name)); // Add the PISystem to be used as the secondary PISystem secondary = myPISystems.Add(secondaryName); secondary.Connect(); // Check if secondary is already a collective if (secondary.Collective != null) throw new InvalidOperationException(string.Format("Secondary '{0}' is already a collective.", secondary.Name)); // Create the collective AFCollective collective = primary.CreateCollective(); primary.Name = "Test-Collective"; // Change the collective name primary.Description = "The Collective"; // Change the collective description // Add members to the collective AFCollectiveMember primaryMember = collective.FindPrimary(); if (primaryMember == null) throw new InvalidOperationException("Could not find primary."); primaryMember.Description = "The Primary Member"; AFCollectiveMember secondaryMember = collective.Members.Add(secondary); secondaryMember.Description = "The Secondary Member"; collective.ApplyChanges(); // Initialize replication of the database on the primary primaryMember.StartReplication(); // Wait until the primary is ready before starting replication // on the secondaries. collective.Refresh(); while (primaryMember.SyncStatus != AFSyncStatus.NoConfiguredSubscriptions) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(30)); collective.Refresh(); } // Initialize replication of the database on the secondaries foreach (AFCollectiveMember member in collective.Members) { if (member.ServerRole != AFServerRole.Primary) member.StartReplication(); } // Display Collective Information Console.WriteLine("Name of Collective = {0}", primary.Name); Console.WriteLine("Description = {0}", primary.Description); foreach (AFCollectiveMember CurMember in primary.Collective.Members) { Console.WriteLine(" Name of Member = {0}", CurMember.Name); Console.WriteLine(" Description = {0}", CurMember.Description); Console.WriteLine(" IsAvailable = {0}", CurMember.IsAvailable); Console.WriteLine(); }
' This example demonstrates how to create and remove a collective. ' Add the PISystem to be used as the primary Dim myPISystems As New PISystems Dim primary As PISystem = myPISystems.Add(primaryName) primary.Connect() ' Check if primary is already a collective If primary.Collective IsNot Nothing Then Throw New InvalidOperationException(String.Format("Primary '{0}' is already a collective.", primary.Name)) End If ' Add the PISystem to be used as the secondary Dim secondary As PISystem = myPISystems.Add(secondaryName) secondary.Connect() ' Check if secondary is already a collective If secondary.Collective IsNot Nothing Then Throw New InvalidOperationException(String.Format("Secondary '{0}' is already a collective.", secondary.Name)) End If ' Create the collective Dim collective As AFCollective = primary.CreateCollective() primary.Name = "Test-Collective" ' Change the collective name primary.Description = "The Collective" ' Change the collective description ' Add members to the collective Dim primaryMember As AFCollectiveMember = collective.FindPrimary() If (primaryMember Is Nothing) Then Throw New InvalidOperationException("Could not find primary.") End If primaryMember.Description = "The Primary Member" Dim secondaryMember As AFCollectiveMember = collective.Members.Add(secondary) secondaryMember.Description = "The Secondary Member" collective.ApplyChanges() ' Initialize replication of the database on the primary primaryMember.StartReplication() ' Wait until the primary is ready before starting replication ' on the secondaries. collective.Refresh() While (primaryMember.SyncStatus <> AFSyncStatus.NoConfiguredSubscriptions) System.Threading.Thread.Sleep(TimeSpan.FromSeconds(30)) collective.Refresh() End While ' Initialize replication of the database on the secondaries For Each member As AFCollectiveMember In collective.Members If (member.ServerRole <> AFServerRole.Primary) Then member.StartReplication() End If Next ' Display Collective Information Console.WriteLine("Name of Collective = {0}", primary.Name) Console.WriteLine("Description = {0}", primary.Description) For Each CurMember As AFCollectiveMember In primary.Collective.Members Console.WriteLine(" Name of Member = {0}", CurMember.Name) Console.WriteLine(" Description = {0}", CurMember.Description) Console.WriteLine(" IsAvailable = {0}", CurMember.IsAvailable) Console.WriteLine() Next
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.