/// <summary> /// Populate this container with AcUser objects as per [constructor parameters](@ref AcUtils#AcUsers#AcUsers). /// </summary> /// <param name="progress">Optionally report progress back to the caller.</param> /// <returns>\e true if list 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> /*! \show_ <tt>show \<-fx | -fix\> users</tt> */ public async Task <bool> initAsync(IProgress <int> progress = null) { bool ret = false; // assume failure try { AcResult r = await AcCommand.runAsync($"show {(_includeDeactivated ? "-fix" : "-fx")} users") .ConfigureAwait(false); if (r != null && r.RetVal == 0) // if command succeeded { XElement xml = XElement.Parse(r.CmdResult); IEnumerable <XElement> query = from element in xml.Elements("Element") select element; List <Task <bool> > tasks = new List <Task <bool> >(query.Count()); Func <Task <bool>, bool> cf = t => { bool res = t.Result; if (res && progress != null) { progress.Report(Interlocked.Increment(ref _counter)); } return(res); }; foreach (XElement e in query) { string name = (string)e.Attribute("Name"); int id = (int)e.Attribute("Number"); // XML attribute isActive exists only if the user is inactive, otherwise it isn't there PrinStatus status = (e.Attribute("isActive") == null) ? PrinStatus.Active : PrinStatus.Inactive; AcUser user = new AcUser(id, name, status); lock (_locker) { Add(user); } Task <bool> t = initUserPropsAsync(user).ContinueWith(cf); tasks.Add(t); } bool[] arr = await Task.WhenAll(tasks).ConfigureAwait(false); ret = (arr != null && arr.All(n => n == true)); } } catch (AcUtilsException ecx) { AcDebug.Log($"AcUtilsException caught and logged in AcUsers.initAsync{Environment.NewLine}{ecx.Message}"); } catch (Exception ecx) { AcDebug.Log($"Exception caught and logged in AcUsers.initAsync{Environment.NewLine}{ecx.Message}"); } return(ret); }
/// <summary> /// Initialize user's AccuRev [principal attributes](@ref AcUtils#AcPrincipal) \e name, \e ID, and \e status (active or inactive). /// AcUser objects are instantiated during AcUsers list construction. This constructor is called internally and not by user code. /// </summary> /// <param name="id">User's AccuRev principal ID number.</param> /// <param name="name">User's AccuRev principal name.</param> /// <param name="status">Whether the user is active or inactive in AccuRev.</param> /*! \sa [AcUsers.initAsync](@ref AcUtils#AcUsers#initAsync), [AcUser.initFromADAsync](@ref AcUtils#AcUser#initFromADAsync), * [AcUser.initGroupsListAsync](@ref AcUtils#AcUser#initGroupsListAsync) */ internal AcUser(int id, string name, PrinStatus status) { _principal.ID = id; _principal.Name = name; _principal.Status = status; }