private void CountComponents(ISwDMConfiguration conf, Dictionary <string, int> cachedCount, ref int totalCount) { foreach (ISwDMComponent6 comp in ((ISwDMConfiguration2)conf).GetComponents() as object[] ?? new object[0]) { totalCount++; if (comp.DocumentType == SwDmDocumentType.swDmDocumentAssembly && !comp.IsSuppressed()) { try { var path = m_PathResolver.ResolvePath(Path.GetDirectoryName(m_ParentAssm.Path), comp.PathName); var confName = comp.ConfigurationName; var cacheKey = $"{path}:{confName}"; if (cachedCount.TryGetValue(cacheKey, out int count)) { totalCount += count; } else { if (File.Exists(path)) { int subTotalCount = 0; var subAssm = m_ParentAssm.SwDmApp.SwDocMgr .GetDocument(path, SwDmDocumentType.swDmDocumentAssembly, true, out SwDmDocumentOpenError err); try { if (subAssm != null) { var subConf = subAssm.ConfigurationManager.GetConfigurationByName(confName); if (subConf != null) { CountComponents(subConf, cachedCount, ref subTotalCount); } } totalCount += subTotalCount; cachedCount.Add(cacheKey, subTotalCount); } finally { subAssm?.CloseDoc(); } } } } catch { } } } }
internal SwDmComponent(SwDmAssembly parentAssm, ISwDMComponent comp) : base(comp) { Component = comp; m_ParentAssm = parentAssm; m_FilePathResolver = new SwDmFilePathResolver(); m_PathLazy = new Lazy <string>(() => { var rootDir = System.IO.Path.GetDirectoryName(OwnerAssembly.Path); return(m_FilePathResolver.ResolvePath(rootDir, CachedPath)); }); }