AcUtils
A high performance abstraction layer for AccuRev

Demo that shows the difference in performance between the synchronous and asynchronous creation of two large lists. Results will vary but in this run the asynchronous way reduced execution time by 35%. [100-((11/17)*100)]

C:\Test\Demo\bin\Release>demo
Lists initialized successfully.
00:00:11 to complete asynchronously.
Lists initialized successfully.
00:00:17 to complete synchronously.

static void Main(string[] args)
{
// initialize domains/user properties class variables _dc and _pc for AcUsers
initAppConfigData();
AcStopWatch swAsync = new AcStopWatch(logAsync);
using (new AcStopWatchMarker(swAsync))
{
Task<bool[]> arr = fooAsync();
if (arr != null && arr.Result.All(n => n == true))
Console.WriteLine("Lists initialized successfully.");
else
Console.WriteLine("One or more lists failed to initialize.");
}
AcStopWatch swSync = new AcStopWatch(logSync);
using (new AcStopWatchMarker(swSync))
{
if (fooSync())
Console.WriteLine("Lists initialized successfully.");
else
Console.WriteLine("One or more lists failed to initialize.");
}
}
private static void logSync(string elapsedTime)
{
string msg = String.Format("{0} to complete synchronously.", elapsedTime);
Console.WriteLine(msg);
}
private static void logAsync(string elapsedTime)
{
string msg = String.Format("{0} to complete asynchronously.", elapsedTime);
Console.WriteLine(msg);
}
private static async Task<bool[]> fooAsync()
{
// all active users, no group membership initialization
AcUsers users = new AcUsers(_dc, _pc);
Task<bool> uini = users.initAsync();
// include all streams in the depots
// defaults to only those depots the script user has permission to view
AcDepots depots = new AcDepots();
Task<bool> dini = depots.initAsync();
// asynchronously await multiple asynchronous operations!
return await Task.WhenAll(uini, dini);
}
private static bool fooSync()
{
// all active users, no group membership initialization
AcUsers users = new AcUsers(_dc, _pc);
Task<bool> uini = users.initAsync();
if (!uini.Result) return false;
// include all streams in the depots
// defaults to only those depots the script user has permission to view
AcDepots depots = new AcDepots();
Task<bool> dini = depots.initAsync();
if (!dini.Result) return false;
return true;
}