17 using System.Collections.Generic;
58 public sealed
class AcRule : IFormattable, IEquatable<AcRule>, IComparable<AcRule>, IComparable
60 #region class variables
63 private string _location;
64 private string _setInStream;
65 private string _xlinkToStream;
73 #region Equality comparison
85 if (ReferenceEquals(other, null))
return false;
86 if (ReferenceEquals(
this, other))
return true;
89 return left.Equals(right);
96 public override bool Equals(
object other)
98 if (ReferenceEquals(other, null))
return false;
99 if (ReferenceEquals(
this, other))
return true;
100 if (GetType() != other.GetType())
return false;
112 return hash.GetHashCode();
117 #region Order comparison
131 if (
AcRule.ReferenceEquals(
this, other))
149 int IComparable.CompareTo(
object other)
152 throw new ArgumentException(
"Argument is not an AcRule",
"other");
164 get {
return _kind; }
165 internal set { _kind = value; }
173 get {
return _type; }
174 internal set { _type = value; }
182 get {
return _location ?? String.Empty; }
183 internal set { _location = value; }
191 get {
return _setInStream ?? String.Empty; }
192 internal set { _setInStream = value; }
200 get {
return _xlinkToStream ?? String.Empty; }
201 internal set { _xlinkToStream = value; }
205 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())
236 if (!String.IsNullOrEmpty(_xlinkToStream))
237 text = $
"SetInStream: {SetInStream}{Environment.NewLine}" +
238 $
"Cross-link (basis): {XlinkToStream}{Environment.NewLine}" +
239 $
"Location: {Location}{Environment.NewLine}" +
240 $
"Rule kind: {Kind}{Environment.NewLine}" +
241 $
"Element type: {Type}{Environment.NewLine}";
243 text = $
"SetInStream: {SetInStream}{Environment.NewLine}" +
244 $
"Location: {Location}{Environment.NewLine}" +
245 $
"Rule kind: {Kind}{Environment.NewLine}" +
246 $
"Element type: {Type}{Environment.NewLine}";
250 return Kind.ToString();
252 return Type.ToString();
260 throw new FormatException($
"The {format} format string is not supported.");
265 public string ToString(
string format)
286 private bool _explicitOnly;
287 [NonSerialized]
private readonly
object _locker =
new object();
288 [NonSerialized]
private int _counter;
290 #region object construction:
319 _explicitOnly = explicitOnly;
360 .ConfigureAwait(
false);
361 if (r != null && r.
RetVal == 0)
363 XElement xml = XElement.Parse(r.
CmdResult);
364 foreach (XElement e
in xml.Elements(
"element"))
367 string kind = (string)e.Attribute(
"kind");
369 string type = (string)e.Attribute(
"elemType");
371 rule.
Location = (string)e.Attribute(
"location");
372 rule.
SetInStream = (string)e.Attribute(
"setInStream");
373 rule.
XlinkToStream = (string)e.Attribute(
"xlinkToStream") ?? String.Empty;
374 lock (_locker) { Add(rule); }
383 AcDebug.
Log($
"AcUtilsException caught and logged in AcRules.initAsync(AcStream){Environment.NewLine}{ecx.Message}");
386 catch (Exception ecx)
388 AcDebug.
Log($
"Exception caught and logged in AcRules.initAsync(AcStream){Environment.NewLine}{ecx.Message}");
408 int num = depot.
Streams.Count();
409 List<Task<bool>> tasks =
new List<Task<bool>>(num);
410 Func<Task<bool>,
bool> cf = t =>
413 if (res && progress != null) progress.Report(Interlocked.Increment(ref _counter));
419 Task<bool> t =
initAsync(stream).ContinueWith(cf);
423 bool[] arr = await Task.WhenAll(tasks).ConfigureAwait(
false);
424 ret = (arr != null && arr.All(n => n ==
true));
427 catch (Exception ecx)
429 AcDebug.
Log($
"Exception caught and logged in AcRules.initAsync(AcDepot){Environment.NewLine}{ecx.Message}");
450 if (!(await depots.
initAsync(null, progress).ConfigureAwait(
false)))
return false;
454 IEnumerable<AcStream> filter = depot.
Streams.Where(s =>
455 streamsCol.OfType<
StreamElement>().Any(se => s.Name == se.Stream));
456 num += filter.Count();
459 List<Task<bool>> tasks =
new List<Task<bool>>(num);
460 Func<Task<bool>,
bool> cf = t =>
463 if (res && progress != null) progress.Report(Interlocked.Increment(ref _counter));
467 foreach (
AcDepot depot
in depots)
469 IEnumerable<AcStream> filter = depot.
Streams.Where(s =>
470 streamsCol.OfType<
StreamElement>().Any(se => s.Name == se.Stream));
473 Task<bool> t =
initAsync(stream).ContinueWith(cf);
478 bool[] arr = await Task.WhenAll(tasks).ConfigureAwait(
false);
479 ret = (arr != null && arr.All(n => n ==
true));
482 catch (Exception ecx)
484 AcDebug.
Log($
"Exception caught and logged in AcRules.initAsync(StreamsCollection){Environment.NewLine}{ecx.Message}");
505 if (!(await depots.
initAsync(depotsCol, progress).ConfigureAwait(
false)))
return false;
509 List<Task<bool>> tasks =
new List<Task<bool>>(num);
510 Func<Task<bool>,
bool> cf = t =>
513 if (res && progress != null) progress.Report(Interlocked.Increment(ref _counter));
519 Task<bool> t =
initAsync(stream).ContinueWith(cf);
523 bool[] arr = await Task.WhenAll(tasks).ConfigureAwait(
false);
524 ret = (arr != null && arr.All(n => n ==
true));
527 catch (Exception ecx)
529 AcDebug.
Log($
"Exception caught and logged in AcRules.initAsync(DepotsCollection){Environment.NewLine}{ecx.Message}");
string XlinkToStream
In the case of a cross-link this is the basis stream for SetInStream.
bool Equals(AcRule other)
IEquatable implementation to determine the equality of instances of type AcRule. Values used to compa...
AccuRev program return value and command result.
ElementType
Indicates the element's type. By default, AccuRev determines the element type for a newly created ver...
ElementType Type
Type of element the rule was placed on: dir, text, binary, ptext, elink, or slink.
The attributes of a stream or workspace include or exclude rule: RuleKind, ElementType, location affected by the rule, stream or workspace the rule was applied to, and (if applicable) the basis stream for cross-links.
The list of AccuRev depots from
.exe.config.
A container of AcRule objects that define the attributes of stream and workspace include and exclude ...
IEnumerable< AcStream > Streams
The list of streams in this depot.
async Task< bool > initAsync(StreamsCollection streamsCol, IProgress< int > progress=null)
Populate this container with AcRule objects for all streams in streamsCol as per constructor paramete...
async Task< bool > initAsync(AcDepot depot, IProgress< int > progress=null)
Populate this container with AcRule objects for all streams in depot as per constructor parameter exp...
int CompareTo(AcRule other)
Generic IComparable implementation (default) for comparing AcRule objects. Sorts by the stream or wor...
async Task< bool > initAsync(AcStream stream)
Populate this container with AcRule objects for stream as per constructor parameter explicitOnly...
RuleKind Kind
Kind of AccuRev rule in use.
async Task< bool > initAsync(DepotsCollection depotsCol=null, IProgress< int > progress=null)
Populate this container with AcDepot objects as per constructor parameters.
A depot object that defines the attributes of an AccuRev depot.
override int GetHashCode()
Override appropriate for type AcRule.
AcRule()
Constructor used during AcRules list construction. It is called internally and not by user code...
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.
AcRules(bool explicitOnly=false)
A container of AcRule objects that define the attributes of stream and workspace include and exclude ...
RuleKind
The kind of AccuRev rule.
string SetInStream
Name of stream or workspace the rule is applied to.
Exception thrown when an AccuRev command fails. The AccuRev program return value is zero (0) on succe...
AccuRev command processing.
An AccuRev stream from the Streams section in
.exe.config.
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...
override bool Equals(object other)
Overridden to determine equality.
A container of AcDepot objects that define AccuRev depots in the repository.
string ToString(string format, IFormatProvider provider)
The ToString implementation.
The list of AccuRev streams from
.exe.config.
async Task< bool > initAsync(DepotsCollection depotsCol, IProgress< int > progress=null)
Populate this container with AcRule objects for all streams in depotsCol as per constructor parameter...
string Location
Depot-relative path of the element the rule affects.