17 using System.Collections.Generic;
72 [DebuggerDisplay(
"{Name} ({ID}), {Host}, {Location} ULevel-Target [{UpdateLevel}:{TargetLevel}]")]
73 public sealed
class AcWorkspace : IFormattable, IEquatable<AcWorkspace>, IComparable<AcWorkspace>, IComparable
75 #region class variables
78 private string _location;
79 private string _storage;
83 private int _targetLevel;
84 private int _updateLevel;
85 private DateTime? _fileModTime;
96 #region Equality comparison
107 if (ReferenceEquals(other, null))
return false;
108 if (ReferenceEquals(
this, other))
return true;
109 var left = Tuple.Create(
ID,
Depot);
110 var right = Tuple.Create(other.
ID, other.
Depot);
111 return left.Equals(right);
118 public override bool Equals(
object other)
120 if (ReferenceEquals(other, null))
return false;
121 if (ReferenceEquals(
this, other))
return true;
122 if (GetType() != other.GetType())
return false;
132 var hash = Tuple.Create(
ID,
Depot);
133 return hash.GetHashCode();
138 #region Order comparison
156 result =
Name.CompareTo(other.
Name);
168 int IComparable.CompareTo(
object other)
171 throw new ArgumentException(
"Argument is not an AcWorkspace",
"other");
183 get {
return _name ?? String.Empty; }
184 internal set { _name = value; }
192 get {
return _hidden; }
193 internal set { _hidden = value; }
223 get {
return _location ?? String.Empty; }
224 internal set { _location = value; }
233 get {
return _storage ?? String.Empty; }
234 internal set { _storage = value; }
243 get {
return _host ?? String.Empty; }
244 internal set { _host = value; }
253 internal set { _id = value; }
261 get {
return _depot; }
262 internal set { _depot = value; }
275 get {
return _targetLevel; }
276 internal set { _targetLevel = value; }
291 get {
return _updateLevel; }
292 internal set { _updateLevel = value; }
303 get {
return _fileModTime; }
304 internal set { _fileModTime = value; }
312 get {
return _type; }
313 internal set { _type = value; }
322 internal set { _eol = value; }
330 get {
return _principal; }
331 internal set { _principal = value; }
345 public string ToString(
string format, IFormatProvider provider)
370 if (provider != null)
372 ICustomFormatter fmt = provider.GetFormat(this.GetType()) as ICustomFormatter;
374 return fmt.Format(format,
this, provider);
377 if (String.IsNullOrEmpty(format))
380 switch (format.ToUpperInvariant())
385 return $
"{Name} ({ID}) {{{Type}}}{Environment.NewLine}" +
386 $
@"Location: ""{Location}"", Storage: ""{Storage}""{Environment.NewLine}" +
387 $
"Host: {Host}, ULevel-Target [{UpdateLevel}:{TargetLevel}]{((TargetLevel != UpdateLevel) ? " (incomplete)
" : String.Empty)}{Environment.NewLine}" +
388 $
"Depot: {Depot}, EOL: {EOL}, Hidden: {Hidden}{Environment.NewLine}";
390 return ID.ToString();
408 return Type.ToString();
410 return EOL.ToString();
416 throw new FormatException($
"The {format} format string is not supported.");
421 public string ToString(
string format)
440 #region class variables
442 private bool _allWSpaces;
443 private bool _includeHidden;
444 private bool _includeRefTrees;
445 [NonSerialized]
private readonly
object _locker =
new object();
448 #region object construction:
487 _allWSpaces = allWSpaces;
488 _includeHidden = includeHidden;
489 _includeRefTrees = includeRefTrees;
502 if (_includeRefTrees)
506 AcResult[] arr = await Task.WhenAll(ws, rt).ConfigureAwait(
false);
507 bool ret = (arr != null && arr.All(n => n != null && n.RetVal == 0));
508 if (!ret)
return false;
517 AcResult r = await ws.ConfigureAwait(
false);
518 if (r != null && r.
RetVal == 0)
549 if (_allWSpaces && _includeHidden)
551 cmd =
"show -fvix -a wspaces";
552 else if (_allWSpaces && !_includeHidden)
554 cmd =
"show -fvx -a wspaces";
555 else if (!_allWSpaces && _includeHidden)
557 cmd =
"show -fvix wspaces";
558 else if (!_allWSpaces && !_includeHidden)
560 cmd =
"show -fvx wspaces";
566 AcDebug.
Log($
"AcUtilsException caught and logged in AcWorkspaces.getWorkspacesXMLAsync{Environment.NewLine}{ecx.Message}");
569 catch (Exception ecx)
571 AcDebug.
Log($
"Exception caught and logged in AcWorkspaces.getWorkspacesXMLAsync{Environment.NewLine}{ecx.Message}");
594 result = await
AcCommand.
runAsync($
"show {(_includeHidden ? "-fvix
" : "-fvx
")} refs").ConfigureAwait(
false);
599 AcDebug.
Log($
"AcUtilsException caught and logged in AcWorkspaces.getReferenceTreesXMLAsync{Environment.NewLine}{ecx.Message}");
602 catch (Exception ecx)
604 AcDebug.
Log($
"Exception caught and logged in AcWorkspaces.getReferenceTreesXMLAsync{Environment.NewLine}{ecx.Message}");
625 XElement xml = XElement.Parse(result.
CmdResult);
626 IEnumerable<XElement> filter;
628 filter =
from w in xml.Elements(
"Element")
630 (
string)w.Attribute(
"depot") equals d.
Name
631 where (
string)w.Attribute(
"depot") ==
depot.Name
634 filter =
from w in xml.Elements(
"Element")
636 (
string)w.Attribute(
"depot") equals d.
Name
639 foreach (XElement e
in filter)
642 ws.
Name = (string)e.Attribute(
"Name");
643 ws.
Hidden = (e.Attribute(
"hidden") != null);
644 ws.
Location = (string)e.Attribute(
"Loc");
645 ws.
Storage = (string)e.Attribute(
"Storage");
646 ws.
Host = (string)e.Attribute(
"Host");
647 ws.
ID = (int)e.Attribute(
"Stream");
648 string temp = (string)e.Attribute(
"depot");
649 ws.
Depot = _depots.getDepot(temp);
653 int type = (int)e.Attribute(
"Type");
655 int eol = (int)e.Attribute(
"EOL");
659 lock (_locker) { Add(ws); }
665 catch (Exception ecx)
667 AcDebug.
Log($
"Exception caught and logged in AcWorkspaces.storeWSpaces{Environment.NewLine}{ecx.Message}");
680 AcWorkspace wspace = this.SingleOrDefault(n => n.Name == name);
681 return (wspace != null) ? wspace.
Depot : null;
692 return this.SingleOrDefault(n => n.ID == ID && n.Depot.Equals(depot));
702 return this.SingleOrDefault(n => n.Name == name);
int ID
AccuRev principal ID number for the user or group.
bool Equals(AcWorkspace other)
IEquatable implementation to determine the equality of instances of type AcWorkspace. Uses the workspace ID number and depot to compare instances.
int ID
Workspace ID number. The same number as AcStream.ID when the stream object is a workspace.
AccuRev program return value and command result.
async Task< AcResult > getReferenceTreesXMLAsync()
Get the list of reference trees in XML and optionally include those that are inactive as per AcWorksp...
WsType Type
Type of workspace: standard, exclusive-file locking, anchor-required, or reference tree...
int CompareTo(AcWorkspace other)
Generic IComparable implementation (default) for comparing AcWorkspace objects to sort by depot name ...
int UpdateLevel
Current update level of the workspace. Also known as the workspace transaction level or x-action...
AcPrincipal Principal
AccuRev principal who owns the workspace.
async Task< AcResult > getWorkspacesXMLAsync()
Get the list of workspaces in XML for all or the current user and optionally include inactive workspa...
WsType
Workspace type the user created. These numeric values are passed by AccuRev and converted to our enum...
string Location
Here Loc is the workspace location; the path on the machine where the workspace is located...
async Task< bool > initAsync(AcDepot depot=null)
Populate this container with AcWorkspace objects as per constructor parameters.
Contains the AccuRev principal attributes name, ID and status (active or inactive) for users and grou...
bool Hidden
True if the workspace has been removed (hidden), False if it is active.
AcWorkspace getWorkspace(string name)
Get the AcWorkspace object for workspace name.
string Host
Machine name where the elements physically reside.
A depot object that defines the attributes of an AccuRev depot.
AcDepot Depot
Depot the workspace is located in.
string ToString(string format, IFormatProvider provider)
The ToString implementation.
A container of AcWorkspace objects that define AccuRev workspaces in the repository.
AcDepot getDepot(string name)
Get the AcDepot object that workspace name is located in.
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.
AcWorkspace getWorkspace(AcDepot depot, int ID)
Get the AcWorkspace object in depot with workspace ID number.
override int GetHashCode()
Override appropriate for type AcWorkspace.
int TargetLevel
Current target level of the workspace. Also known as the target transaction level or target x-action...
WsEOL EOL
End-of-line character in use by the workspace: platform-appropriate, Unix/Linux style, or Windows style.
string Name
AccuRev principal name for the user or group.
Exception thrown when an AccuRev command fails. The AccuRev program return value is zero (0) on succe...
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.
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 Name
Name of the workspace, e.g. MARS_DEV3_barnyrd
A container of AcDepot objects that define AccuRev depots in the repository.
AcStream getBasis()
Get the basis (parent) stream for this workspace.
string ToString(string format, IFormatProvider provider)
The ToString implementation.
DateTime FileModTime
This property value is used in AccuRev's update algorithm while processing the update command...
string Storage
Location on the Host where the elements physically reside.
A workspace object that defines the attributes of an AccuRev workspace. AcWorkspace objects are insta...
bool storeWSpaces(AcResult result, AcDepot depot=null)
Convert AcResult.CmdResult XML from result into AcWorkspace objects and add them to our container...
WsEOL
End-of-line character used by the workspace. These numeric values are passed by AccuRev and converted...
override bool Equals(object other)
Overridden to determine equality.
AcWorkspaces(AcDepots depots, bool allWSpaces, bool includeHidden, bool includeRefTrees=false)
A container of AcWorkspace objects that define AccuRev workspaces in the repository.
AcWorkspace()
Constructor used during AcWorkspaces list construction. It is called internally and not by user code...