AcUtils
A high performance abstraction layer for AccuRev
AcPrincipal.cs
Go to the documentation of this file.
1 
16 using System;
17 using System.Collections.Generic;
18 using System.Diagnostics;
19 
20 namespace AcUtils
21 {
22  #region enums
23 
24  public enum PrinStatus
29  {
32  Unknown,
35  Inactive,
38  Active
39  };
41  #endregion
42 
50  [Serializable]
51  [DebuggerDisplay("{Name} ({ID}) {Status}")]
52  public sealed class AcPrincipal : IEquatable<AcPrincipal>, IComparable<AcPrincipal>, IComparable
53  {
54  #region Class variables
55  private int _id;
56  private string _name;
57  private PrinStatus _status = PrinStatus.Unknown;
58  private SortedSet<string> _members;
59  #endregion
60 
61  #region Constructors
62  internal AcPrincipal() { }
66  #endregion
67 
68  #region Equality comparison
69 
71  public bool Equals(AcPrincipal other)
78  {
79  if (ReferenceEquals(other, null)) return false;
80  if (ReferenceEquals(this, other)) return true;
81  return ID == other.ID;
82  }
83 
88  public override bool Equals(object other)
89  {
90  if (ReferenceEquals(other, null)) return false;
91  if (ReferenceEquals(this, other)) return true;
92  if (GetType() != other.GetType()) return false;
93  return Equals(other as AcPrincipal);
94  }
95 
100  public override int GetHashCode()
101  {
102  return ID;
103  }
105  #endregion
106 
107  #region Order comparison
108 
110  public int CompareTo(AcPrincipal other)
116  {
117  int result;
118  if (AcPrincipal.ReferenceEquals(this, other))
119  result = 0;
120  else
121  result = String.Compare(Name, other.Name);
122  return result;
123  }
124 
131  int IComparable.CompareTo(object other)
132  {
133  if (!(other is AcPrincipal))
134  throw new ArgumentException("Argument is not an AcPrincipal", "other");
135  AcPrincipal o = (AcPrincipal)other;
136  return this.CompareTo(o);
137  }
139  #endregion
140 
144  public int ID
145  {
146  get { return _id; }
147  internal set { _id = value; }
148  }
149 
153  public string Name
154  {
155  get { return _name ?? String.Empty; }
156  internal set { _name = value; }
157  }
158 
162  public PrinStatus Status
163  {
164  get { return _status; }
165  internal set { _status = value; }
166  }
167 
174 
176  public SortedSet<string> Members
177  {
178  get { return _members; }
179  internal set { _members = value; }
180  }
181 
185  public override string ToString()
186  {
187  return Name;
188  }
189  }
190 }
override bool Equals(object other)
Overridden to determine equality.
Definition: AcPrincipal.cs:88
int ID
AccuRev principal ID number for the user or group.
Definition: AcPrincipal.cs:145
AcPrincipal()
Constructor used during AcUsers and AcGroups list construction. It is called internally and not by us...
Definition: AcPrincipal.cs:65
override int GetHashCode()
Override appropriate for type AcPrincipal.
Definition: AcPrincipal.cs:100
PrinStatus
Whether the principal is active or inactive in AccuRev.
Definition: AcPrincipal.cs:28
Contains the AccuRev principal attributes name, ID and status (active or inactive) for users and grou...
Definition: AcPrincipal.cs:52
int CompareTo(AcPrincipal other)
Generic IComparable implementation (default) for comparing AcPrincipal objects to sort by AccuRev pri...
Definition: AcPrincipal.cs:115
string Name
AccuRev principal name for the user or group.
Definition: AcPrincipal.cs:154
SortedSet< string > Members
The list of groups a user has membership in, or the list of principals (users and groups) in a group...
Definition: AcPrincipal.cs:177
override string ToString()
Returns the AccuRev principal name.
Definition: AcPrincipal.cs:185
bool Equals(AcPrincipal other)
IEquatable implementation to determine the equality of instances of type AcPrincipal. Uses the AccuRev principal ID number to compare instances.
Definition: AcPrincipal.cs:77
PrinStatus Status
Whether the principal is active or inactive in AccuRev.
Definition: AcPrincipal.cs:163