<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<assert assertuienabled="false"/>
<sources>
<source name="Triggers">
<listeners>
<remove name="Default"/>
<add name="AcLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"/>
</listeners>
</source>
</sources>
</system.diagnostics>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
using System.Collections.Generic;
namespace Triggers
{
class Program
{
static int Main()
{
if (!init()) return 1;
Task<Triggers> t = getTriggersAsync();
Triggers triggers = t.Result;
if (triggers == null) return 1;
Console.WriteLine(triggers);
return 0;
}
private async static Task<Triggers> getTriggersAsync()
{
List<string> depots = await AcQuery.getDepotNameListAsync();
if (depots == null) return null;
Triggers triggers = new Triggers(depots);
return (await triggers.initAsync()) ? triggers : null;
}
private static bool init()
{
if (!AcDebug.initAcLogging())
{
Console.WriteLine("Logging support initialization failed.");
return false;
}
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(AcDebug.unhandledException);
Task<string> prncpl = AcQuery.getPrincipalAsync();
if (String.IsNullOrEmpty(prncpl.Result))
{
AcDebug.Log($"Not logged into AccuRev.{Environment.NewLine}Please login and try again.");
return false;
}
return true;
}
}
public sealed class Triggers : List<XElement>
{
#region class variables
private List<string> _depots;
private readonly object _locker = new object();
#endregion
public Triggers(List<string> depots) { _depots = depots; }
public async Task<bool> initAsync()
{
List<Task<bool>> tasks = new List<Task<bool>>(_depots.Count);
foreach (
string depot in _depots)
tasks.Add(initListAsync(depot));
bool[] arr = await Task.WhenAll(tasks);
return (arr != null && arr.All(n => n == true));
}
private async Task<bool> initListAsync(string depot)
{
bool ret = false;
try
{
AcResult result = await AcCommand.runAsync($@"show -p ""{depot}"" -fx triggers");
if (result != null && result.RetVal == 0)
{
XElement xml = XElement.Parse(result.CmdResult);
xml.AddAnnotation(depot);
lock (_locker) { Add(xml); }
ret = true;
}
}
catch (AcUtilsException exc)
{
AcDebug.Log($"AcUtilsException caught and logged in Program.initListAsync{Environment.NewLine}{exc.Message}");
}
catch (Exception ecx)
{
AcDebug.Log($"Exception caught and logged in Program.initListAsync{Environment.NewLine}{ecx.Message}");
}
return ret;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder($"As of {DateTime.Now.ToString()}{Environment.NewLine}");
foreach (XElement e in this.OrderBy(n => n.Annotation<string>()))
{
string depot = e.Annotation<string>();
sb.AppendLine(depot);
foreach (XElement t in e.Elements("Element").OrderBy(n => (string)n.Attribute("Type")))
sb.AppendLine($"\t{(string)t.Attribute("Type")}: {(string)t.Attribute("Name")}");
}
return sb.ToString();
}
}
}