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