// Run the hist command for depots listed in LatestOverlaps.exe.config and add the results to // our history list class variable. Returns true if initialization succeeded, false otherwise. // AcUtilsException caught and logged in %LOCALAPPDATA%\AcTools\Logs\LatestOverlaps-YYYY-MM-DD.log // on hist command failure. Exception caught and logged in same for a range of exceptions. private static async Task <bool> initHistAsync(DateTime past) { bool ret = false; // assume failure try { string timeHrsAgo = AcDateTime.DateTime2AcDate(past); // get date in string format suitable for AccuRev CLI List <Task <AcResult> > tasks = new List <Task <AcResult> >(_depots.Count); foreach (AcDepot depot in _depots) { tasks.Add(AcCommand.runAsync($@"hist -k promote -p ""{depot}"" -t now-""{timeHrsAgo}"" -fex")); } _hist = new List <XElement>(_depots.Count); while (tasks.Count > 0) { Task <AcResult> r = await Task.WhenAny(tasks); tasks.Remove(r); if (r == null || r.Result.RetVal != 0) { return(false); } XElement xml = XElement.Parse(r.Result.CmdResult); _hist.Add(xml); } ret = true; // if we're here then all completed successfully } catch (AcUtilsException exc) { AcDebug.Log($"AcUtilsException caught and logged in Program.initHistAsync{Environment.NewLine}{exc.Message}"); } catch (Exception ecx) { AcDebug.Log($"Exception caught and logged in Program.initHistAsync{Environment.NewLine}{ecx.Message}"); } return(ret); }
// Initialize our history and stat lists for each stream listed in the LatestPromotions.exe.config Streams section. // AcUtilsException caught and logged in %LOCALAPPDATA%\AcTools\Logs\LatestPromotions-YYYY-MM-DD.log on hist or stat // command failure. Exception caught and logged in same on failure to handle a range of exceptions. private static async Task <bool> initListsAsync(DateTime past) { bool ret = false; // assume failure try { string timeHrsAgo = AcDateTime.DateTime2AcDate(past); // get date in string format suitable for AccuRev CLI List <Task <AcResult> >[] tasks = new List <Task <AcResult> > [2]; tasks[0] = new List <Task <AcResult> >(); // for hist results tasks[1] = new List <Task <AcResult> >(); // for stat results // Alternatively change Equals() to Contains() and modify LatestPromotions.exe.config stream values // accordingly to filter on stream name subsets, e.g. <add stream="DEV"/> for all streams with DEV in their name. foreach (AcStream stream in _depots.SelectMany(d => d.Streams .Where(s => _selStreams.OfType <StreamElement>().Any(se => s.Name.Equals(se.Stream))))) { Task <AcResult> hr = AcCommand.runAsync($@"hist -k promote -s ""{stream}"" -t now-""{timeHrsAgo}"" -fx"); tasks[0].Add(hr); Task <AcResult> sr = AcCommand.runAsync($@"stat -s ""{stream}"" -d -fx"); // stream's default group tasks[1].Add(sr); } _hist = new List <XElement>(tasks[0].Count); while (tasks[0].Count > 0) // process hist results { Task <AcResult> r = await Task.WhenAny(tasks[0]); tasks[0].Remove(r); if (r == null || r.Result.RetVal != 0) { return(false); } XElement xml = XElement.Parse(r.Result.CmdResult); _hist.Add(xml); } while (tasks[1].Count > 0) // process stat results { Task <AcResult> r = await Task.WhenAny(tasks[1]); tasks[1].Remove(r); if (r == null || r.Result.RetVal != 0) { return(false); } if (!Stat.init(r.Result.CmdResult)) { return(false); } } ret = true; // if we're here then all completed successfully } catch (AcUtilsException exc) { AcDebug.Log($"AcUtilsException caught and logged in Program.initListsAsync{Environment.NewLine}{exc.Message}"); } catch (Exception ecx) { AcDebug.Log($"Exception caught and logged in Program.initListsAsync{Environment.NewLine}{ecx.Message}"); } return(ret); }