AcUtils
A high performance abstraction layer for AccuRev
Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
AcUtils.AcGroups Class Reference

A container class for AcPrincipal objects that define AccuRev groups. More...

Collaboration diagram for AcUtils.AcGroups:
Collaboration graph
[legend]

Public Member Functions

AcPrincipal getPrincipal (string name)
 Retrieves the AcPrincipal object for AccuRev group name. More...
 
string getMembers (string group)
 Returns the list of members in group as a formatted string. List optionally initialized by AcGroups constructor when includeMembersList param is true. More...
 
Two-part object construction:
 AcGroups (bool includeMembersList=false, bool includeDeactivated=false)
 A container class for AcPrincipal objects that define AccuRev groups. Elements contain AccuRev group principal attributes name, ID, and status (active or inactive), and optionally their members list. Including group membership (includeMembersList = true) is slower, so we give the option to exclude it when the list isn't needed. Deactivated (removed) groups can be included in the list as well. More...
 
async Task< bool > initAsync (IProgress< int > progress=null)
 Populate this container with AcPrincipal objects as per constructor parameters. More...
 

Static Public Member Functions

static bool isMember (string user, string group)
 Determines if user is a member of group by way of direct or indirect (implicit) membership, e.g. Mary is implicitly a member of groupA because she's a member of groupB which is a member of groupA. More...
 

Private Member Functions

async Task< bool > initMembersListAsync (string group)
 Optionally called during list construction to initialize the list of principals (users and groups) that are direct (explicit) members of group. This method is called internally and not by user code. More...
 

Detailed Description

A container class for AcPrincipal objects that define AccuRev groups.

Elements contain AccuRev group principal attributes name, ID, and status (active or inactive), and optionally their members list. Deactivated (removed) groups can be included in the list as well.

Definition at line 37 of file AcGroups.cs.

Constructor & Destructor Documentation

AcUtils.AcGroups.AcGroups ( bool  includeMembersList = false,
bool  includeDeactivated = false 
)
inline

A container class for AcPrincipal objects that define AccuRev groups. Elements contain AccuRev group principal attributes name, ID, and status (active or inactive), and optionally their members list. Including group membership (includeMembersList = true) is slower, so we give the option to exclude it when the list isn't needed. Deactivated (removed) groups can be included in the list as well.

A group's membership list is comprised of principals (users and groups) who were explicitly added to the group by the addmember command and not those with implicit membership, i.e. if principal is a member of groupA and groupA is a member of groupB, principal is implicitly a member of groupB. In this case the principal would not appear in groupB's members list.

Parameters
includeMembersListtrue to include group membership initialization for each group (slower), false for no initialization (faster).
includeDeactivatedtrue to include deactivated (removed) groups, otherwise false.
public static async Task<bool> showGroupsAsync()
{
var progress = new Progress<int>(n =>
{
if ((n % 10) == 0)
Console.WriteLine("Initializing group memberships: " + n);
});
AcGroups groups = new AcGroups(includeMembersList: true); // true to initialize each group's membership list
if (!(await groups.initAsync(progress))) return false; // initialization failure, check log file
foreach (AcPrincipal prncpl in groups.OrderBy(n => n))
{
Console.WriteLine(prncpl);
if (prncpl.Members != null) // if initialized as per includeMembersList param
{
string members = groups.getMembers(prncpl.Name);
Console.WriteLine("\t" + members);
}
}
return true;
}
See also
initAsync, AcGroups.initMembersListAsync, default comparer, AcUsers constructor

Definition at line 91 of file AcGroups.cs.

Member Function Documentation

string AcUtils.AcGroups.getMembers ( string  group)
inline

Returns the list of members in group as a formatted string. List optionally initialized by AcGroups constructor when includeMembersList param is true.

Parameters
groupAccuRev group name to query.
Returns
Group's membership list as an ordered formatted comma-delimited string, otherwise null if membership list was not initialized.
See also
AcGroups.isMember, AcUser.getGroups

Definition at line 311 of file AcGroups.cs.

AcPrincipal AcUtils.AcGroups.getPrincipal ( string  name)
inline

Retrieves the AcPrincipal object for AccuRev group name.

Parameters
nameAccuRev group name to query.
Returns
AcPrincipal object for group name if found, otherwise null.

Definition at line 299 of file AcGroups.cs.

Referenced by AcUtils.AcGroups.getMembers(), and AcUtils.AcGroups.initMembersListAsync().

async Task<bool> AcUtils.AcGroups.initAsync ( IProgress< int >  progress = null)
inline

Populate this container with AcPrincipal objects as per constructor parameters.

Parameters
progressOptionally report progress back to the caller when group membership initialization is requested as per constructor parameter includeMembersList.
Returns
true if initialization succeeded, false otherwise.
Exceptions
AcUtilsExceptioncaught and logged in %LOCALAPPDATA%\AcTools\Logs\<prog_name>-YYYY-MM-DD.log on show command failure.
Exceptioncaught and logged in same on failure to handle a range of exceptions.
show command:
show <-fx | -fix> groups

Definition at line 107 of file AcGroups.cs.

async Task<bool> AcUtils.AcGroups.initMembersListAsync ( string  group)
inlineprivate

Optionally called during list construction to initialize the list of principals (users and groups) that are direct (explicit) members of group. This method is called internally and not by user code.

Membership lists for inactive groups are empty (not initialized). An inactive group's membership list will reappear when the group is reactivated.

Parameters
groupName of AccuRev group.
Returns
true if no exception was thrown and operation succeeded, false otherwise.
Exceptions
AcUtilsExceptioncaught and logged in %LOCALAPPDATA%\AcTools\Logs\<prog_name>-YYYY-MM-DD.log on show command failure.
Exceptioncaught and logged in same on failure to handle a range of exceptions.
See also
AcUser.initGroupsListAsync
show command:
show -fx -g <group> members
AccuNote:
Unlike the show command used here, its show -fx -u <user> groups counterpart does include memberships resulting from indirect (implicit) membership.

Definition at line 187 of file AcGroups.cs.

Referenced by AcUtils.AcGroups.initAsync().

static bool AcUtils.AcGroups.isMember ( string  user,
string  group 
)
inlinestatic

Determines if user is a member of group by way of direct or indirect (implicit) membership, e.g. Mary is implicitly a member of groupA because she's a member of groupB which is a member of groupA.

Parameters
userAccuRev principal name of user.
groupAccuRev principal name of group.
Returns
true if user is a member of group or false if not a member.
Exceptions
AcUtilsExceptionthrown on AccuRev program invocation failure for the ismember command.
Win32Exceptioncaught and logged in %LOCALAPPDATA%\AcTools\Logs\<prog_name>-YYYY-MM-DD.log on error spawning the AccuRev process that runs the command.
InvalidOperationExceptioncaught and logged in same on failure to handle a range of exceptions.
See also
AcGroups.getMembers, AcUser.getGroups
ismember command:
ismember <user> <group>
Note
The AccuRev program return value for ismember is zero (0) whether the user is a member of the group or not. It is the command's output (STDOUT) that is "1" (one) if the user is a member of the group or "0" (zero) if not a member.
Warning
The server admin trigger must return zero (0) for ismember to prevent an endless recursive loop.

Definition at line 242 of file AcGroups.cs.