17 using System.Collections.Generic;
45 public sealed
class AcProperty : IFormattable, IEquatable<AcProperty>, IComparable<AcProperty>, IComparable
47 #region class variables
52 private string _propName;
53 private string _propValue;
61 #region Equality comparison
73 if (ReferenceEquals(other, null))
return false;
74 if (ReferenceEquals(
this, other))
return true;
77 return left.Equals(right);
84 public override bool Equals(
object other)
86 if (ReferenceEquals(other, null))
return false;
87 if (ReferenceEquals(
this, other))
return true;
88 if (GetType() != other.GetType())
return false;
100 return hash.GetHashCode();
105 #region Order comparison
125 result = String.Compare(
Name, other.
Name);
139 int IComparable.CompareTo(
object other)
142 throw new ArgumentException(
"Argument is not an AcProperty",
"other");
154 get {
return _kind; }
155 internal set { _kind = value; }
163 get {
return _depot; }
164 internal set { _depot = value; }
173 internal set { _id = value; }
181 get {
return _name ?? String.Empty; }
182 internal set { _name = value; }
190 get {
return _propName ?? String.Empty; }
191 internal set { _propName = value; }
199 get {
return _propValue ?? String.Empty; }
200 internal set { _propValue = value; }
204 public string ToString(
string format, IFormatProvider provider)
221 if (provider != null)
223 ICustomFormatter fmt = provider.GetFormat(this.GetType()) as ICustomFormatter;
225 return fmt.Format(format,
this, provider);
228 if (String.IsNullOrEmpty(format))
231 switch (format.ToUpperInvariant())
237 text = $
"{Name} ({ID}), {PropName}={PropValue}";
239 text = $
"{Depot}, {Name} ({ID}), {PropName}={PropValue}";
243 return Kind.ToString();
247 return ID.ToString();
255 throw new FormatException($
"The {format} format string is not supported.");
260 public string ToString(
string format)
280 #region class variables
281 [NonSerialized]
private readonly
object _locker =
new object();
284 #region object construction:
336 if (
stream != null && includeHidden)
337 cmd = $
@"getproperty -fix -s ""{stream}""";
338 else if (
stream != null && !includeHidden)
339 cmd = $
@"getproperty -fx -s ""{stream}""";
340 else if (includeHidden)
341 cmd = $
@"getproperty -fix -ks -p ""{depot}""";
343 cmd = $
@"getproperty -fx -ks -p ""{depot}""";
346 if (r != null && r.
RetVal == 0)
348 XElement xml = XElement.Parse(r.
CmdResult);
349 foreach (XElement e
in xml.Elements(
"property"))
352 string kind = (string)e.Attribute(
"kind");
354 property.Depot =
depot;
355 property.ID = (int)e.Attribute(
"streamNumber");
356 property.Name = (string)e.Attribute(
"streamName");
357 property.PropName = (string)e.Attribute(
"propertyName");
358 property.PropValue = (string)e;
359 lock (_locker) { Add(property); }
368 AcDebug.
Log($
"AcUtilsException caught and logged in AcProperties.initAsync(AcDepot, AcStream, bool){Environment.NewLine}{ecx.Message}");
371 catch (Exception ecx)
373 AcDebug.
Log($
"Exception caught and logged in AcProperties.initAsync(AcDepot, AcStream, bool){Environment.NewLine}{ecx.Message}");
391 public async Task<bool>
initAsync(
string prncpl = null,
bool includeHidden =
false)
397 if (!String.IsNullOrEmpty(prncpl) && includeHidden)
398 cmd = $
@"getproperty -fix -u ""{prncpl}""";
399 else if (!String.IsNullOrEmpty(prncpl) && !includeHidden)
400 cmd = $
@"getproperty -fx -u ""{prncpl}""";
401 else if (includeHidden)
402 cmd =
"getproperty -fix -ku";
404 cmd =
"getproperty -fx -ku";
407 if (r != null && r.
RetVal == 0)
409 XElement xml = XElement.Parse(r.
CmdResult);
410 foreach (XElement e
in xml.Elements(
"property"))
413 string kind = (string)e.Attribute(
"kind");
415 property.ID = (int)e.Attribute(
"principalNumber");
416 property.Name = (string)e.Attribute(
"principalName");
417 property.PropName = (string)e.Attribute(
"propertyName");
418 property.PropValue = (string)e;
419 lock (_locker) { Add(property); }
428 AcDebug.
Log($
"AcUtilsException caught and logged in AcProperties.initAsync(string, bool){Environment.NewLine}{ecx.Message}");
431 catch (Exception ecx)
433 AcDebug.
Log($
"Exception caught and logged in AcProperties.initAsync(string, bool){Environment.NewLine}{ecx.Message}");
bool Equals(AcProperty other)
IEquatable implementation to determine the equality of instances of type AcProperty. Uses Kind, depot (when Kind is stream, otherwise null), stream or principal ID number, and property name to compare instances.
AccuRev program return value and command result.
A property object that defines the attributes of an AccuRev property assigned to a stream or principa...
override int GetHashCode()
Override appropriate for type AcProperty.
int ID
Stream or principal ID number this property is assigned to.
string Name
Stream or principal name this property is assigned to.
string PropValue
Property value.
int CompareTo(AcProperty other)
Generic IComparable implementation (default) for comparing AcProperty objects. Sorts by [[depot...
A depot object that defines the attributes of an AccuRev depot.
async Task< bool > initAsync(AcDepot depot, AcStream stream=null, bool includeHidden=false)
Populate this container with AcProperty objects for all streams in depot or just stream in depot...
PropKind
Type of the property, either principal or stream.
A stream object that defines the attributes of an AccuRev stream. AcStream objects are instantiated d...
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.
PropKind Kind
Kind of property, either principal or stream.
async Task< bool > initAsync(string prncpl=null, bool includeHidden=false)
Populate this container with AcProperty objects for all principals or a specific principal only...
override bool Equals(object other)
Overridden to determine equality.
Exception thrown when an AccuRev command fails. The AccuRev program return value is zero (0) on succe...
A container of AcProperty objects that define AccuRev properties assigned to a stream or principal by...
AccuRev command processing.
static async Task< AcResult > runAsync(string command, ICmdValidate validator=null)
Run the AccuRev command asynchronously with non-blocking I/O.
int CompareTo(AcDepot other)
Generic IComparable implementation (default) for comparing AcDepot objects to sort by depot name...
Use to log and display error and general purpose text messages, and to save the XML param data sent b...
string ToString(string format, IFormatProvider provider)
The ToString implementation.
string ToString(string format, IFormatProvider provider)
The ToString implementation.
string PropName
Property name.
AcProperty()
Constructor used during AcProperties list construction. It is called internally and not by user code...
AcProperties()
A container of AcProperty objects that define AccuRev properties assigned to a stream or principal by...
AcDepot Depot
Depot when Kind is stream, otherwise null.