//! \name Two-part object construction: //@{ /// <summary> /// A container of AcWorkspace objects that define AccuRev workspaces in the repository. /// </summary> /// <param name="depots">AcDepots creation defaults to the list of depots the script user has access rights to view based on their ACL permissions.</param> /// <param name="allWSpaces">\e true to include all workspaces, not just those that belong to the principal.</param> /// <param name="includeHidden">\e true to include deactivated (removed) workspaces/reference trees.</param> /// <param name="includeRefTrees">\e true to include reference trees.</param> /*! \code * public static async Task<bool> showWorkspacesAsync() * { * var progress = new Progress<int>(n => * { * if ((n % 10) == 0) Console.WriteLine("Initializing: " + n); * }); * * // depots list is required for workspace list construction * // defaults to those the script user can view based on ACL permissions * AcDepots depots = new AcDepots(); * if (!(await depots.initAsync(null, progress))) return false; * * // false to include only the script user's workspaces (not all) * // true to include their deactivated (hidden) workspaces * AcWorkspaces wspaces = new AcWorkspaces(depots, allWSpaces: false, includeHidden: true); * if (!(await wspaces.initAsync())) return false; * * foreach (AcWorkspace wspace in wspaces.OrderBy(n => n.Hidden).ThenBy(n => n.Name)) * Console.WriteLine(wspace.ToString("lv") + Environment.NewLine); * * return true; * } * \endcode */ /*! \sa initAsync, [default comparer](@ref AcWorkspace#CompareTo) */ /*! \pre \e depots cannot be initialized in parallel with AcWorkspaces initialization; it must be a fully initialized list. */ public AcWorkspaces(AcDepots depots, bool allWSpaces, bool includeHidden, bool includeRefTrees = false) { _depots = depots; _allWSpaces = allWSpaces; _includeHidden = includeHidden; _includeRefTrees = includeRefTrees; }
/// <summary> /// Populate this container with AcRule objects for all streams in \e streamsCol /// as per [constructor parameter](@ref AcUtils#AcRules#AcRules) \e explicitOnly. /// </summary> /// <param name="streamsCol">The list of streams to query for rules.</param> /// <param name="progress">Optionally report progress back to the caller.</param> /// <returns>\e true if no failure occurred and list was initialized successfully, \e false otherwise.</returns> /// <exception cref="Exception">caught and [logged](@ref AcUtils#AcDebug#initAcLogging) in /// <tt>\%LOCALAPPDATA\%\\AcTools\\Logs\\<prog_name\>-YYYY-MM-DD.log</tt> on failure to handle a range of exceptions.</exception> public async Task <bool> initAsync(StreamsCollection streamsCol, IProgress <int> progress = null) { bool ret = false; // assume failure try { AcDepots depots = new AcDepots(); if (!(await depots.initAsync(null, progress).ConfigureAwait(false))) { return(false); } int num = 0; // get number of streams for tasks list foreach (AcDepot depot in depots) { IEnumerable <AcStream> filter = depot.Streams.Where(s => streamsCol.OfType <StreamElement>().Any(se => s.Name == se.Stream)); num += filter.Count(); } List <Task <bool> > tasks = new List <Task <bool> >(num); Func <Task <bool>, bool> cf = t => { bool res = t.Result; if (res && progress != null) { progress.Report(Interlocked.Increment(ref _counter)); } return(res); }; foreach (AcDepot depot in depots) { IEnumerable <AcStream> filter = depot.Streams.Where(s => streamsCol.OfType <StreamElement>().Any(se => s.Name == se.Stream)); foreach (AcStream stream in filter) { Task <bool> t = initAsync(stream).ContinueWith(cf); tasks.Add(t); } } bool[] arr = await Task.WhenAll(tasks).ConfigureAwait(false); ret = (arr != null && arr.All(n => n == true)); // true if all succeeded } catch (Exception ecx) { AcDebug.Log($"Exception caught and logged in AcRules.initAsync(StreamsCollection){Environment.NewLine}{ecx.Message}"); } return(ret); }
/// <summary> /// Populate this container with AcLock objects on streams in \e depots. /// </summary> /// <param name="depots">Limit the list of locks to those on streams in \e depots only. Depot names in \e depots /// must match their respective AccuRev depot name exactly.</param> /// <returns>\e true if initialization succeeded, \e false otherwise.</returns> /// <exception cref="AcUtilsException">caught and [logged](@ref AcUtils#AcDebug#initAcLogging) /// in <tt>\%LOCALAPPDATA\%\\AcTools\\Logs\\<prog_name\>-YYYY-MM-DD.log</tt> on \c show command failure.</exception> /// <exception cref="Exception">caught and logged in same on failure to handle a range of exceptions.</exception> /*! \sa [AcLocks constructor](@ref AcUtils#AcLocks#AcLocks), initAsync(AcDepot), initAsync(StreamsCollection) */ /*! \show_ <tt>show -fx locks</tt> */ public async Task <bool> initAsync(DepotsCollection depots) { AcDepots dlist = new AcDepots(); if (!(await dlist.initAsync(depots).ConfigureAwait(false))) { return(false); } bool ret = false; // assume failure try { AcResult r = await AcCommand.runAsync("show -fx locks").ConfigureAwait(false); if (r != null && r.RetVal == 0) { bool result = true; XElement xml = XElement.Parse(r.CmdResult); for (int ii = 0; ii < dlist.Count && result; ii++) { AcDepot depot = dlist[ii]; IEnumerable <XElement> query = from e in xml.Elements("Element") join AcStream s in depot.Streams on(string) e.Attribute("Name") equals s.Name select e; result = initList(query); } ret = result; } } catch (AcUtilsException ecx) { AcDebug.Log($"AcUtilsException caught and logged in AcLocks.initAsync(DepotsCollection){Environment.NewLine}{ecx.Message}"); } catch (Exception ecx) { AcDebug.Log($"Exception caught and logged in AcLocks.initAsync(DepotsCollection){Environment.NewLine}{ecx.Message}"); } return(ret); }
/// <summary> /// Populate this container with AcRule objects for all streams in \e depotsCol /// as per [constructor parameter](@ref AcUtils#AcRules#AcRules) \e explicitOnly. /// </summary> /// <param name="depotsCol">The list of depots to query for rules.</param> /// <param name="progress">Optionally report progress back to the caller.</param> /// <returns>\e true if no failure occurred and list was initialized successfully, \e false otherwise.</returns> /// <exception cref="Exception">caught and [logged](@ref AcUtils#AcDebug#initAcLogging) in /// <tt>\%LOCALAPPDATA\%\\AcTools\\Logs\\<prog_name\>-YYYY-MM-DD.log</tt> on failure to handle a range of exceptions.</exception> public async Task <bool> initAsync(DepotsCollection depotsCol, IProgress <int> progress = null) { bool ret = false; // assume failure try { AcDepots depots = new AcDepots(); if (!(await depots.initAsync(depotsCol, progress).ConfigureAwait(false))) { return(false); } int num = 0; // get number of streams for tasks list foreach (AcDepot depot in depots) { num += depot.Streams.Count(); } List <Task <bool> > tasks = new List <Task <bool> >(num); Func <Task <bool>, bool> cf = t => { bool res = t.Result; if (res && progress != null) { progress.Report(Interlocked.Increment(ref _counter)); } return(res); }; foreach (AcStream stream in depots.SelectMany(d => d.Streams)) { Task <bool> t = initAsync(stream).ContinueWith(cf); tasks.Add(t); } bool[] arr = await Task.WhenAll(tasks).ConfigureAwait(false); ret = (arr != null && arr.All(n => n == true)); } catch (Exception ecx) { AcDebug.Log($"Exception caught and logged in AcRules.initAsync(DepotsCollection){Environment.NewLine}{ecx.Message}"); } return(ret); }