17 using System.Collections.Generic;
73 [DebuggerDisplay(
"{Name} ({ID}) {Type}, basis: {BasisName} ({BasisID})")]
74 public sealed
class AcStream : IFormattable, IEquatable<AcStream>, IComparable<AcStream>, IComparable
76 #region class variables
79 private string _basisName;
82 private bool _isDynamic;
84 private DateTime? _time;
86 private DateTime _startTime;
88 private bool _hasDefaultGroup;
97 #region Equality comparison
108 if (ReferenceEquals(other, null))
return false;
109 if (ReferenceEquals(
this, other))
return true;
110 var left = Tuple.Create(
ID,
Depot);
111 var right = Tuple.Create(other.
ID, other.
Depot);
112 return left.Equals(right);
119 public override bool Equals(
object other)
121 if (ReferenceEquals(other, null))
return false;
122 if (ReferenceEquals(
this, other))
return true;
123 if (GetType() != other.GetType())
return false;
133 var hash = Tuple.Create(
ID,
Depot);
134 return hash.GetHashCode();
139 #region Order comparison
151 if (
AcStream.ReferenceEquals(
this, other))
154 result = String.Compare(
Name, other.
Name);
165 int IComparable.CompareTo(
object other)
168 throw new ArgumentException(
"Argument is not an AcStream",
"other");
180 get {
return _name ?? String.Empty; }
181 internal set { _name = value; }
190 internal set { _id = value; }
198 get {
return _basisName ?? String.Empty; }
199 internal set { _basisName = value; }
207 get {
return _basisID; }
208 internal set { _basisID = value; }
216 get {
return _depot; }
217 internal set { _depot = value; }
226 get {
return _isDynamic; }
227 internal set { _isDynamic = value; }
236 get {
return _type; }
237 internal set { _type = value; }
247 public DateTime?
Time
249 get {
return _time; }
250 internal set { _time = value; }
258 get {
return _startTime; }
259 internal set { _startTime = value; }
267 get {
return _hidden; }
268 internal set { _hidden = value; }
276 get {
return _hasDefaultGroup; }
277 internal set { _hasDefaultGroup = value; }
291 public string ToString(
string format, IFormatProvider provider)
313 if (provider != null)
315 ICustomFormatter fmt = provider.GetFormat(this.GetType()) as ICustomFormatter;
317 return fmt.Format(format,
this, provider);
320 if (String.IsNullOrEmpty(format))
323 switch (format.ToUpperInvariant())
328 return $
"{Name} ({ID}) {{{Type}}} {Time}{Environment.NewLine}" +
329 $
"Basis: {BasisName} ({BasisID}){Environment.NewLine}" +
330 $
"Depot: {Depot}, Hidden: {Hidden}{(Hidden ? String.Empty : ",
HasDefaultGroup:
" + HasDefaultGroup)}";
332 return ID.ToString();
334 return Type.ToString();
336 return Time.ToString();
352 throw new FormatException($
"The {format} format string is not supported.");
357 public string ToString(
string format)
377 #region class variables
378 private bool _dynamicOnly;
379 private bool _includeHidden;
380 [NonSerialized]
private readonly
object _locker =
new object();
383 #region object construction:
406 internal AcStreams(
bool dynamicOnly,
bool includeHidden)
408 _dynamicOnly = dynamicOnly;
409 _includeHidden = includeHidden;
441 $
@"{((listfile == null) ? String.Empty : "-l
" + "" + listfile + "")} streams")
442 .ConfigureAwait(
false);
443 if (result != null && result.
RetVal == 0)
445 XElement xml = XElement.Parse(result.
CmdResult);
446 IEnumerable<XElement> filter = null;
448 filter =
from s in xml.Elements(
"stream")
449 where (
bool)s.Attribute(
"isDynamic") ==
true select s;
451 filter =
from s in xml.Elements(
"stream") select s;
453 foreach (XElement e
in filter)
456 stream.
Name = (string)e.Attribute(
"name");
457 stream.
ID = (int)e.Attribute(
"streamNumber");
458 stream.
BasisName = (string)e.Attribute(
"basis") ?? String.Empty;
459 stream.
BasisID = (
int?)e.Attribute(
"basisStreamNumber") ?? -1;
461 stream.
IsDynamic = (bool)e.Attribute(
"isDynamic");
462 string type = (string)e.Attribute(
"type");
465 stream.
Time = e.acxTime(
"time");
466 stream.
StartTime = (DateTime)e.acxTime(
"startTime");
468 stream.
Hidden = (e.Attribute(
"hidden") != null);
470 lock (_locker) { Add(stream); }
479 AcDebug.
Log($
"AcUtilsException caught and logged in AcStreams.initAsync{Environment.NewLine}{ecx.Message}");
482 catch (Exception ecx)
484 AcDebug.
Log($
"Exception caught and logged in AcStreams.initAsync{Environment.NewLine}{ecx.Message}");
499 return this.SingleOrDefault(n => n.Name == name);
int CompareTo(AcStream other)
Generic IComparable implementation (default) for comparing AcStream objects to sort by stream name...
AccuRev program return value and command result.
int BasisID
Basis stream ID number.
async Task< bool > initAsync(AcDepot depot, string listfile=null)
Populate this container with AcStream objects as per constructor parameters. AcStream objects are ins...
bool IsDynamic
Whether the stream is a dynamic stream or not. false in the case of a workspace, snapshot or passthro...
AcStream getBasis()
Get this stream's basis (parent) stream.
AcStreams(bool dynamicOnly, bool includeHidden)
A container of AcStream objects that define AccuRev streams. AcStream objects are instantiated during...
A depot object that defines the attributes of an AccuRev depot.
bool HasDefaultGroup
Whether the stream has a default group or not.
override int GetHashCode()
Override appropriate for type AcStream.
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.
AcDepot Depot
Depot the stream is located in.
bool Equals(AcStream other)
IEquatable implementation to determine the equality of instances of type AcStream. Uses the stream ID number and depot to compare instances.
StreamType Type
The kind of stream: unknown, normal, dynamic, regular, workspace, snapshot, passthru, passthrough, gated or staging.
AcStream()
AcStream objects are instantiated during AcDepot and AcDepots construction. This constructor is calle...
string BasisName
Basis stream name.
DateTime Time
Stream's time basis or when the snapshot stream was created, otherwise null.
Exception thrown when an AccuRev command fails. The AccuRev program return value is zero (0) on succe...
StreamType
The type of stream.
AcStream getBasis(string name)
Get the basis (parent) stream for stream name.
AccuRev command processing.
static async Task< AcResult > runAsync(string command, ICmdValidate validator=null)
Run the AccuRev command asynchronously with non-blocking I/O.
string ToString(string format, IFormatProvider provider)
The actual implementation of the ToString method.
Use to log and display error and general purpose text messages, and to save the XML param data sent b...
DateTime StartTime
Stream's creation time or last time its name, time basis or state (remove, reactivate, reparent) changed.
A container of AcStream objects that define AccuRev streams. AcStream objects are instantiated during...
string ToString(string format, IFormatProvider provider)
The ToString implementation.
AcStream getStream(string name)
Get the AcStream object for stream name.
override bool Equals(object other)
Overridden to determine equality.
bool Hidden
Whether the stream is hidden or not.