private void UserGroupsTraverse(Siemens.Engineering.HW.DeviceUserGroupComposition ugc) { foreach (var ug in ugc) { if (ug != null) { WriteDeviceList(ug.Devices); UserGroupsTraverse(ug.Groups); } } }
protected override void ProcessRecord() { base.ProcessRecord(); if (path == null) { WriteDeviceList(project.Devices); WriteDeviceList(project.UngroupedDevicesGroup.Devices); if (recursive) { UserGroupsTraverse(project.DeviceGroups); } } else { string[] ugnames = path.Split(pathDelimeter, StringSplitOptions.RemoveEmptyEntries); WriteDebug($"path is {path}"); Siemens.Engineering.HW.DeviceUserGroupComposition ugc = project.DeviceGroups; Siemens.Engineering.HW.DeviceUserGroup ug = null; if (ugnames.Length > 0) { WriteDebug($"the root group is {ugnames[0]}"); foreach (String gn in ugnames) { if (ugc != null) { WriteDebug($"the group {gn} is finding"); ug = ugc.Find(gn); if (ug != null) { ugc = ug.Groups; WriteDebug($"the group {gn} is found"); } else { ThrowTerminatingError(new ErrorRecord(new ItemNotFoundException(), $"the specified group '{gn}' does not exist", ErrorCategory.InvalidArgument, path)); break; } } else { ThrowTerminatingError(new ErrorRecord(new ItemNotFoundException(), $"the specified group does '{gn}' not exist", ErrorCategory.InvalidArgument, path)); break; } } } else { WriteDebug($"the single group is {path}"); ug = ugc.Find(path); } if (ug != null) { WriteDeviceList(ug.Devices); if (recursive) { UserGroupsTraverse(ug.Groups); } } else { WriteWarning("The user group is empty or doesn't exist."); } } }