private void UserGroupsTraverse(Siemens.Engineering.SW.Blocks.PlcBlockUserGroupComposition ugc) { foreach (var ug in ugc) { if (ug != null) { WriteBlockList(ug.Blocks); UserGroupsTraverse(ug.Groups); } } }
protected override void ProcessRecord() { base.ProcessRecord(); if ( (path == null) || (path.Equals(pathDelimeter[0].ToString())) || (path.Equals(pathDelimeter[1].ToString())) ) { WriteBlockList(program.BlockGroup.Blocks); if (recursive) { UserGroupsTraverse(program.BlockGroup.Groups); } if (includeSystemGroup) { if (recursive) { SysGroupsTraverse(program.BlockGroup.SystemBlockGroups); } else { var bx = program.BlockGroup.SystemBlockGroups.First(); WriteBlockList(bx.Blocks); } } } else { string[] ugnames = path.Split(pathDelimeter, StringSplitOptions.RemoveEmptyEntries); WriteDebug($"path is {path}"); Siemens.Engineering.SW.Blocks.PlcBlockUserGroupComposition ugc = program.BlockGroup.Groups; Siemens.Engineering.SW.Blocks.PlcBlockUserGroup 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) { WriteBlockList(ug.Blocks); if (recursive) { UserGroupsTraverse(ug.Groups); } } else { WriteWarning("The user group is empty or doesn't exist."); } } }