private SldDMComponentItem GetComponentInfo( SwDMComponent9 currentComponent, int level, int parentId) { if (currentComponent == null || level < 0 || parentId <= 0) { return(null); } string fullPath = currentComponent.PathName;; SldDMComponentItem item = SldDMComponentItem.GenerateTheNext(); item.ParentId = parentId; item.Level = level; try { item.FullPath = fullPath; item.FeatureName = currentComponent.Name2; item.FeatureId = currentComponent.GetID(); item.IsSuppressed = currentComponent.IsSuppressed(); item.FileName2D = EngineeringDrawingFile.Get2DFileNameIfExisting(fullPath); item.Visible = !currentComponent.IsHidden(); SwDmDocumentOpenError openResult; SwDMDocument17 doc = currentComponent.GetDocument2(true, this.GlobalSearchOption, out openResult) as SwDMDocument17; if (doc == null || openResult != SwDmDocumentOpenError.swDmDocumentOpenErrorNone) { Debug.WriteLine(string.Format("GetComponentInfo:couldn't open {0},the return value is:{1}", fullPath, openResult.ToString())); return(null); } SwDMConfiguration14 config = doc.ConfigurationManager.GetConfigurationByName(currentComponent.ConfigurationName) as SwDMConfiguration14; if (File.Exists(fullPath)) { item.AllCustomProperties = GetDocumentPropertiesViaDM.RetrievePropertiesUnderConfig( fullPath, config, GetDocumentPropertiesViaDM.PropertyNamesOftenUsed, true); } item.ConfigurationCount = doc.ConfigurationManager.GetConfigurationCount(); item.ChildrenCount = doc.GetComponentCount(); doc.CloseDoc(); Marshal.ReleaseComObject(doc); this.CallbackGettingExtraInfo?.Invoke(ref item); } catch (Exception ex) { Debug.WriteLine(string.Format("GetComponentInfo:when dealing {0}, exception occurred:{1}", fullPath, ex.Message)); } return(item); }
private int GetCurrentComponentInfo( SwDMComponent9 currentComponent, string fullPath, int level, int parentId) { if (currentComponent == null || string.IsNullOrEmpty(fullPath) || level < 0 || parentId <= 0) { return(-1); } SldDMComponentItem item = SldDMComponentItem.GenerateTheNext(); Task task = Task.Factory.StartNew(() => { item.ParentId = parentId; item.Level = level; item.FullPath = fullPath; item.FeatureName = currentComponent.Name2; item.FeatureId = currentComponent.GetID(); item.IsSuppressed = currentComponent.IsSuppressed(); item.FileName2D = EngineeringDrawingFile.Get2DFileNameIfExisting(fullPath); item.Visible = !currentComponent.IsHidden(); try { SwDmDocumentOpenError openResult; SwDMDocument17 doc = currentComponent.GetDocument2(true, this.GlobalSearchOption, out openResult) as SwDMDocument17; if (doc == null || openResult != SwDmDocumentOpenError.swDmDocumentOpenErrorNone) { Debug.WriteLine(string.Format("GetCurrentComponentInfo:couldn't open {0},the return value is :{1}", fullPath, openResult.ToString())); return; } SwDMConfiguration14 config = doc.ConfigurationManager.GetConfigurationByName(currentComponent.ConfigurationName) as SwDMConfiguration14; if (File.Exists(fullPath)) { item.AllCustomProperties = GetDocumentPropertiesViaDM.RetrievePropertiesUnderConfig( fullPath, config, GetDocumentPropertiesViaDM.PropertyNamesOftenUsed, true); } item.ConfigurationCount = doc.ConfigurationManager.GetConfigurationCount(); item.ChildrenCount = doc.GetComponentCount(); this.ResultsAtPopulating.Enqueue(item); doc.CloseDoc(); Marshal.ReleaseComObject(doc); } catch (Exception ex) { Debug.WriteLine(string.Format("GetCurrentComponentInfo:when dealing {0}, exception occurred:{1}", fullPath, ex.Message)); return; } this.CallbackGettingExtraInfo?.Invoke(ref item); Debug.WriteLine(string.Format("GetCurrentComponentInfo:got [{0}] (ID={1})", fullPath, item.Id)); }); string originalExt; SwDmDocumentType docType = SldFileExtentionChecker.CheckDM(fullPath, out originalExt); if (docType == SwDmDocumentType.swDmDocumentAssembly) { this.AllWalkingTasks.Enqueue(new ComponentAndTask_Assembly() { ParentId = parentId, TheTask = task, FullPath = fullPath, Id = item.Id }); } else { this.AllWalkingTasks.Enqueue(new ComponentAndTask_Part() { ParentId = parentId, TheTask = task, FullPath = fullPath, Id = item.Id }); } return(item.Id); }