17 using System.Collections.Generic;
77 public sealed
class AcPermission : IFormattable, IEquatable<AcPermission>, IComparable<AcPermission>, IComparable
79 #region class variables
82 private string _appliesTo;
90 private bool _inheritable;
101 #region Equality comparison
113 if (ReferenceEquals(other, null))
return false;
114 if (ReferenceEquals(
this, other))
return true;
117 return left.Equals(right);
124 public override bool Equals(
object other)
126 if (ReferenceEquals(other, null))
return false;
127 if (ReferenceEquals(
this, other))
return true;
128 if (GetType() != other.GetType())
return false;
140 return hash.GetHashCode();
145 #region Order comparison
162 result = String.Compare(
Name, other.
Name);
176 int IComparable.CompareTo(
object other)
179 throw new ArgumentException(
"Argument is not an AcPermission",
"other");
191 get {
return _kind; }
192 internal set { _kind = value; }
200 get {
return _name ?? String.Empty; }
201 internal set { _name = value; }
210 get {
return _appliesTo ?? String.Empty; }
211 internal set { _appliesTo = value; }
220 get {
return _type; }
221 internal set { _type = value; }
230 get {
return _rights; }
231 internal set { _rights = value; }
243 get {
return _inheritable; }
244 internal set { _inheritable = value; }
248 public string ToString(
string format, IFormatProvider provider)
269 if (provider != null)
271 ICustomFormatter fmt = provider.GetFormat(this.GetType()) as ICustomFormatter;
273 return fmt.Format(format,
this, provider);
276 if (String.IsNullOrEmpty(format))
279 switch (format.ToUpperInvariant())
283 string who = $
"{((Type == PermType.builtin) ? AppliesTo : Type.ToString() + " " + AppliesTo)}";
284 return $
@"Permission on {Name} {Kind} applies to {who} {{{Rights}, {(Inheritable ? "inherit
" : "no inherit
")}}}";
287 return Kind.ToString();
293 return Type.ToString();
305 throw new FormatException($
"The {format} format string is not supported.");
310 public string ToString(
string format)
331 #region class variables
333 [NonSerialized]
private readonly
object _locker =
new object();
341 get {
return _kind; }
342 internal set { _kind = value; }
345 #region object construction:
397 if (r != null && r.
RetVal == 0)
399 XElement xml = XElement.Parse(r.
CmdResult);
400 foreach (XElement e
in xml.Elements(
"Element"))
403 perm.
Name = (string)e.Attribute(
"Name");
404 perm.
AppliesTo = (string)e.Attribute(
"Group");
405 string type = (string)e.Attribute(
"Type");
407 string rights = (string)e.Attribute(
"Rights");
409 perm.
Inheritable = (bool)e.Attribute(
"Inheritable");
410 lock (_locker) { Add(perm); }
419 AcDebug.
Log($
"AcUtilsException caught and logged in AcPermissions.initAsync{Environment.NewLine}{ecx.Message}");
422 catch (Exception ecx)
424 AcDebug.
Log($
"Exception caught and logged in AcPermissions.initAsync{Environment.NewLine}{ecx.Message}");
string Name
Name of the depot or stream this permission applies to.
PermKind Kind
Whether the list of permissions held pertain to depots or streams.
string ToString(string format, IFormatProvider provider)
The ToString implementation.
AccuRev program return value and command result.
PermRights
Whether permission rights to Name in AppliesTo is all or none.
override int GetHashCode()
Override appropriate for type AcPermission.
AcPermissions(PermKind kind)
A container of AcPermission objects that define AccuRev access control list (ACL) entries...
A permission object that defines the attributes of an AccuRev access control list (ACL) entry...
PermKind
Whether permissions pertain to depots or streams. Set when the permission is created by the setacl co...
string AppliesTo
Principal name of the group or user this permission applies to or one of the built-in types anyuser o...
string CmdResult
The command result (usually XML) emitted by AccuRev.
int RetVal
The AccuRev program return value for the command, otherwise minus one (-1) on error.
static void Log(string message, bool formatting=true)
Write the message text to STDOUT, to weekly log files located in %LOCALAPPDATA%\AcTools\Logs, and to trigger.log in the AccuRev server's ..storage\site_slice\logs folder in the case of triggers.
PermKind Kind
Whether the permission pertains to a depot or stream.
Exception thrown when an AccuRev command fails. The AccuRev program return value is zero (0) on succe...
int CompareTo(AcPermission other)
Generic IComparable implementation (default) for comparing AcPermission objects to sort by Name and t...
AccuRev command processing.
static async Task< AcResult > runAsync(string command, ICmdValidate validator=null)
Run the AccuRev command asynchronously with non-blocking I/O.
Use to log and display error and general purpose text messages, and to save the XML param data sent b...
async Task< bool > initAsync(string name=null)
Populate this container with AcPermission objects.
bool Equals(AcPermission other)
IEquatable implementation to determine the equality of instances of type AcPermission. Uses Kind, Name, and AppliesTo to compare instances.
A container of AcPermission objects that define AccuRev access control list (ACL) entries...
PermType
Whether AppliesTo is the principal name for a group, user, or builtin type.
bool Inheritable
For depots, when true permission applies to the depot and its entire stream hierarchy, when false permission applies only to AccuWork issues in the depot and not its version-controlled elements. For streams, when true permission applies to the stream and its entire subhierarchy, when false permission applies only to the stream.
AcPermission(PermKind kind)
Constructor used during AcPermissions list construction. It is called internally and not by user code...
PermType Type
Whether AppliesTo is the principal name for a group, user, or a builtin type.
PermRights Rights
Whether permission rights to Name in AppliesTo is all or none.
override bool Equals(object other)
Overridden to determine equality.